25
25
#include "nir_builder.h"
27
27
static nir_ssa_def *
28
load_frag_coord(nir_builder *b, const nir_input_attachment_options *options)
28
load_frag_coord(nir_builder *b, nir_deref_instr *deref,
29
const nir_input_attachment_options *options)
30
if (options->use_fragcoord_sysval)
31
return nir_load_frag_coord(b);
34
nir_find_variable_with_location(b->shader, nir_var_shader_in,
37
pos = nir_variable_create(b->shader, nir_var_shader_in,
38
glsl_vec4_type(), NULL);
39
pos->data.location = VARYING_SLOT_POS;
31
if (options->use_fragcoord_sysval) {
32
nir_ssa_def *frag_coord = nir_load_frag_coord(b);
33
if (options->unscaled_input_attachment_ir3) {
34
nir_variable *var = nir_deref_instr_get_variable(deref);
35
unsigned base = var->data.index;
36
nir_ssa_def *unscaled_frag_coord = nir_load_frag_coord_unscaled_ir3(b);
37
if (deref->deref_type == nir_deref_type_array) {
38
nir_ssa_def *unscaled =
39
nir_i2b(b, nir_iand(b, nir_ishr(b,
40
nir_imm_int(b, options->unscaled_input_attachment_ir3 >> base),
41
deref->arr.index.ssa),
43
frag_coord = nir_bcsel(b, unscaled, unscaled_frag_coord, frag_coord);
45
assert(deref->deref_type == nir_deref_type_var);
46
bool unscaled = (options->unscaled_input_attachment_ir3 >> base) & 1;
47
frag_coord = unscaled ? unscaled_frag_coord : frag_coord;
53
nir_variable *pos = nir_get_variable_with_location(b->shader, nir_var_shader_in,
54
VARYING_SLOT_POS, glsl_vec4_type());
42
57
* From Vulkan spec:
43
58
* "The OriginLowerLeft execution mode must not be used; fragment entry
63
78
gl_varying_slot slot = options->use_view_id_for_layer ?
64
79
VARYING_SLOT_VIEW_INDEX : VARYING_SLOT_LAYER;
65
nir_variable *layer_id =
66
nir_find_variable_with_location(b->shader, nir_var_shader_in, slot);
68
if (layer_id == NULL) {
69
layer_id = nir_variable_create(b->shader, nir_var_shader_in,
70
glsl_int_type(), NULL);
71
layer_id->data.location = slot;
72
layer_id->data.interpolation = INTERP_MODE_FLAT;
73
layer_id->data.driver_location = b->shader->num_inputs++;
80
nir_variable *layer_id = nir_get_variable_with_location(b->shader, nir_var_shader_in,
81
slot, glsl_int_type());
82
layer_id->data.interpolation = INTERP_MODE_FLAT;
76
84
return nir_load_var(b, layer_id);
93
101
b->cursor = nir_instr_remove(&load->instr);
95
nir_ssa_def *frag_coord = load_frag_coord(b, options);
103
nir_ssa_def *frag_coord = load_frag_coord(b, deref, options);
96
104
frag_coord = nir_f2i32(b, frag_coord);
97
105
nir_ssa_def *offset = nir_ssa_for_src(b, load->src[1], 2);
98
106
nir_ssa_def *pos = nir_iadd(b, frag_coord, offset);
115
123
tex->texture_index = 0;
116
124
tex->sampler_index = 0;
118
tex->src[0].src_type = nir_tex_src_texture_deref;
119
tex->src[0].src = nir_src_for_ssa(&deref->dest.ssa);
121
tex->src[1].src_type = nir_tex_src_coord;
122
tex->src[1].src = nir_src_for_ssa(coord);
126
tex->src[0] = nir_tex_src_for_ssa(nir_tex_src_texture_deref,
128
tex->src[1] = nir_tex_src_for_ssa(nir_tex_src_coord, coord);
123
129
tex->coord_components = 3;
125
tex->src[2].src_type = nir_tex_src_lod;
126
tex->src[2].src = nir_src_for_ssa(nir_imm_int(b, 0));
131
tex->src[2] = nir_tex_src_for_ssa(nir_tex_src_lod, nir_imm_int(b, 0));
128
133
if (image_dim == GLSL_SAMPLER_DIM_SUBPASS_MS) {
129
134
tex->op = nir_texop_txf_ms;
134
139
tex->texture_non_uniform = nir_intrinsic_access(load) & ACCESS_NON_UNIFORM;
136
nir_ssa_dest_init(&tex->instr, &tex->dest, nir_tex_instr_dest_size(tex), 32, NULL);
141
nir_ssa_dest_init(&tex->instr, &tex->dest, nir_tex_instr_dest_size(tex),
137
143
nir_builder_instr_insert(b, &tex->instr);
139
145
if (tex->is_sparse) {
163
169
b->cursor = nir_before_instr(&tex->instr);
165
nir_ssa_def *frag_coord = load_frag_coord(b, options);
171
nir_ssa_def *frag_coord = load_frag_coord(b, deref, options);
166
172
frag_coord = nir_f2i32(b, frag_coord);
168
174
nir_ssa_def *layer = load_layer_id(b, options);