mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-21 23:11:01 +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.
77 lines
2.4 KiB
Plaintext
77 lines
2.4 KiB
Plaintext
// language: metal2.0
|
|
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
|
|
struct _mslBufferSizes {
|
|
metal::uint size0;
|
|
};
|
|
|
|
struct type3 {
|
|
metal::uint2 inner[2];
|
|
};
|
|
typedef int type5[1];
|
|
struct Bar {
|
|
metal::float4x4 matrix;
|
|
metal::atomic_int atom;
|
|
char _pad2[4];
|
|
type3 arr;
|
|
type5 data;
|
|
};
|
|
struct type9 {
|
|
int inner[5];
|
|
};
|
|
|
|
struct fooInput {
|
|
};
|
|
struct fooOutput {
|
|
metal::float4 member [[position]];
|
|
};
|
|
vertex fooOutput foo(
|
|
metal::uint vi [[vertex_id]]
|
|
, device Bar& bar [[buffer(0)]]
|
|
, constant _mslBufferSizes& _buffer_sizes [[buffer(24)]]
|
|
) {
|
|
float foo1 = 0.0;
|
|
type9 c;
|
|
float baz = foo1;
|
|
foo1 = 1.0;
|
|
metal::float4x4 matrix = bar.matrix;
|
|
type3 arr = bar.arr;
|
|
float b = bar.matrix[3].x;
|
|
int a = bar.data[(1 + (_buffer_sizes.size0 - 88 - 4) / 4) - 2u];
|
|
bar.matrix[1].z = 1.0;
|
|
bar.matrix = metal::float4x4(metal::float4(0.0), metal::float4(1.0), metal::float4(2.0), metal::float4(3.0));
|
|
for(int _i=0; _i<2; ++_i) bar.arr.inner[_i] = type3 {metal::uint2(0u), metal::uint2(1u)}.inner[_i];
|
|
for(int _i=0; _i<5; ++_i) c.inner[_i] = type9 {a, static_cast<int>(b), 3, 4, 5}.inner[_i];
|
|
c.inner[vi + 1u] = 42;
|
|
int value = c.inner[vi];
|
|
return fooOutput { matrix * static_cast<metal::float4>(metal::int4(value)) };
|
|
}
|
|
|
|
|
|
kernel void atomics(
|
|
device Bar& bar [[buffer(0)]]
|
|
, constant _mslBufferSizes& _buffer_sizes [[buffer(24)]]
|
|
) {
|
|
int tmp;
|
|
int value = metal::atomic_load_explicit(&bar.atom, metal::memory_order_relaxed);
|
|
int _e6 = metal::atomic_fetch_add_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e6;
|
|
int _e9 = metal::atomic_fetch_sub_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e9;
|
|
int _e12 = metal::atomic_fetch_and_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e12;
|
|
int _e15 = metal::atomic_fetch_or_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e15;
|
|
int _e18 = metal::atomic_fetch_xor_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e18;
|
|
int _e21 = metal::atomic_fetch_min_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e21;
|
|
int _e24 = metal::atomic_fetch_max_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e24;
|
|
int _e27 = metal::atomic_exchange_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e27;
|
|
metal::atomic_store_explicit(&bar.atom, value, metal::memory_order_relaxed);
|
|
return;
|
|
}
|