~mmach/netext73/mesa-ryzen

« back to all changes in this revision

Viewing changes to src/compiler/nir/nir_lower_input_attachments.c

  • Committer: mmach
  • Date: 2023-11-02 21:31:35 UTC
  • Revision ID: netbit73@gmail.com-20231102213135-18d4tzh7tj0uz752
2023-11-02 22:11:57

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "nir_builder.h"
26
26
 
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)
29
30
{
30
 
   if (options->use_fragcoord_sysval)
31
 
      return nir_load_frag_coord(b);
32
 
 
33
 
   nir_variable *pos =
34
 
      nir_find_variable_with_location(b->shader, nir_var_shader_in,
35
 
                                      VARYING_SLOT_POS);
36
 
   if (pos == NULL) {
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),
 
42
                                nir_imm_int(b, 1)));
 
43
            frag_coord = nir_bcsel(b, unscaled, unscaled_frag_coord, frag_coord);
 
44
         } else {
 
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;
 
48
         }
 
49
      }
 
50
      return frag_coord;
40
51
   }
 
52
 
 
53
   nir_variable *pos = nir_get_variable_with_location(b->shader, nir_var_shader_in,
 
54
                                                      VARYING_SLOT_POS, glsl_vec4_type());
 
55
 
41
56
   /**
42
57
    * From Vulkan spec:
43
58
    *   "The OriginLowerLeft execution mode must not be used; fragment entry
62
77
 
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);
67
 
 
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++;
74
 
   }
 
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;
75
83
 
76
84
   return nir_load_var(b, layer_id);
77
85
}
92
100
 
93
101
   b->cursor = nir_instr_remove(&load->instr);
94
102
 
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;
117
125
 
118
 
   tex->src[0].src_type = nir_tex_src_texture_deref;
119
 
   tex->src[0].src = nir_src_for_ssa(&deref->dest.ssa);
120
 
 
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,
 
127
                                     &deref->dest.ssa);
 
128
   tex->src[1] = nir_tex_src_for_ssa(nir_tex_src_coord, coord);
123
129
   tex->coord_components = 3;
124
130
 
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));
127
132
 
128
133
   if (image_dim == GLSL_SAMPLER_DIM_SUBPASS_MS) {
129
134
      tex->op = nir_texop_txf_ms;
133
138
 
134
139
   tex->texture_non_uniform = nir_intrinsic_access(load) & ACCESS_NON_UNIFORM;
135
140
 
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),
 
142
                     32);
137
143
   nir_builder_instr_insert(b, &tex->instr);
138
144
 
139
145
   if (tex->is_sparse) {
162
168
 
163
169
   b->cursor = nir_before_instr(&tex->instr);
164
170
 
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);
167
173
 
168
174
   nir_ssa_def *layer = load_layer_id(b, options);