Add atomic operation tests for multisample storage images
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / data / vulkan / amber / texture / multisample / atomic / storage_image_r32ui.amber
1 #!amber
2 # Copyright 2020 Google LLC
3 #
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
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16 DEVICE_FEATURE shaderStorageImageMultisample
17
18 SHADER compute compute_shader GLSL
19 #version 430
20
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;
24
25 void main()
26 {
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);
33
34     // Initialize texture with id + sample id
35     for (int s = 0; s < 4; s++)
36         imageStore(texture, loc + workGroupOffset, s, uvec4(s + id));
37
38     memoryBarrierImage();
39     barrier();
40
41     for (int s = 0; s < 4; s++)
42     {
43         // Add id to both location and partner location.
44         imageAtomicAdd(texture, loc + workGroupOffset, s, id);
45         imageAtomicAdd(texture, partnerLoc + workGroupOffset, s, id);
46
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);
50     }
51
52     memoryBarrierImage();
53     barrier();
54
55     for (int s = 0; s < 4; s++)
56     {
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);
61     }
62
63     memoryBarrierImage();
64     barrier();
65
66     for (int s = 0; s < 4; s++)
67     {
68         // Finally mask out one of LSBs based on sample
69         imageAtomicAnd(texture, loc + workGroupOffset, s, ~(1u << s));
70     }
71
72     // Verification
73     bool ok = true;
74
75     for (int s = 0; s < 4; s++)
76     {
77         if (imageLoad(texture, loc + workGroupOffset, s).r != (((s + id * 2 + partnerId) | 0xcc000000) & ~(1u << s)))
78             ok = false;
79     }
80
81     vec4 color = ok ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
82     imageStore(result, loc + workGroupOffset, color);
83 }
84 END
85
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
88
89 PIPELINE compute pipeline
90   ATTACH compute_shader
91
92   BIND BUFFER texture AS storage_image DESCRIPTOR_SET 0 BINDING 0
93   BIND BUFFER result AS storage_image DESCRIPTOR_SET 0 BINDING 1
94 END
95
96 RUN pipeline 4 4 1
97
98 EXPECT result IDX 0 0 SIZE 64 64 EQ_RGBA 0 255 0 255