glsl: Simplify vector constructors from scalars.
authorEmma Anholt <emma@anholt.net>
Thu, 2 Mar 2023 18:11:54 +0000 (10:11 -0800)
committerMarge Bot <emma+marge@anholt.net>
Tue, 21 Mar 2023 00:51:24 +0000 (00:51 +0000)
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 <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21666>

src/compiler/glsl/ast_function.cpp
src/compiler/glsl/tests/lower_precision_test.py

index f1c9ee9..64c7517 100644 (file)
@@ -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;
index b968ce3..fcb85f9 100644 (file)
@@ -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\) \) \)'),
+
 ]