glsl: add extra pp tokens workaround and enable for CoR
authorTimothy Arceri <tarceri@itsqueeze.com>
Thu, 29 Oct 2020 03:19:01 +0000 (14:19 +1100)
committerMarge Bot <eric+marge@anholt.net>
Thu, 29 Oct 2020 23:35:58 +0000 (23:35 +0000)
The CTS now tests to make sure these are not allowed. However, previously
drivers (including Mesa) would allow them to exist and just issue a
warning. Some old applications such as Champions of Regnum seem to
depend on this.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/422

Fixes: 43047384c331 ("glsl/glcpp: Promote "extra token at end of directive" from warning to error")

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7361>

src/compiler/glsl/glcpp/glcpp-parse.y
src/gallium/auxiliary/pipe-loader/driinfo_gallium.h
src/gallium/frontends/dri/dri_screen.c
src/gallium/include/frontend/api.h
src/mesa/drivers/dri/i965/intel_screen.c
src/mesa/main/mtypes.h
src/mesa/state_tracker/st_extensions.c
src/util/00-mesa-defaults.conf
src/util/driconf.h

index 173e1a1..2359967 100644 (file)
@@ -781,7 +781,10 @@ replacement_list:
 junk:
        /* empty */
 |      pp_tokens {
-               glcpp_error(&@1, parser, "extra tokens at end of directive");
+               if (parser->gl_ctx->Const.AllowExtraPPTokens)
+                       glcpp_warning(&@1, parser, "extra tokens at end of directive");
+               else
+                       glcpp_error(&@1, parser, "extra tokens at end of directive");
        }
 ;
 
index 95e27bc..41051bc 100644 (file)
@@ -22,6 +22,7 @@ DRI_CONF_SECTION_DEBUG
    DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED(false)
    DRI_CONF_DISABLE_ARB_GPU_SHADER5(false)
    DRI_CONF_FORCE_GLSL_VERSION(0)
+   DRI_CONF_ALLOW_EXTRA_PP_TOKENS(false)
    DRI_CONF_ALLOW_GLSL_EXTENSION_DIRECTIVE_MIDSHADER(false)
    DRI_CONF_ALLOW_GLSL_120_SUBSET_IN_110(false)
    DRI_CONF_ALLOW_GLSL_BUILTIN_CONST_EXPRESSION(false)
index f476333..0e9f391 100644 (file)
@@ -72,6 +72,8 @@ dri_fill_st_options(struct dri_screen *screen)
       driQueryOptionb(optionCache, "force_glsl_extensions_warn");
    options->force_glsl_version =
       driQueryOptioni(optionCache, "force_glsl_version");
+   options->allow_extra_pp_tokens =
+      driQueryOptionb(optionCache, "allow_extra_pp_tokens");
    options->allow_glsl_extension_directive_midshader =
       driQueryOptionb(optionCache, "allow_glsl_extension_directive_midshader");
    options->allow_glsl_120_subset_in_110 =
index 9dcabe0..d4f47a1 100644 (file)
@@ -220,6 +220,7 @@ struct st_config_options
    bool disable_arb_gpu_shader5;
    bool force_glsl_extensions_warn;
    unsigned force_glsl_version;
+   bool allow_extra_pp_tokens;
    bool allow_glsl_extension_directive_midshader;
    bool allow_glsl_120_subset_in_110;
    bool allow_glsl_builtin_const_expression;
index 97efe2d..4492d43 100644 (file)
@@ -79,6 +79,7 @@ static const driOptionDescription brw_driconf[] = {
       DRI_CONF_DISABLE_GLSL_LINE_CONTINUATIONS(false)
       DRI_CONF_DISABLE_BLEND_FUNC_EXTENDED(false)
       DRI_CONF_DUAL_COLOR_BLEND_BY_LOCATION(false)
+      DRI_CONF_ALLOW_EXTRA_PP_TOKENS(false)
       DRI_CONF_ALLOW_GLSL_EXTENSION_DIRECTIVE_MIDSHADER(false)
       DRI_CONF_ALLOW_GLSL_BUILTIN_VARIABLE_REDECLARATION(false)
       DRI_CONF_ALLOW_GLSL_CROSS_STAGE_INTERPOLATION_MISMATCH(false)
index 04b9702..b3de442 100644 (file)
@@ -3876,6 +3876,14 @@ struct gl_constants
    GLboolean AllowLayoutQualifiersOnFunctionParameters;
 
    /**
+    * Allow extra tokens at end of preprocessor directives. The CTS now tests
+    * to make sure these are not allowed. However, previously drivers would
+    * allow them to exist and just issue a warning so some old applications
+    * depend on this.
+    */
+   GLboolean AllowExtraPPTokens;
+
+   /**
     * Force computing the absolute value for sqrt() and inversesqrt() to follow
     * D3D9 when apps rely on this behaviour.
     */
index 6258d08..38370e1 100644 (file)
@@ -1133,6 +1133,8 @@ void st_init_extensions(struct pipe_screen *screen,
       consts->ForceGLSLVersion = options->force_glsl_version;
    }
 
+   consts->AllowExtraPPTokens = options->allow_extra_pp_tokens;
+
    consts->AllowHigherCompatVersion = options->allow_higher_compat_version;
 
    consts->ForceGLSLAbsSqrt = options->force_glsl_abs_sqrt;
index b7c37eb..816169b 100644 (file)
@@ -246,6 +246,10 @@ TODO: document the other workarounds.
             <option name="allow_glsl_layout_qualifier_on_function_parameters" value="true" />
         </application>
 
+        <application name="Champions of Regnum" executable="game">
+            <option name="allow_extra_pp_tokens" value="true" />
+        </application>
+
         <application name="Wolfenstein The Old Blood" executable="WolfOldBlood_x64.exe">
             <option name="force_compat_profile" value="true" />
         </application>
index c67b0b6..92b9a8c 100644 (file)
    DRI_CONF_OPT_I(force_glsl_version, def, 0, 999, \
                   "Force a default GLSL version for shaders that lack an explicit #version line")
 
+#define DRI_CONF_ALLOW_EXTRA_PP_TOKENS(def) \
+   DRI_CONF_OPT_B(allow_extra_pp_tokens, def, \
+                  "Allow extra tokens at end of preprocessor directives.")
+
 #define DRI_CONF_ALLOW_GLSL_EXTENSION_DIRECTIVE_MIDSHADER(def) \
    DRI_CONF_OPT_B(allow_glsl_extension_directive_midshader, def, \
                   "Allow GLSL #extension directives in the middle of shaders")