nir/lower_input_attachments: Support loading layer id as an input

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5719>
This commit is contained in:
Connor Abbott 2020-07-01 17:16:01 +02:00 committed by Marge Bot
parent e72895767b
commit d243bf1032
5 changed files with 27 additions and 2 deletions

View File

@ -508,6 +508,7 @@ radv_shader_compile_to_nir(struct radv_device *device,
NIR_PASS_V(nir, nir_lower_input_attachments,
&(nir_input_attachment_options) {
.use_fragcoord_sysval = true,
.use_layer_id_sysval = true,
});
NIR_PASS_V(nir, nir_remove_dead_variables,

View File

@ -4460,6 +4460,7 @@ bool nir_lower_idiv(nir_shader *shader, enum nir_lower_idiv_path path);
typedef struct nir_input_attachment_options {
bool use_fragcoord_sysval;
bool use_layer_id_sysval;
} nir_input_attachment_options;
bool nir_lower_input_attachments(nir_shader *shader,

View File

@ -50,6 +50,27 @@ load_frag_coord(const nir_input_attachment_options *options, nir_builder *b)
return nir_load_var(b, pos);
}
static nir_ssa_def *
load_layer_id(const nir_input_attachment_options *options, nir_builder *b)
{
if (options->use_layer_id_sysval)
return nir_load_layer_id(b);
nir_variable *layer_id =
nir_find_variable_with_location(b->shader, nir_var_shader_in,
VARYING_SLOT_LAYER);
if (layer_id == NULL) {
layer_id = nir_variable_create(b->shader, nir_var_shader_in,
glsl_int_type(), NULL);
layer_id->data.location = VARYING_SLOT_LAYER;
layer_id->data.interpolation = INTERP_MODE_FLAT;
layer_id->data.driver_location = b->shader->num_inputs++;
}
return nir_load_var(b, layer_id);
}
static bool
try_lower_input_load(nir_function_impl *impl, nir_intrinsic_instr *load,
const nir_input_attachment_options *options)
@ -73,7 +94,7 @@ try_lower_input_load(nir_function_impl *impl, nir_intrinsic_instr *load,
nir_ssa_def *offset = nir_ssa_for_src(&b, load->src[1], 2);
nir_ssa_def *pos = nir_iadd(&b, frag_coord, offset);
nir_ssa_def *layer = nir_load_layer_id(&b);
nir_ssa_def *layer = load_layer_id(options, &b);
nir_ssa_def *coord =
nir_vec3(&b, nir_channel(&b, pos, 0), nir_channel(&b, pos, 1), layer);
@ -144,7 +165,7 @@ try_lower_input_texop(nir_function_impl *impl, nir_tex_instr *tex,
nir_ssa_def *frag_coord = load_frag_coord(options, &b);
frag_coord = nir_f2i32(&b, frag_coord);
nir_ssa_def *layer = nir_load_layer_id(&b);
nir_ssa_def *layer = load_layer_id(options, &b);
nir_ssa_def *coord = nir_vec3(&b, nir_channel(&b, frag_coord, 0),
nir_channel(&b, frag_coord, 1), layer);

View File

@ -774,6 +774,7 @@ tu_shader_create(struct tu_device *dev,
NIR_PASS_V(nir, nir_lower_input_attachments,
&(nir_input_attachment_options) {
.use_fragcoord_sysval = true,
.use_layer_id_sysval = true,
});
}

View File

@ -747,6 +747,7 @@ anv_pipeline_lower_nir(struct anv_pipeline *pipeline,
NIR_PASS_V(nir, nir_lower_input_attachments,
&(nir_input_attachment_options) {
.use_fragcoord_sysval = true,
.use_layer_id_sysval = true,
});
}