st/glsl_to_nir: make sure the variant has the correct locations set

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: 891d46f517 ("st/glsl_to_nir: dont add duplicate state tokens")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14837

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
(cherry picked from commit a6fcc2835e)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40092>
This commit is contained in:
Timothy Arceri 2026-02-13 10:36:43 +11:00 committed by Eric Engestrom
parent d7fa6a4deb
commit 6fb7a07c79
2 changed files with 16 additions and 6 deletions

View file

@ -4484,7 +4484,7 @@
"description": "st/glsl_to_nir: make sure the variant has the correct locations set",
"nominated": true,
"nomination_type": 2,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": "891d46f517ce451c7df3f0d46f907b30308721b1",
"notes": null

View file

@ -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);