mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-30 10:03:58 +01:00
Use the local (not global) invocation id to decide which invocation should do the initialization, so that every workgroup gets initialized, not just the first.
266 lines
7.7 KiB
Plaintext
266 lines
7.7 KiB
Plaintext
// language: metal2.0
|
|
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
|
|
using metal::uint;
|
|
|
|
struct _mslBufferSizes {
|
|
uint size1;
|
|
};
|
|
|
|
struct GlobalConst {
|
|
uint a;
|
|
char _pad1[12];
|
|
metal::packed_uint3 b;
|
|
int c;
|
|
};
|
|
struct AlignedWrapper {
|
|
int value;
|
|
};
|
|
struct type_5 {
|
|
metal::float2x2 inner[2];
|
|
};
|
|
struct type_7 {
|
|
metal::atomic_int inner[10];
|
|
};
|
|
struct type_9 {
|
|
metal::uint2 inner[2];
|
|
};
|
|
typedef AlignedWrapper type_10[1];
|
|
struct Bar {
|
|
metal::float4x3 _matrix;
|
|
type_5 matrix_array;
|
|
metal::atomic_int atom;
|
|
type_7 atom_arr;
|
|
char _pad4[4];
|
|
type_9 arr;
|
|
type_10 data;
|
|
};
|
|
struct Baz {
|
|
metal::float3x2 m;
|
|
};
|
|
struct type_15 {
|
|
metal::float4x2 inner[2];
|
|
};
|
|
struct MatCx2InArray {
|
|
type_15 am;
|
|
};
|
|
struct type_18 {
|
|
float inner[10];
|
|
};
|
|
struct type_19 {
|
|
type_18 inner[5];
|
|
};
|
|
struct type_22 {
|
|
int inner[5];
|
|
};
|
|
struct type_26 {
|
|
metal::float4 inner[2];
|
|
};
|
|
constant metal::uint3 const_type_1_ = {0u, 0u, 0u};
|
|
constant GlobalConst const_GlobalConst = {0u, {}, const_type_1_, 0};
|
|
constant metal::float2 const_type_13_ = {0.0, 0.0};
|
|
constant metal::float4x2 const_type_14_ = {const_type_13_, const_type_13_, const_type_13_, const_type_13_};
|
|
constant type_15 const_type_15_ = {const_type_14_, const_type_14_};
|
|
constant type_18 const_type_18_ = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
|
constant type_19 const_type_19_ = {const_type_18_, const_type_18_, const_type_18_, const_type_18_, const_type_18_};
|
|
constant metal::int2 const_type_12_ = {0, 0};
|
|
|
|
void test_matrix_within_struct_accesses(
|
|
constant Baz& baz
|
|
) {
|
|
int idx = {};
|
|
Baz t = {};
|
|
idx = 1;
|
|
int _e2 = idx;
|
|
idx = _e2 - 1;
|
|
metal::float3x2 unnamed = baz.m;
|
|
metal::float2 unnamed_1 = baz.m[0];
|
|
int _e15 = idx;
|
|
metal::float2 unnamed_2 = baz.m[_e15];
|
|
float unnamed_3 = baz.m[0].y;
|
|
int _e29 = idx;
|
|
float unnamed_4 = baz.m[0][_e29];
|
|
int _e34 = idx;
|
|
float unnamed_5 = baz.m[_e34].y;
|
|
int _e41 = idx;
|
|
int _e43 = idx;
|
|
float unnamed_6 = baz.m[_e41][_e43];
|
|
t = Baz {metal::float3x2(metal::float2(1.0), metal::float2(2.0), metal::float2(3.0))};
|
|
int _e55 = idx;
|
|
idx = _e55 + 1;
|
|
t.m = metal::float3x2(metal::float2(6.0), metal::float2(5.0), metal::float2(4.0));
|
|
t.m[0] = metal::float2(9.0);
|
|
int _e72 = idx;
|
|
t.m[_e72] = metal::float2(90.0);
|
|
t.m[0].y = 10.0;
|
|
int _e85 = idx;
|
|
t.m[0][_e85] = 20.0;
|
|
int _e89 = idx;
|
|
t.m[_e89].y = 30.0;
|
|
int _e95 = idx;
|
|
int _e97 = idx;
|
|
t.m[_e95][_e97] = 40.0;
|
|
return;
|
|
}
|
|
|
|
void test_matrix_within_array_within_struct_accesses(
|
|
constant MatCx2InArray& nested_mat_cx2_
|
|
) {
|
|
int idx_1 = {};
|
|
MatCx2InArray t_1 = {};
|
|
idx_1 = 1;
|
|
int _e2 = idx_1;
|
|
idx_1 = _e2 - 1;
|
|
type_15 unnamed_7 = nested_mat_cx2_.am;
|
|
metal::float4x2 unnamed_8 = nested_mat_cx2_.am.inner[0];
|
|
metal::float2 unnamed_9 = nested_mat_cx2_.am.inner[0][0];
|
|
int _e24 = idx_1;
|
|
metal::float2 unnamed_10 = nested_mat_cx2_.am.inner[0][_e24];
|
|
float unnamed_11 = nested_mat_cx2_.am.inner[0][0].y;
|
|
int _e42 = idx_1;
|
|
float unnamed_12 = nested_mat_cx2_.am.inner[0][0][_e42];
|
|
int _e49 = idx_1;
|
|
float unnamed_13 = nested_mat_cx2_.am.inner[0][_e49].y;
|
|
int _e58 = idx_1;
|
|
int _e60 = idx_1;
|
|
float unnamed_14 = nested_mat_cx2_.am.inner[0][_e58][_e60];
|
|
t_1 = MatCx2InArray {const_type_15_};
|
|
int _e66 = idx_1;
|
|
idx_1 = _e66 + 1;
|
|
for(int _i=0; _i<2; ++_i) t_1.am.inner[_i] = const_type_15_.inner[_i];
|
|
t_1.am.inner[0] = metal::float4x2(metal::float2(8.0), metal::float2(7.0), metal::float2(6.0), metal::float2(5.0));
|
|
t_1.am.inner[0][0] = metal::float2(9.0);
|
|
int _e93 = idx_1;
|
|
t_1.am.inner[0][_e93] = metal::float2(90.0);
|
|
t_1.am.inner[0][0].y = 10.0;
|
|
int _e110 = idx_1;
|
|
t_1.am.inner[0][0][_e110] = 20.0;
|
|
int _e116 = idx_1;
|
|
t_1.am.inner[0][_e116].y = 30.0;
|
|
int _e124 = idx_1;
|
|
int _e126 = idx_1;
|
|
t_1.am.inner[0][_e124][_e126] = 40.0;
|
|
return;
|
|
}
|
|
|
|
float read_from_private(
|
|
thread float& foo_1
|
|
) {
|
|
float _e1 = foo_1;
|
|
return _e1;
|
|
}
|
|
|
|
float test_arr_as_arg(
|
|
type_19 a
|
|
) {
|
|
return a.inner[4].inner[9];
|
|
}
|
|
|
|
void assign_through_ptr_fn(
|
|
threadgroup uint& p
|
|
) {
|
|
p = 42u;
|
|
return;
|
|
}
|
|
|
|
void assign_array_through_ptr_fn(
|
|
thread type_26& foo_2
|
|
) {
|
|
for(int _i=0; _i<2; ++_i) foo_2.inner[_i] = type_26 {metal::float4(1.0), metal::float4(2.0)}.inner[_i];
|
|
return;
|
|
}
|
|
|
|
struct foo_vertInput {
|
|
};
|
|
struct foo_vertOutput {
|
|
metal::float4 member [[position]];
|
|
};
|
|
vertex foo_vertOutput foo_vert(
|
|
uint vi [[vertex_id]]
|
|
, device Bar const& bar [[buffer(0)]]
|
|
, constant Baz& baz [[buffer(1)]]
|
|
, device metal::int2 const& qux [[buffer(2)]]
|
|
, constant MatCx2InArray& nested_mat_cx2_ [[buffer(3)]]
|
|
, constant _mslBufferSizes& _buffer_sizes [[buffer(24)]]
|
|
) {
|
|
float foo = {};
|
|
type_22 c2_ = {};
|
|
foo = 0.0;
|
|
float baz_1 = foo;
|
|
foo = 1.0;
|
|
test_matrix_within_struct_accesses(baz);
|
|
test_matrix_within_array_within_struct_accesses(nested_mat_cx2_);
|
|
metal::float4x3 _matrix = bar._matrix;
|
|
type_9 arr_1 = bar.arr;
|
|
float b = bar._matrix[3].x;
|
|
int a_1 = bar.data[(1 + (_buffer_sizes.size1 - 160 - 8) / 8) - 2u].value;
|
|
metal::int2 c = qux;
|
|
float _e34 = read_from_private(foo);
|
|
for(int _i=0; _i<5; ++_i) c2_.inner[_i] = type_22 {a_1, static_cast<int>(b), 3, 4, 5}.inner[_i];
|
|
c2_.inner[vi + 1u] = 42;
|
|
int value = c2_.inner[vi];
|
|
float _e48 = test_arr_as_arg(const_type_19_);
|
|
return foo_vertOutput { metal::float4(_matrix * static_cast<metal::float4>(metal::int4(value)), 2.0) };
|
|
}
|
|
|
|
|
|
struct foo_fragOutput {
|
|
metal::float4 member_1 [[color(0)]];
|
|
};
|
|
fragment foo_fragOutput foo_frag(
|
|
device Bar& bar [[buffer(0)]]
|
|
, device metal::int2& qux [[buffer(2)]]
|
|
, constant _mslBufferSizes& _buffer_sizes [[buffer(24)]]
|
|
) {
|
|
bar._matrix[1].z = 1.0;
|
|
bar._matrix = metal::float4x3(metal::float3(0.0), metal::float3(1.0), metal::float3(2.0), metal::float3(3.0));
|
|
for(int _i=0; _i<2; ++_i) bar.arr.inner[_i] = type_9 {metal::uint2(0u), metal::uint2(1u)}.inner[_i];
|
|
bar.data[1].value = 1;
|
|
qux = const_type_12_;
|
|
return foo_fragOutput { metal::float4(0.0) };
|
|
}
|
|
|
|
|
|
kernel void atomics(
|
|
device Bar& bar [[buffer(0)]]
|
|
, constant _mslBufferSizes& _buffer_sizes [[buffer(24)]]
|
|
) {
|
|
int tmp = {};
|
|
int value_1 = metal::atomic_load_explicit(&bar.atom, metal::memory_order_relaxed);
|
|
int _e7 = metal::atomic_fetch_add_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e7;
|
|
int _e11 = metal::atomic_fetch_sub_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e11;
|
|
int _e15 = metal::atomic_fetch_and_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e15;
|
|
int _e19 = metal::atomic_fetch_or_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e19;
|
|
int _e23 = metal::atomic_fetch_xor_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e23;
|
|
int _e27 = metal::atomic_fetch_min_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e27;
|
|
int _e31 = metal::atomic_fetch_max_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e31;
|
|
int _e35 = metal::atomic_exchange_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e35;
|
|
metal::atomic_store_explicit(&bar.atom, value_1, metal::memory_order_relaxed);
|
|
return;
|
|
}
|
|
|
|
|
|
kernel void assign_through_ptr(
|
|
metal::uint3 __local_invocation_id [[thread_position_in_threadgroup]]
|
|
, threadgroup uint& val
|
|
) {
|
|
if (metal::all(__local_invocation_id == metal::uint3(0u))) {
|
|
val = {};
|
|
}
|
|
metal::threadgroup_barrier(metal::mem_flags::mem_threadgroup);
|
|
type_26 arr = {};
|
|
for(int _i=0; _i<2; ++_i) arr.inner[_i] = type_26 {metal::float4(6.0), metal::float4(7.0)}.inner[_i];
|
|
assign_through_ptr_fn(val);
|
|
assign_array_through_ptr_fn(arr);
|
|
return;
|
|
}
|