| #include <metal_stdlib> |
| using namespace metal; |
| |
| template<typename T, size_t N> |
| struct tint_array { |
| const constant T& operator[](size_t i) const constant { return elements[i]; } |
| device T& operator[](size_t i) device { return elements[i]; } |
| const device T& operator[](size_t i) const device { return elements[i]; } |
| thread T& operator[](size_t i) thread { return elements[i]; } |
| const thread T& operator[](size_t i) const thread { return elements[i]; } |
| threadgroup T& operator[](size_t i) threadgroup { return elements[i]; } |
| const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; } |
| T elements[N]; |
| }; |
| |
| struct tint_packed_vec3_u32_array_element { |
| packed_uint3 packed; |
| }; |
| |
| struct S_packed_vec3 { |
| packed_uint3 a; |
| uint b; |
| tint_array<tint_packed_vec3_u32_array_element, 4> c; |
| }; |
| |
| struct S { |
| uint3 a; |
| uint b; |
| tint_array<uint3, 4> c; |
| }; |
| |
| #define TINT_ISOLATE_UB(VOLATILE_NAME) \ |
| volatile bool VOLATILE_NAME = true; \ |
| if (VOLATILE_NAME) |
| |
| struct tint_module_vars_struct { |
| const constant S_packed_vec3* ubuffer; |
| device S_packed_vec3* sbuffer; |
| threadgroup S_packed_vec3* wbuffer; |
| }; |
| |
| void tint_store_array_packed_vec3_1(threadgroup tint_array<tint_packed_vec3_u32_array_element, 4>* const to, tint_array<uint3, 4> value) { |
| (*to)[0u].packed = packed_uint3(value[0u]); |
| (*to)[1u].packed = packed_uint3(value[1u]); |
| (*to)[2u].packed = packed_uint3(value[2u]); |
| (*to)[3u].packed = packed_uint3(value[3u]); |
| } |
| |
| void tint_store_array_packed_vec3(threadgroup S_packed_vec3* const to, S value) { |
| (*to).a = packed_uint3(value.a); |
| (*to).b = value.b; |
| tint_store_array_packed_vec3_1((&(*to).c), value.c); |
| } |
| |
| void tint_store_and_preserve_padding_1(device tint_array<tint_packed_vec3_u32_array_element, 4>* const target, tint_array<uint3, 4> value_param) { |
| { |
| uint v = 0u; |
| v = 0u; |
| TINT_ISOLATE_UB(tint_volatile_true) while(true) { |
| uint const v_1 = v; |
| if ((v_1 >= 4u)) { |
| break; |
| } |
| (*target)[v_1].packed = packed_uint3(value_param[v_1]); |
| { |
| v = (v_1 + 1u); |
| } |
| continue; |
| } |
| } |
| } |
| |
| void tint_store_and_preserve_padding(device S_packed_vec3* const target, S value_param) { |
| (*target).a = packed_uint3(value_param.a); |
| (*target).b = value_param.b; |
| tint_store_and_preserve_padding_1((&(*target).c), value_param.c); |
| } |
| |
| tint_array<uint3, 4> tint_load_array_packed_vec3_1(device tint_array<tint_packed_vec3_u32_array_element, 4>* const from) { |
| uint3 const v_2 = uint3((*from)[0u].packed); |
| uint3 const v_3 = uint3((*from)[1u].packed); |
| uint3 const v_4 = uint3((*from)[2u].packed); |
| return tint_array<uint3, 4>{v_2, v_3, v_4, uint3((*from)[3u].packed)}; |
| } |
| |
| S tint_load_struct_packed_vec3_1(device S_packed_vec3* const from) { |
| uint3 const v_5 = uint3((*from).a); |
| uint const v_6 = (*from).b; |
| return S{.a=v_5, .b=v_6, .c=tint_load_array_packed_vec3_1((&(*from).c))}; |
| } |
| |
| tint_array<uint3, 4> tint_load_array_packed_vec3(const constant tint_array<tint_packed_vec3_u32_array_element, 4>* const from) { |
| uint3 const v_7 = uint3((*from)[0u].packed); |
| uint3 const v_8 = uint3((*from)[1u].packed); |
| uint3 const v_9 = uint3((*from)[2u].packed); |
| return tint_array<uint3, 4>{v_7, v_8, v_9, uint3((*from)[3u].packed)}; |
| } |
| |
| S tint_load_struct_packed_vec3(const constant S_packed_vec3* const from) { |
| uint3 const v_10 = uint3((*from).a); |
| uint const v_11 = (*from).b; |
| return S{.a=v_10, .b=v_11, .c=tint_load_array_packed_vec3((&(*from).c))}; |
| } |
| |
| void foo(tint_module_vars_struct tint_module_vars) { |
| S const u = tint_load_struct_packed_vec3(tint_module_vars.ubuffer); |
| S const s = tint_load_struct_packed_vec3_1(tint_module_vars.sbuffer); |
| S const w = tint_load_struct_packed_vec3_1(tint_module_vars.sbuffer); |
| tint_store_and_preserve_padding(tint_module_vars.sbuffer, S{}); |
| tint_store_array_packed_vec3(tint_module_vars.wbuffer, S{}); |
| } |