util/driconf: add workarounds for the Chronicles of Riddick
authortwisted89 <twisted89@gmail.com>
Tue, 8 Aug 2023 21:19:55 +0000 (22:19 +0100)
committerMarge Bot <emma+marge@anholt.net>
Thu, 24 Aug 2023 22:38:56 +0000 (22:38 +0000)
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24567>

src/compiler/glsl/builtin_functions.cpp
src/compiler/glsl/glsl_parser_extras.cpp
src/compiler/glsl/glsl_parser_extras.h
src/gallium/auxiliary/pipe-loader/driinfo_gallium.h
src/gallium/auxiliary/util/u_driconf.c
src/gallium/include/frontend/api.h
src/mesa/main/consts_exts.h
src/mesa/state_tracker/st_extensions.c
src/util/00-mesa-defaults.conf
src/util/driconf.h

index 97e37e4..a141b87 100644 (file)
@@ -144,7 +144,7 @@ deprecated_texture(const _mesa_glsl_parse_state *state)
 static bool
 deprecated_texture_derivatives_only(const _mesa_glsl_parse_state *state)
 {
-   return deprecated_texture(state) && derivatives_only(state);
+   return (deprecated_texture(state) && derivatives_only(state)) || state->allow_vertex_texture_bias;
 }
 
 static bool
index 8795b0a..c5435f9 100644 (file)
@@ -317,6 +317,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_shader_extension =
+      ctx->Const.AliasShaderExtension;
+   this->allow_vertex_texture_bias =
+      ctx->Const.AllowVertexTextureBias;
    this->allow_glsl_120_subset_in_110 =
       ctx->Const.AllowGLSL120SubsetIn110;
    this->allow_builtin_variable_redeclaration =
@@ -815,16 +819,50 @@ void _mesa_glsl_extension::set_flags(_mesa_glsl_parse_state *state,
 }
 
 /**
+ * Check alias_shader_extension for any aliased shader extensions
+ */
+static const char *find_extension_alias(_mesa_glsl_parse_state *state, const char *name)
+{
+   char *exts, *field, *ext_alias = NULL;
+
+   /* Copy alias_shader_extension because strtok() is destructive. */
+   exts = strdup(state->alias_shader_extension);
+   if (exts) {
+      for (field = strtok(exts, ","); field != NULL; field = strtok(NULL, ",")) {
+         if(strncmp(name, field, strlen(name)) == 0) {
+            field = strstr(field, ":");
+            if(field) {
+               ext_alias = strdup(field + 1);
+            }
+            break;
+         }
+      }
+      
+      free(exts);
+   }
+   return ext_alias;
+}
+
+/**
  * 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)
 {
+   const char *ext_alias = NULL;
+   if (state->alias_shader_extension) {
+      ext_alias = find_extension_alias(state, name);
+      name = ext_alias ? ext_alias : name;
+   }
+   
    for (unsigned i = 0; i < ARRAY_SIZE(_mesa_glsl_supported_extensions); ++i) {
       if (strcmp(name, _mesa_glsl_supported_extensions[i].name) == 0) {
+         free((void *)ext_alias);
          return &_mesa_glsl_supported_extensions[i];
       }
    }
+
+   free((void *)ext_alias);
    return NULL;
 }
 
@@ -879,7 +917,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, api, gl_version) ||
            (state->consts->AllowGLSLCompatShaders &&
index 8e69cfc..3d956a9 100644 (file)
@@ -961,6 +961,8 @@ struct _mesa_glsl_parse_state {
    bool layer_viewport_relative;
 
    bool allow_extension_directive_midshader;
+   char *alias_shader_extension;
+   bool allow_vertex_texture_bias;
    bool allow_glsl_120_subset_in_110;
    bool allow_builtin_variable_redeclaration;
    bool ignore_write_to_readonly_var;
index c4f34c6..f764916 100644 (file)
@@ -21,6 +21,8 @@ DRI_CONF_SECTION_DEBUG
    DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED(false)
    DRI_CONF_DISABLE_ARB_GPU_SHADER5(false)
    DRI_CONF_DISABLE_UNIFORM_ARRAY_RESIZE(false)
+   DRI_CONF_ALIAS_SHADER_EXTENSION()
+   DRI_CONF_ALLOW_VERTEX_TEXTURE_BIAS(false)
    DRI_CONF_FORCE_GLSL_VERSION(0)
    DRI_CONF_ALLOW_EXTRA_PP_TOKENS(false)
    DRI_CONF_ALLOW_GLSL_EXTENSION_DIRECTIVE_MIDSHADER(false)
index 7280cfb..165de18 100644 (file)
@@ -42,6 +42,8 @@ u_driconf_fill_st_options(struct st_config_options *options,
    query_bool_option(disable_arb_gpu_shader5);
    query_bool_option(disable_glsl_line_continuations);
    query_bool_option(disable_uniform_array_resize);
+   query_string_option(alias_shader_extension);
+   query_bool_option(allow_vertex_texture_bias);
    query_bool_option(force_compat_shaders);
    query_bool_option(force_glsl_extensions_warn);
    query_int_option(force_glsl_version);
index bef0a8d..712cbe9 100644 (file)
@@ -171,6 +171,8 @@ struct st_config_options
    bool disable_glsl_line_continuations;
    bool disable_arb_gpu_shader5;
    bool disable_uniform_array_resize;
+   char *alias_shader_extension;
+   bool allow_vertex_texture_bias;
    bool force_compat_shaders;
    bool force_glsl_extensions_warn;
    unsigned force_glsl_version;
index 0245a06..b80f69b 100644 (file)
@@ -799,6 +799,16 @@ struct gl_constants
    bool DisableUniformArrayResize;
 
    /**
+    * Alias extension e.g. GL_ATI_shader_texture_lod to GL_ARB_shader_texture_lod.
+    */
+   char *AliasShaderExtension;
+
+   /**
+    * Allow fs-only bias argument in vertex shaders.
+    */
+   GLboolean AllowVertexTextureBias;
+
+   /**
     * Align varyings to POT in a slot
     *
     * Drivers that prefer varyings to be aligned to POT must set this value to GL_TRUE
index c19f308..8cc079e 100644 (file)
@@ -1468,6 +1468,11 @@ void st_init_extensions(struct pipe_screen *screen,
    if (options->disable_uniform_array_resize)
       consts->DisableUniformArrayResize = 1;
 
+   consts->AliasShaderExtension = options->alias_shader_extension;
+
+   if (options->allow_vertex_texture_bias)
+      consts->AllowVertexTextureBias = GL_TRUE;
+
    if (options->allow_glsl_extension_directive_midshader)
       consts->AllowGLSLExtensionDirectiveMidShader = GL_TRUE;
 
index 37b34af..fc03354 100644 (file)
@@ -161,6 +161,12 @@ TODO: document the other workarounds.
             <option name="disable_uniform_array_resize" value="true" />
         </application>
 
+        <application name="The Chronicles of Riddick: Assault on Dark Athena" executable="DarkAthena.exe">
+               <option name="disable_uniform_array_resize" value="true" />
+            <option name="alias_shader_extension" value="GL_ATI_shader_texture_lod:GL_ARB_shader_texture_lod" />
+            <option name="allow_vertex_texture_bias" value="true" />
+        </application>
+
         <application name="Dying Light" executable="DyingLightGame">
             <option name="allow_glsl_builtin_variable_redeclaration" value="true" />
         </application>
index c6409ec..b9132f0 100644 (file)
    DRI_CONF_OPT_B(disable_uniform_array_resize, def, \
                   "Disable the glsl optimisation that resizes uniform arrays")
 
+#define DRI_CONF_ALIAS_SHADER_EXTENSION() \
+   DRI_CONF_OPT_S_NODEF(alias_shader_extension, "Allow  alias for shader extensions")
+
+#define DRI_CONF_ALLOW_VERTEX_TEXTURE_BIAS(def) \
+   DRI_CONF_OPT_B(allow_vertex_texture_bias, def, \
+                  "Allow GL2 vertex shaders to have access to texture2D/textureCube with bias variants")
+
 #define DRI_CONF_FORCE_GLSL_VERSION(def) \
    DRI_CONF_OPT_I(force_glsl_version, def, 0, 999, \
                   "Force a default GLSL version for shaders that lack an explicit #version line")