mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-30 18:14:18 +01:00
* [hlsl-out] add padding at the end of structs and after struct members of type matrix and array (when necessary) * use wrapped constructor fn for constants * add array as fn arg test * fix glsl array fn arg * add wrapped constructor for arrays * [glsl-out] support multidimensional arrays * address comments
179 lines
4.8 KiB
Plaintext
179 lines
4.8 KiB
Plaintext
// language: metal2.0
|
|
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
|
|
using metal::uint;
|
|
|
|
struct _mslBufferSizes {
|
|
uint size0;
|
|
};
|
|
|
|
struct AlignedWrapper {
|
|
int value;
|
|
};
|
|
struct type_3 {
|
|
metal::float2x2 inner[2];
|
|
};
|
|
struct type_6 {
|
|
metal::uint2 inner[2];
|
|
};
|
|
typedef AlignedWrapper type_7[1];
|
|
struct Bar {
|
|
metal::float4x3 matrix;
|
|
type_3 matrix_array;
|
|
metal::atomic_int atom;
|
|
char _pad3[4];
|
|
type_6 arr;
|
|
type_7 data;
|
|
};
|
|
struct Baz {
|
|
metal::float3x2 m;
|
|
};
|
|
struct type_12 {
|
|
float inner[10];
|
|
};
|
|
struct type_13 {
|
|
type_12 inner[5];
|
|
};
|
|
struct type_17 {
|
|
int inner[5];
|
|
};
|
|
constant type_12 const_type_12_ = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
|
constant type_13 const_type_13_ = {const_type_12_, const_type_12_, const_type_12_, const_type_12_, const_type_12_};
|
|
|
|
void test_matrix_within_struct_accesses(
|
|
constant Baz& baz
|
|
) {
|
|
int idx = 9;
|
|
metal::float3x2 unnamed_1;
|
|
metal::float2 unnamed_2;
|
|
metal::float2 unnamed_3;
|
|
float unnamed_4;
|
|
float unnamed_5;
|
|
float unnamed_6;
|
|
float unnamed_7;
|
|
Baz t;
|
|
int _e4 = idx;
|
|
idx = _e4 - 1;
|
|
metal::float3x2 _e8 = baz.m;
|
|
unnamed_1 = _e8;
|
|
metal::float2 _e13 = baz.m[0];
|
|
unnamed_2 = _e13;
|
|
int _e16 = idx;
|
|
metal::float2 _e18 = baz.m[_e16];
|
|
unnamed_3 = _e18;
|
|
float _e25 = baz.m[0].y;
|
|
unnamed_4 = _e25;
|
|
int _e30 = idx;
|
|
float _e32 = baz.m[0][_e30];
|
|
unnamed_5 = _e32;
|
|
int _e35 = idx;
|
|
float _e39 = baz.m[_e35].y;
|
|
unnamed_6 = _e39;
|
|
int _e42 = idx;
|
|
int _e44 = idx;
|
|
float _e46 = baz.m[_e42][_e44];
|
|
unnamed_7 = _e46;
|
|
t = Baz {metal::float3x2(metal::float2(1.0), metal::float2(2.0), metal::float2(3.0))};
|
|
int _e57 = idx;
|
|
idx = _e57 + 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 _e74 = idx;
|
|
t.m[_e74] = metal::float2(90.0);
|
|
t.m[0].y = 10.0;
|
|
int _e87 = idx;
|
|
t.m[0][_e87] = 20.0;
|
|
int _e91 = idx;
|
|
t.m[_e91].y = 30.0;
|
|
int _e97 = idx;
|
|
int _e99 = idx;
|
|
t.m[_e97][_e99] = 40.0;
|
|
return;
|
|
}
|
|
|
|
float read_from_private(
|
|
thread float& foo_1
|
|
) {
|
|
float _e3 = foo_1;
|
|
return _e3;
|
|
}
|
|
|
|
float test_arr_as_arg(
|
|
type_13 a
|
|
) {
|
|
return a.inner[4].inner[9];
|
|
}
|
|
|
|
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)]]
|
|
, constant _mslBufferSizes& _buffer_sizes [[buffer(24)]]
|
|
) {
|
|
float foo = 0.0;
|
|
type_17 c;
|
|
float unnamed;
|
|
float baz_1 = foo;
|
|
foo = 1.0;
|
|
test_matrix_within_struct_accesses(baz);
|
|
metal::float4x3 matrix = bar.matrix;
|
|
type_6 arr = bar.arr;
|
|
float b = bar.matrix[3].x;
|
|
int a_1 = bar.data[(1 + (_buffer_sizes.size0 - 120 - 8) / 8) - 2u].value;
|
|
float _e28 = read_from_private(foo);
|
|
for(int _i=0; _i<5; ++_i) c.inner[_i] = type_17 {a_1, static_cast<int>(b), 3, 4, 5}.inner[_i];
|
|
c.inner[vi + 1u] = 42;
|
|
int value = c.inner[vi];
|
|
float _e42 = test_arr_as_arg(const_type_13_);
|
|
unnamed = _e42;
|
|
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)]]
|
|
, 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_6 {metal::uint2(0u), metal::uint2(1u)}.inner[_i];
|
|
bar.data[1].value = 1;
|
|
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 _e10 = metal::atomic_fetch_sub_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e10;
|
|
int _e13 = metal::atomic_fetch_and_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e13;
|
|
int _e16 = metal::atomic_fetch_or_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e16;
|
|
int _e19 = metal::atomic_fetch_xor_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e19;
|
|
int _e22 = metal::atomic_fetch_min_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e22;
|
|
int _e25 = metal::atomic_fetch_max_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e25;
|
|
int _e28 = metal::atomic_exchange_explicit(&bar.atom, 5, metal::memory_order_relaxed);
|
|
tmp = _e28;
|
|
metal::atomic_store_explicit(&bar.atom, value_1, metal::memory_order_relaxed);
|
|
return;
|
|
}
|