Ben Clayton | c0af5c5 | 2022-06-02 14:36:10 +0000 | [diff] [blame] | 1 | #include <metal_stdlib> |
| 2 | |
| 3 | using namespace metal; |
| 4 | uint tint_first_trailing_bit(uint v) { |
| 5 | uint x = uint(v); |
| 6 | uint const b16 = select(16u, 0u, bool((x & 65535u))); |
| 7 | x = (x >> b16); |
| 8 | uint const b8 = select(8u, 0u, bool((x & 255u))); |
| 9 | x = (x >> b8); |
| 10 | uint const b4 = select(4u, 0u, bool((x & 15u))); |
| 11 | x = (x >> b4); |
| 12 | uint const b2 = select(2u, 0u, bool((x & 3u))); |
| 13 | x = (x >> b2); |
| 14 | uint const b1 = select(1u, 0u, bool((x & 1u))); |
| 15 | uint const is_zero = select(0u, 4294967295u, (x == 0u)); |
| 16 | return uint((((((b16 | b8) | b4) | b2) | b1) | is_zero)); |
| 17 | } |
| 18 | |
Natalie Chouinard | e902718 | 2024-06-13 18:50:19 +0000 | [diff] [blame] | 19 | uint firstTrailingBit_47d475() { |
Ben Clayton | c0af5c5 | 2022-06-02 14:36:10 +0000 | [diff] [blame] | 20 | uint arg_0 = 1u; |
| 21 | uint res = tint_first_trailing_bit(arg_0); |
Natalie Chouinard | e902718 | 2024-06-13 18:50:19 +0000 | [diff] [blame] | 22 | return res; |
Ben Clayton | c0af5c5 | 2022-06-02 14:36:10 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Natalie Chouinard | e902718 | 2024-06-13 18:50:19 +0000 | [diff] [blame] | 25 | fragment void fragment_main(device uint* tint_symbol_1 [[buffer(0)]]) { |
| 26 | *(tint_symbol_1) = firstTrailingBit_47d475(); |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | kernel void compute_main(device uint* tint_symbol_2 [[buffer(0)]]) { |
| 31 | *(tint_symbol_2) = firstTrailingBit_47d475(); |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | struct VertexOutput { |
| 36 | float4 pos; |
| 37 | uint prevent_dce; |
Ben Clayton | c0af5c5 | 2022-06-02 14:36:10 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
Natalie Chouinard | e902718 | 2024-06-13 18:50:19 +0000 | [diff] [blame] | 40 | struct tint_symbol { |
| 41 | uint prevent_dce [[user(locn0)]] [[flat]]; |
| 42 | float4 pos [[position]]; |
| 43 | }; |
| 44 | |
| 45 | VertexOutput vertex_main_inner() { |
| 46 | VertexOutput out = {}; |
| 47 | out.pos = float4(0.0f); |
| 48 | out.prevent_dce = firstTrailingBit_47d475(); |
| 49 | return out; |
Ben Clayton | c0af5c5 | 2022-06-02 14:36:10 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Natalie Chouinard | e902718 | 2024-06-13 18:50:19 +0000 | [diff] [blame] | 52 | vertex tint_symbol vertex_main() { |
| 53 | VertexOutput const inner_result = vertex_main_inner(); |
Ben Clayton | c0af5c5 | 2022-06-02 14:36:10 +0000 | [diff] [blame] | 54 | tint_symbol wrapper_result = {}; |
Natalie Chouinard | e902718 | 2024-06-13 18:50:19 +0000 | [diff] [blame] | 55 | wrapper_result.pos = inner_result.pos; |
| 56 | wrapper_result.prevent_dce = inner_result.prevent_dce; |
Ben Clayton | c0af5c5 | 2022-06-02 14:36:10 +0000 | [diff] [blame] | 57 | return wrapper_result; |
| 58 | } |
| 59 | |