diff options
author | Icecream95 <[email protected]> | 2020-07-14 22:18:21 +1200 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-07-17 14:50:26 +0000 |
commit | 4e986568b8bda39da6cc843a2f0d16d432e17ce3 (patch) | |
tree | 3073d1f7917b588436c99567613e8522c7d477f8 | |
parent | 314ba5e17450c8c14c2191bcd5675a9eaaac69d8 (diff) |
nir: Fix lower_two_sided_color when the face is an input
Fixes the two-sided-lighting and vertex-program-two-side piglit tests
on Panfrost.
v2: Use an existing variable for gl_FrontFacing if present.
Reviewed-by: Alyssa Rosenzweig <[email protected]>
Reviewed-by: Rob Clark <[email protected]>
Tested-by: Urja Rannikko <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5915>
-rw-r--r-- | src/compiler/nir/nir_lower_two_sided_color.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/compiler/nir/nir_lower_two_sided_color.c b/src/compiler/nir/nir_lower_two_sided_color.c index 1cab733f5d4..80cf27f6ffa 100644 --- a/src/compiler/nir/nir_lower_two_sided_color.c +++ b/src/compiler/nir/nir_lower_two_sided_color.c @@ -32,10 +32,12 @@ typedef struct { nir_builder b; nir_shader *shader; + bool face_sysval; struct { nir_variable *front; /* COLn */ nir_variable *back; /* BFCn */ } colors[MAX_COLORS]; + nir_variable *face; int colors_count; } lower_2side_state; @@ -64,6 +66,29 @@ create_input(nir_shader *shader, gl_varying_slot slot, return var; } +static nir_variable * +create_face_input(nir_shader *shader) +{ + nir_foreach_variable(var, &shader->inputs) { + if (var->data.location == VARYING_SLOT_FACE) + return var; + } + + nir_variable *var = rzalloc(shader, nir_variable); + + var->data.driver_location = shader->num_inputs++; + var->type = glsl_bool_type(); + var->data.mode = nir_var_shader_in; + var->name = "gl_FrontFacing"; + var->data.index = 0; + var->data.location = VARYING_SLOT_FACE; + var->data.interpolation = INTERP_MODE_FLAT; + + exec_list_push_tail(&shader->inputs, &var->node); + + return var; +} + static nir_ssa_def * load_input(nir_builder *b, nir_variable *in) { @@ -112,6 +137,9 @@ setup_inputs(lower_2side_state *state) state->colors[i].front->data.interpolation); } + if (!state->face_sysval) + state->face = create_face_input(state->shader); + return 0; } @@ -160,7 +188,12 @@ nir_lower_two_sided_color_block(nir_block *block, /* gl_FrontFace is a boolean but the intrinsic constructor creates * 32-bit value by default. */ - nir_ssa_def *face = nir_load_front_face(b, 1); + 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); @@ -199,6 +232,7 @@ nir_lower_two_sided_color(nir_shader *shader, bool face_sysval) { lower_2side_state state = { .shader = shader, + .face_sysval = face_sysval, }; if (shader->info.stage != MESA_SHADER_FRAGMENT) |