91 lines
3.9 KiB
Plaintext
91 lines
3.9 KiB
Plaintext
#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 Uniforms {
|
|
/* 0x0000 */ uint dstTextureFlipY;
|
|
/* 0x0004 */ uint channelCount;
|
|
/* 0x0008 */ uint2 srcCopyOrigin;
|
|
/* 0x0010 */ uint2 dstCopyOrigin;
|
|
/* 0x0018 */ uint2 copySize;
|
|
};
|
|
|
|
struct OutputBuf {
|
|
/* 0x0000 */ tint_array<uint, 1> result;
|
|
};
|
|
|
|
bool aboutEqual(float value, float expect) {
|
|
return (fabs((value - expect)) < 0.001f);
|
|
}
|
|
|
|
void tint_symbol_inner(uint3 GlobalInvocationID, texture2d<float, access::sample> tint_symbol_7, texture2d<float, access::sample> tint_symbol_8, const constant Uniforms* const tint_symbol_9, device OutputBuf* const tint_symbol_10) {
|
|
uint2 const srcSize = uint2(tint_symbol_7.get_width(), tint_symbol_7.get_height());
|
|
uint2 const dstSize = uint2(tint_symbol_8.get_width(), tint_symbol_8.get_height());
|
|
uint2 const dstTexCoord = uint2(uint3(GlobalInvocationID).xy);
|
|
float4 const nonCoveredColor = float4(0.0f, 1.0f, 0.0f, 1.0f);
|
|
bool success = true;
|
|
if (((((dstTexCoord[0] < (*(tint_symbol_9)).dstCopyOrigin[0]) || (dstTexCoord[1] < (*(tint_symbol_9)).dstCopyOrigin[1])) || (dstTexCoord[0] >= ((*(tint_symbol_9)).dstCopyOrigin[0] + (*(tint_symbol_9)).copySize[0]))) || (dstTexCoord[1] >= ((*(tint_symbol_9)).dstCopyOrigin[1] + (*(tint_symbol_9)).copySize[1])))) {
|
|
success = (success && all((tint_symbol_8.read(uint2(int2(dstTexCoord)), 0) == nonCoveredColor)));
|
|
} else {
|
|
uint2 srcTexCoord = ((dstTexCoord - (*(tint_symbol_9)).dstCopyOrigin) + (*(tint_symbol_9)).srcCopyOrigin);
|
|
if (((*(tint_symbol_9)).dstTextureFlipY == 1u)) {
|
|
srcTexCoord[1] = ((srcSize[1] - srcTexCoord[1]) - 1u);
|
|
}
|
|
float4 const srcColor = tint_symbol_7.read(uint2(int2(srcTexCoord)), 0);
|
|
float4 const dstColor = tint_symbol_8.read(uint2(int2(dstTexCoord)), 0);
|
|
if (((*(tint_symbol_9)).channelCount == 2u)) {
|
|
bool tint_symbol_2 = success;
|
|
if (tint_symbol_2) {
|
|
tint_symbol_2 = aboutEqual(dstColor[0], srcColor[0]);
|
|
}
|
|
bool tint_symbol_1 = tint_symbol_2;
|
|
if (tint_symbol_1) {
|
|
tint_symbol_1 = aboutEqual(dstColor[1], srcColor[1]);
|
|
}
|
|
success = tint_symbol_1;
|
|
} else {
|
|
bool tint_symbol_6 = success;
|
|
if (tint_symbol_6) {
|
|
tint_symbol_6 = aboutEqual(dstColor[0], srcColor[0]);
|
|
}
|
|
bool tint_symbol_5 = tint_symbol_6;
|
|
if (tint_symbol_5) {
|
|
tint_symbol_5 = aboutEqual(dstColor[1], srcColor[1]);
|
|
}
|
|
bool tint_symbol_4 = tint_symbol_5;
|
|
if (tint_symbol_4) {
|
|
tint_symbol_4 = aboutEqual(dstColor[2], srcColor[2]);
|
|
}
|
|
bool tint_symbol_3 = tint_symbol_4;
|
|
if (tint_symbol_3) {
|
|
tint_symbol_3 = aboutEqual(dstColor[3], srcColor[3]);
|
|
}
|
|
success = tint_symbol_3;
|
|
}
|
|
}
|
|
uint const outputIndex = ((GlobalInvocationID[1] * dstSize[0]) + GlobalInvocationID[0]);
|
|
if (success) {
|
|
(*(tint_symbol_10)).result[outputIndex] = 1u;
|
|
} else {
|
|
(*(tint_symbol_10)).result[outputIndex] = 0u;
|
|
}
|
|
}
|
|
|
|
kernel void tint_symbol(texture2d<float, access::sample> tint_symbol_11 [[texture(0)]], texture2d<float, access::sample> tint_symbol_12 [[texture(1)]], const constant Uniforms* tint_symbol_13 [[buffer(0)]], device OutputBuf* tint_symbol_14 [[buffer(1)]], uint3 GlobalInvocationID [[thread_position_in_grid]]) {
|
|
tint_symbol_inner(GlobalInvocationID, tint_symbol_11, tint_symbol_12, tint_symbol_13, tint_symbol_14);
|
|
return;
|
|
}
|
|
|