• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!amber
2
3# Test barriers insude control-flow which is sometimes uniform and sometimes non-uniform. This is
4# valid provided the barrier is never executed when the control-flow is non-uniform. To do this we
5# have 2 conditions, which generate 3 possible paths. The first workgroup chooses non-uniformly
6# between the two paths which don't reach the barrier, while the second workgroup uniformly chooses
7# the path with the barrier. The barrier path does some simple operations through shared memory in
8# order to prevent compilers removing the barrier altogether.
9#
10# TODO: On implementations that use a subgroup size of 128 the barrier is still equivalent to a subgroup
11# barrier, so the difference between uniform and non-uniform control won't make a difference. We should
12# force the minimum subgroup size or something.
13
14SHADER compute compute_shader GLSL
15#version 310 es
16
17layout(local_size_x = 128) in;
18
19layout(set=0, binding = 0) buffer B {
20   uint a1[64];
21   uint a2[64];
22
23   uint x;
24} b;
25
26layout(set=0, binding=1) buffer C {
27   uint y[256];
28} c;
29
30shared uint s[128];
31
32void main() {
33   uint l = b.x;
34
35   /* To save us having enormous buffers, force each workgroup to consume only 32 slots */
36   uint a_idx = (gl_LocalInvocationIndex & 31u) + 32u * gl_WorkGroupID.x;
37
38   if (b.a1[a_idx] == 0u) {
39      l = 2u;
40   } else {
41      if (b.a2[a_idx] == 0u) {
42         l = 3u;
43      } else {
44         /* In order for the barrier to be required, reverse the values of a2 through shared memory.
45            If the subgroup is as large as the workgroup here then the barrier can still be removed,
46            so the test should make sure that doesn't happen. */
47         s[gl_LocalInvocationIndex] = l + b.a2[a_idx];
48
49         barrier();
50
51         l = s[127u - gl_LocalInvocationIndex];
52      }
53   }
54
55   c.y[gl_GlobalInvocationID.x] = l;
56}
57END
58
59BUFFER input_buf DATA_TYPE uint32 DATA
60# First 32 values are used by WG 0 to select the non-uniform path. Second 32 are uniform for WG 1.
610 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
620 0 0 0 2 0 0 0 7 0 3 0 9 0 1 0 0 0 5 0 0 0 0 0 8 0 2 0 7 0 0 0    1 1 1 1 2 1 1 1 7 1 3 1 9 1 1 1 1 1 5 1 1 1 1 1 8 1 2 1 7 1 1 1
63# b.x at the end. A random number.
6442
65END
66
67BUFFER res_buf DATA_TYPE uint32 DATA
68# Initialise result to a value not stored in the test so that every lane must write the correct value to pass.
690 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
700 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
710 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
720 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
73END
74
75BUFFER reference_buffer DATA_TYPE uint32 DATA
76# First workgroup hits either the l = 2 or l = 3 paths non-uniformly.
772 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3
782 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3
792 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3
802 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3 2 3
81# Second workgroup has uniform control flow past the barrier. Result is 42 + b.a2, reversed through shared memory.
8243 43 43 49 43 44 43 50 43 43 43 43 43 47 43 43 43 43 43 51 43 45 43 49 43 43 43 44 43 43 43 43
8343 43 43 49 43 44 43 50 43 43 43 43 43 47 43 43 43 43 43 51 43 45 43 49 43 43 43 44 43 43 43 43
8443 43 43 49 43 44 43 50 43 43 43 43 43 47 43 43 43 43 43 51 43 45 43 49 43 43 43 44 43 43 43 43
8543 43 43 49 43 44 43 50 43 43 43 43 43 47 43 43 43 43 43 51 43 45 43 49 43 43 43 44 43 43 43 43
86END
87
88PIPELINE compute pipeline
89    ATTACH compute_shader
90
91    BIND BUFFER input_buf AS storage DESCRIPTOR_SET 0 BINDING 0
92    BIND BUFFER res_buf AS storage DESCRIPTOR_SET 0 BINDING 1
93END
94
95# Spawn 2 workgroups, one with non-uniform control flow, the other with a barrier.
96RUN pipeline 2 1 1
97
98EXPECT res_buf EQ_BUFFER reference_buffer
99