mesa: extend GLSLZeroInit semantics

This commit introduces a new way to zero-init variables but keep the
old one to not break any existing behavior.

With this change GLSLZeroInit becomes an integer, with the following
possible values:
 - 0: no 0 init
 - 1: current behavior
 - 2: new behavior. Similar to 1, except ir_var_function_out type are
      0 initialized but ir_var_shader_out.

The rationale behind 2 is: zero initializing ir_var_shader_out can
prevent some optimization where out variables are completely eliminated
when not written to.

On the other hand, zero initializing "ir_var_function_out" has no
effect on correct shaders but typically helps shadertoy since the main
function is:

   void mainImage(out vec4 fragColor) { ... }

So with this change we're sure that fragColor will always get a value.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4607>
This commit is contained in:
Pierre-Eric Pelloux-Prayer
2020-04-24 18:32:02 +02:00
parent 679421628b
commit ea289d1502
4 changed files with 8 additions and 4 deletions
+2
View File
@@ -84,6 +84,8 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
this->forced_language_version = ctx->Const.ForceGLSLVersion;
if (ctx->Const.GLSLZeroInit == 1) {
this->zero_init = (1u << ir_var_auto) | (1u << ir_var_temporary) | (1u << ir_var_shader_out);
} else if (ctx->Const.GLSLZeroInit == 2) {
this->zero_init = (1u << ir_var_auto) | (1u << ir_var_temporary) | (1u << ir_var_function_out);
} else {
this->zero_init = 0;
}
+1 -1
View File
@@ -924,7 +924,7 @@ brw_process_driconf_options(struct brw_context *brw)
ctx->Const.ForceGLSLAbsSqrt =
driQueryOptionb(options, "force_glsl_abs_sqrt");
ctx->Const.GLSLZeroInit = driQueryOptionb(options, "glsl_zero_init");
ctx->Const.GLSLZeroInit = driQueryOptionb(options, "glsl_zero_init") ? 1 : 0;
brw->dual_color_blend_by_location =
driQueryOptionb(options, "dual_color_blend_by_location");
+2 -2
View File
@@ -3868,9 +3868,9 @@ struct gl_constants
GLboolean ForceGLSLAbsSqrt;
/**
* Force uninitialized variables to default to zero.
* Types of variable to default initialized to zero.
*/
GLboolean GLSLZeroInit;
GLuint GLSLZeroInit;
/**
* Treat integer textures using GL_LINEAR filters as GL_NEAREST.
+3 -1
View File
@@ -1203,7 +1203,9 @@ void st_init_extensions(struct pipe_screen *screen,
extensions->EXT_texture_integer = GL_FALSE;
}
consts->GLSLZeroInit = options->glsl_zero_init;
if (options->glsl_zero_init) {
consts->GLSLZeroInit = 1;
}
consts->ForceIntegerTexNearest = options->force_integer_tex_nearest;