From ea289d1502dc5739ec9bf69328c037b72dc02789 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Fri, 24 Apr 2020 18:32:02 +0200 Subject: [PATCH] mesa: extend GLSLZeroInit semantics MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Part-of: --- src/compiler/glsl/glsl_parser_extras.cpp | 2 ++ src/mesa/drivers/dri/i965/brw_context.c | 2 +- src/mesa/main/mtypes.h | 4 ++-- src/mesa/state_tracker/st_extensions.c | 4 +++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp index 5b8e5b4c48f..e610fda002c 100644 --- a/src/compiler/glsl/glsl_parser_extras.cpp +++ b/src/compiler/glsl/glsl_parser_extras.cpp @@ -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; } diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c index c9fd56c547e..42a0c663b6e 100644 --- a/src/mesa/drivers/dri/i965/brw_context.c +++ b/src/mesa/drivers/dri/i965/brw_context.c @@ -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"); diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index a46eb72da9a..7046e8adfa3 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -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. diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index 6b102074bfb..2403bd60a8c 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -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; -- 2.30.2