Mesa (staging/21.2): glsl: evaluate switch expression once
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Aug 10 17:38:28 UTC 2021
Module: Mesa
Branch: staging/21.2
Commit: b17e7ddbaeede47a2f7610b774dd5039bf433814
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=b17e7ddbaeede47a2f7610b774dd5039bf433814
Author: Marcin Ślusarz <marcin.slusarz at intel.com>
Date: Fri Aug 6 10:49:29 2021 +0200
glsl: evaluate switch expression once
v2: intialize test_val in constructor
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5185
Signed-off-by: Marcin Ślusarz <marcin.slusarz at intel.com>
Cc: mesa-stable
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12234>
(cherry picked from commit bdae3c366e1b8bda26702fdbdf9e6d8fab446cb2)
---
.pick_status.json | 2 +-
src/compiler/glsl/ast.h | 3 +++
src/compiler/glsl/ast_to_hir.cpp | 16 +++++++++++-----
src/compiler/glsl/glsl_parser_extras.cpp | 1 +
4 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/.pick_status.json b/.pick_status.json
index 7fd6ada5674..923e8bd9c28 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -76,7 +76,7 @@
"description": "glsl: evaluate switch expression once",
"nominated": true,
"nomination_type": 0,
- "resolution": 0,
+ "resolution": 1,
"main_sha": null,
"because_sha": null
},
diff --git a/src/compiler/glsl/ast.h b/src/compiler/glsl/ast.h
index 3a960c2ff32..c6b578cb894 100644
--- a/src/compiler/glsl/ast.h
+++ b/src/compiler/glsl/ast.h
@@ -1170,6 +1170,9 @@ public:
protected:
void test_to_hir(exec_list *, struct _mesa_glsl_parse_state *);
+ void eval_test_expression(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state);
+ ir_rvalue *test_val;
};
class ast_iteration_statement : public ast_node {
diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp
index 2ab21f2ffaa..370f6934bd4 100644
--- a/src/compiler/glsl/ast_to_hir.cpp
+++ b/src/compiler/glsl/ast_to_hir.cpp
@@ -6678,6 +6678,13 @@ key_contents(const void *key)
return ((struct case_label *) key)->value;
}
+void
+ast_switch_statement::eval_test_expression(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state)
+{
+ if (test_val == NULL)
+ test_val = this->test_expression->hir(instructions, state);
+}
ir_rvalue *
ast_switch_statement::hir(exec_list *instructions,
@@ -6685,16 +6692,15 @@ ast_switch_statement::hir(exec_list *instructions,
{
void *ctx = state;
- ir_rvalue *const test_expression =
- this->test_expression->hir(instructions, state);
+ this->eval_test_expression(instructions, state);
/* From page 66 (page 55 of the PDF) of the GLSL 1.50 spec:
*
* "The type of init-expression in a switch statement must be a
* scalar integer."
*/
- if (!test_expression->type->is_scalar() ||
- !test_expression->type->is_integer_32()) {
+ if (!test_val->type->is_scalar() ||
+ !test_val->type->is_integer_32()) {
YYLTYPE loc = this->test_expression->get_location();
_mesa_glsl_error(& loc,
@@ -6807,7 +6813,7 @@ ast_switch_statement::test_to_hir(exec_list *instructions,
*/
test_expression->set_is_lhs(true);
/* Cache value of test expression. */
- ir_rvalue *const test_val = test_expression->hir(instructions, state);
+ this->eval_test_expression(instructions, state);
state->switch_state.test_var = new(ctx) ir_variable(test_val->type,
"switch_test_tmp",
diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
index 44c041633d2..35dd433bc89 100644
--- a/src/compiler/glsl/glsl_parser_extras.cpp
+++ b/src/compiler/glsl/glsl_parser_extras.cpp
@@ -1595,6 +1595,7 @@ ast_switch_statement::ast_switch_statement(ast_expression *test_expression,
{
this->test_expression = test_expression;
this->body = body;
+ this->test_val = NULL;
}
More information about the mesa-commit
mailing list