mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-29 01:23:57 +01:00
* [hlsl-out] fix matCx2 as global uniform * [hlsl-out] update comments * [hlsl-out] fix `row_major` not being written on global arrays of matrices and also write it on nested arrays of matrices * [hlsl-out] fix matCx2's nested inside global arrays * [hlsl-out] fix struct members of type array<matCx2> * [hlsl-out] test mat2x4 to make sure our matCx2 code behaves properly
241 lines
6.9 KiB
Plaintext
241 lines
6.9 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_8 {
|
|
metal::uint2 inner[2];
|
|
};
|
|
typedef AlignedWrapper type_9[1];
|
|
struct Bar {
|
|
metal::float4x3 _matrix;
|
|
type_5 matrix_array;
|
|
metal::atomic_int atom;
|
|
char _pad3[4];
|
|
type_8 arr;
|
|
type_9 data;
|
|
};
|
|
struct Baz {
|
|
metal::float3x2 m;
|
|
};
|
|
struct type_13 {
|
|
metal::float4x2 inner[2];
|
|
};
|
|
struct MatCx2InArray {
|
|
type_13 am;
|
|
};
|
|
struct type_17 {
|
|
float inner[10];
|
|
};
|
|
struct type_18 {
|
|
type_17 inner[5];
|
|
};
|
|
struct type_21 {
|
|
int inner[5];
|
|
};
|
|
constant metal::uint3 const_type_1_ = {0u, 0u, 0u};
|
|
constant GlobalConst const_GlobalConst = {0u, {}, const_type_1_, 0};
|
|
constant metal::float2 const_type_14_ = {0.0, 0.0};
|
|
constant metal::float4x2 const_type_12_ = {const_type_14_, const_type_14_, const_type_14_, const_type_14_};
|
|
constant type_13 const_type_13_ = {const_type_12_, const_type_12_};
|
|
constant type_17 const_type_17_ = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
|
constant type_18 const_type_18_ = {const_type_17_, const_type_17_, const_type_17_, const_type_17_, const_type_17_};
|
|
constant metal::int2 const_type_11_ = {0, 0};
|
|
|
|
void test_matrix_within_struct_accesses(
|
|
constant Baz& baz
|
|
) {
|
|
int idx = 1;
|
|
Baz t = {};
|
|
int _e6 = idx;
|
|
idx = _e6 - 1;
|
|
metal::float3x2 unnamed = baz.m;
|
|
metal::float2 unnamed_1 = baz.m[0];
|
|
int _e16 = idx;
|
|
metal::float2 unnamed_2 = baz.m[_e16];
|
|
float unnamed_3 = baz.m[0].y;
|
|
int _e28 = idx;
|
|
float unnamed_4 = baz.m[0][_e28];
|
|
int _e32 = idx;
|
|
float unnamed_5 = baz.m[_e32].y;
|
|
int _e38 = idx;
|
|
int _e40 = idx;
|
|
float unnamed_6 = baz.m[_e38][_e40];
|
|
t = Baz {metal::float3x2(metal::float2(1.0), metal::float2(2.0), metal::float2(3.0))};
|
|
int _e52 = idx;
|
|
idx = _e52 + 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 _e69 = idx;
|
|
t.m[_e69] = metal::float2(90.0);
|
|
t.m[0].y = 10.0;
|
|
int _e82 = idx;
|
|
t.m[0][_e82] = 20.0;
|
|
int _e86 = idx;
|
|
t.m[_e86].y = 30.0;
|
|
int _e92 = idx;
|
|
int _e94 = idx;
|
|
t.m[_e92][_e94] = 40.0;
|
|
return;
|
|
}
|
|
|
|
void test_matrix_within_array_within_struct_accesses(
|
|
constant MatCx2InArray& nested_mat_cx2_
|
|
) {
|
|
int idx_1 = 1;
|
|
MatCx2InArray t_1 = {};
|
|
int _e7 = idx_1;
|
|
idx_1 = _e7 - 1;
|
|
type_13 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 _e25 = idx_1;
|
|
metal::float2 unnamed_10 = nested_mat_cx2_.am.inner[0][_e25];
|
|
float unnamed_11 = nested_mat_cx2_.am.inner[0][0].y;
|
|
int _e41 = idx_1;
|
|
float unnamed_12 = nested_mat_cx2_.am.inner[0][0][_e41];
|
|
int _e47 = idx_1;
|
|
float unnamed_13 = nested_mat_cx2_.am.inner[0][_e47].y;
|
|
int _e55 = idx_1;
|
|
int _e57 = idx_1;
|
|
float unnamed_14 = nested_mat_cx2_.am.inner[0][_e55][_e57];
|
|
t_1 = MatCx2InArray {const_type_13_};
|
|
int _e63 = idx_1;
|
|
idx_1 = _e63 + 1;
|
|
for(int _i=0; _i<2; ++_i) t_1.am.inner[_i] = const_type_13_.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 _e90 = idx_1;
|
|
t_1.am.inner[0][_e90] = metal::float2(90.0);
|
|
t_1.am.inner[0][0].y = 10.0;
|
|
int _e107 = idx_1;
|
|
t_1.am.inner[0][0][_e107] = 20.0;
|
|
int _e113 = idx_1;
|
|
t_1.am.inner[0][_e113].y = 30.0;
|
|
int _e121 = idx_1;
|
|
int _e123 = idx_1;
|
|
t_1.am.inner[0][_e121][_e123] = 40.0;
|
|
return;
|
|
}
|
|
|
|
float read_from_private(
|
|
thread float& foo_1
|
|
) {
|
|
float _e6 = foo_1;
|
|
return _e6;
|
|
}
|
|
|
|
float test_arr_as_arg(
|
|
type_18 a
|
|
) {
|
|
return a.inner[4].inner[9];
|
|
}
|
|
|
|
void assign_through_ptr_fn(
|
|
threadgroup uint& p
|
|
) {
|
|
p = 42u;
|
|
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 = 0.0;
|
|
type_21 c = {};
|
|
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_8 arr = bar.arr;
|
|
float b = bar._matrix[3].x;
|
|
int a_1 = bar.data[(1 + (_buffer_sizes.size1 - 120 - 8) / 8) - 2u].value;
|
|
metal::int2 c_1 = qux;
|
|
float _e32 = read_from_private(foo);
|
|
for(int _i=0; _i<5; ++_i) c.inner[_i] = type_21 {a_1, static_cast<int>(b), 3, 4, 5}.inner[_i];
|
|
c.inner[vi + 1u] = 42;
|
|
int value = c.inner[vi];
|
|
float _e46 = test_arr_as_arg(const_type_18_);
|
|
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_8 {metal::uint2(0u), metal::uint2(1u)}.inner[_i];
|
|
bar.data[1].value = 1;
|
|
qux = const_type_11_;
|
|
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 _e10 = metal::atomic_fetch_add_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e10;
|
|
int _e13 = metal::atomic_fetch_sub_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e13;
|
|
int _e16 = metal::atomic_fetch_and_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e16;
|
|
int _e19 = metal::atomic_fetch_or_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e19;
|
|
int _e22 = metal::atomic_fetch_xor_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e22;
|
|
int _e25 = metal::atomic_fetch_min_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e25;
|
|
int _e28 = metal::atomic_fetch_max_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e28;
|
|
int _e31 = metal::atomic_exchange_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e31;
|
|
metal::atomic_store_explicit(&bar.atom, value_1, metal::memory_order_relaxed);
|
|
return;
|
|
}
|
|
|
|
|
|
kernel void assign_through_ptr(
|
|
threadgroup uint& val
|
|
) {
|
|
assign_through_ptr_fn(val);
|
|
return;
|
|
}
|