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 <alyssa.rosenzweig@collabora.com> Reviewed-by: Rob Clark <robdclark@chromium.org> Tested-by: Urja Rannikko <urjaman@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5915>
This commit is contained in:
@@ -32,10 +32,12 @@
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
nir_builder b;
|
nir_builder b;
|
||||||
nir_shader *shader;
|
nir_shader *shader;
|
||||||
|
bool face_sysval;
|
||||||
struct {
|
struct {
|
||||||
nir_variable *front; /* COLn */
|
nir_variable *front; /* COLn */
|
||||||
nir_variable *back; /* BFCn */
|
nir_variable *back; /* BFCn */
|
||||||
} colors[MAX_COLORS];
|
} colors[MAX_COLORS];
|
||||||
|
nir_variable *face;
|
||||||
int colors_count;
|
int colors_count;
|
||||||
} lower_2side_state;
|
} lower_2side_state;
|
||||||
|
|
||||||
@@ -64,6 +66,29 @@ create_input(nir_shader *shader, gl_varying_slot slot,
|
|||||||
return var;
|
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 *
|
static nir_ssa_def *
|
||||||
load_input(nir_builder *b, nir_variable *in)
|
load_input(nir_builder *b, nir_variable *in)
|
||||||
{
|
{
|
||||||
@@ -112,6 +137,9 @@ setup_inputs(lower_2side_state *state)
|
|||||||
state->colors[i].front->data.interpolation);
|
state->colors[i].front->data.interpolation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!state->face_sysval)
|
||||||
|
state->face = create_face_input(state->shader);
|
||||||
|
|
||||||
return 0;
|
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
|
/* gl_FrontFace is a boolean but the intrinsic constructor creates
|
||||||
* 32-bit value by default.
|
* 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;
|
nir_ssa_def *front, *back;
|
||||||
if (intr->intrinsic == nir_intrinsic_load_deref) {
|
if (intr->intrinsic == nir_intrinsic_load_deref) {
|
||||||
front = nir_load_var(b, state->colors[idx].front);
|
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 = {
|
lower_2side_state state = {
|
||||||
.shader = shader,
|
.shader = shader,
|
||||||
|
.face_sysval = face_sysval,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (shader->info.stage != MESA_SHADER_FRAGMENT)
|
if (shader->info.stage != MESA_SHADER_FRAGMENT)
|
||||||
|
Reference in New Issue
Block a user