mesa: add force_explicit_uniform_loc_zero workaround

Allows a uniform name to be passed to force_explicit_uniform_loc_zero
allowing us to set that uniform to an explicit location of zero.

Cc: mesa-stable
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
(cherry picked from commit 87ae5cab94)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40752>
This commit is contained in:
Timothy Arceri 2026-02-19 13:15:17 +11:00 committed by Eric Engestrom
parent 1cfb84c060
commit 1f9129a359
10 changed files with 24 additions and 7 deletions

View file

@ -6294,7 +6294,7 @@
"description": "mesa: add force_explicit_uniform_loc_zero workaround",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -3379,19 +3379,21 @@ static void
apply_explicit_location(const struct ast_type_qualifier *qual,
ir_variable *var,
struct _mesa_glsl_parse_state *state,
YYLTYPE *loc)
YYLTYPE *loc, bool force_explict_uniform_loc_zero)
{
bool fail = false;
unsigned qual_location;
unsigned qual_location = 0;
if (!process_qualifier_constant(state, loc, "location", qual->location,
&qual_location)) {
&qual_location) &&
!force_explict_uniform_loc_zero) {
return;
}
/* Checks for GL_ARB_explicit_uniform_location. */
if (qual->flags.q.uniform) {
if (!state->check_explicit_uniform_location_allowed(loc, var))
if (!force_explict_uniform_loc_zero &&
!state->check_explicit_uniform_location_allowed(loc, var))
return;
const struct gl_constants *consts = state->consts;
@ -3919,8 +3921,13 @@ apply_layout_qualifier_to_variable(const struct ast_type_qualifier *qual,
qual_string);
}
if (qual->flags.q.explicit_location) {
apply_explicit_location(qual, var, state, loc);
bool force_explict_uniform_loc_zero =
state->ctx->Const.ForceExplicitUniformLocZero && qual->flags.q.uniform &&
strcmp(state->ctx->Const.ForceExplicitUniformLocZero, var->name) == 0;
if (qual->flags.q.explicit_location || force_explict_uniform_loc_zero) {
apply_explicit_location(qual, var, state, loc,
force_explict_uniform_loc_zero);
if (qual->flags.q.explicit_component) {
unsigned qual_component;

View file

@ -47,6 +47,7 @@ DRI_CONF_SECTION_DEBUG
DRI_CONF_TRANSCODE_ETC(false)
DRI_CONF_TRANSCODE_ASTC(false)
DRI_CONF_ALLOW_COMPRESSED_FALLBACK(true)
DRI_CONF_FORCE_EXPLICIT_UNIFORM_LOC_ZERO()
DRI_CONF_FORCE_GL_VENDOR()
DRI_CONF_FORCE_GL_RENDERER()
DRI_CONF_OVERRIDE_VRAM_SIZE()

View file

@ -73,6 +73,7 @@ u_driconf_fill_st_options(struct st_config_options *options,
query_bool_option(transcode_etc);
query_bool_option(transcode_astc);
query_bool_option(allow_compressed_fallback);
query_string_option(force_explicit_uniform_loc_zero);
query_string_option(force_gl_vendor);
query_string_option(force_gl_renderer);
query_string_option(mesa_extension_override);

View file

@ -588,6 +588,7 @@ dri_destroy_screen(struct dri_screen *screen)
{
dri_release_screen(screen);
free(screen->options.force_explicit_uniform_loc_zero);
free(screen->options.force_gl_vendor);
free(screen->options.force_gl_renderer);
free(screen->options.mesa_extension_override);

View file

@ -242,6 +242,7 @@ stw_cleanup(void)
return;
}
free(stw_dev->st_options.force_explicit_uniform_loc_zero);
free(stw_dev->st_options.force_gl_vendor);
free(stw_dev->st_options.force_gl_renderer);
free(stw_dev->st_options.mesa_extension_override);

View file

@ -203,6 +203,7 @@ struct st_config_options
bool transcode_etc;
bool transcode_astc;
bool allow_compressed_fallback;
char *force_explicit_uniform_loc_zero;
char *force_gl_vendor;
char *force_gl_renderer;
char *mesa_extension_override;

View file

@ -931,6 +931,7 @@ struct gl_constants
/** GL_ARB_spirv_extensions */
struct spirv_supported_extensions *SpirVExtensions;
char *ForceExplicitUniformLocZero;
char *VendorOverride;
char *RendererOverride;

View file

@ -1341,6 +1341,7 @@ void st_init_extensions(struct pipe_screen *screen,
consts->ForceIntegerTexNearest = options->force_integer_tex_nearest;
consts->ForceExplicitUniformLocZero = options->force_explicit_uniform_loc_zero;
consts->VendorOverride = options->force_gl_vendor;
consts->RendererOverride = options->force_gl_renderer;

View file

@ -259,6 +259,9 @@
DRI_CONF_OPT_B(glthread_nop_check_framebuffer_status, def, \
"glthread always returns GL_FRAMEBUFFER_COMPLETE to prevent synchronization.")
#define DRI_CONF_FORCE_EXPLICIT_UNIFORM_LOC_ZERO() \
DRI_CONF_OPT_S_NODEF(force_explicit_uniform_loc_zero, "Forces an explicit uniform location of zero for the uniform.")
#define DRI_CONF_FORCE_GL_VENDOR() \
DRI_CONF_OPT_S_NODEF(force_gl_vendor, "Override GPU vendor string.")