From 5231bbe32eb14d3a32720e36462721d47ec2fd8d Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Fri, 5 Sep 2025 10:29:24 +1000 Subject: [PATCH] st/glsl: set driver loc after lowering clipplane We need to store the driver location when we add it to the state param list. Currently this code only works because st_nir_assign_uniform_locations() later adds duplicate params but this will be fixed in a following patch. Unfortunatly we could not simply move nir_lower_clip to the state tracker like we did in the reset of this MR as it is also called directly from some drivers. Also to avoid making nir depend on the gl_parameter defintions we simply loop over the results of the lowering and fix up the locations. Reviewed-by: Mike Blumenkrantz Part-of: --- src/mesa/state_tracker/st_program.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index a56f2506598..8eed848fccf 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -713,7 +713,8 @@ lower_ucp(struct st_context *st, clipplane_state[i][0] = STATE_CLIP_INTERNAL; clipplane_state[i][1] = i; } - _mesa_add_state_reference(params, clipplane_state[i]); + if (!st->allow_st_finalize_nir_twice) + _mesa_add_state_reference(params, clipplane_state[i]); } if (nir->info.stage == MESA_SHADER_VERTEX || @@ -724,6 +725,25 @@ lower_ucp(struct st_context *st, NIR_PASS(_, nir, nir_lower_clip_gs, ucp_enables, can_compact, clipplane_state); } + + if (st->allow_st_finalize_nir_twice) { + nir_foreach_variable_with_modes(uniform, nir, nir_var_uniform | + nir_var_image) { + if (!uniform->state_slots || !st->allow_st_finalize_nir_twice) + continue; + + for (int plane = 0; plane < MAX_CLIP_PLANES; plane++) { + char tmp[100]; + snprintf(tmp, ARRAY_SIZE(tmp), "gl_ClipPlane%dMESA", plane); + if (strcmp(uniform->name, tmp) == 0) { + unsigned loc = + _mesa_add_state_reference(params, clipplane_state[plane]); + uniform->data.driver_location = st->ctx->Const.PackedDriverUniformStorage ? + params->Parameters[loc].ValueOffset : loc; + } + } + } + } } }