| #include <metal_stdlib> |
| using namespace metal; |
| |
| template<typename T, size_t N> |
| struct tint_array { |
| const constant T& operator[](size_t i) const constant { return elements[i]; } |
| device T& operator[](size_t i) device { return elements[i]; } |
| const device T& operator[](size_t i) const device { return elements[i]; } |
| thread T& operator[](size_t i) thread { return elements[i]; } |
| const thread T& operator[](size_t i) const thread { return elements[i]; } |
| threadgroup T& operator[](size_t i) threadgroup { return elements[i]; } |
| const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; } |
| T elements[N]; |
| }; |
| |
| struct OutputBuf { |
| /* 0x0000 */ tint_array<uint, 1> result; |
| }; |
| |
| struct Uniforms { |
| /* 0x0000 */ uint dstTextureFlipY; |
| /* 0x0004 */ uint isFloat16; |
| /* 0x0008 */ uint isRGB10A2Unorm; |
| /* 0x000c */ uint channelCount; |
| }; |
| |
| struct tint_module_vars_struct { |
| texture2d<float, access::sample> src; |
| texture2d<float, access::sample> dst; |
| device OutputBuf* output; |
| const constant Uniforms* uniforms; |
| }; |
| |
| #define TINT_ISOLATE_UB(VOLATILE_NAME) \ |
| {volatile bool VOLATILE_NAME = false; if (VOLATILE_NAME) break;} |
| |
| uint ConvertToFp16FloatValue(float fp32) { |
| return 1u; |
| } |
| |
| uint4 tint_v4f32_to_v4u32(float4 value) { |
| return select(uint4(4294967295u), select(uint4(0u), uint4(value), (value >= float4(0.0f))), (value <= float4(4294967040.0f))); |
| } |
| |
| void tint_symbol_inner(uint3 GlobalInvocationID, tint_module_vars_struct tint_module_vars) { |
| uint const v = tint_module_vars.src.get_width(0u); |
| uint2 size = uint2(v, tint_module_vars.src.get_height(0u)); |
| uint2 dstTexCoord = GlobalInvocationID.xy; |
| uint2 srcTexCoord = dstTexCoord; |
| if (((*tint_module_vars.uniforms).dstTextureFlipY == 1u)) { |
| srcTexCoord[1u] = ((size[1u] - dstTexCoord[1u]) - 1u); |
| } |
| float4 srcColor = tint_module_vars.src.read(srcTexCoord, 0); |
| float4 dstColor = tint_module_vars.dst.read(dstTexCoord, 0); |
| bool success = true; |
| uint4 srcColorBits = 0u; |
| uint4 dstColorBits = tint_v4f32_to_v4u32(dstColor); |
| { |
| uint i = 0u; |
| while(true) { |
| TINT_ISOLATE_UB(tint_volatile_false) |
| if ((i < (*tint_module_vars.uniforms).channelCount)) { |
| } else { |
| break; |
| } |
| uint const v_1 = i; |
| srcColorBits[v_1] = ConvertToFp16FloatValue(srcColor[i]); |
| bool v_2 = false; |
| if (success) { |
| v_2 = (srcColorBits[i] == dstColorBits[i]); |
| } else { |
| v_2 = false; |
| } |
| success = v_2; |
| { |
| i = (i + 1u); |
| } |
| continue; |
| } |
| } |
| uint outputIndex = ((GlobalInvocationID[1u] * uint(size[0u])) + GlobalInvocationID[0u]); |
| if (success) { |
| (*tint_module_vars.output).result[outputIndex] = 1u; |
| } else { |
| (*tint_module_vars.output).result[outputIndex] = 0u; |
| } |
| } |
| |
| kernel void tint_symbol(uint3 GlobalInvocationID [[thread_position_in_grid]], texture2d<float, access::sample> src [[texture(0)]], texture2d<float, access::sample> dst [[texture(1)]], device OutputBuf* output [[buffer(1)]], const constant Uniforms* uniforms [[buffer(0)]]) { |
| tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.src=src, .dst=dst, .output=output, .uniforms=uniforms}; |
| tint_symbol_inner(GlobalInvocationID, tint_module_vars); |
| } |