aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Eric Pelloux-Prayer <[email protected]>2020-04-24 17:55:38 +0200
committerPierre-Eric Pelloux-Prayer <[email protected]>2020-05-05 12:26:02 +0200
commitfa6b22d36a915f27dee576063aead9e2c577f966 (patch)
treebae7effb2dc5f8357cf2e96b2ebac20f66539e98
parent84f58a08634d0ea07f557ffa5b91c9c8777a2b04 (diff)
glsl: rework zero initialization
This commit makes zero_init a bitfield of types of variables to zeroinit. This will allow some flexibility that will be used in the next commit. Reviewed-by: Marek Olšák <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4607>
-rw-r--r--src/compiler/glsl/ast_to_hir.cpp13
-rw-r--r--src/compiler/glsl/glsl_parser_extras.cpp6
-rw-r--r--src/compiler/glsl/glsl_parser_extras.h3
3 files changed, 16 insertions, 6 deletions
diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index 9cd3af83a48..fb7c2cce924 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -5265,10 +5265,8 @@ ast_declarator_list::hir(exec_list *instructions,
apply_layout_qualifier_to_variable(&this->type->qualifier, var, state,
&loc);
- if ((var->data.mode == ir_var_auto || var->data.mode == ir_var_temporary
- || var->data.mode == ir_var_shader_out)
- && (var->type->is_numeric() || var->type->is_boolean())
- && state->zero_init) {
+ if ((state->zero_init & (1u << var->data.mode)) &&
+ (var->type->is_numeric() || var->type->is_boolean())) {
const ir_constant_data data = { { 0 } };
var->data.has_initializer = true;
var->constant_initializer = new(var) ir_constant(var->type, &data);
@@ -5861,6 +5859,13 @@ ast_parameter_declarator::hir(exec_list *instructions,
apply_type_qualifier_to_variable(& this->type->qualifier, var, state, & loc,
true);
+ if (((1u << var->data.mode) & state->zero_init) &&
+ (var->type->is_numeric() || var->type->is_boolean())) {
+ const ir_constant_data data = { { 0 } };
+ var->data.has_initializer = true;
+ var->constant_initializer = new(var) ir_constant(var->type, &data);
+ }
+
/* From section 4.1.7 of the GLSL 4.40 spec:
*
* "Opaque variables cannot be treated as l-values; hence cannot
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index c394f00480a..5b8e5b4c48f 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -82,7 +82,11 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
/* Set default language version and extensions */
this->language_version = 110;
this->forced_language_version = ctx->Const.ForceGLSLVersion;
- this->zero_init = ctx->Const.GLSLZeroInit;
+ if (ctx->Const.GLSLZeroInit == 1) {
+ this->zero_init = (1u << ir_var_auto) | (1u << ir_var_temporary) | (1u << ir_var_shader_out);
+ } else {
+ this->zero_init = 0;
+ }
this->gl_version = 20;
this->compat_shader = true;
this->es_shader = false;
diff --git a/src/compiler/glsl/glsl_parser_extras.h b/src/compiler/glsl/glsl_parser_extras.h
index 49e1f1e2a51..bdc0d9ab827 100644
--- a/src/compiler/glsl/glsl_parser_extras.h
+++ b/src/compiler/glsl/glsl_parser_extras.h
@@ -388,7 +388,8 @@ struct _mesa_glsl_parse_state {
bool compat_shader;
unsigned language_version;
unsigned forced_language_version;
- bool zero_init;
+ /* Bitfield of ir_variable_mode to zero init */
+ uint32_t zero_init;
unsigned gl_version;
gl_shader_stage stage;