mesa: add AllowGLSLCrossStageInterpolationMismatch workaround
authorTapani Pälli <tapani.palli@intel.com>
Fri, 24 Nov 2017 05:46:07 +0000 (07:46 +0200)
committerTapani Pälli <tapani.palli@intel.com>
Thu, 30 Nov 2017 09:43:10 +0000 (11:43 +0200)
This fixes issues seen with certain versions of Unreal Engine 4 editor
and games built with that using GLSL 4.30.

v2: add driinfo_gallium change (Emil Velikov)

Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97852
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103801
Acked-by: Andres Gomez <agomez@igalia.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/glsl/link_varyings.cpp
src/gallium/auxiliary/pipe-loader/driinfo_gallium.h
src/gallium/include/state_tracker/st_api.h
src/gallium/state_trackers/dri/dri_screen.c
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/intel_screen.c
src/mesa/main/mtypes.h
src/mesa/state_tracker/st_extensions.c
src/util/drirc
src/util/xmlpool/t_options.h

index 72309365a030773cfcc5ff185cd61ad8942f2cee..0f53cd4aa950971913f9d1dc97f8c2377331b6ef 100644 (file)
@@ -189,7 +189,8 @@ process_xfb_layout_qualifiers(void *mem_ctx, const gl_linked_shader *sh,
  * matching input to another stage.
  */
 static void
-cross_validate_types_and_qualifiers(struct gl_shader_program *prog,
+cross_validate_types_and_qualifiers(struct gl_context *ctx,
+                                    struct gl_shader_program *prog,
                                     const ir_variable *input,
                                     const ir_variable *output,
                                     gl_shader_stage consumer_stage,
@@ -343,17 +344,30 @@ cross_validate_types_and_qualifiers(struct gl_shader_program *prog,
    }
    if (input_interpolation != output_interpolation &&
        prog->data->Version < 440) {
-      linker_error(prog,
-                   "%s shader output `%s' specifies %s "
-                   "interpolation qualifier, "
-                   "but %s shader input specifies %s "
-                   "interpolation qualifier\n",
-                   _mesa_shader_stage_to_string(producer_stage),
-                   output->name,
-                   interpolation_string(output->data.interpolation),
-                   _mesa_shader_stage_to_string(consumer_stage),
-                   interpolation_string(input->data.interpolation));
-      return;
+      if (!ctx->Const.AllowGLSLCrossStageInterpolationMismatch) {
+         linker_error(prog,
+                      "%s shader output `%s' specifies %s "
+                      "interpolation qualifier, "
+                      "but %s shader input specifies %s "
+                      "interpolation qualifier\n",
+                      _mesa_shader_stage_to_string(producer_stage),
+                      output->name,
+                      interpolation_string(output->data.interpolation),
+                      _mesa_shader_stage_to_string(consumer_stage),
+                      interpolation_string(input->data.interpolation));
+         return;
+      } else {
+         linker_warning(prog,
+                        "%s shader output `%s' specifies %s "
+                        "interpolation qualifier, "
+                        "but %s shader input specifies %s "
+                        "interpolation qualifier\n",
+                        _mesa_shader_stage_to_string(producer_stage),
+                        output->name,
+                        interpolation_string(output->data.interpolation),
+                        _mesa_shader_stage_to_string(consumer_stage),
+                        interpolation_string(input->data.interpolation));
+      }
    }
 }
 
@@ -361,7 +375,8 @@ cross_validate_types_and_qualifiers(struct gl_shader_program *prog,
  * Validate front and back color outputs against single color input
  */
 static void
-cross_validate_front_and_back_color(struct gl_shader_program *prog,
+cross_validate_front_and_back_color(struct gl_context *ctx,
+                                    struct gl_shader_program *prog,
                                     const ir_variable *input,
                                     const ir_variable *front_color,
                                     const ir_variable *back_color,
@@ -369,11 +384,11 @@ cross_validate_front_and_back_color(struct gl_shader_program *prog,
                                     gl_shader_stage producer_stage)
 {
    if (front_color != NULL && front_color->data.assigned)
-      cross_validate_types_and_qualifiers(prog, input, front_color,
+      cross_validate_types_and_qualifiers(ctx, prog, input, front_color,
                                           consumer_stage, producer_stage);
 
    if (back_color != NULL && back_color->data.assigned)
-      cross_validate_types_and_qualifiers(prog, input, back_color,
+      cross_validate_types_and_qualifiers(ctx, prog, input, back_color,
                                           consumer_stage, producer_stage);
 }
 
@@ -710,7 +725,7 @@ cross_validate_outputs_to_inputs(struct gl_context *ctx,
          const ir_variable *const back_color =
             parameters.get_variable("gl_BackColor");
 
-         cross_validate_front_and_back_color(prog, input,
+         cross_validate_front_and_back_color(ctx, prog, input,
                                              front_color, back_color,
                                              consumer->Stage, producer->Stage);
       } else if (strcmp(input->name, "gl_SecondaryColor") == 0 && input->data.used) {
@@ -720,7 +735,7 @@ cross_validate_outputs_to_inputs(struct gl_context *ctx,
          const ir_variable *const back_color =
             parameters.get_variable("gl_BackSecondaryColor");
 
-         cross_validate_front_and_back_color(prog, input,
+         cross_validate_front_and_back_color(ctx, prog, input,
                                              front_color, back_color,
                                              consumer->Stage, producer->Stage);
       } else {
@@ -770,7 +785,7 @@ cross_validate_outputs_to_inputs(struct gl_context *ctx,
              */
             if (!(input->get_interface_type() &&
                   output->get_interface_type()))
-               cross_validate_types_and_qualifiers(prog, input, output,
+               cross_validate_types_and_qualifiers(ctx, prog, input, output,
                                                    consumer->Stage,
                                                    producer->Stage);
          } else {
index d2d2c9d3a5c7a674aa8ee95c518968b7345b0efa..003a3d7089e76a7d36fe145bafc2e30ed446e961 100644 (file)
@@ -23,6 +23,7 @@ DRI_CONF_SECTION_DEBUG
    DRI_CONF_FORCE_GLSL_VERSION(0)
    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")
    DRI_CONF_ALLOW_HIGHER_COMPAT_VERSION("false")
    DRI_CONF_FORCE_GLSL_ABS_SQRT("false")
    DRI_CONF_GLSL_CORRECT_DERIVATIVES_AFTER_DISCARD("false")
index a407b980d94276b0b14720ec5cb0787d2925edb6..44d6b474f8f34aaa9bcaf024b89cc64bc9783486 100644 (file)
@@ -224,6 +224,7 @@ struct st_config_options
    boolean allow_higher_compat_version;
    boolean glsl_zero_init;
    boolean force_glsl_abs_sqrt;
+   boolean allow_glsl_cross_stage_interpolation_mismatch;
    unsigned char config_options_sha1[20];
 };
 
index 31b2c37bfd0a9b8906b7e0624dc0f17d8c76b406..1ca511612adc8f43b2dfe45a46b5f13543249821 100644 (file)
@@ -81,6 +81,8 @@ dri_fill_st_options(struct dri_screen *screen)
    options->glsl_zero_init = driQueryOptionb(optionCache, "glsl_zero_init");
    options->force_glsl_abs_sqrt =
       driQueryOptionb(optionCache, "force_glsl_abs_sqrt");
+   options->allow_glsl_cross_stage_interpolation_mismatch =
+      driQueryOptionb(optionCache, "allow_glsl_cross_stage_interpolation_mismatch");
 
    driComputeOptionsSha1(optionCache, options->config_options_sha1);
 }
index dd55b43669881fb97e2453290acdbcfebe5fca5c..b62852d90c8f6d9bea1612fa53f67258b215d2ac 100644 (file)
@@ -816,6 +816,9 @@ brw_process_driconf_options(struct brw_context *brw)
    brw->dual_color_blend_by_location =
       driQueryOptionb(options, "dual_color_blend_by_location");
 
+   ctx->Const.AllowGLSLCrossStageInterpolationMismatch =
+      driQueryOptionb(options, "allow_glsl_cross_stage_interpolation_mismatch");
+
    ctx->Const.dri_config_options_sha1 = ralloc_array(brw, unsigned char, 20);
    driComputeOptionsSha1(&brw->screen->optionCache,
                          ctx->Const.dri_config_options_sha1);
index 38769babf0c079f20989fa0782e88ca7915748d8..db1552c1880d264739079f5083c605e5ee88b9f9 100644 (file)
@@ -81,6 +81,7 @@ DRI_CONF_BEGIN
       DRI_CONF_DUAL_COLOR_BLEND_BY_LOCATION("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")
       DRI_CONF_ALLOW_HIGHER_COMPAT_VERSION("false")
       DRI_CONF_FORCE_GLSL_ABS_SQRT("false")
 
index 96775824ea67948bbb92d8cec7f6933d4150b3ee..0e8a05359a4b0883fc8f2616d10dd9e069c6afa5 100644 (file)
@@ -3717,6 +3717,11 @@ struct gl_constants
     */
    GLboolean AllowGLSLBuiltinVariableRedeclaration;
 
+   /**
+    * Allow GLSL interpolation qualifier mismatch across shader stages.
+    */
+   GLboolean AllowGLSLCrossStageInterpolationMismatch;
+
    /**
     * Allow creating a higher compat profile (version 3.1+) for apps that
     * request it. Be careful when adding that driconf option because some
index de3d1ef4e9bd8b4f7c9e10342e38d70b25197f66..9ef0df1e9261b98b6f0a2138f5294d30577c8e09 100644 (file)
@@ -941,6 +941,8 @@ void st_init_extensions(struct pipe_screen *screen,
 
    consts->dri_config_options_sha1 = options->config_options_sha1;
 
+   consts->AllowGLSLCrossStageInterpolationMismatch = options->allow_glsl_cross_stage_interpolation_mismatch;
+
    if (consts->GLSLVersion >= 400)
       extensions->ARB_gpu_shader5 = GL_TRUE;
    if (consts->GLSLVersion >= 410)
index 05630eb1a92ab8925f2593c8e2ae4eb386d7ed85..9d27330036ec532764b954dcc163a643652db7c5 100644 (file)
@@ -160,6 +160,14 @@ TODO: document the other workarounds.
             <option name="glsl_correct_derivatives_after_discard" value="true"/>
         </application>
 
+        <application name="Unreal 4 Editor" executable="UE4Editor">
+            <option name="allow_glsl_cross_stage_interpolation_mismatch" value="true"/>
+        </application>
+
+        <application name="Observer" executable="TheObserver-Linux-Shipping">
+            <option name="allow_glsl_cross_stage_interpolation_mismatch" value="true"/>
+        </application>
+
         <!-- The GL thread whitelist is below, workarounds are above.
              Keep it that way. -->
 
index 41f6ebd62d30e1041d09c453cdbbd4171840c19e..bd553085c86a82f1d6b243b0497980dfd1025b40 100644 (file)
@@ -135,6 +135,10 @@ DRI_CONF_OPT_BEGIN_B(glsl_correct_derivatives_after_discard, def) \
         DRI_CONF_DESC(en,gettext("Implicit and explicit derivatives after a discard behave as if the discard didn't happen")) \
 DRI_CONF_OPT_END
 
+#define DRI_CONF_ALLOW_GLSL_CROSS_STAGE_INTERPOLATION_MISMATCH(def) \
+DRI_CONF_OPT_BEGIN_B(allow_glsl_cross_stage_interpolation_mismatch, def) \
+        DRI_CONF_DESC(en,gettext("Allow interpolation qualifier mismatch across shader stages")) \
+DRI_CONF_OPT_END
 
 /**
  * \brief Image quality-related options