2021-06-19 08:18:50 +00:00
|
|
|
struct Uniforms {
|
2022-03-28 14:31:22 +00:00
|
|
|
dstTextureFlipY : u32,
|
|
|
|
channelCount : u32,
|
|
|
|
srcCopyOrigin : vec2<u32>,
|
|
|
|
dstCopyOrigin : vec2<u32>,
|
|
|
|
copySize : vec2<u32>,
|
2022-01-19 18:11:17 +00:00
|
|
|
}
|
2021-06-19 08:18:50 +00:00
|
|
|
|
|
|
|
struct OutputBuf {
|
2022-03-28 14:31:22 +00:00
|
|
|
result : array<u32>,
|
2022-01-19 18:11:17 +00:00
|
|
|
}
|
2021-06-19 08:18:50 +00:00
|
|
|
|
2022-01-19 22:46:57 +00:00
|
|
|
@group(0) @binding(0) var src : texture_2d<f32>;
|
2021-06-19 08:18:50 +00:00
|
|
|
|
2022-01-19 22:46:57 +00:00
|
|
|
@group(0) @binding(1) var dst : texture_2d<f32>;
|
2021-06-19 08:18:50 +00:00
|
|
|
|
2022-01-19 22:46:57 +00:00
|
|
|
@group(0) @binding(2) var<storage, read_write> output : OutputBuf;
|
2021-06-19 08:18:50 +00:00
|
|
|
|
2022-01-19 22:46:57 +00:00
|
|
|
@group(0) @binding(3) var<uniform> uniforms : Uniforms;
|
2021-06-19 08:18:50 +00:00
|
|
|
|
|
|
|
fn aboutEqual(value : f32, expect : f32) -> bool {
|
|
|
|
return (abs((value - expect)) < 0.001);
|
|
|
|
}
|
|
|
|
|
2022-01-19 22:46:57 +00:00
|
|
|
@stage(compute) @workgroup_size(1, 1, 1)
|
|
|
|
fn main(@builtin(global_invocation_id) GlobalInvocationID : vec3<u32>) {
|
2021-06-19 08:18:50 +00:00
|
|
|
let srcSize : vec2<i32> = textureDimensions(src);
|
|
|
|
let dstSize : vec2<i32> = textureDimensions(dst);
|
|
|
|
let dstTexCoord : vec2<u32> = vec2<u32>(GlobalInvocationID.xy);
|
|
|
|
let nonCoveredColor : vec4<f32> = vec4<f32>(0.0, 1.0, 0.0, 1.0);
|
|
|
|
var success : bool = true;
|
|
|
|
if (((((dstTexCoord.x < uniforms.dstCopyOrigin.x) || (dstTexCoord.y < uniforms.dstCopyOrigin.y)) || (dstTexCoord.x >= (uniforms.dstCopyOrigin.x + uniforms.copySize.x))) || (dstTexCoord.y >= (uniforms.dstCopyOrigin.y + uniforms.copySize.y)))) {
|
|
|
|
success = (success && all((textureLoad(dst, vec2<i32>(dstTexCoord), 0) == nonCoveredColor)));
|
|
|
|
} else {
|
|
|
|
var srcTexCoord : vec2<u32> = ((dstTexCoord - uniforms.dstCopyOrigin) + uniforms.srcCopyOrigin);
|
|
|
|
if ((uniforms.dstTextureFlipY == 1u)) {
|
|
|
|
srcTexCoord.y = ((u32(srcSize.y) - srcTexCoord.y) - 1u);
|
|
|
|
}
|
|
|
|
let srcColor : vec4<f32> = textureLoad(src, vec2<i32>(srcTexCoord), 0);
|
|
|
|
let dstColor : vec4<f32> = textureLoad(dst, vec2<i32>(dstTexCoord), 0);
|
|
|
|
if ((uniforms.channelCount == 2u)) {
|
|
|
|
success = ((success && aboutEqual(dstColor.r, srcColor.r)) && aboutEqual(dstColor.g, srcColor.g));
|
|
|
|
} else {
|
|
|
|
success = ((((success && aboutEqual(dstColor.r, srcColor.r)) && aboutEqual(dstColor.g, srcColor.g)) && aboutEqual(dstColor.b, srcColor.b)) && aboutEqual(dstColor.a, srcColor.a));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let outputIndex : u32 = ((GlobalInvocationID.y * u32(dstSize.x)) + GlobalInvocationID.x);
|
|
|
|
if (success) {
|
|
|
|
output.result[outputIndex] = 1u;
|
|
|
|
} else {
|
|
|
|
output.result[outputIndex] = 0u;
|
|
|
|
}
|
|
|
|
}
|