James Price | 60107e7 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 1 | #include <metal_stdlib> |
James Price | 555c256 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 2 | |
James Price | 60107e7 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 3 | using namespace metal; |
Ben Clayton | f47887d | 2022-06-24 17:01:59 +0000 | [diff] [blame] | 4 | |
| 5 | template<typename T, size_t N> |
| 6 | struct tint_array { |
| 7 | const constant T& operator[](size_t i) const constant { return elements[i]; } |
| 8 | device T& operator[](size_t i) device { return elements[i]; } |
| 9 | const device T& operator[](size_t i) const device { return elements[i]; } |
| 10 | thread T& operator[](size_t i) thread { return elements[i]; } |
| 11 | const thread T& operator[](size_t i) const thread { return elements[i]; } |
| 12 | threadgroup T& operator[](size_t i) threadgroup { return elements[i]; } |
| 13 | const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; } |
| 14 | T elements[N]; |
| 15 | }; |
| 16 | |
Ben Clayton | 02262d8 | 2024-01-23 18:09:39 +0000 | [diff] [blame] | 17 | #define TINT_ISOLATE_UB(VOLATILE_NAME) \ |
| 18 | volatile bool VOLATILE_NAME = true; \ |
| 19 | if (VOLATILE_NAME) |
Ben Clayton | 9be037c | 2024-01-19 20:58:56 +0000 | [diff] [blame] | 20 | |
James Price | 0e22bdb | 2023-03-20 21:46:01 +0000 | [diff] [blame] | 21 | struct tint_private_vars_struct { |
| 22 | uint i; |
| 23 | }; |
| 24 | |
James Price | 555c256 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 25 | struct S { |
James Price | 60107e7 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 26 | int a; |
| 27 | float4 b; |
| 28 | float2x2 c; |
| 29 | }; |
James Price | 555c256 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 30 | |
James Price | 0e22bdb | 2023-03-20 21:46:01 +0000 | [diff] [blame] | 31 | int idx1(thread tint_private_vars_struct* const tint_private_vars) { |
| 32 | (*(tint_private_vars)).i = ((*(tint_private_vars)).i + 1u); |
James Price | 555c256 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 33 | return 1; |
| 34 | } |
| 35 | |
James Price | 0e22bdb | 2023-03-20 21:46:01 +0000 | [diff] [blame] | 36 | int idx2(thread tint_private_vars_struct* const tint_private_vars) { |
| 37 | (*(tint_private_vars)).i = ((*(tint_private_vars)).i + 2u); |
James Price | 555c256 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 38 | return 1; |
| 39 | } |
| 40 | |
James Price | 0e22bdb | 2023-03-20 21:46:01 +0000 | [diff] [blame] | 41 | int idx3(thread tint_private_vars_struct* const tint_private_vars) { |
| 42 | (*(tint_private_vars)).i = ((*(tint_private_vars)).i + 3u); |
James Price | 555c256 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 43 | return 1; |
| 44 | } |
| 45 | |
James Price | 0e22bdb | 2023-03-20 21:46:01 +0000 | [diff] [blame] | 46 | void foo(thread tint_private_vars_struct* const tint_private_vars) { |
Ben Clayton | f47887d | 2022-06-24 17:01:59 +0000 | [diff] [blame] | 47 | tint_array<float, 4> a = tint_array<float, 4>{}; |
James Price | 60107e7 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 48 | { |
James Price | 0e22bdb | 2023-03-20 21:46:01 +0000 | [diff] [blame] | 49 | int const tint_symbol_2 = idx1(tint_private_vars); |
Ben Clayton | 3cde73c | 2023-03-02 17:18:27 +0000 | [diff] [blame] | 50 | int const tint_symbol_save = tint_symbol_2; |
Ben Clayton | f47887d | 2022-06-24 17:01:59 +0000 | [diff] [blame] | 51 | a[tint_symbol_save] = (a[tint_symbol_save] * 2.0f); |
Ben Clayton | 02262d8 | 2024-01-23 18:09:39 +0000 | [diff] [blame] | 52 | TINT_ISOLATE_UB(tint_volatile_true) while(true) { |
James Price | 0e22bdb | 2023-03-20 21:46:01 +0000 | [diff] [blame] | 53 | int const tint_symbol_3 = idx2(tint_private_vars); |
Ben Clayton | f47887d | 2022-06-24 17:01:59 +0000 | [diff] [blame] | 54 | if (!((a[tint_symbol_3] < 10.0f))) { |
James Price | 60107e7 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 55 | break; |
| 56 | } |
| 57 | { |
| 58 | } |
| 59 | { |
James Price | 0e22bdb | 2023-03-20 21:46:01 +0000 | [diff] [blame] | 60 | int const tint_symbol_4 = idx3(tint_private_vars); |
James Price | 60107e7 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 61 | int const tint_symbol_1_save = tint_symbol_4; |
Ben Clayton | f47887d | 2022-06-24 17:01:59 +0000 | [diff] [blame] | 62 | a[tint_symbol_1_save] = (a[tint_symbol_1_save] + 1.0f); |
James Price | 60107e7 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
James Price | 555c256 | 2022-03-31 22:30:10 +0000 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | |