<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 30, 2016 at 11:42 AM, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Saturday, June 25, 2016 8:37:47 AM PDT Rob Clark wrote:<br>
> From: Rob Clark <<a href="mailto:robclark@freedesktop.org">robclark@freedesktop.org</a>><br>
><br>
> Some games are sloppy.. perhaps because it is defined behavior for DX or<br>
> perhaps because nv blob driver defaults things to zero.<br>
><br>
> So add driconf param to force uninitialized variables to default to zero.<br>
><br>
> This issue was observed with rust, from steam store. But has surfaced<br>
> elsewhere in the past.<br>
><br>
> Signed-off-by: Rob Clark <<a href="mailto:robclark@freedesktop.org">robclark@freedesktop.org</a>><br>
> ---<br>
> Note that I left out the drirc bit, since not entirely sure how to<br>
> identify this game. (I don't actually have the game, just working off<br>
> of an apitrace)<br>
><br>
> Possibly worth mentioning that for the shaders using uninitialized vars<br>
> having zero-initializers lets constant-propagation get rid of a whole<br>
> lot of instructions. One shader I saw dropped to less than half of<br>
> it's original instruction count.<br>
><br>
> Second patch in the series is just fixing an i965 bug that was exposed<br>
> by this patch.<br>
<br>
</span>I'm a bit surprised to see this at the GLSL IR level...handling it for<br>
nir_ssa_undef would probably be simpler. But I suppose this works too.<br></blockquote><div><br></div><div>That was my suggestion. I figured the gallium people would want it too.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class=""><br>
> src/compiler/glsl/ast_to_hir.cpp | 9 +++++++++<br>
> src/compiler/glsl/glsl_parser_extras.cpp | 1 +<br>
> src/compiler/glsl/glsl_parser_extras.h | 1 +<br>
> src/gallium/include/state_tracker/st_api.h | 1 +<br>
> src/gallium/state_trackers/dri/dri_screen.c | 2 ++<br>
> src/mesa/drivers/dri/common/xmlpool/t_options.h | 5 ++++-<br>
> src/mesa/drivers/dri/i965/brw_context.c | 2 ++<br>
> src/mesa/drivers/dri/i965/intel_screen.c | 4 ++++<br>
> src/mesa/main/mtypes.h | 5 +++++<br>
> src/mesa/state_tracker/st_extensions.c | 2 ++<br>
> 10 files changed, 31 insertions(+), 1 deletion(-)<br>
><br>
> diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp<br>
> index 0cfce68..d2c284f 100644<br>
> --- a/src/compiler/glsl/ast_to_hir.cpp<br>
> +++ b/src/compiler/glsl/ast_to_hir.cpp<br>
> @@ -4697,6 +4697,15 @@ ast_declarator_list::hir(exec_list *instructions,<br>
> apply_layout_qualifier_to_variable(&this->type->qualifier, var, state,<br>
> &loc);<br>
><br>
> + if ((var->data.mode == ir_var_auto || var->data.mode == ir_var_temporary)<br>
> + && (var->type->base_type >= GLSL_TYPE_UINT)<br>
> + && (var->type->base_type <= GLSL_TYPE_BOOL)<br>
<br>
</span>I'd prefer:<br>
<br>
&& (var->type->is_numeric() || var->type->is_boolean())<br>
<br>
Either way,<br>
Reviewed-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
<br>
Patch 2 also gets an R-b with Jason's feedback (d[0] and u[0] on LHS)<br>
taken care of.<br>
<div class="HOEnZb"><div class="h5"><br>
> + && state->zero_init) {<br>
> + const ir_constant_data data = {0};<br>
> + var->data.has_initializer = true;<br>
> + var->constant_initializer = new(var) ir_constant(var->type, &data);<br>
> + }<br>
> +<br>
> if (this->type->qualifier.flags.q.invariant) {<br>
> if (!is_varying_var(var, state->stage)) {<br>
> _mesa_glsl_error(&loc, state,<br>
> diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp<br>
> index 09f7477..fc2859a 100644<br>
> --- a/src/compiler/glsl/glsl_parser_extras.cpp<br>
> +++ b/src/compiler/glsl/glsl_parser_extras.cpp<br>
> @@ -74,6 +74,7 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,<br>
> /* Set default language version and extensions */<br>
> this->language_version = 110;<br>
> this->forced_language_version = ctx->Const.ForceGLSLVersion;<br>
> + this->zero_init = ctx->Const.GLSLZeroInit;<br>
> this->es_shader = false;<br>
> this->ARB_texture_rectangle_enable = true;<br>
><br>
> diff --git a/src/compiler/glsl/glsl_parser_extras.h b/src/compiler/glsl/glsl_parser_extras.h<br>
> index 8c43292..669b3d1 100644<br>
> --- a/src/compiler/glsl/glsl_parser_extras.h<br>
> +++ b/src/compiler/glsl/glsl_parser_extras.h<br>
> @@ -306,6 +306,7 @@ struct _mesa_glsl_parse_state {<br>
> bool es_shader;<br>
> unsigned language_version;<br>
> unsigned forced_language_version;<br>
> + bool zero_init;<br>
> gl_shader_stage stage;<br>
><br>
> /**<br>
> diff --git a/src/gallium/include/state_tracker/st_api.h b/src/gallium/include/state_tracker/st_api.h<br>
> index 41daa47..21d5177 100644<br>
> --- a/src/gallium/include/state_tracker/st_api.h<br>
> +++ b/src/gallium/include/state_tracker/st_api.h<br>
> @@ -242,6 +242,7 @@ struct st_config_options<br>
> unsigned force_glsl_version;<br>
> boolean force_s3tc_enable;<br>
> boolean allow_glsl_extension_directive_midshader;<br>
> + boolean glsl_zero_init;<br>
> };<br>
><br>
> /**<br>
> diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c<br>
> index 2ac55c8..b16585a 100644<br>
> --- a/src/gallium/state_trackers/dri/dri_screen.c<br>
> +++ b/src/gallium/state_trackers/dri/dri_screen.c<br>
> @@ -74,6 +74,7 @@ const __DRIconfigOptionsExtension gallium_config_options = {<br>
><br>
> DRI_CONF_SECTION_MISCELLANEOUS<br>
> DRI_CONF_ALWAYS_HAVE_DEPTH_BUFFER("false")<br>
> + DRI_CONF_GLSL_ZERO_INIT("false")<br>
> DRI_CONF_SECTION_END<br>
> DRI_CONF_END<br>
> };<br>
> @@ -98,6 +99,7 @@ dri_fill_st_options(struct st_config_options *options,<br>
> driQueryOptionb(optionCache, "force_s3tc_enable");<br>
> options->allow_glsl_extension_directive_midshader =<br>
> driQueryOptionb(optionCache, "allow_glsl_extension_directive_midshader");<br>
> + options->glsl_zero_init = driQueryOptionb(optionCache, "glsl_zero_init");<br>
> }<br>
><br>
> static const __DRIconfig **<br>
> diff --git a/src/mesa/drivers/dri/common/xmlpool/t_options.h b/src/mesa/drivers/dri/common/xmlpool/t_options.h<br>
> index 4b298a4..341c376 100644<br>
> --- a/src/mesa/drivers/dri/common/xmlpool/t_options.h<br>
> +++ b/src/mesa/drivers/dri/common/xmlpool/t_options.h<br>
> @@ -337,7 +337,10 @@ DRI_CONF_OPT_BEGIN_B(always_have_depth_buffer, def) \<br>
> DRI_CONF_DESC(en,gettext("Create all visuals with a depth buffer")) \<br>
> DRI_CONF_OPT_END<br>
><br>
> -<br>
> +#define DRI_CONF_GLSL_ZERO_INIT(def) \<br>
> +DRI_CONF_OPT_BEGIN_B(glsl_zero_init, def) \<br>
> + DRI_CONF_DESC(en,gettext("Force uninitialized variables to default to zero")) \<br>
> +DRI_CONF_OPT_END<br>
><br>
> /**<br>
> * \brief Initialization configuration options<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c<br>
> index c7a66cb..66d4e94 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_context.c<br>
> +++ b/src/mesa/drivers/dri/i965/brw_context.c<br>
> @@ -826,6 +826,8 @@ brw_process_driconf_options(struct brw_context *brw)<br>
> ctx->Const.AllowGLSLExtensionDirectiveMidShader =<br>
> driQueryOptionb(options, "allow_glsl_extension_directive_midshader");<br>
><br>
> + ctx->Const.GLSLZeroInit = driQueryOptionb(options, "glsl_zero_init");<br>
> +<br>
> brw->dual_color_blend_by_location =<br>
> driQueryOptionb(options, "dual_color_blend_by_location");<br>
> }<br>
> diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c<br>
> index 869119b..5aa28c6 100644<br>
> --- a/src/mesa/drivers/dri/i965/intel_screen.c<br>
> +++ b/src/mesa/drivers/dri/i965/intel_screen.c<br>
> @@ -88,6 +88,10 @@ DRI_CONF_BEGIN<br>
> DRI_CONF_DESC(en, "Perform code generation at shader link time.")<br>
> DRI_CONF_OPT_END<br>
> DRI_CONF_SECTION_END<br>
> +<br>
> + DRI_CONF_SECTION_MISCELLANEOUS<br>
> + DRI_CONF_GLSL_ZERO_INIT("false")<br>
> + DRI_CONF_SECTION_END<br>
> DRI_CONF_END<br>
> };<br>
><br>
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h<br>
> index 73ae55d..2210658 100644<br>
> --- a/src/mesa/main/mtypes.h<br>
> +++ b/src/mesa/main/mtypes.h<br>
> @@ -3514,6 +3514,11 @@ struct gl_constants<br>
> GLboolean AllowGLSLExtensionDirectiveMidShader;<br>
><br>
> /**<br>
> + * Force uninitialized variables to default to zero.<br>
> + */<br>
> + GLboolean GLSLZeroInit;<br>
> +<br>
> + /**<br>
> * Does the driver support real 32-bit integers? (Otherwise, integers are<br>
> * simulated via floats.)<br>
> */<br>
> diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c<br>
> index 412f598..e56d282 100644<br>
> --- a/src/mesa/state_tracker/st_extensions.c<br>
> +++ b/src/mesa/state_tracker/st_extensions.c<br>
> @@ -926,6 +926,8 @@ void st_init_extensions(struct pipe_screen *screen,<br>
> extensions->EXT_texture_integer = GL_FALSE;<br>
> }<br>
><br>
> + consts->GLSLZeroInit = options->glsl_zero_init;<br>
> +<br>
> consts->UniformBooleanTrue = consts->NativeIntegers ? ~0U : fui(1.0f);<br>
><br>
> /* Below are the cases which cannot be moved into tables easily. */<br>
><br>
<br>
</div></div></blockquote></div><br></div></div>