2 # Copyright 2020 Google LLC
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 DEVICE_FEATURE shaderStorageImageMultisample
18 SHADER compute compute_shader GLSL
21 layout(local_size_x = 16, local_size_y = 16) in;
22 uniform layout(set=0, binding=0, r32ui) uimage2DMS texture;
23 uniform layout(set=0, binding=1, rgba8) image2D result;
27 ivec2 loc = ivec2(gl_LocalInvocationID.xy);
28 // Partner location is a mirror in local workgroup space.
29 ivec2 partnerLoc = ivec2(15) - loc;
30 uint id = loc.y * 16 + loc.x;
31 uint partnerId = partnerLoc.y * 16 + partnerLoc.x;
32 ivec2 workGroupOffset = ivec2(gl_WorkGroupID.xy) * ivec2(16);
34 // Initialize texture with id + sample id
35 for (int s = 0; s < 4; s++)
36 imageStore(texture, loc + workGroupOffset, s, uvec4(s + id));
41 for (int s = 0; s < 4; s++)
43 // Add id to both location and partner location.
44 imageAtomicAdd(texture, loc + workGroupOffset, s, id);
45 imageAtomicAdd(texture, partnerLoc + workGroupOffset, s, id);
47 // Set MSB for location and the second MSB for partner.
48 imageAtomicOr(texture, loc + workGroupOffset, s, 1u << 31);
49 imageAtomicOr(texture, partnerLoc + workGroupOffset, s, 1u << 30);
55 for (int s = 0; s < 4; s++)
57 // XOR with two patterns in the second highest byte. Should set this
58 // byte to 0xc. The order of XOR operations don't matter.
59 imageAtomicXor(texture, loc + workGroupOffset, s, 0x0a000000);
60 imageAtomicXor(texture, partnerLoc + workGroupOffset, s, 0x06000000);
66 for (int s = 0; s < 4; s++)
68 // Finally mask out one of LSBs based on sample
69 imageAtomicAnd(texture, loc + workGroupOffset, s, ~(1u << s));
75 for (int s = 0; s < 4; s++)
77 if (imageLoad(texture, loc + workGroupOffset, s).r != (((s + id * 2 + partnerId) | 0xcc000000) & ~(1u << s)))
81 vec4 color = ok ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
82 imageStore(result, loc + workGroupOffset, color);
86 IMAGE texture FORMAT R32_UINT DIM_2D WIDTH 64 HEIGHT 64 SAMPLES 4
87 IMAGE result FORMAT R8G8B8A8_UNORM DIM_2D WIDTH 64 HEIGHT 64 FILL 0
89 PIPELINE compute pipeline
92 BIND BUFFER texture AS storage_image DESCRIPTOR_SET 0 BINDING 0
93 BIND BUFFER result AS storage_image DESCRIPTOR_SET 0 BINDING 1
98 EXPECT result IDX 0 0 SIZE 64 64 EQ_RGBA 0 255 0 255