nir: Always use sysvals in lower_input_attachments()
The last holdouts of the var options are gone so we can just emit the system values. This is overall simpler as it confines all the sysval to var logic to nir_lower_sysvals_to_varyings(). Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com> Reviewed-by: Emma Anholt <emma@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38562>
This commit is contained in:
committed by
Marge Bot
parent
5bbbf5cf9b
commit
4711e5954e
@@ -794,8 +794,6 @@ hk_lower_nir(struct hk_device *dev, nir_shader *nir,
|
||||
if (nir->info.stage == MESA_SHADER_FRAGMENT) {
|
||||
NIR_PASS(_, nir, nir_lower_input_attachments,
|
||||
&(nir_input_attachment_options){
|
||||
.use_fragcoord_sysval = true,
|
||||
.use_layer_id_sysval = true,
|
||||
.use_view_id_for_layer = is_multiview,
|
||||
});
|
||||
|
||||
|
||||
@@ -6042,8 +6042,6 @@ bool nir_lower_idiv(nir_shader *shader, const nir_lower_idiv_options *options);
|
||||
|
||||
typedef struct nir_input_attachment_options {
|
||||
bool use_ia_coord_intrin;
|
||||
bool use_fragcoord_sysval;
|
||||
bool use_layer_id_sysval;
|
||||
bool use_view_id_for_layer;
|
||||
bool unscaled_depth_stencil_ir3;
|
||||
uint32_t unscaled_input_attachment_ir3;
|
||||
|
||||
@@ -28,59 +28,34 @@ static nir_def *
|
||||
load_frag_coord(nir_builder *b, nir_deref_instr *deref,
|
||||
const nir_input_attachment_options *options)
|
||||
{
|
||||
if (options->use_fragcoord_sysval) {
|
||||
nir_def *frag_coord = nir_load_frag_coord(b);
|
||||
if (options->unscaled_input_attachment_ir3 ||
|
||||
options->unscaled_depth_stencil_ir3) {
|
||||
nir_variable *var = nir_deref_instr_get_variable(deref);
|
||||
unsigned base = var->data.index;
|
||||
nir_def *unscaled_frag_coord = nir_load_frag_coord_unscaled_ir3(b);
|
||||
if (deref->deref_type == nir_deref_type_array &&
|
||||
options->unscaled_input_attachment_ir3) {
|
||||
nir_def *unscaled =
|
||||
nir_i2b(b, nir_iand(b, nir_ishr(b, nir_imm_int(b, options->unscaled_input_attachment_ir3 >> base), deref->arr.index.ssa),
|
||||
nir_imm_int(b, 1)));
|
||||
frag_coord = nir_bcsel(b, unscaled, unscaled_frag_coord, frag_coord);
|
||||
} else {
|
||||
assert(deref->deref_type == nir_deref_type_var);
|
||||
bool unscaled = base == NIR_VARIABLE_NO_INDEX ? options->unscaled_depth_stencil_ir3 : ((options->unscaled_input_attachment_ir3 >> base) & 1);
|
||||
frag_coord = unscaled ? unscaled_frag_coord : frag_coord;
|
||||
}
|
||||
nir_def *frag_coord = nir_load_frag_coord(b);
|
||||
if (options->unscaled_input_attachment_ir3 ||
|
||||
options->unscaled_depth_stencil_ir3) {
|
||||
nir_variable *var = nir_deref_instr_get_variable(deref);
|
||||
unsigned base = var->data.index;
|
||||
nir_def *unscaled_frag_coord = nir_load_frag_coord_unscaled_ir3(b);
|
||||
if (deref->deref_type == nir_deref_type_array &&
|
||||
options->unscaled_input_attachment_ir3) {
|
||||
nir_def *unscaled =
|
||||
nir_i2b(b, nir_iand(b, nir_ishr(b, nir_imm_int(b, options->unscaled_input_attachment_ir3 >> base), deref->arr.index.ssa),
|
||||
nir_imm_int(b, 1)));
|
||||
frag_coord = nir_bcsel(b, unscaled, unscaled_frag_coord, frag_coord);
|
||||
} else {
|
||||
assert(deref->deref_type == nir_deref_type_var);
|
||||
bool unscaled = base == NIR_VARIABLE_NO_INDEX ? options->unscaled_depth_stencil_ir3 : ((options->unscaled_input_attachment_ir3 >> base) & 1);
|
||||
frag_coord = unscaled ? unscaled_frag_coord : frag_coord;
|
||||
}
|
||||
return frag_coord;
|
||||
}
|
||||
|
||||
nir_variable *pos = nir_get_variable_with_location(b->shader, nir_var_shader_in,
|
||||
VARYING_SLOT_POS, glsl_vec4_type());
|
||||
|
||||
/**
|
||||
* From Vulkan spec:
|
||||
* "The OriginLowerLeft execution mode must not be used; fragment entry
|
||||
* points must declare OriginUpperLeft."
|
||||
*
|
||||
* So at this point origin_upper_left should be true
|
||||
*/
|
||||
assert(b->shader->info.fs.origin_upper_left == true);
|
||||
|
||||
return nir_load_var(b, pos);
|
||||
return frag_coord;
|
||||
}
|
||||
|
||||
static nir_def *
|
||||
load_layer_id(nir_builder *b, const nir_input_attachment_options *options)
|
||||
{
|
||||
if (options->use_layer_id_sysval) {
|
||||
if (options->use_view_id_for_layer)
|
||||
return nir_load_view_index(b);
|
||||
else
|
||||
return nir_load_layer_id(b);
|
||||
}
|
||||
|
||||
gl_varying_slot slot = options->use_view_id_for_layer ? VARYING_SLOT_VIEW_INDEX : VARYING_SLOT_LAYER;
|
||||
nir_variable *layer_id = nir_get_variable_with_location(b->shader, nir_var_shader_in,
|
||||
slot, glsl_int_type());
|
||||
layer_id->data.interpolation = INTERP_MODE_FLAT;
|
||||
|
||||
return nir_load_var(b, layer_id);
|
||||
if (options->use_view_id_for_layer)
|
||||
return nir_load_view_index(b);
|
||||
else
|
||||
return nir_load_layer_id(b);
|
||||
}
|
||||
|
||||
static nir_def *
|
||||
|
||||
@@ -2781,8 +2781,6 @@ tu_shader_create(struct tu_device *dev,
|
||||
|
||||
if (nir->info.stage == MESA_SHADER_FRAGMENT) {
|
||||
const nir_input_attachment_options att_options = {
|
||||
.use_fragcoord_sysval = true,
|
||||
.use_layer_id_sysval = true,
|
||||
/* When using multiview rendering, we must use
|
||||
* gl_ViewIndex as the layer id to pass to the texture
|
||||
* sampling function. gl_Layer doesn't work when
|
||||
|
||||
@@ -408,10 +408,7 @@ iris_ensure_indirect_generation_shader(struct iris_batch *batch)
|
||||
NIR_PASS(_, nir, nir_propagate_invariant, false);
|
||||
|
||||
NIR_PASS(_, nir, nir_lower_input_attachments,
|
||||
&(nir_input_attachment_options) {
|
||||
.use_fragcoord_sysval = true,
|
||||
.use_layer_id_sysval = true,
|
||||
});
|
||||
&(nir_input_attachment_options) { });
|
||||
|
||||
/* Reset sizes before gathering information */
|
||||
nir->global_mem_size = 0;
|
||||
|
||||
@@ -104,10 +104,7 @@ compile_shader(struct anv_device *device,
|
||||
|
||||
if (stage == MESA_SHADER_FRAGMENT) {
|
||||
NIR_PASS(_, nir, nir_lower_input_attachments,
|
||||
&(nir_input_attachment_options) {
|
||||
.use_fragcoord_sysval = true,
|
||||
.use_layer_id_sysval = true,
|
||||
});
|
||||
&(nir_input_attachment_options) { });
|
||||
} else {
|
||||
nir_lower_compute_system_values_options options = {
|
||||
.has_base_workgroup_id = true,
|
||||
|
||||
@@ -1300,10 +1300,7 @@ anv_shader_lower_nir(struct anv_device *device,
|
||||
if (nir->info.stage == MESA_SHADER_FRAGMENT) {
|
||||
NIR_PASS(_, nir, nir_lower_wpos_center);
|
||||
NIR_PASS(_, nir, nir_lower_input_attachments,
|
||||
&(nir_input_attachment_options) {
|
||||
.use_fragcoord_sysval = true,
|
||||
.use_layer_id_sysval = true,
|
||||
});
|
||||
&(nir_input_attachment_options) { });
|
||||
}
|
||||
|
||||
if (nir->info.stage == MESA_SHADER_COMPUTE &&
|
||||
|
||||
@@ -477,10 +477,7 @@ anv_pipeline_lower_nir(struct anv_pipeline *pipeline,
|
||||
if (nir->info.stage == MESA_SHADER_FRAGMENT) {
|
||||
NIR_PASS(_, nir, nir_lower_wpos_center);
|
||||
NIR_PASS(_, nir, nir_lower_input_attachments,
|
||||
&(nir_input_attachment_options) {
|
||||
.use_fragcoord_sysval = true,
|
||||
.use_layer_id_sysval = true,
|
||||
});
|
||||
&(nir_input_attachment_options) { });
|
||||
}
|
||||
|
||||
NIR_PASS(_, nir, anv_nir_lower_ycbcr_textures, layout);
|
||||
|
||||
@@ -1910,10 +1910,7 @@ msl_preprocess_nir(struct nir_shader *nir)
|
||||
NIR_PASS(_, nir, nir_lower_system_values);
|
||||
|
||||
if (nir->info.stage == MESA_SHADER_FRAGMENT) {
|
||||
nir_input_attachment_options input_attachment_options = {
|
||||
.use_fragcoord_sysval = true,
|
||||
.use_layer_id_sysval = true,
|
||||
};
|
||||
nir_input_attachment_options input_attachment_options = { };
|
||||
NIR_PASS(_, nir, nir_lower_input_attachments, &input_attachment_options);
|
||||
/* KK_WORKAROUND_4 */
|
||||
NIR_PASS(_, nir, nir_lower_is_helper_invocation);
|
||||
|
||||
@@ -967,8 +967,6 @@ dxil_spirv_nir_passes(nir_shader *nir,
|
||||
if (nir->info.stage == MESA_SHADER_FRAGMENT) {
|
||||
NIR_PASS(_, nir, nir_lower_input_attachments,
|
||||
&(nir_input_attachment_options){
|
||||
.use_fragcoord_sysval = true,
|
||||
.use_layer_id_sysval = true,
|
||||
.use_view_id_for_layer = !conf->lower_view_index,
|
||||
});
|
||||
|
||||
|
||||
@@ -1094,10 +1094,7 @@ lower_input_attachment_loads(nir_shader *nir,
|
||||
&ia_load_ctx);
|
||||
|
||||
/* Lower the remaining input attachment loads. */
|
||||
struct nir_input_attachment_options lower_input_attach_opts = {
|
||||
.use_fragcoord_sysval = true,
|
||||
.use_layer_id_sysval = true,
|
||||
};
|
||||
struct nir_input_attachment_options lower_input_attach_opts = { };
|
||||
NIR_PASS(progress, nir, nir_lower_input_attachments,
|
||||
&lower_input_attach_opts);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user