| #include <metal_stdlib> |
| using namespace metal; |
| |
| struct atomic_compare_exchange_result_i32 { |
| int old_value; |
| bool exchanged; |
| }; |
| |
| struct tint_module_vars_struct { |
| device atomic_int* a; |
| thread bool* continue_execution; |
| }; |
| |
| struct foo_outputs { |
| int tint_symbol [[color(0)]]; |
| }; |
| |
| atomic_compare_exchange_result_i32 v(device atomic_int* const atomic_ptr, int cmp, int val) { |
| int old_value = cmp; |
| bool const v_1 = atomic_compare_exchange_weak_explicit(atomic_ptr, (&old_value), val, memory_order_relaxed, memory_order_relaxed); |
| return atomic_compare_exchange_result_i32{.old_value=old_value, .exchanged=v_1}; |
| } |
| |
| int foo_inner(tint_module_vars_struct tint_module_vars) { |
| (*tint_module_vars.continue_execution) = false; |
| int x = 0; |
| atomic_compare_exchange_result_i32 v_2 = {}; |
| if ((*tint_module_vars.continue_execution)) { |
| v_2 = v(tint_module_vars.a, 0, 1); |
| } |
| atomic_compare_exchange_result_i32 const result = v_2; |
| if (result.exchanged) { |
| x = result.old_value; |
| } |
| if (!((*tint_module_vars.continue_execution))) { |
| discard_fragment(); |
| } |
| return x; |
| } |
| |
| fragment foo_outputs foo(device atomic_int* a [[buffer(0)]]) { |
| thread bool continue_execution = true; |
| tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.a=a, .continue_execution=(&continue_execution)}; |
| foo_outputs tint_wrapper_result = {}; |
| tint_wrapper_result.tint_symbol = foo_inner(tint_module_vars); |
| return tint_wrapper_result; |
| } |