mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-05 00:20:11 +01:00
radv/nir_lower_viewport_to_zero: intrinsic pass
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33655>
This commit is contained in:
parent
2504e7951b
commit
c025a211f2
1 changed files with 16 additions and 35 deletions
|
|
@ -10,42 +10,23 @@
|
|||
#include "nir_builder.h"
|
||||
#include "radv_nir.h"
|
||||
|
||||
static bool
|
||||
pass(nir_builder *b, nir_intrinsic_instr *intr, void *_)
|
||||
{
|
||||
if (intr->intrinsic != nir_intrinsic_load_deref)
|
||||
return false;
|
||||
|
||||
nir_variable *var = nir_intrinsic_get_var(intr, 0);
|
||||
if (var->data.mode != nir_var_shader_in || var->data.location != VARYING_SLOT_VIEWPORT)
|
||||
return false;
|
||||
|
||||
b->cursor = nir_before_instr(&intr->instr);
|
||||
nir_def_replace(&intr->def, nir_imm_zero(b, 1, 32));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
radv_nir_lower_viewport_to_zero(nir_shader *nir)
|
||||
{
|
||||
nir_function_impl *impl = nir_shader_get_entrypoint(nir);
|
||||
bool progress = false;
|
||||
|
||||
nir_builder b = nir_builder_create(impl);
|
||||
|
||||
/* There should be only one deref load for VIEWPORT after lower_io_to_temporaries. */
|
||||
nir_foreach_block (block, impl) {
|
||||
nir_foreach_instr (instr, block) {
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
continue;
|
||||
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
if (intr->intrinsic != nir_intrinsic_load_deref)
|
||||
continue;
|
||||
|
||||
nir_variable *var = nir_intrinsic_get_var(intr, 0);
|
||||
if (var->data.mode != nir_var_shader_in || var->data.location != VARYING_SLOT_VIEWPORT)
|
||||
continue;
|
||||
|
||||
b.cursor = nir_before_instr(instr);
|
||||
|
||||
nir_def_rewrite_uses(&intr->def, nir_imm_zero(&b, 1, 32));
|
||||
progress = true;
|
||||
break;
|
||||
}
|
||||
if (progress)
|
||||
break;
|
||||
}
|
||||
|
||||
if (progress)
|
||||
nir_metadata_preserve(impl, nir_metadata_control_flow);
|
||||
else
|
||||
nir_metadata_preserve(impl, nir_metadata_all);
|
||||
|
||||
return progress;
|
||||
return nir_shader_intrinsics_pass(nir, pass, nir_metadata_control_flow, NULL);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue