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 <aitor@lunarg.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41568>
This commit is contained in:
squidbus 2026-05-13 17:50:20 -07:00 committed by Marge Bot
parent bed2ba22f2
commit 7b938e8fe3

View file

@ -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 = {};