From e0a111540f0f54c7ff0f0d0b046f184f033008f7 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Wed, 30 Apr 2025 14:51:44 +1000 Subject: [PATCH] util/driconf: add force_gl_depth_component_type_int workaround MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allow us to force mesa to use GL_UNSIGNED_INT rather than GL_UNSIGNED_SHORT for when chosing the texture format for GL_DEPTH_COMPONENT. The increased depth precision allows us to match the Nvidia/AMD closed drivers default behaviour. Here we also enable the workaround for the remastered tombraider games. Cc: mesa-stable Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/13032 Reviewed-by: Marek Olšák Part-of: --- src/gallium/auxiliary/pipe-loader/driinfo_gallium.h | 1 + src/gallium/auxiliary/util/u_driconf.c | 1 + src/gallium/include/frontend/api.h | 1 + src/mesa/main/consts_exts.h | 3 +++ src/mesa/state_tracker/st_extensions.c | 2 ++ src/mesa/state_tracker/st_format.c | 5 +++++ src/util/00-mesa-defaults.conf | 4 ++++ src/util/driconf.h | 3 +++ 8 files changed, 20 insertions(+) diff --git a/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h b/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h index 1175995e6c1..23b565bc989 100644 --- a/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h +++ b/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h @@ -43,6 +43,7 @@ DRI_CONF_SECTION_DEBUG DRI_CONF_FORCE_COMPAT_SHADERS(false) DRI_CONF_FORCE_GL_NAMES_REUSE() DRI_CONF_FORCE_GL_MAP_BUFFER_SYNCHRONIZED(false) + DRI_CONF_FORCE_GL_DEPTH_COMPONENT_TYPE_INT(false) DRI_CONF_TRANSCODE_ETC(false) DRI_CONF_TRANSCODE_ASTC(false) DRI_CONF_ALLOW_COMPRESSED_FALLBACK(true) diff --git a/src/gallium/auxiliary/util/u_driconf.c b/src/gallium/auxiliary/util/u_driconf.c index ef6ae1c2ed8..085b196b52d 100644 --- a/src/gallium/auxiliary/util/u_driconf.c +++ b/src/gallium/auxiliary/util/u_driconf.c @@ -69,6 +69,7 @@ u_driconf_fill_st_options(struct st_config_options *options, query_bool_option(ignore_discard_framebuffer); query_int_option(reuse_gl_names); query_bool_option(force_gl_map_buffer_synchronized); + query_bool_option(force_gl_depth_component_type_int); query_bool_option(transcode_etc); query_bool_option(transcode_astc); query_bool_option(allow_compressed_fallback); diff --git a/src/gallium/include/frontend/api.h b/src/gallium/include/frontend/api.h index 26712fe7180..1bf6ea0ced6 100644 --- a/src/gallium/include/frontend/api.h +++ b/src/gallium/include/frontend/api.h @@ -198,6 +198,7 @@ struct st_config_options bool force_integer_tex_nearest; int reuse_gl_names; bool force_gl_map_buffer_synchronized; + bool force_gl_depth_component_type_int; bool transcode_etc; bool transcode_astc; bool allow_compressed_fallback; diff --git a/src/mesa/main/consts_exts.h b/src/mesa/main/consts_exts.h index 1a9be719da1..7a561ecd83a 100644 --- a/src/mesa/main/consts_exts.h +++ b/src/mesa/main/consts_exts.h @@ -926,6 +926,9 @@ struct gl_constants /** Override GL_MAP_UNSYNCHRONIZED_BIT */ bool ForceMapBufferSynchronized; + /** Override GL_DEPTH_COMPONENT type from unsigned short to unsigned int */ + bool ForceDepthComponentTypeInt; + /** GL_ARB_get_program_binary */ GLuint NumProgramBinaryFormats; diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index 775f00caa4b..92ead66e516 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -1196,6 +1196,8 @@ void st_init_extensions(struct pipe_screen *screen, consts->ForceMapBufferSynchronized = options->force_gl_map_buffer_synchronized; + consts->ForceDepthComponentTypeInt = options->force_gl_depth_component_type_int; + consts->PrimitiveRestartFixedIndex = screen->caps.primitive_restart_fixed_index; diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index b040c0c4f17..4c6e1fa26ca 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -1328,6 +1328,11 @@ st_ChooseTextureFormat(struct gl_context *ctx, GLenum target, bool is_renderbuffer = false; enum pipe_texture_target pTarget; + if (ctx->Const.ForceDepthComponentTypeInt && + internalFormat == GL_DEPTH_COMPONENT && + type == GL_UNSIGNED_SHORT) + type = GL_UNSIGNED_INT; + if (target == GL_RENDERBUFFER) { pTarget = PIPE_TEXTURE_2D; is_renderbuffer = true; diff --git a/src/util/00-mesa-defaults.conf b/src/util/00-mesa-defaults.conf index 253a1a1e8f4..d8cc6b63392 100644 --- a/src/util/00-mesa-defaults.conf +++ b/src/util/00-mesa-defaults.conf @@ -185,6 +185,10 @@ TODO: document the other workarounds.