blob: c7b0190656646df0ef01cbe60019ff2e228d542f [file] [log] [blame]
James Pricede734312024-05-16 22:20:44 +00001#include <metal_stdlib>
2using namespace metal;
James Price48be7e82024-06-19 22:38:07 +00003
James Pricede734312024-05-16 22:20:44 +00004template<typename T, size_t N>
5struct tint_array {
6 const constant T& operator[](size_t i) const constant { return elements[i]; }
7 device T& operator[](size_t i) device { return elements[i]; }
8 const device T& operator[](size_t i) const device { return elements[i]; }
9 thread T& operator[](size_t i) thread { return elements[i]; }
10 const thread T& operator[](size_t i) const thread { return elements[i]; }
11 threadgroup T& operator[](size_t i) threadgroup { return elements[i]; }
12 const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; }
13 T elements[N];
14};
dan sinclairf1f381a2023-11-22 09:44:15 +000015
James Pricede734312024-05-16 22:20:44 +000016struct S {
17 tint_array<int, 4> arr;
18};
James Price48be7e82024-06-19 22:38:07 +000019
James Pricede734312024-05-16 22:20:44 +000020struct tint_module_vars_struct {
21 device int* s;
22};
dan sinclaira01fd242023-12-05 20:23:42 +000023
James Pricede734312024-05-16 22:20:44 +000024int foo() {
25 tint_array<int, 4> const src = tint_array<int, 4>{};
26 tint_array<int, 4> dst = {};
27 S dst_struct = {};
28 tint_array<tint_array<int, 4>, 2> dst_array = {};
29 thread tint_array<int, 4>* const dst_ptr = (&dst);
30 thread S* const dst_struct_ptr = (&dst_struct);
31 thread tint_array<tint_array<int, 4>, 2>* const dst_array_ptr = (&dst_array);
32 dst_struct.arr = src;
33 dst_array[1] = src;
34 (*dst_ptr) = src;
35 (*dst_struct_ptr).arr = src;
36 (*dst_array_ptr)[0] = src;
James Price2d245582024-09-04 16:04:34 +000037 return as_type<int>((as_type<uint>(as_type<int>((as_type<uint>((*dst_ptr)[0]) + as_type<uint>((*dst_struct_ptr).arr[0])))) + as_type<uint>((*dst_array_ptr)[0][0])));
dan sinclaira01fd242023-12-05 20:23:42 +000038}
James Price48be7e82024-06-19 22:38:07 +000039
James Pricede734312024-05-16 22:20:44 +000040kernel void tint_symbol(device int* s [[buffer(0)]]) {
James Price47fddc22024-05-17 19:29:38 +000041 tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.s=s};
James Pricede734312024-05-16 22:20:44 +000042 (*tint_module_vars.s) = foo();
dan sinclaira01fd242023-12-05 20:23:42 +000043}