From 60e5abdbaa6c6da7f2f3888f4308581da36d9b54 Mon Sep 17 00:00:00 2001 From: Mary Guillemard Date: Mon, 6 Oct 2025 09:30:38 +0200 Subject: [PATCH] asahi: Move compiler preprocess out of agx_nir_lower_gs We run agx_preprocess_nir as the last step of each new compute shaders in agx_nir_lower_gs but we could move this out of the pass and makes it the driver responsability to call it. Signed-off-by: Mary Guillemard Part-of: --- src/asahi/compiler/agx_compile.c | 3 +++ src/asahi/lib/agx_nir_lower_gs.c | 3 --- src/asahi/vulkan/hk_shader.c | 4 ++++ src/gallium/drivers/asahi/agx_state.c | 4 ++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index 677f3f12dc3..3e039d2c73f 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -3672,6 +3672,9 @@ agx_nir_lower_fdiv(nir_builder *b, nir_alu_instr *alu, void *_) void agx_preprocess_nir(nir_shader *nir) { + if (!nir) + return; + NIR_PASS(_, nir, nir_lower_vars_to_ssa); /* Lower large arrays to scratch and small arrays to csel */ diff --git a/src/asahi/lib/agx_nir_lower_gs.c b/src/asahi/lib/agx_nir_lower_gs.c index f6aed2c3e71..45928d9d203 100644 --- a/src/asahi/lib/agx_nir_lower_gs.c +++ b/src/asahi/lib/agx_nir_lower_gs.c @@ -459,7 +459,6 @@ create_geometry_count_shader(nir_shader *gs, struct lower_gs_state *state) NIR_PASS(_, shader, nir_shader_intrinsics_pass, lower_id, nir_metadata_control_flow, NULL); - agx_preprocess_nir(shader); return shader; } @@ -833,7 +832,6 @@ create_gs_rast_shader(const nir_shader *gs, const struct lower_gs_state *state) nir_lower_default_point_size(shader); } - agx_preprocess_nir(shader); return shader; } @@ -951,7 +949,6 @@ create_pre_gs(struct agx_xfb_key *key) nir_load_stat_query_address_poly(b, .base = PIPE_STAT_QUERY_C_PRIMITIVES), nir_load_stat_query_address_poly(b, .base = PIPE_STAT_QUERY_C_INVOCATIONS)); - agx_preprocess_nir(b->shader); return b->shader; } diff --git a/src/asahi/vulkan/hk_shader.c b/src/asahi/vulkan/hk_shader.c index fc2bee43563..0cce56c0ec4 100644 --- a/src/asahi/vulkan/hk_shader.c +++ b/src/asahi/vulkan/hk_shader.c @@ -1348,6 +1348,10 @@ hk_compile_shader(struct hk_device *dev, struct vk_shader_compile_info *info, NIR_PASS(_, nir, agx_nir_lower_gs, &count, &rast, &pre_gs, &count_variant->info.gs); + agx_preprocess_nir(count); + agx_preprocess_nir(rast); + agx_preprocess_nir(pre_gs); + struct hk_shader *shader = &obj->variants[HK_GS_VARIANT_RAST]; hk_lower_hw_vs(rast, shader, false); shader->info.gs = count_variant->info.gs; diff --git a/src/gallium/drivers/asahi/agx_state.c b/src/gallium/drivers/asahi/agx_state.c index 6ad71bc1231..91489b117ac 100644 --- a/src/gallium/drivers/asahi/agx_state.c +++ b/src/gallium/drivers/asahi/agx_state.c @@ -1593,6 +1593,10 @@ agx_compile_variant(struct agx_device *dev, struct pipe_context *pctx, } else if (nir->info.stage == MESA_SHADER_GEOMETRY) { NIR_PASS(_, nir, agx_nir_lower_gs, &gs_count, &gs_copy, &pre_gs, &gs_info); + + agx_preprocess_nir(gs_count); + agx_preprocess_nir(gs_copy); + agx_preprocess_nir(pre_gs); } else if (nir->info.stage == MESA_SHADER_FRAGMENT) { struct asahi_fs_shader_key *key = &key_->fs;