From 7b938e8fe300771816b7feeb30642dcc43ffd089 Mon Sep 17 00:00:00 2001 From: squidbus <1249084-squidbus@users.noreply.gitlab.freedesktop.org> Date: Wed, 13 May 2026 17:50:20 -0700 Subject: [PATCH] kk: Fix compute system value and algebric lowering in pre-compiles Changes are the result of two issues: - In library form, workgroup size is not lowered. Only once the pre-compiles are distinct variants with entry-points can we lower uses of the workgroup size input. - Some unimplemented instructions like `ufind_msb` would make their way through to the final shader, if they are generated by other algebraic optimizations. `nir_opt_algebraic` needs to be run in a loop to ensure they are eliminated. Reviewed-by: Aitor Camacho Part-of: --- src/kosmickrisp/clc/kk_clc.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/kosmickrisp/clc/kk_clc.c b/src/kosmickrisp/clc/kk_clc.c index f17403f718e..c18059c1645 100644 --- a/src/kosmickrisp/clc/kk_clc.c +++ b/src/kosmickrisp/clc/kk_clc.c @@ -277,6 +277,11 @@ main(int argc, char **argv) NIR_PASS(_, s, nir_lower_vars_to_explicit_types, nir_var_mem_shared, glsl_get_cl_type_size_align); + /* Workgroup size cannot be lowered when the shader is in library form, + * so we need to lower compute system values again now that it is a + * variant with a distinct entry-point. */ + NIR_PASS(_, s, nir_lower_compute_system_values, NULL); + NIR_PASS(_, s, nir_lower_explicit_io, nir_var_mem_shared, nir_address_format_62bit_generic); @@ -296,8 +301,14 @@ main(int argc, char **argv) NIR_PASS(_, s, nir_convert_from_ssa, true, true); NIR_PASS(_, s, nir_trivialize_registers); - /* nir_lower_explicit_io will create unpack_64 we need to lower */ - NIR_PASS(_, s, nir_opt_algebraic); + /* nir_lower_explicit_io will create unpack_64 we need to lower. + * Perform in a loop to make sure any optimizations that result in + * instructions we don't implement are fully lowered */ + bool progress = false; + do { + progress = false; + NIR_PASS(progress, s, nir_opt_algebraic); + } while (progress); nir_shader_gather_info(s, nir_shader_get_entrypoint(s)); struct nir_to_msl_options options = {};