summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Ślusarz <marcin.slusarz@intel.com>2021-08-06 10:49:29 +0200
committerEric Engestrom <eric@engestrom.ch>2021-08-10 22:40:25 +0100
commitfa80586e180b3defcdc776006714d5fe7efcdc16 (patch)
tree4a00826f46545cd243786c4531d85dcb9dc10b7d
parent85a95f8cc6f5c750ebc1ea28ca3bd4c140bcc501 (diff)
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@intel.com> Cc: mesa-stable Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com> Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12234> (cherry picked from commit bdae3c366e1b8bda26702fdbdf9e6d8fab446cb2)
-rw-r--r--.pick_status.json2
-rw-r--r--src/compiler/glsl/ast.h3
-rw-r--r--src/compiler/glsl/ast_to_hir.cpp16
-rw-r--r--src/compiler/glsl/glsl_parser_extras.cpp1
4 files changed, 16 insertions, 6 deletions
diff --git a/.pick_status.json b/.pick_status.json
index ec79f1ec43f..eae7c062177 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -157,7 +157,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 6808a4e72b6..fc0b64ca199 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;
}