From 9a2d66f5a55ebcf814e459542c8a63b27e515b64 Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Thu, 2 Mar 2023 10:11:54 -0800 Subject: [PATCH] glsl: Simplify vector constructors from scalars. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No need to generate a temp in this case. Cleanup I noticed while looking at lower_precision behavior (and I've included a testcase to sanity check that things work out). This causes a tiny amount of scheduling change on freedreno: total instructions in shared programs: 11010012 -> 11010012 (0.00%) instructions in affected programs: 147 -> 147 (0.00%) Reviewed-by: Marek Olšák Part-of: --- src/compiler/glsl/ast_function.cpp | 10 +--------- src/compiler/glsl/tests/lower_precision_test.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/compiler/glsl/ast_function.cpp b/src/compiler/glsl/ast_function.cpp index f1c9ee99d85..64c7517b4cc 100644 --- a/src/compiler/glsl/ast_function.cpp +++ b/src/compiler/glsl/ast_function.cpp @@ -1455,15 +1455,7 @@ emit_inline_vector_constructor(const glsl_type *type, const unsigned lhs_components = type->components(); if (single_scalar_parameter(parameters)) { ir_rvalue *first_param = (ir_rvalue *)parameters->get_head_raw(); - ir_rvalue *rhs = new(ctx) ir_swizzle(first_param, 0, 0, 0, 0, - lhs_components); - ir_dereference_variable *lhs = new(ctx) ir_dereference_variable(var); - const unsigned mask = (1U << lhs_components) - 1; - - assert(rhs->type == lhs->type); - - ir_instruction *inst = new(ctx) ir_assignment(lhs, rhs, mask); - instructions->push_tail(inst); + return new(ctx) ir_swizzle(first_param, 0, 0, 0, 0, lhs_components); } else { unsigned base_component = 0; unsigned base_lhs_component = 0; diff --git a/src/compiler/glsl/tests/lower_precision_test.py b/src/compiler/glsl/tests/lower_precision_test.py index b968ce37245..fcb85f90b5a 100644 --- a/src/compiler/glsl/tests/lower_precision_test.py +++ b/src/compiler/glsl/tests/lower_precision_test.py @@ -2274,6 +2274,19 @@ TESTS = [ } """, r'\(constant uint \(3'), # should be uint16_t + + Test("vec4 constructor from float", + """ + uniform highp float a; + uniform mediump float b; + + void main() + { + gl_FragColor = vec4(a) * b; + } + """, + r'\(expression vec4 \* \(swiz xxxx \(var_ref a\) \)\(expression float f162f \(var_ref b\) \) \)'), + ]