st/glsl_to_nir: make sure the variant has the correct locations set
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

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>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39867>
This commit is contained in:
Timothy Arceri 2026-02-13 10:36:43 +11:00 committed by Marge Bot
parent c3aae0714c
commit a6fcc2835e

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