From 69d7fcd6135a7713c02fffe644c09a6d738e767a Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Wed, 5 Nov 2025 12:07:59 -0500 Subject: [PATCH] pan: Move point size and viewport lowering to postprocess Panvk calls pan_preprocess_nir() from its preprocess hook that it hands off to the Vulkan pipeline code. That hook gets called before we have the opportunity to lower geometry shaders. This means that we get our viewports lowered for the VS and then the geometry shader is trying to work on lowered viewports, which is wrong. Instead, we want to lower later and only apply the viewport transform in the shader that runs as the hardware VS. Reviewed-by: Olivia Lee Part-of: --- src/panfrost/compiler/bifrost_compile.c | 5 ++--- src/panfrost/midgard/midgard_compile.c | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/panfrost/compiler/bifrost_compile.c b/src/panfrost/compiler/bifrost_compile.c index 89e41b1d4a7..34516f5600c 100644 --- a/src/panfrost/compiler/bifrost_compile.c +++ b/src/panfrost/compiler/bifrost_compile.c @@ -5946,9 +5946,6 @@ bifrost_preprocess_nir(nir_shader *nir, unsigned gpu_id) if (pan_arch(gpu_id) <= 7) NIR_PASS(_, nir, pan_nir_lower_vertex_id); - NIR_PASS(_, nir, nir_lower_viewport_transform); - NIR_PASS(_, nir, nir_lower_point_size, 1.0, 0.0); - nir_variable *psiz = nir_find_variable_with_location( nir, nir_var_shader_out, VARYING_SLOT_PSIZ); if (psiz != NULL) @@ -6011,6 +6008,8 @@ bifrost_postprocess_nir(nir_shader *nir, unsigned gpu_id) NIR_PASS(_, nir, bifrost_nir_lower_load_output); } else if (nir->info.stage == MESA_SHADER_VERTEX) { + NIR_PASS(_, nir, nir_lower_viewport_transform); + NIR_PASS(_, nir, nir_lower_point_size, 1.0, 0.0); NIR_PASS(_, nir, pan_nir_lower_noperspective_vs); if (pan_arch(gpu_id) >= 9) { diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index 6e8a332eea6..619d0a99d8e 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -377,11 +377,8 @@ midgard_preprocess_nir(nir_shader *nir, UNUSED unsigned gpu_id) */ NIR_PASS(_, nir, nir_lower_vars_to_ssa); - if (nir->info.stage == MESA_SHADER_VERTEX) { + if (nir->info.stage == MESA_SHADER_VERTEX) NIR_PASS(_, nir, pan_nir_lower_vertex_id); - NIR_PASS(_, nir, nir_lower_viewport_transform); - NIR_PASS(_, nir, nir_lower_point_size, 1.0, 0.0); - } NIR_PASS(_, nir, nir_lower_var_copies); NIR_PASS(_, nir, nir_lower_vars_to_ssa); @@ -398,6 +395,9 @@ midgard_postprocess_nir(nir_shader *nir, UNUSED unsigned gpu_id) midgard_lower_texture_nir(nir, gpu_id); if (nir->info.stage == MESA_SHADER_VERTEX) { + NIR_PASS(_, nir, nir_lower_viewport_transform); + NIR_PASS(_, nir, nir_lower_point_size, 1.0, 0.0); + /* nir_lower[_explicit]_io is lazy and emits mul+add chains even * for offsets it could figure out are constant. Do some * constant folding before pan_nir_lower_store_component below.