From a6fcc2835ead0282c2bb6c29e0eed3711b2ec6d1 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Fri, 13 Feb 2026 10:36:43 +1100 Subject: [PATCH] st/glsl_to_nir: make sure the variant has the correct locations set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For drivers that set allow_st_finalize_nir_twice locations are set when the variable is created. But for variants here we update the locations in case parameter opt pass or something else changed the location. Fixes: 891d46f517ce ("st/glsl_to_nir: dont add duplicate state tokens") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14837 Reviewed-by: Marek Olšák Reviewed-by: Mike Blumenkrantz Part-of: --- src/mesa/state_tracker/st_glsl_to_nir.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index 6f8198bda6e..53f4235678d 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -115,7 +115,7 @@ st_nir_lookup_parameter_index(struct gl_program *prog, nir_variable *var) static void st_nir_assign_uniform_locations(struct st_context *st, struct gl_program *prog, - nir_shader *nir, bool is_before_variants) + nir_shader *nir) { struct gl_context *ctx = st->ctx; int shaderidx = 0; @@ -135,10 +135,20 @@ st_nir_assign_uniform_locations(struct st_context *st, imageidx += type_size(uniform->type); } } else if (uniform->state_slots) { - if (st->allow_st_finalize_nir_twice && !is_before_variants) - continue; - const gl_state_index16 *const stateTokens = uniform->state_slots[0].tokens; + if (st->allow_st_finalize_nir_twice) { + /* Make sure the variant has the correct locations set */ + loc = _mesa_lookup_state_param_idx(prog->Parameters, stateTokens); + if (loc >= 0) { + if (ctx->Const.PackedDriverUniformStorage) { + uniform->data.driver_location = + prog->Parameters->Parameters[loc].ValueOffset; + } else + uniform->data.driver_location = loc; + } + + continue; + } unsigned comps; if (glsl_type_is_struct_or_ifc(type)) { @@ -735,7 +745,7 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog, NIR_PASS(_, nir, nir_lower_tex, &opts); } - st_nir_assign_uniform_locations(st, prog, nir, is_before_variants); + st_nir_assign_uniform_locations(st, prog, nir); /* Set num_uniforms in number of attribute slots (vec4s) */ nir->num_uniforms = DIV_ROUND_UP(prog->Parameters->NumParameterValues, 4);