Mesa (master): mesa: extend GLSLZeroInit semantics
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue May 5 11:35:12 UTC 2020
Module: Mesa
Branch: master
Commit: ea289d1502dc5739ec9bf69328c037b72dc02789
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=ea289d1502dc5739ec9bf69328c037b72dc02789
Author: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Date: Fri Apr 24 18:32:02 2020 +0200
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 at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4607>
---
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;
More information about the mesa-commit
mailing list