From 21f28350bb12c50fcd7f4d5f2a42462f9fd9ce4f Mon Sep 17 00:00:00 2001 From: Ilia Mirkin Date: Sat, 5 Sep 2015 13:55:07 -0400 Subject: [PATCH] mesa: add options to allow Chronicles of Riddick to run The game has shaders that attempt to use GL_ATI_shader_texture_lod expecting identical functionality as the ARB version. Alias it when finding extensions to avoid polluting a lot of other code with the two different variants. Additionally the game has a shader header which has calls to texture2D and textureCube with bias, and that header is used in both vertex and pixel shaders. Allow just those two functions for now without worrying about providing all the variants. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=91169 Signed-off-by: Ilia Mirkin --- src/gallium/include/state_tracker/st_api.h | 2 ++ src/gallium/state_trackers/dri/dri_screen.c | 6 ++++++ src/glsl/builtin_functions.cpp | 10 ++++++++-- src/glsl/glsl_parser_extras.cpp | 12 ++++++++++-- src/glsl/glsl_parser_extras.h | 2 ++ src/mesa/drivers/dri/common/xmlpool/t_options.h | 10 ++++++++++ src/mesa/main/mtypes.h | 10 ++++++++++ src/mesa/state_tracker/st_extensions.c | 6 ++++++ 8 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/gallium/include/state_tracker/st_api.h b/src/gallium/include/state_tracker/st_api.h index 356863d..6d12245 100644 --- a/src/gallium/include/state_tracker/st_api.h +++ b/src/gallium/include/state_tracker/st_api.h @@ -247,6 +247,8 @@ struct st_config_options unsigned force_glsl_version; boolean force_s3tc_enable; boolean allow_glsl_extension_directive_midshader; + boolean alias_ati_to_arb_shader_texture_lod; + boolean allow_vertex_texture_bias; }; /** diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index c4c2d9c..5fbd127 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -70,6 +70,8 @@ const __DRIconfigOptionsExtension gallium_config_options = { DRI_CONF_DISABLE_SHADER_BIT_ENCODING("false") DRI_CONF_FORCE_GLSL_VERSION(0) DRI_CONF_ALLOW_GLSL_EXTENSION_DIRECTIVE_MIDSHADER("false") + DRI_CONF_ALIAS_ATI_TO_ARB_SHADER_TEXTURE_LOD("false") + DRI_CONF_ALLOW_VERTEX_TEXTURE_BIAS("false") DRI_CONF_SECTION_END DRI_CONF_SECTION_MISCELLANEOUS @@ -98,6 +100,10 @@ dri_fill_st_options(struct st_config_options *options, driQueryOptionb(optionCache, "force_s3tc_enable"); options->allow_glsl_extension_directive_midshader = driQueryOptionb(optionCache, "allow_glsl_extension_directive_midshader"); + options->alias_ati_to_arb_shader_texture_lod = + driQueryOptionb(optionCache, "alias_ati_to_arb_shader_texture_lod"); + options->allow_vertex_texture_bias = + driQueryOptionb(optionCache, "allow_vertex_texture_bias"); } static const __DRIconfig ** diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp index 5e05199..952fa5d 100644 --- a/src/glsl/builtin_functions.cpp +++ b/src/glsl/builtin_functions.cpp @@ -149,6 +149,12 @@ es31(const _mesa_glsl_parse_state *state) } static bool +fs_only_txb(const _mesa_glsl_parse_state *state) +{ + return fs_only(state) || state->allow_vertex_texture_bias; +} + +static bool texture_rectangle(const _mesa_glsl_parse_state *state) { return state->ARB_texture_rectangle_enable; @@ -2120,7 +2126,7 @@ builtin_builder::create_builtins() add_function("texture2D", _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type), - _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type), + _texture(ir_txb, fs_only_txb, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type), _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec2_type), NULL); @@ -2171,7 +2177,7 @@ builtin_builder::create_builtins() add_function("textureCube", _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type), - _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type), + _texture(ir_txb, fs_only_txb, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type), NULL); add_function("textureCubeLod", diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp index 939a03c..54237f8 100644 --- a/src/glsl/glsl_parser_extras.cpp +++ b/src/glsl/glsl_parser_extras.cpp @@ -259,6 +259,10 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx, sizeof(this->atomic_counter_offsets)); this->allow_extension_directive_midshader = ctx->Const.AllowGLSLExtensionDirectiveMidShader; + this->alias_ati_to_arb_shader_texture_lod = + ctx->Const.AliasATItoARBShaderTextureLod; + this->allow_vertex_texture_bias = + ctx->Const.AllowVertexTextureBias; } /** @@ -689,8 +693,12 @@ void _mesa_glsl_extension::set_flags(_mesa_glsl_parse_state *state, * Find an extension by name in _mesa_glsl_supported_extensions. If * the name is not found, return NULL. */ -static const _mesa_glsl_extension *find_extension(const char *name) +static const _mesa_glsl_extension *find_extension(_mesa_glsl_parse_state *state, + const char *name) { + if (state->alias_ati_to_arb_shader_texture_lod && + strcmp(name, "GL_ATI_shader_texture_lod") == 0) + name = "GL_ARB_shader_texture_lod"; for (unsigned i = 0; i < ARRAY_SIZE(_mesa_glsl_supported_extensions); ++i) { if (strcmp(name, _mesa_glsl_supported_extensions[i].name) == 0) { return &_mesa_glsl_supported_extensions[i]; @@ -738,7 +746,7 @@ _mesa_glsl_process_extension(const char *name, YYLTYPE *name_locp, } } } else { - const _mesa_glsl_extension *extension = find_extension(name); + const _mesa_glsl_extension *extension = find_extension(state, name); if (extension && extension->compatible_with_state(state)) { extension->set_flags(state, behavior); } else { diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h index 295cd10..60f7e54 100644 --- a/src/glsl/glsl_parser_extras.h +++ b/src/glsl/glsl_parser_extras.h @@ -603,6 +603,8 @@ struct _mesa_glsl_parse_state { unsigned atomic_counter_offsets[MAX_COMBINED_ATOMIC_BUFFERS]; bool allow_extension_directive_midshader; + bool alias_ati_to_arb_shader_texture_lod; + bool allow_vertex_texture_bias; /** * Known subroutine type declarations. diff --git a/src/mesa/drivers/dri/common/xmlpool/t_options.h b/src/mesa/drivers/dri/common/xmlpool/t_options.h index 4e5a721..067459e 100644 --- a/src/mesa/drivers/dri/common/xmlpool/t_options.h +++ b/src/mesa/drivers/dri/common/xmlpool/t_options.h @@ -110,6 +110,16 @@ DRI_CONF_OPT_BEGIN_B(allow_glsl_extension_directive_midshader, def) \ DRI_CONF_DESC(en,gettext("Allow GLSL #extension directives in the middle of shaders")) \ DRI_CONF_OPT_END +#define DRI_CONF_ALIAS_ATI_TO_ARB_SHADER_TEXTURE_LOD(def) \ +DRI_CONF_OPT_BEGIN_B(alias_ati_to_arb_shader_texture_lod, def) \ + DRI_CONF_DESC(en,gettext("Support GL_ATI_shader_texture_lod as if it were the ARB version")) \ +DRI_CONF_OPT_END + +#define DRI_CONF_ALLOW_VERTEX_TEXTURE_BIAS(def) \ +DRI_CONF_OPT_BEGIN_B(allow_vertex_texture_bias, def) \ + DRI_CONF_DESC(en,gettext("Allow GL2 vertex shaders to have access to texture2D/textureCube with bias variants")) \ +DRI_CONF_OPT_END + /** diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 85a9f5d..44296bf 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -3390,6 +3390,16 @@ struct gl_constants GLboolean AllowGLSLExtensionDirectiveMidShader; /** + * Alias GL_ATI_shader_texture_lod to GL_ARB_shader_texture_lod. + */ + GLboolean AliasATItoARBShaderTextureLod; + + /** + * Allow fs-only bias argument in vertex shaders. + */ + GLboolean AllowVertexTextureBias; + + /** * Does the driver support real 32-bit integers? (Otherwise, integers are * simulated via floats.) */ diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index 17f572f..82911c5 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -839,6 +839,12 @@ void st_init_extensions(struct pipe_screen *screen, if (options->allow_glsl_extension_directive_midshader) consts->AllowGLSLExtensionDirectiveMidShader = GL_TRUE; + if (options->alias_ati_to_arb_shader_texture_lod) + consts->AliasATItoARBShaderTextureLod = GL_TRUE; + + if (options->allow_vertex_texture_bias) + consts->AllowVertexTextureBias = GL_TRUE; + consts->MinMapBufferAlignment = screen->get_param(screen, PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT); -- 2.4.6