Daniel Koch | 83170e3 | 2019-03-26 13:45:33 -0400 | [diff] [blame] | 1 | #version 320 es
|
| 2 |
|
| 3 | #extension GL_KHR_shader_subgroup_ballot: enable
|
| 4 |
|
| 5 | layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
| 6 |
|
| 7 | layout(binding = 0) buffer Buffers
|
| 8 | {
|
| 9 | vec4 f4;
|
| 10 | ivec4 i4;
|
| 11 | uvec4 u4;
|
| 12 | } data[4];
|
| 13 |
|
| 14 | void main()
|
| 15 | {
|
| 16 | uint invocation = (gl_SubgroupInvocationID + gl_SubgroupSize) % 4u;
|
| 17 |
|
| 18 | uvec4 relMask = gl_SubgroupEqMask +
|
| 19 | gl_SubgroupGeMask +
|
| 20 | gl_SubgroupGtMask +
|
| 21 | gl_SubgroupLeMask +
|
| 22 | gl_SubgroupLtMask;
|
| 23 |
|
| 24 | uvec4 result = subgroupBallot(true);
|
| 25 |
|
| 26 | data[0].u4.x = subgroupBallotBitCount(result);
|
| 27 | data[0].u4.y = subgroupBallotBitExtract(result, 0u) ? 1u : 0u;
|
| 28 | data[0].u4.z = subgroupBallotInclusiveBitCount(result) + subgroupBallotExclusiveBitCount(result);
|
| 29 | data[0].u4.w = subgroupBallotFindLSB(result) + subgroupBallotFindMSB(result);
|
| 30 |
|
| 31 | if ((relMask == result) && subgroupInverseBallot(data[0].u4))
|
| 32 | {
|
| 33 | data[1].f4.x = subgroupBroadcast(data[0].f4.x, 3u);
|
| 34 | data[1].f4.xy = subgroupBroadcast(data[1].f4.xy, 3u);
|
| 35 | data[1].f4.xyz = subgroupBroadcast(data[2].f4.xyz, 3u);
|
| 36 | data[1].f4 = subgroupBroadcast(data[3].f4, 3u);
|
| 37 |
|
| 38 | data[2].i4.x = subgroupBroadcast(data[0].i4.x, 2u);
|
| 39 | data[2].i4.xy = subgroupBroadcast(data[1].i4.xy, 2u);
|
| 40 | data[2].i4.xyz = subgroupBroadcast(data[2].i4.xyz, 2u);
|
| 41 | data[2].i4 = subgroupBroadcast(data[3].i4, 2u);
|
| 42 |
|
| 43 | data[3].u4.x = subgroupBroadcast(data[0].u4.x, 1u);
|
| 44 | data[3].u4.xy = subgroupBroadcast(data[1].u4.xy, 1u);
|
| 45 | data[3].u4.xyz = subgroupBroadcast(data[2].u4.xyz, 1u);
|
| 46 | data[3].u4 = subgroupBroadcast(data[3].u4, 1u);
|
| 47 |
|
| 48 | data[0].i4.x = int(subgroupBroadcast(data[0].i4.x < 0, 1u));
|
| 49 | data[0].i4.xy = ivec2(subgroupBroadcast(lessThan(data[1].i4.xy, ivec2(0)), 1u));
|
| 50 | data[0].i4.xyz = ivec3(subgroupBroadcast(lessThan(data[1].i4.xyz, ivec3(0)), 1u));
|
| 51 | data[0].i4 = ivec4(subgroupBroadcast(lessThan(data[1].i4, ivec4(0)), 1u));
|
| 52 | }
|
| 53 | else
|
| 54 | {
|
| 55 | data[1].f4.x = subgroupBroadcastFirst(data[0].f4.x);
|
| 56 | data[1].f4.xy = subgroupBroadcastFirst(data[1].f4.xy);
|
| 57 | data[1].f4.xyz = subgroupBroadcastFirst(data[2].f4.xyz);
|
| 58 | data[1].f4 = subgroupBroadcastFirst(data[3].f4);
|
| 59 |
|
| 60 | data[2].i4.x = subgroupBroadcastFirst(data[0].i4.x);
|
| 61 | data[2].i4.xy = subgroupBroadcastFirst(data[1].i4.xy);
|
| 62 | data[2].i4.xyz = subgroupBroadcastFirst(data[2].i4.xyz);
|
| 63 | data[2].i4 = subgroupBroadcastFirst(data[3].i4);
|
| 64 |
|
| 65 | data[3].u4.x = subgroupBroadcastFirst(data[0].u4.x);
|
| 66 | data[3].u4.xy = subgroupBroadcastFirst(data[1].u4.xy);
|
| 67 | data[3].u4.xyz = subgroupBroadcastFirst(data[2].u4.xyz);
|
| 68 | data[3].u4 = subgroupBroadcastFirst(data[3].u4);
|
| 69 |
|
| 70 | data[0].i4.x = int(subgroupBroadcastFirst(data[0].i4.x < 0));
|
| 71 | data[0].i4.xy = ivec2(subgroupBroadcastFirst(lessThan(data[1].i4.xy, ivec2(0))));
|
| 72 | data[0].i4.xyz = ivec3(subgroupBroadcastFirst(lessThan(data[1].i4.xyz, ivec3(0))));
|
| 73 | data[0].i4 = ivec4(subgroupBroadcastFirst(lessThan(data[1].i4, ivec4(0))));
|
| 74 | }
|
| 75 | }
|