2022-11-14 20:30:38 +00:00
|
|
|
#include <metal_stdlib>
|
|
|
|
|
|
|
|
using namespace metal;
|
|
|
|
|
|
|
|
struct atomic_compare_exchange_resulti32 {
|
|
|
|
int old_value;
|
|
|
|
bool exchanged;
|
|
|
|
};
|
|
|
|
atomic_compare_exchange_resulti32 atomicCompareExchangeWeak_1(device atomic_int* atomic, int compare, int value) {
|
|
|
|
int old_value = compare;
|
|
|
|
bool exchanged = atomic_compare_exchange_weak_explicit(atomic, &old_value, value, memory_order_relaxed, memory_order_relaxed);
|
|
|
|
return {old_value, exchanged};
|
|
|
|
}
|
|
|
|
|
2023-03-20 21:46:01 +00:00
|
|
|
struct tint_private_vars_struct {
|
|
|
|
bool tint_discarded;
|
|
|
|
};
|
|
|
|
|
2022-11-14 20:30:38 +00:00
|
|
|
struct tint_symbol_2 {
|
|
|
|
int old_value;
|
|
|
|
bool exchanged;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct tint_symbol {
|
|
|
|
int value [[color(0)]];
|
|
|
|
};
|
|
|
|
|
2023-03-20 21:46:01 +00:00
|
|
|
int foo_inner(thread tint_private_vars_struct* const tint_private_vars, device atomic_int* const tint_symbol_4) {
|
|
|
|
(*(tint_private_vars)).tint_discarded = true;
|
2022-11-14 20:30:38 +00:00
|
|
|
int x = 0;
|
|
|
|
tint_symbol_2 tint_symbol_1 = {};
|
2023-03-20 21:46:01 +00:00
|
|
|
if (!((*(tint_private_vars)).tint_discarded)) {
|
|
|
|
atomic_compare_exchange_resulti32 const tint_symbol_3 = atomicCompareExchangeWeak_1(tint_symbol_4, 0, 1);
|
2022-11-14 20:30:38 +00:00
|
|
|
tint_symbol_1.old_value = tint_symbol_3.old_value;
|
|
|
|
tint_symbol_1.exchanged = tint_symbol_3.exchanged;
|
|
|
|
}
|
|
|
|
tint_symbol_2 const result = tint_symbol_1;
|
|
|
|
if (result.exchanged) {
|
|
|
|
x = result.old_value;
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2023-03-20 21:46:01 +00:00
|
|
|
fragment tint_symbol foo(device atomic_int* tint_symbol_5 [[buffer(0)]]) {
|
|
|
|
thread tint_private_vars_struct tint_private_vars = {};
|
|
|
|
tint_private_vars.tint_discarded = false;
|
|
|
|
int const inner_result = foo_inner(&(tint_private_vars), tint_symbol_5);
|
2022-11-14 20:30:38 +00:00
|
|
|
tint_symbol wrapper_result = {};
|
|
|
|
wrapper_result.value = inner_result;
|
2023-03-20 21:46:01 +00:00
|
|
|
if (tint_private_vars.tint_discarded) {
|
2022-11-14 20:30:38 +00:00
|
|
|
discard_fragment();
|
|
|
|
}
|
|
|
|
return wrapper_result;
|
|
|
|
}
|
|
|
|
|