Merge pull request #3031 from rg3igalia/sub-group-size-arb-flat-fix
[platform/upstream/glslang.git] / Test / glsl.450.subgroupBallot.comp
1 #version 450\r
2 \r
3 #extension GL_KHR_shader_subgroup_ballot: enable\r
4 \r
5 layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;\r
6 \r
7 layout(binding = 0) buffer Buffers\r
8 {\r
9     vec4  f4;\r
10     ivec4 i4;\r
11     uvec4 u4;\r
12     dvec4 d4;\r
13 } data[4];\r
14 \r
15 void main()\r
16 {\r
17     uint invocation = (gl_SubgroupInvocationID + gl_SubgroupSize) % 4;\r
18 \r
19     uvec4 relMask = gl_SubgroupEqMask +\r
20                        gl_SubgroupGeMask +\r
21                        gl_SubgroupGtMask +\r
22                        gl_SubgroupLeMask +\r
23                        gl_SubgroupLtMask;\r
24 \r
25     uvec4 result = subgroupBallot(true);\r
26 \r
27     data[invocation].u4.x = subgroupBallotBitCount(result);\r
28     data[invocation].u4.y = subgroupBallotBitExtract(result, 0) ? 1 : 0;\r
29     data[invocation].u4.z = subgroupBallotInclusiveBitCount(result) + subgroupBallotExclusiveBitCount(result);\r
30     data[invocation].u4.w = subgroupBallotFindLSB(result) + subgroupBallotFindMSB(result);\r
31 \r
32     if ((relMask == result) && subgroupInverseBallot(data[0].u4))\r
33     {\r
34         data[invocation].f4.x   = subgroupBroadcast(data[0].f4.x,    3);\r
35         data[invocation].f4.xy  = subgroupBroadcast(data[1].f4.xy,   3);\r
36         data[invocation].f4.xyz = subgroupBroadcast(data[2].f4.xyz,  3);\r
37         data[invocation].f4     = subgroupBroadcast(data[3].f4,      3);\r
38 \r
39         data[invocation].i4.x   = subgroupBroadcast(data[0].i4.x,    2);\r
40         data[invocation].i4.xy  = subgroupBroadcast(data[1].i4.xy,   2);\r
41         data[invocation].i4.xyz = subgroupBroadcast(data[2].i4.xyz,  2);\r
42         data[invocation].i4     = subgroupBroadcast(data[3].i4,      2);\r
43 \r
44         data[invocation].u4.x   = subgroupBroadcast(data[0].u4.x,    1);\r
45         data[invocation].u4.xy  = subgroupBroadcast(data[1].u4.xy,   1);\r
46         data[invocation].u4.xyz = subgroupBroadcast(data[2].u4.xyz,  1);\r
47         data[invocation].u4     = subgroupBroadcast(data[3].u4,      1);\r
48 \r
49         data[invocation].d4.x   = subgroupBroadcast(data[0].d4.x,    0);\r
50         data[invocation].d4.xy  = subgroupBroadcast(data[1].d4.xy,   0);\r
51         data[invocation].d4.xyz = subgroupBroadcast(data[2].d4.xyz,  0);\r
52         data[invocation].d4     = subgroupBroadcast(data[3].d4,      0);\r
53 \r
54         data[invocation].i4.x   = int(subgroupBroadcast(data[0].i4.x < 0,            1));\r
55         data[invocation].i4.xy  = ivec2(subgroupBroadcast(lessThan(data[1].i4.xy, ivec2(0)), 1));\r
56         data[invocation].i4.xyz = ivec3(subgroupBroadcast(lessThan(data[1].i4.xyz, ivec3(0)), 1));\r
57         data[invocation].i4     = ivec4(subgroupBroadcast(lessThan(data[1].i4, ivec4(0)), 1));\r
58     }\r
59     else\r
60     {\r
61         data[invocation].f4.x   = subgroupBroadcastFirst(data[0].f4.x);\r
62         data[invocation].f4.xy  = subgroupBroadcastFirst(data[1].f4.xy);\r
63         data[invocation].f4.xyz = subgroupBroadcastFirst(data[2].f4.xyz);\r
64         data[invocation].f4     = subgroupBroadcastFirst(data[3].f4);\r
65 \r
66         data[invocation].i4.x   = subgroupBroadcastFirst(data[0].i4.x);\r
67         data[invocation].i4.xy  = subgroupBroadcastFirst(data[1].i4.xy);\r
68         data[invocation].i4.xyz = subgroupBroadcastFirst(data[2].i4.xyz);\r
69         data[invocation].i4     = subgroupBroadcastFirst(data[3].i4);\r
70 \r
71         data[invocation].u4.x   = subgroupBroadcastFirst(data[0].u4.x);\r
72         data[invocation].u4.xy  = subgroupBroadcastFirst(data[1].u4.xy);\r
73         data[invocation].u4.xyz = subgroupBroadcastFirst(data[2].u4.xyz);\r
74         data[invocation].u4     = subgroupBroadcastFirst(data[3].u4);\r
75 \r
76         data[invocation].d4.x   = subgroupBroadcastFirst(data[0].d4.x);\r
77         data[invocation].d4.xy  = subgroupBroadcastFirst(data[1].d4.xy);\r
78         data[invocation].d4.xyz = subgroupBroadcastFirst(data[2].d4.xyz);\r
79         data[invocation].d4     = subgroupBroadcastFirst(data[3].d4);\r
80 \r
81         data[invocation].i4.x   = int(subgroupBroadcastFirst(data[0].i4.x < 0));\r
82         data[invocation].i4.xy  = ivec2(subgroupBroadcastFirst(lessThan(data[1].i4.xy, ivec2(0))));\r
83         data[invocation].i4.xyz = ivec3(subgroupBroadcastFirst(lessThan(data[1].i4.xyz, ivec3(0))));\r
84         data[invocation].i4     = ivec4(subgroupBroadcastFirst(lessThan(data[1].i4, ivec4(0))));\r
85     }\r
86 }\r