mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-21 15:00:57 +01:00
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.
59 lines
1.6 KiB
Plaintext
59 lines
1.6 KiB
Plaintext
// language: metal1.1
|
|
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
|
|
struct Foo {
|
|
metal::float4 a;
|
|
int b;
|
|
};
|
|
constant metal::float4 v_f32_one = {1.0, 1.0, 1.0, 1.0};
|
|
constant metal::float4 v_f32_zero = {0.0, 0.0, 0.0, 0.0};
|
|
constant metal::float4 v_f32_half = {0.5, 0.5, 0.5, 0.5};
|
|
constant metal::int4 v_i32_one = {1, 1, 1, 1};
|
|
|
|
metal::float4 builtins(
|
|
) {
|
|
int s1_ = true ? 1 : 0;
|
|
metal::float4 s2_ = true ? v_f32_one : v_f32_zero;
|
|
metal::float4 s3_ = metal::select(v_f32_one, v_f32_zero, metal::bool4(false, false, false, false));
|
|
metal::float4 m1_ = metal::mix(v_f32_zero, v_f32_one, v_f32_half);
|
|
metal::float4 m2_ = metal::mix(v_f32_zero, v_f32_one, 0.10000000149011612);
|
|
float b1_ = as_type<float>(v_i32_one.x);
|
|
metal::float4 b2_ = as_type<metal::float4>(v_i32_one);
|
|
metal::int4 v_i32_zero = static_cast<metal::int4>(v_f32_zero);
|
|
return ((((static_cast<metal::float4>(metal::int4(s1_) + v_i32_zero) + s2_) + m1_) + m2_) + metal::float4(b1_)) + b2_;
|
|
}
|
|
|
|
metal::float4 splat(
|
|
) {
|
|
metal::float2 a = ((metal::float2(1.0) + metal::float2(2.0)) - metal::float2(3.0)) / metal::float2(4.0);
|
|
metal::int4 b = metal::int4(5) % metal::int4(2);
|
|
return a.xyxy + static_cast<metal::float4>(b);
|
|
}
|
|
|
|
int unary(
|
|
) {
|
|
if (!true) {
|
|
return 1;
|
|
} else {
|
|
return !1;
|
|
}
|
|
}
|
|
|
|
float constructors(
|
|
) {
|
|
Foo foo;
|
|
foo = Foo {metal::float4(1.0), 1};
|
|
float _e11 = foo.a.x;
|
|
return _e11;
|
|
}
|
|
|
|
kernel void main1(
|
|
) {
|
|
metal::float4 _e4 = builtins();
|
|
metal::float4 _e5 = splat();
|
|
int _e6 = unary();
|
|
float _e7 = constructors();
|
|
return;
|
|
}
|