util/driconf: add force_gl_depth_component_type_int workaround

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 <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34752>
(cherry picked from commit e0a111540f0f54c7ff0f0d0b046f184f033008f7)
This commit is contained in:
Timothy Arceri
2025-04-30 14:51:44 +10:00
committed by Eric Engestrom
parent d762b354c7
commit 52d082981f
9 changed files with 21 additions and 1 deletions

View File

@@ -704,7 +704,7 @@
"description": "util/driconf: add force_gl_depth_component_type_int workaround",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -185,6 +185,10 @@ TODO: document the other workarounds.
<option name="allow_glsl_extension_directive_midshader" value="true" />
</application>
<application name="TombRaider 4-5-6 Remastered" executable="tomb456.exe">
<option name="force_gl_depth_component_type_int" value="true" />
</application>
<application name="Warsow (32-bit)" executable="warsow.i386">
<option name="allow_glsl_extension_directive_midshader" value="true" />
</application>

View File

@@ -291,6 +291,9 @@
#define DRI_CONF_FORCE_GL_MAP_BUFFER_SYNCHRONIZED(def) \
DRI_CONF_OPT_B(force_gl_map_buffer_synchronized, def, "Override GL_MAP_UNSYNCHRONIZED_BIT.")
#define DRI_CONF_FORCE_GL_DEPTH_COMPONENT_TYPE_INT(def) \
DRI_CONF_OPT_B(force_gl_depth_component_type_int, def, "Override GL_DEPTH_COMPONENT type from unsigned short to unsigned int")
#define DRI_CONF_TRANSCODE_ETC(def) \
DRI_CONF_OPT_B(transcode_etc, def, "Transcode ETC formats to DXTC if unsupported")