mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-06-19 08:28:21 +02:00
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 bdae3c366e)
This commit is contained in:
parent
85a95f8cc6
commit
fa80586e18
4 changed files with 16 additions and 6 deletions
|
|
@ -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
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue