blob: 190496d4ec3003b2da7f5fca7dc326ead5b749e8 [file] [log] [blame]
James Price60107e72022-03-31 22:30:10 +00001#include <metal_stdlib>
James Price555c2562022-03-31 22:30:10 +00002
James Price60107e72022-03-31 22:30:10 +00003using namespace metal;
Ben Claytonf47887d2022-06-24 17:01:59 +00004
5template<typename T, size_t N>
6struct 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 Clayton02262d82024-01-23 18:09:39 +000017#define TINT_ISOLATE_UB(VOLATILE_NAME) \
18 volatile bool VOLATILE_NAME = true; \
19 if (VOLATILE_NAME)
Ben Clayton9be037c2024-01-19 20:58:56 +000020
James Price0e22bdb2023-03-20 21:46:01 +000021struct tint_private_vars_struct {
22 uint i;
23};
24
James Price555c2562022-03-31 22:30:10 +000025struct S {
James Price60107e72022-03-31 22:30:10 +000026 int a;
27 float4 b;
28 float2x2 c;
29};
James Price555c2562022-03-31 22:30:10 +000030
James Price0e22bdb2023-03-20 21:46:01 +000031int idx1(thread tint_private_vars_struct* const tint_private_vars) {
32 (*(tint_private_vars)).i = ((*(tint_private_vars)).i + 1u);
James Price555c2562022-03-31 22:30:10 +000033 return 1;
34}
35
James Price0e22bdb2023-03-20 21:46:01 +000036int idx2(thread tint_private_vars_struct* const tint_private_vars) {
37 (*(tint_private_vars)).i = ((*(tint_private_vars)).i + 2u);
James Price555c2562022-03-31 22:30:10 +000038 return 1;
39}
40
James Price0e22bdb2023-03-20 21:46:01 +000041int idx3(thread tint_private_vars_struct* const tint_private_vars) {
42 (*(tint_private_vars)).i = ((*(tint_private_vars)).i + 3u);
James Price555c2562022-03-31 22:30:10 +000043 return 1;
44}
45
James Price0e22bdb2023-03-20 21:46:01 +000046void foo(thread tint_private_vars_struct* const tint_private_vars) {
Ben Claytonf47887d2022-06-24 17:01:59 +000047 tint_array<float, 4> a = tint_array<float, 4>{};
James Price60107e72022-03-31 22:30:10 +000048 {
James Price0e22bdb2023-03-20 21:46:01 +000049 int const tint_symbol_2 = idx1(tint_private_vars);
Ben Clayton3cde73c2023-03-02 17:18:27 +000050 int const tint_symbol_save = tint_symbol_2;
Ben Claytonf47887d2022-06-24 17:01:59 +000051 a[tint_symbol_save] = (a[tint_symbol_save] * 2.0f);
Ben Clayton02262d82024-01-23 18:09:39 +000052 TINT_ISOLATE_UB(tint_volatile_true) while(true) {
James Price0e22bdb2023-03-20 21:46:01 +000053 int const tint_symbol_3 = idx2(tint_private_vars);
Ben Claytonf47887d2022-06-24 17:01:59 +000054 if (!((a[tint_symbol_3] < 10.0f))) {
James Price60107e72022-03-31 22:30:10 +000055 break;
56 }
57 {
58 }
59 {
James Price0e22bdb2023-03-20 21:46:01 +000060 int const tint_symbol_4 = idx3(tint_private_vars);
James Price60107e72022-03-31 22:30:10 +000061 int const tint_symbol_1_save = tint_symbol_4;
Ben Claytonf47887d2022-06-24 17:01:59 +000062 a[tint_symbol_1_save] = (a[tint_symbol_1_save] + 1.0f);
James Price60107e72022-03-31 22:30:10 +000063 }
64 }
James Price555c2562022-03-31 22:30:10 +000065 }
66}
67