glsl: Simplify vector constructors from scalars.

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>
This commit is contained in:
Emma Anholt
2023-03-02 10:11:54 -08:00
committed by Marge Bot
parent 92ea49edcb
commit 9a2d66f5a5
2 changed files with 14 additions and 9 deletions
+1 -9
View 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;
@@ -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\) \) \)'),
]