From 1f9129a359a838d6d6276ecf0b56c0ef3821b3c4 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Thu, 19 Feb 2026 13:15:17 +1100 Subject: [PATCH] mesa: add force_explicit_uniform_loc_zero workaround MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (cherry picked from commit 87ae5cab948cdf3d9bad9b23c3667a56feab9695) Part-of: --- .pick_status.json | 2 +- src/compiler/glsl/ast_to_hir.cpp | 19 +++++++++++++------ .../auxiliary/pipe-loader/driinfo_gallium.h | 1 + src/gallium/auxiliary/util/u_driconf.c | 1 + src/gallium/frontends/dri/dri_screen.c | 1 + src/gallium/frontends/wgl/stw_device.c | 1 + src/gallium/include/frontend/api.h | 1 + src/mesa/main/consts_exts.h | 1 + src/mesa/state_tracker/st_extensions.c | 1 + src/util/driconf.h | 3 +++ 10 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index ff803335f1b..b082a8ad873 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -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 diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp index 92a8a9b5d98..b5c3027b687 100644 --- a/src/compiler/glsl/ast_to_hir.cpp +++ b/src/compiler/glsl/ast_to_hir.cpp @@ -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; diff --git a/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h b/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h index a812f5bb44f..4886abe9f62 100644 --- a/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h +++ b/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h @@ -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() diff --git a/src/gallium/auxiliary/util/u_driconf.c b/src/gallium/auxiliary/util/u_driconf.c index 298d44a2dbb..e38373fc22c 100644 --- a/src/gallium/auxiliary/util/u_driconf.c +++ b/src/gallium/auxiliary/util/u_driconf.c @@ -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); diff --git a/src/gallium/frontends/dri/dri_screen.c b/src/gallium/frontends/dri/dri_screen.c index d158b0002c8..1bf46cd31e5 100644 --- a/src/gallium/frontends/dri/dri_screen.c +++ b/src/gallium/frontends/dri/dri_screen.c @@ -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); diff --git a/src/gallium/frontends/wgl/stw_device.c b/src/gallium/frontends/wgl/stw_device.c index 9b098e02036..6ef6856360f 100644 --- a/src/gallium/frontends/wgl/stw_device.c +++ b/src/gallium/frontends/wgl/stw_device.c @@ -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); diff --git a/src/gallium/include/frontend/api.h b/src/gallium/include/frontend/api.h index 1bae937b41f..994a7abf181 100644 --- a/src/gallium/include/frontend/api.h +++ b/src/gallium/include/frontend/api.h @@ -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; diff --git a/src/mesa/main/consts_exts.h b/src/mesa/main/consts_exts.h index de58a3100cb..1f0b8a7fe93 100644 --- a/src/mesa/main/consts_exts.h +++ b/src/mesa/main/consts_exts.h @@ -931,6 +931,7 @@ struct gl_constants /** GL_ARB_spirv_extensions */ struct spirv_supported_extensions *SpirVExtensions; + char *ForceExplicitUniformLocZero; char *VendorOverride; char *RendererOverride; diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index 0b5d11e4aeb..a882caa5e54 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -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; diff --git a/src/util/driconf.h b/src/util/driconf.h index 95f1c764906..b1a4c8ace98 100644 --- a/src/util/driconf.h +++ b/src/util/driconf.h @@ -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.")