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->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;
}
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");
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.
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;