Files
wgpu/tests/out/hlsl/operators.hlsl
T
Jim Blandy 3fdd8592fc [wgsl-in] Rework Load Rule handling and indirection.
Make the parser code more closely follow the spec's grammar around
`unary_expression`, `postfix_expression`, and `singular_expression`.

Change the handling of postfix expressions (indexing, member/component access,
and swizzling) to apply the indirection at the appropriate time, resulting in
code improvements on all output formats. For example, where we used to generate
the following MSL:

    metal::float4 _e13 = bar.matrix[3];
    float b = _e13.x;

we now generate, simply:

    float b = bar.matrix[3].x;

Propagate WGSL reference types correctly, so that parenthesizing expressions no
longer causes the Load Rule to be applied.

Together with #1332 (already landed), this is a replacement for #1312, and
unblocks #1352.

Fixes #1351.
2021-09-14 16:17:57 -04:00

65 lines
1.6 KiB
HLSL

static const float4 v_f32_one = float4(1.0, 1.0, 1.0, 1.0);
static const float4 v_f32_zero = float4(0.0, 0.0, 0.0, 0.0);
static const float4 v_f32_half = float4(0.5, 0.5, 0.5, 0.5);
static const int4 v_i32_one = int4(1, 1, 1, 1);
struct Foo {
float4 a;
int b;
};
float4 builtins()
{
int s1_ = (true ? 1 : 0);
float4 s2_ = (true ? float4(1.0, 1.0, 1.0, 1.0) : float4(0.0, 0.0, 0.0, 0.0));
float4 s3_ = (bool4(false, false, false, false) ? float4(0.0, 0.0, 0.0, 0.0) : float4(1.0, 1.0, 1.0, 1.0));
float4 m1_ = lerp(float4(0.0, 0.0, 0.0, 0.0), float4(1.0, 1.0, 1.0, 1.0), float4(0.5, 0.5, 0.5, 0.5));
float4 m2_ = lerp(float4(0.0, 0.0, 0.0, 0.0), float4(1.0, 1.0, 1.0, 1.0), 0.10000000149011612);
float b1_ = float(int4(1, 1, 1, 1).x);
float4 b2_ = float4(int4(1, 1, 1, 1));
int4 v_i32_zero = int4(float4(0.0, 0.0, 0.0, 0.0));
return (((((float4((int4(s1_.xxxx) + v_i32_zero)) + s2_) + m1_) + m2_) + float4(b1_.xxxx)) + b2_);
}
float4 splat()
{
float2 a = (((float2(1.0.xx) + float2(2.0.xx)) - float2(3.0.xx)) / float2(4.0.xx));
int4 b = (int4(5.xxxx) % int4(2.xxxx));
return (a.xyxy + float4(b));
}
int unary()
{
if (!true) {
return 1;
} else {
return !1;
}
}
Foo ConstructFoo(float4 arg0, int arg1) {
Foo ret;
ret.a = arg0;
ret.b = arg1;
return ret;
}
float constructors()
{
Foo foo = (Foo)0;
foo = ConstructFoo(float4(1.0.xxxx), 1);
float _expr11 = foo.a.x;
return _expr11;
}
[numthreads(1, 1, 1)]
void main()
{
const float4 _e4 = builtins();
const float4 _e5 = splat();
const int _e6 = unary();
const float _e7 = constructors();
return;
}