From 8f77187e3e27b4bac6172d2b4308737762aa6b48 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Mon, 4 Jul 2022 08:32:37 -0700 Subject: [PATCH] freedreno/ir3: Fix GS clip-plane lowering And also handle tess. In all cases, we want to use the VS lowering pass on the last geometry stage. We don't make a special exception for GS like other drivers, because GS gets lowered into a quasi-VS. Signed-off-by: Rob Clark Part-of: --- src/freedreno/ir3/ir3_nir.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/freedreno/ir3/ir3_nir.c b/src/freedreno/ir3/ir3_nir.c index 009d5a884d1..5670a0a77db 100644 --- a/src/freedreno/ir3/ir3_nir.c +++ b/src/freedreno/ir3/ir3_nir.c @@ -608,6 +608,25 @@ ir3_nir_lower_view_layer_id(nir_shader *nir, bool layer_zero, bool view_zero) return progress; } +static bool +lower_ucp_vs(struct ir3_shader_variant *so) +{ + if (!so->key.ucp_enables) + return false; + + gl_shader_stage last_geom_stage = MESA_SHADER_VERTEX; + + if (so->key.tessellation) { + last_geom_stage = MESA_SHADER_TESS_EVAL; + } else if (so->key.has_gs) { + last_geom_stage = MESA_SHADER_GEOMETRY; + } else { + last_geom_stage = MESA_SHADER_VERTEX; + } + + return so->type == last_geom_stage; +} + void ir3_nir_lower_variant(struct ir3_shader_variant *so, nir_shader *s) { @@ -647,10 +666,11 @@ ir3_nir_lower_variant(struct ir3_shader_variant *so, nir_shader *s) } } - if (s->info.stage == MESA_SHADER_VERTEX) { - if (so->key.ucp_enables) - progress |= - OPT(s, nir_lower_clip_vs, so->key.ucp_enables, false, true, NULL); + /* Note that it is intentional to use the VS lowering pass for GS, since we + * lower GS into something that looks more like a VS in ir3_nir_lower_gs(): + */ + if (lower_ucp_vs(so)) { + progress |= OPT(s, nir_lower_clip_vs, so->key.ucp_enables, false, true, NULL); } else if (s->info.stage == MESA_SHADER_FRAGMENT) { bool layer_zero = so->key.layer_zero && (s->info.inputs_read & VARYING_BIT_LAYER);