anv,nir: Use sample_pos_or_center in lower_wpos_center

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14198>
This commit is contained in:
Jason Ekstrand 2021-12-02 14:41:41 -06:00 committed by Marge Bot
parent 3c89dbdbfe
commit deec7a590b
3 changed files with 14 additions and 21 deletions

View File

@ -5016,7 +5016,7 @@ typedef struct nir_lower_wpos_ytransform_options {
bool nir_lower_wpos_ytransform(nir_shader *shader,
const nir_lower_wpos_ytransform_options *options);
bool nir_lower_wpos_center(nir_shader *shader, const bool for_sample_shading);
bool nir_lower_wpos_center(nir_shader *shader);
bool nir_lower_pntc_ytransform(nir_shader *shader,
const gl_state_index16 clipplane_state_tokens[][STATE_LENGTH]);

View File

@ -45,8 +45,7 @@
*/
static void
update_fragcoord(nir_builder *b, nir_intrinsic_instr *intr,
const bool for_sample_shading)
update_fragcoord(nir_builder *b, nir_intrinsic_instr *intr)
{
nir_ssa_def *wpos = &intr->dest.ssa;
@ -54,26 +53,21 @@ update_fragcoord(nir_builder *b, nir_intrinsic_instr *intr,
b->cursor = nir_after_instr(&intr->instr);
if (!for_sample_shading) {
wpos = nir_fadd(b, wpos, nir_imm_vec4(b, 0.5f, 0.5f, 0.0f, 0.0f));
} else {
nir_ssa_def *spos = nir_load_sample_pos(b);
nir_ssa_def *spos = nir_load_sample_pos_or_center(b);
wpos = nir_fadd(b, wpos,
nir_vec4(b,
nir_channel(b, spos, 0),
nir_channel(b, spos, 1),
nir_imm_float(b, 0.0f),
nir_imm_float(b, 0.0f)));
}
wpos = nir_fadd(b, wpos,
nir_vec4(b,
nir_channel(b, spos, 0),
nir_channel(b, spos, 1),
nir_imm_float(b, 0.0f),
nir_imm_float(b, 0.0f)));
nir_ssa_def_rewrite_uses_after(&intr->dest.ssa, wpos,
wpos->parent_instr);
}
static bool
lower_wpos_center_block(nir_builder *b, nir_block *block,
const bool for_sample_shading)
lower_wpos_center_block(nir_builder *b, nir_block *block)
{
bool progress = false;
@ -81,7 +75,7 @@ lower_wpos_center_block(nir_builder *b, nir_block *block,
if (instr->type == nir_instr_type_intrinsic) {
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
if (intr->intrinsic == nir_intrinsic_load_frag_coord) {
update_fragcoord(b, intr, for_sample_shading);
update_fragcoord(b, intr);
progress = true;
}
}
@ -91,7 +85,7 @@ lower_wpos_center_block(nir_builder *b, nir_block *block,
}
bool
nir_lower_wpos_center(nir_shader *shader, const bool for_sample_shading)
nir_lower_wpos_center(nir_shader *shader)
{
bool progress = false;
nir_builder b;
@ -103,7 +97,7 @@ nir_lower_wpos_center(nir_shader *shader, const bool for_sample_shading)
nir_builder_init(&b, function->impl);
nir_foreach_block(block, function->impl) {
progress = lower_wpos_center_block(&b, block, for_sample_shading) ||
progress = lower_wpos_center_block(&b, block) ||
progress;
}
nir_metadata_preserve(function->impl, nir_metadata_block_index |

View File

@ -802,8 +802,7 @@ anv_pipeline_lower_nir(struct anv_pipeline *pipeline,
if (nir->info.fs.uses_sample_shading)
anv_pipeline_to_graphics(pipeline)->sample_shading_enable = true;
NIR_PASS_V(nir, nir_lower_wpos_center,
anv_pipeline_to_graphics(pipeline)->sample_shading_enable);
NIR_PASS_V(nir, nir_lower_wpos_center);
NIR_PASS_V(nir, nir_lower_input_attachments,
&(nir_input_attachment_options) {
.use_fragcoord_sysval = true,