mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 13:58:04 +02:00
nir/nir_lower_two_sided_color: Use the nir_shader_instructions_pass() helper
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> Reviewed-by: Emma Anholt <emma@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11683>
This commit is contained in:
parent
7e5dde11ef
commit
0ddf98e85d
2 changed files with 61 additions and 81 deletions
|
|
@ -5502,7 +5502,7 @@ void nir_lower_point_size_mov(nir_shader *shader,
|
|||
|
||||
bool nir_lower_frexp(nir_shader *nir);
|
||||
|
||||
void nir_lower_two_sided_color(nir_shader *shader, bool face_sysval);
|
||||
bool nir_lower_two_sided_color(nir_shader *shader, bool face_sysval);
|
||||
|
||||
bool nir_lower_clamp_color_outputs(nir_shader *shader);
|
||||
|
||||
|
|
|
|||
|
|
@ -130,90 +130,70 @@ setup_inputs(lower_2side_state *state)
|
|||
}
|
||||
|
||||
static bool
|
||||
nir_lower_two_sided_color_block(nir_block *block,
|
||||
lower_2side_state *state)
|
||||
nir_lower_two_sided_color_instr(nir_builder *b, nir_instr *instr, void *data)
|
||||
{
|
||||
nir_builder *b = &state->b;
|
||||
lower_2side_state *state = data;
|
||||
|
||||
nir_foreach_instr_safe(instr, block) {
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
continue;
|
||||
if (instr->type != nir_instr_type_intrinsic)
|
||||
return false;
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
|
||||
nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
|
||||
|
||||
int idx;
|
||||
if (intr->intrinsic == nir_intrinsic_load_input) {
|
||||
for (idx = 0; idx < state->colors_count; idx++) {
|
||||
unsigned drvloc =
|
||||
state->colors[idx].front->data.driver_location;
|
||||
if (nir_intrinsic_base(intr) == drvloc) {
|
||||
assert(nir_src_is_const(intr->src[0]));
|
||||
break;
|
||||
}
|
||||
int idx;
|
||||
if (intr->intrinsic == nir_intrinsic_load_input) {
|
||||
for (idx = 0; idx < state->colors_count; idx++) {
|
||||
unsigned drvloc =
|
||||
state->colors[idx].front->data.driver_location;
|
||||
if (nir_intrinsic_base(intr) == drvloc) {
|
||||
assert(nir_src_is_const(intr->src[0]));
|
||||
break;
|
||||
}
|
||||
} else if (intr->intrinsic == nir_intrinsic_load_deref) {
|
||||
nir_variable *var = nir_intrinsic_get_var(intr, 0);
|
||||
if (var->data.mode != nir_var_shader_in)
|
||||
continue;
|
||||
|
||||
for (idx = 0; idx < state->colors_count; idx++) {
|
||||
unsigned loc = state->colors[idx].front->data.location;
|
||||
if (var->data.location == loc)
|
||||
break;
|
||||
}
|
||||
} else
|
||||
continue;
|
||||
|
||||
if (idx == state->colors_count)
|
||||
continue;
|
||||
|
||||
/* replace load_input(COLn) with
|
||||
* bcsel(load_system_value(FACE), load_input(COLn), load_input(BFCn))
|
||||
*/
|
||||
b->cursor = nir_before_instr(&intr->instr);
|
||||
/* gl_FrontFace is a boolean but the intrinsic constructor creates
|
||||
* 32-bit value by default.
|
||||
*/
|
||||
nir_ssa_def *face;
|
||||
if (state->face_sysval)
|
||||
face = nir_load_front_face(b, 1);
|
||||
else
|
||||
face = nir_load_var(b, state->face);
|
||||
|
||||
nir_ssa_def *front, *back;
|
||||
if (intr->intrinsic == nir_intrinsic_load_deref) {
|
||||
front = nir_load_var(b, state->colors[idx].front);
|
||||
back = nir_load_var(b, state->colors[idx].back);
|
||||
} else {
|
||||
front = load_input(b, state->colors[idx].front);
|
||||
back = load_input(b, state->colors[idx].back);
|
||||
}
|
||||
nir_ssa_def *color = nir_bcsel(b, face, front, back);
|
||||
} else if (intr->intrinsic == nir_intrinsic_load_deref) {
|
||||
nir_variable *var = nir_intrinsic_get_var(intr, 0);
|
||||
if (var->data.mode != nir_var_shader_in)
|
||||
return false;
|
||||
|
||||
assert(intr->dest.is_ssa);
|
||||
nir_ssa_def_rewrite_uses(&intr->dest.ssa, color);
|
||||
for (idx = 0; idx < state->colors_count; idx++) {
|
||||
unsigned loc = state->colors[idx].front->data.location;
|
||||
if (var->data.location == loc)
|
||||
break;
|
||||
}
|
||||
} else
|
||||
return false;
|
||||
|
||||
if (idx == state->colors_count)
|
||||
return false;
|
||||
|
||||
/* replace load_input(COLn) with
|
||||
* bcsel(load_system_value(FACE), load_input(COLn), load_input(BFCn))
|
||||
*/
|
||||
b->cursor = nir_before_instr(&intr->instr);
|
||||
/* gl_FrontFace is a boolean but the intrinsic constructor creates
|
||||
* 32-bit value by default.
|
||||
*/
|
||||
nir_ssa_def *face;
|
||||
if (state->face_sysval)
|
||||
face = nir_load_front_face(b, 1);
|
||||
else
|
||||
face = nir_load_var(b, state->face);
|
||||
|
||||
nir_ssa_def *front, *back;
|
||||
if (intr->intrinsic == nir_intrinsic_load_deref) {
|
||||
front = nir_load_var(b, state->colors[idx].front);
|
||||
back = nir_load_var(b, state->colors[idx].back);
|
||||
} else {
|
||||
front = load_input(b, state->colors[idx].front);
|
||||
back = load_input(b, state->colors[idx].back);
|
||||
}
|
||||
nir_ssa_def *color = nir_bcsel(b, face, front, back);
|
||||
|
||||
assert(intr->dest.is_ssa);
|
||||
nir_ssa_def_rewrite_uses(&intr->dest.ssa, color);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
nir_lower_two_sided_color_impl(nir_function_impl *impl,
|
||||
lower_2side_state *state)
|
||||
{
|
||||
nir_builder *b = &state->b;
|
||||
|
||||
nir_builder_init(b, impl);
|
||||
|
||||
nir_foreach_block(block, impl) {
|
||||
nir_lower_two_sided_color_block(block, state);
|
||||
}
|
||||
|
||||
nir_metadata_preserve(impl, nir_metadata_block_index |
|
||||
nir_metadata_dominance);
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
nir_lower_two_sided_color(nir_shader *shader, bool face_sysval)
|
||||
{
|
||||
lower_2side_state state = {
|
||||
|
|
@ -222,14 +202,14 @@ nir_lower_two_sided_color(nir_shader *shader, bool face_sysval)
|
|||
};
|
||||
|
||||
if (shader->info.stage != MESA_SHADER_FRAGMENT)
|
||||
return;
|
||||
return false;
|
||||
|
||||
if (setup_inputs(&state) != 0)
|
||||
return;
|
||||
|
||||
nir_foreach_function(function, shader) {
|
||||
if (function->impl)
|
||||
nir_lower_two_sided_color_impl(function->impl, &state);
|
||||
}
|
||||
return false;
|
||||
|
||||
return nir_shader_instructions_pass(shader,
|
||||
nir_lower_two_sided_color_instr,
|
||||
nir_metadata_block_index |
|
||||
nir_metadata_dominance,
|
||||
&state);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue