glsl: add driconf to zero-init unintialized vars
authorRob Clark <robclark@freedesktop.org>
Fri, 24 Jun 2016 18:28:51 +0000 (14:28 -0400)
committerRob Clark <robdclark@gmail.com>
Sat, 2 Jul 2016 13:00:19 +0000 (09:00 -0400)
Some games are sloppy.. perhaps because it is defined behavior for DX or
perhaps because nv blob driver defaults things to zero.

So add driconf param to force uninitialized variables to default to zero.

This issue was observed with rust, from steam store.  But has surfaced
elsewhere in the past.

Signed-off-by: Rob Clark <robclark@freedesktop.org>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/glsl/ast_to_hir.cpp
src/compiler/glsl/glsl_parser_extras.cpp
src/compiler/glsl/glsl_parser_extras.h
src/gallium/include/state_tracker/st_api.h
src/gallium/state_trackers/dri/dri_screen.c
src/mesa/drivers/dri/common/drirc
src/mesa/drivers/dri/common/xmlpool/t_options.h
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

index 0cfce6893ee747582ba5742d602aac5c4477d3ad..8ddc084cab7f0adf12913f44374323dc40453ae9 100644 (file)
@@ -4697,6 +4697,14 @@ ast_declarator_list::hir(exec_list *instructions,
       apply_layout_qualifier_to_variable(&this->type->qualifier, var, state,
                                          &loc);
 
+      if ((var->data.mode == ir_var_auto || var->data.mode == ir_var_temporary)
+          && (var->type->is_numeric() || var->type->is_boolean())
+          && state->zero_init) {
+         const ir_constant_data data = {0};
+         var->data.has_initializer = true;
+         var->constant_initializer = new(var) ir_constant(var->type, &data);
+      }
+
       if (this->type->qualifier.flags.q.invariant) {
          if (!is_varying_var(var, state->stage)) {
             _mesa_glsl_error(&loc, state,
index fab64bbb87bcacea66c827e002db8e1bebb36e3e..96014247e5d8adb8ec6093d45b14dd40fd6e88a6 100644 (file)
@@ -74,6 +74,7 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
    /* Set default language version and extensions */
    this->language_version = 110;
    this->forced_language_version = ctx->Const.ForceGLSLVersion;
+   this->zero_init = ctx->Const.GLSLZeroInit;
    this->es_shader = false;
    this->ARB_texture_rectangle_enable = true;
 
index 8c43292d8aa3a544642d8f4a36d655aa56c65302..669b3d1b201e2040dd34726eacee9c117d8e584d 100644 (file)
@@ -306,6 +306,7 @@ struct _mesa_glsl_parse_state {
    bool es_shader;
    unsigned language_version;
    unsigned forced_language_version;
+   bool zero_init;
    gl_shader_stage stage;
 
    /**
index 41daa47986cc26780574668bb7de3ef99617d530..21d5177aa2fbf0413b35ceeb253028850d00fab2 100644 (file)
@@ -242,6 +242,7 @@ struct st_config_options
    unsigned force_glsl_version;
    boolean force_s3tc_enable;
    boolean allow_glsl_extension_directive_midshader;
+   boolean glsl_zero_init;
 };
 
 /**
index 2ac55c88926c3785ca463162db0c547efd178f46..b16585a38cc2ba76a1e12c135a0ac1c70b7cbdef 100644 (file)
@@ -74,6 +74,7 @@ const __DRIconfigOptionsExtension gallium_config_options = {
 
       DRI_CONF_SECTION_MISCELLANEOUS
          DRI_CONF_ALWAYS_HAVE_DEPTH_BUFFER("false")
+         DRI_CONF_GLSL_ZERO_INIT("false")
       DRI_CONF_SECTION_END
    DRI_CONF_END
 };
@@ -98,6 +99,7 @@ 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->glsl_zero_init = driQueryOptionb(optionCache, "glsl_zero_init");
 }
 
 static const __DRIconfig **
index 3912d8b8c7e6fafc64cbd693dd77e04dd72eb8ec..af84ee82e8a6708b19a6ae055d2a96af0bfdf8e8 100644 (file)
@@ -96,5 +96,9 @@ TODO: document the other workarounds.
         <application name="Warsow (64-bit)" executable="warsow.x86_64">
             <option name="allow_glsl_extension_directive_midshader" value="true" />
         </application>
+
+        <application name="Rust" executable="rust">
+            <option name="glsl_zero_init" value="true"/>
+        </application>
     </device>
 </driconf>
index 4b298a46112d9aedffc51dc17a9410c536ea818f..341c3763deedee64616eac06446d7f0d85803e42 100644 (file)
@@ -337,7 +337,10 @@ DRI_CONF_OPT_BEGIN_B(always_have_depth_buffer, def) \
         DRI_CONF_DESC(en,gettext("Create all visuals with a depth buffer")) \
 DRI_CONF_OPT_END
 
-
+#define DRI_CONF_GLSL_ZERO_INIT(def) \
+DRI_CONF_OPT_BEGIN_B(glsl_zero_init, def) \
+        DRI_CONF_DESC(en,gettext("Force uninitialized variables to default to zero")) \
+DRI_CONF_OPT_END
 
 /**
  * \brief Initialization configuration options
index 5e3c9d169b356e19e671fa8c806b9b2477820ccf..3f0c2e3b4832c707ab817ed42931041bdfa3ae49 100644 (file)
@@ -827,6 +827,8 @@ brw_process_driconf_options(struct brw_context *brw)
    ctx->Const.AllowGLSLExtensionDirectiveMidShader =
       driQueryOptionb(options, "allow_glsl_extension_directive_midshader");
 
+   ctx->Const.GLSLZeroInit = driQueryOptionb(options, "glsl_zero_init");
+
    brw->dual_color_blend_by_location =
       driQueryOptionb(options, "dual_color_blend_by_location");
 }
index 1c71e09e7ad1273686325362476e60ddf26578c7..432ab7bdb6361cd932616ac5ac3d0d75088a9b71 100644 (file)
@@ -88,6 +88,10 @@ DRI_CONF_BEGIN
         DRI_CONF_DESC(en, "Perform code generation at shader link time.")
       DRI_CONF_OPT_END
    DRI_CONF_SECTION_END
+
+   DRI_CONF_SECTION_MISCELLANEOUS
+      DRI_CONF_GLSL_ZERO_INIT("false")
+   DRI_CONF_SECTION_END
 DRI_CONF_END
 };
 
index cab315df23d51dc5550f83b8449a405c098606a7..29e47debfc258fd0cd6cdaece0407eb2409c1b33 100644 (file)
@@ -3535,6 +3535,11 @@ struct gl_constants
     */
    GLboolean AllowGLSLExtensionDirectiveMidShader;
 
+   /**
+    * Force uninitialized variables to default to zero.
+    */
+   GLboolean GLSLZeroInit;
+
    /**
     * Does the driver support real 32-bit integers?  (Otherwise, integers are
     * simulated via floats.)
index c5ecd5a2dd7f8dddeffa05a8b203fa918edc6b67..3d27ca3a905e498593d97b62e2c2376cffd06263 100644 (file)
@@ -925,6 +925,8 @@ void st_init_extensions(struct pipe_screen *screen,
       extensions->EXT_texture_integer = GL_FALSE;
    }
 
+   consts->GLSLZeroInit = options->glsl_zero_init;
+
    consts->UniformBooleanTrue = consts->NativeIntegers ? ~0U : fui(1.0f);
 
    /* Below are the cases which cannot be moved into tables easily. */