From fa6b22d36a915f27dee576063aead9e2c577f966 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Fri, 24 Apr 2020 17:55:38 +0200 Subject: [PATCH] glsl: rework zero initialization MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Part-of: --- src/compiler/glsl/ast_to_hir.cpp | 13 +++++++++---- src/compiler/glsl/glsl_parser_extras.cpp | 6 +++++- src/compiler/glsl/glsl_parser_extras.h | 3 ++- 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 9cd3af8..fb7c2cc 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 c394f00..5b8e5b4 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 49e1f1e..bdc0d9a 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; -- 2.7.4