From 310eabacc0eb4b83fce03d441ee28555bb7529d3 Mon Sep 17 00:00:00 2001 From: Mary Guillemard Date: Wed, 13 Aug 2025 10:54:58 +0000 Subject: [PATCH] panfrost: Move nir_lower_io outside of postprocess Moving it out of there will allow us to shuffle and move API specific parts out of there. Signed-off-by: Mary Guillemard Reviewed-by: Olivia Lee Part-of: --- src/gallium/drivers/panfrost/pan_shader.c | 21 +++++++++++++++++++++ src/panfrost/compiler/bifrost_compile.c | 19 ------------------- src/panfrost/midgard/midgard_compile.c | 9 --------- src/panfrost/vulkan/panvk_vX_shader.c | 21 +++++++++++++++++++++ 4 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_shader.c b/src/gallium/drivers/panfrost/pan_shader.c index ba1abedabfa..6cb8ae62f4b 100644 --- a/src/gallium/drivers/panfrost/pan_shader.c +++ b/src/gallium/drivers/panfrost/pan_shader.c @@ -467,6 +467,12 @@ panfrost_bind_fs_state(struct pipe_context *pctx, void *hwcso) panfrost_update_shader_variant(ctx, MESA_SHADER_VERTEX); } +static int +glsl_type_size(const struct glsl_type *type, bool bindless) +{ + return glsl_count_attribute_slots(type, false); +} + static void * panfrost_create_shader_state(struct pipe_context *pctx, const struct pipe_shader_state *cso) @@ -499,6 +505,21 @@ panfrost_create_shader_state(struct pipe_context *pctx, /* Then run the suite of lowering and optimization, including I/O lowering */ struct panfrost_device *dev = pan_device(pctx->screen); pan_shader_preprocess(nir, panfrost_device_gpu_id(dev)); + + NIR_PASS(_, nir, nir_lower_io, nir_var_shader_in | nir_var_shader_out, + glsl_type_size, nir_lower_io_use_interpolated_input_intrinsics); + + if (dev->arch >= 6 && nir->info.stage == MESA_SHADER_VERTEX) + NIR_PASS(_, nir, pan_nir_lower_noperspective_vs); + if (dev->arch >= 6 && nir->info.stage == MESA_SHADER_FRAGMENT) + NIR_PASS(_, nir, pan_nir_lower_noperspective_fs); + + /* 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 bifrost_nir_lower_store_component below. + */ + NIR_PASS(_, nir, nir_opt_constant_folding); + pan_shader_postprocess(nir, panfrost_device_gpu_id(dev)); if (nir->info.stage == MESA_SHADER_FRAGMENT) diff --git a/src/panfrost/compiler/bifrost_compile.c b/src/panfrost/compiler/bifrost_compile.c index baa380610e6..7d4e6a562ea 100644 --- a/src/panfrost/compiler/bifrost_compile.c +++ b/src/panfrost/compiler/bifrost_compile.c @@ -5137,12 +5137,6 @@ va_gather_stats(bi_context *ctx, unsigned size, struct valhall_stats *out) MAX2(MAX3(out->fma, out->cvt, out->sfu), MAX3(out->v, out->t, out->ls)); } -static int -glsl_type_size(const struct glsl_type *type, bool bindless) -{ - return glsl_count_attribute_slots(type, false); -} - /* Split stores to memory. We don't split stores to vertex outputs, since * nir_lower_io_vars_to_temporaries will ensure there's only a single write. */ @@ -5954,19 +5948,6 @@ void bifrost_postprocess_nir(nir_shader *nir, unsigned gpu_id) { MESA_TRACE_FUNC(); - NIR_PASS(_, nir, nir_lower_io, nir_var_shader_in | nir_var_shader_out, - glsl_type_size, nir_lower_io_use_interpolated_input_intrinsics); - - if (nir->info.stage == MESA_SHADER_VERTEX) - NIR_PASS(_, nir, pan_nir_lower_noperspective_vs); - if (nir->info.stage == MESA_SHADER_FRAGMENT) - NIR_PASS(_, nir, pan_nir_lower_noperspective_fs); - - /* 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 bifrost_nir_lower_store_component below. - */ - NIR_PASS(_, nir, nir_opt_constant_folding); if (nir->info.stage == MESA_SHADER_FRAGMENT) { NIR_PASS(_, nir, nir_lower_mediump_io, diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index ce910210269..de4aac1f3fa 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -210,12 +210,6 @@ attach_constants(compiler_context *ctx, midgard_instruction *ins, memcpy(&ins->constants, constants, 16); } -static int -glsl_type_size(const struct glsl_type *type, bool bindless) -{ - return glsl_count_attribute_slots(type, false); -} - static bool midgard_nir_lower_global_load_instr(nir_builder *b, nir_intrinsic_instr *intr, void *data) @@ -403,9 +397,6 @@ midgard_postprocess_nir(nir_shader *nir, unsigned gpu_id) { unsigned quirks = midgard_get_quirks(gpu_id); - NIR_PASS(_, nir, nir_lower_io, nir_var_shader_in | nir_var_shader_out, - glsl_type_size, nir_lower_io_use_interpolated_input_intrinsics); - if (nir->info.stage == MESA_SHADER_VERTEX) { /* nir_lower[_explicit]_io is lazy and emits mul+add chains even * for offsets it could figure out are constant. Do some diff --git a/src/panfrost/vulkan/panvk_vX_shader.c b/src/panfrost/vulkan/panvk_vX_shader.c index f3b66f2c328..6fdf6def48a 100644 --- a/src/panfrost/vulkan/panvk_vX_shader.c +++ b/src/panfrost/vulkan/panvk_vX_shader.c @@ -762,6 +762,12 @@ lookup_ycbcr_conversion(const void *_state, uint32_t set, &sampler->vk.ycbcr_conversion->state : NULL; } +static int +glsl_type_size(const struct glsl_type *type, bool bindless) +{ + return glsl_count_attribute_slots(type, false); +} + static void panvk_lower_nir(struct panvk_device *dev, nir_shader *nir, uint32_t set_layout_count, @@ -918,6 +924,21 @@ panvk_lower_nir(struct panvk_device *dev, nir_shader *nir, } pan_shader_preprocess(nir, compile_input->gpu_id); + + NIR_PASS(_, nir, nir_lower_io, nir_var_shader_in | nir_var_shader_out, + glsl_type_size, nir_lower_io_use_interpolated_input_intrinsics); + + if (nir->info.stage == MESA_SHADER_VERTEX) + NIR_PASS(_, nir, pan_nir_lower_noperspective_vs); + if (nir->info.stage == MESA_SHADER_FRAGMENT) + NIR_PASS(_, nir, pan_nir_lower_noperspective_fs); + + /* 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 bifrost_nir_lower_store_component below. + */ + NIR_PASS(_, nir, nir_opt_constant_folding); + pan_shader_postprocess(nir, compile_input->gpu_id); if (stage == MESA_SHADER_VERTEX)