| 1 |
#version 450 |
| 2 |
|
| 3 |
#if defined(GL_KHR_shader_subgroup_ballot) |
| 4 |
#extension GL_KHR_shader_subgroup_ballot : require |
| 5 |
#elif defined(GL_NV_shader_thread_group) |
| 6 |
#extension GL_NV_shader_thread_group : require |
| 7 |
#elif defined(GL_ARB_shader_ballot) && defined(GL_ARB_shader_int64) |
| 8 |
#extension GL_ARB_shader_int64 : enable |
| 9 |
#extension GL_ARB_shader_ballot : require |
| 10 |
#else |
| 11 |
#error No extensions available to emulate requested subgroup feature. |
| 12 |
#endif |
| 13 |
|
| 14 |
#if defined(GL_KHR_shader_subgroup_basic) |
| 15 |
#extension GL_KHR_shader_subgroup_basic : require |
| 16 |
#elif defined(GL_NV_shader_thread_group) |
| 17 |
#extension GL_NV_shader_thread_group : require |
| 18 |
#elif defined(GL_ARB_shader_ballot) && defined(GL_ARB_shader_int64) |
| 19 |
#extension GL_ARB_shader_int64 : enable |
| 20 |
#extension GL_ARB_shader_ballot : require |
| 21 |
#elif defined(GL_AMD_gcn_shader) && (defined(GL_AMD_gpu_shader_int64) || defined(GL_NV_gpu_shader5)) |
| 22 |
#extension GL_AMD_gpu_shader_int64 : enable |
| 23 |
#extension GL_NV_gpu_shader5 : enable |
| 24 |
#extension GL_AMD_gcn_shader : require |
| 25 |
#else |
| 26 |
#error No extensions available to emulate requested subgroup feature. |
| 27 |
#endif |
| 28 |
|
| 29 |
#if defined(GL_KHR_shader_subgroup_basic) |
| 30 |
#extension GL_KHR_shader_subgroup_basic : require |
| 31 |
#elif defined(GL_NV_shader_thread_group) |
| 32 |
#extension GL_NV_shader_thread_group : require |
| 33 |
#elif defined(GL_ARB_shader_ballot) && defined(GL_ARB_shader_int64) |
| 34 |
#extension GL_ARB_shader_int64 : enable |
| 35 |
#extension GL_ARB_shader_ballot : require |
| 36 |
#else |
| 37 |
#error No extensions available to emulate requested subgroup feature. |
| 38 |
#endif |
| 39 |
|
| 40 |
#if defined(GL_KHR_shader_subgroup_basic) |
| 41 |
#extension GL_KHR_shader_subgroup_basic : require |
| 42 |
#elif defined(GL_NV_shader_thread_group) |
| 43 |
#extension GL_NV_shader_thread_group : require |
| 44 |
#else |
| 45 |
#error No extensions available to emulate requested subgroup feature. |
| 46 |
#endif |
| 47 |
|
| 48 |
#if defined(GL_KHR_shader_subgroup_basic) |
| 49 |
#extension GL_KHR_shader_subgroup_basic : require |
| 50 |
#elif defined(GL_NV_shader_thread_group) |
| 51 |
#extension GL_NV_shader_thread_group : require |
| 52 |
#else |
| 53 |
#error No extensions available to emulate requested subgroup feature. |
| 54 |
#endif |
| 55 |
|
| 56 |
#if defined(GL_KHR_shader_subgroup_ballot) |
| 57 |
#extension GL_KHR_shader_subgroup_ballot : require |
| 58 |
#elif defined(GL_ARB_shader_ballot) && defined(GL_ARB_shader_int64) |
| 59 |
#extension GL_ARB_shader_int64 : enable |
| 60 |
#extension GL_ARB_shader_ballot : require |
| 61 |
#elif defined(GL_NV_shader_thread_shuffle) |
| 62 |
#extension GL_NV_shader_thread_shuffle : require |
| 63 |
#else |
| 64 |
#error No extensions available to emulate requested subgroup feature. |
| 65 |
#endif |
| 66 |
|
| 67 |
#if defined(GL_KHR_shader_subgroup_ballot) |
| 68 |
#extension GL_KHR_shader_subgroup_ballot : require |
| 69 |
#elif defined(GL_NV_shader_thread_group) |
| 70 |
#extension GL_NV_shader_thread_group : require |
| 71 |
#endif |
| 72 |
|
| 73 |
#if defined(GL_KHR_shader_subgroup_vote) |
| 74 |
#extension GL_KHR_shader_subgroup_vote : require |
| 75 |
#elif defined(GL_AMD_gcn_shader) && (defined(GL_AMD_gpu_shader_int64) || defined(GL_NV_gpu_shader5)) |
| 76 |
#extension GL_AMD_gpu_shader_int64 : enable |
| 77 |
#extension GL_NV_gpu_shader5 : enable |
| 78 |
#extension GL_AMD_gcn_shader : require |
| 79 |
#elif defined(GL_NV_gpu_shader_5) |
| 80 |
#extension GL_NV_gpu_shader_5 : require |
| 81 |
#elif defined(GL_ARB_shader_group_vote) |
| 82 |
#extension GL_ARB_shader_group_vote : require |
| 83 |
#else |
| 84 |
#error No extensions available to emulate requested subgroup feature. |
| 85 |
#endif |
| 86 |
|
| 87 |
#if defined(GL_KHR_shader_subgroup_basic) |
| 88 |
#extension GL_KHR_shader_subgroup_basic : require |
| 89 |
#elif defined(GL_NV_shader_thread_group) |
| 90 |
#extension GL_NV_shader_thread_group : require |
| 91 |
#elif defined(GL_ARB_shader_ballot) && defined(GL_ARB_shader_int64) |
| 92 |
#extension GL_ARB_shader_int64 : enable |
| 93 |
#extension GL_ARB_shader_ballot : require |
| 94 |
#elif defined(GL_AMD_gcn_shader) && (defined(GL_AMD_gpu_shader_int64) || defined(GL_NV_gpu_shader5)) |
| 95 |
#extension GL_AMD_gpu_shader_int64 : enable |
| 96 |
#extension GL_NV_gpu_shader5 : enable |
| 97 |
#extension GL_AMD_gcn_shader : require |
| 98 |
#else |
| 99 |
#error No extensions available to emulate requested subgroup feature. |
| 100 |
#endif |
| 101 |
|
| 102 |
#if defined(GL_KHR_shader_subgroup_basic) |
| 103 |
#extension GL_KHR_shader_subgroup_basic : require |
| 104 |
#endif |
| 105 |
|
| 106 |
#if defined(GL_KHR_shader_subgroup_ballot) |
| 107 |
#extension GL_KHR_shader_subgroup_ballot : require |
| 108 |
#elif defined(GL_NV_shader_thread_group) |
| 109 |
#extension GL_NV_shader_thread_group : require |
| 110 |
#elif defined(GL_ARB_shader_ballot) && defined(GL_ARB_shader_int64) |
| 111 |
#extension GL_ARB_shader_int64 : enable |
| 112 |
#extension GL_ARB_shader_ballot : require |
| 113 |
#else |
| 114 |
#error No extensions available to emulate requested subgroup feature. |
| 115 |
#endif |
| 116 |
|
| 117 |
#if defined(GL_NV_shader_thread_group) |
| 118 |
#extension GL_NV_shader_thread_group : require |
| 119 |
#endif |
| 120 |
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; |
| 121 |
|
| 122 |
layout(binding = 0, std430) buffer SSBO |
| 123 |
{ |
| 124 |
float FragColor; |
| 125 |
} _9; |
| 126 |
|
| 127 |
#if defined(GL_KHR_shader_subgroup_ballot) |
| 128 |
#elif defined(GL_NV_shader_thread_group) |
| 129 |
#define gl_SubgroupEqMask uvec4(gl_ThreadEqMaskNV, 0u, 0u, 0u) |
| 130 |
#define gl_SubgroupGeMask uvec4(gl_ThreadGeMaskNV, 0u, 0u, 0u) |
| 131 |
#define gl_SubgroupGtMask uvec4(gl_ThreadGtMaskNV, 0u, 0u, 0u) |
| 132 |
#define gl_SubgroupLeMask uvec4(gl_ThreadLeMaskNV, 0u, 0u, 0u) |
| 133 |
#define gl_SubgroupLtMask uvec4(gl_ThreadLtMaskNV, 0u, 0u, 0u) |
| 134 |
#elif defined(GL_ARB_shader_ballot) |
| 135 |
#define gl_SubgroupEqMask uvec4(unpackUint2x32(gl_SubGroupEqMaskARB), 0u, 0u) |
| 136 |
#define gl_SubgroupGeMask uvec4(unpackUint2x32(gl_SubGroupGeMaskARB), 0u, 0u) |
| 137 |
#define gl_SubgroupGtMask uvec4(unpackUint2x32(gl_SubGroupGtMaskARB), 0u, 0u) |
| 138 |
#define gl_SubgroupLeMask uvec4(unpackUint2x32(gl_SubGroupLeMaskARB), 0u, 0u) |
| 139 |
#define gl_SubgroupLtMask uvec4(unpackUint2x32(gl_SubGroupLtMaskARB), 0u, 0u) |
| 140 |
#endif |
| 141 |
|
| 142 |
#if defined(GL_KHR_shader_subgroup_basic) |
| 143 |
#elif defined(GL_NV_shader_thread_group) |
| 144 |
#define gl_SubgroupSize gl_WarpSizeNV |
| 145 |
#elif defined(GL_ARB_shader_ballot) |
| 146 |
#define gl_SubgroupSize gl_SubGroupSizeARB |
| 147 |
#elif defined(GL_AMD_gcn_shader) |
| 148 |
#define gl_SubgroupSize uint(gl_SIMDGroupSizeAMD) |
| 149 |
#endif |
| 150 |
|
| 151 |
#if defined(GL_KHR_shader_subgroup_basic) |
| 152 |
#elif defined(GL_NV_shader_thread_group) |
| 153 |
#define gl_SubgroupInvocationID gl_ThreadInWarpNV |
| 154 |
#elif defined(GL_ARB_shader_ballot) |
| 155 |
#define gl_SubgroupInvocationID gl_SubGroupInvocationARB |
| 156 |
#endif |
| 157 |
|
| 158 |
#if defined(GL_KHR_shader_subgroup_basic) |
| 159 |
#elif defined(GL_NV_shader_thread_group) |
| 160 |
#define gl_SubgroupID gl_WarpIDNV |
| 161 |
#endif |
| 162 |
|
| 163 |
#if defined(GL_KHR_shader_subgroup_basic) |
| 164 |
#elif defined(GL_NV_shader_thread_group) |
| 165 |
#define gl_NumSubgroups gl_WarpsPerSMNV |
| 166 |
#endif |
| 167 |
|
| 168 |
#if defined(GL_KHR_shader_subgroup_ballot) |
| 169 |
#elif defined(GL_ARB_shader_ballot) |
| 170 |
int subgroupBroadcastFirst(int value) { return readFirstInvocationARB(value); } |
| 171 |
ivec2 subgroupBroadcastFirst(ivec2 value) { return readFirstInvocationARB(value); } |
| 172 |
ivec3 subgroupBroadcastFirst(ivec3 value) { return readFirstInvocationARB(value); } |
| 173 |
ivec4 subgroupBroadcastFirst(ivec4 value) { return readFirstInvocationARB(value); } |
| 174 |
uint subgroupBroadcastFirst(uint value) { return readFirstInvocationARB(value); } |
| 175 |
uvec2 subgroupBroadcastFirst(uvec2 value) { return readFirstInvocationARB(value); } |
| 176 |
uvec3 subgroupBroadcastFirst(uvec3 value) { return readFirstInvocationARB(value); } |
| 177 |
uvec4 subgroupBroadcastFirst(uvec4 value) { return readFirstInvocationARB(value); } |
| 178 |
float subgroupBroadcastFirst(float value) { return readFirstInvocationARB(value); } |
| 179 |
vec2 subgroupBroadcastFirst(vec2 value) { return readFirstInvocationARB(value); } |
| 180 |
vec3 subgroupBroadcastFirst(vec3 value) { return readFirstInvocationARB(value); } |
| 181 |
vec4 subgroupBroadcastFirst(vec4 value) { return readFirstInvocationARB(value); } |
| 182 |
double subgroupBroadcastFirst(double value) { return readFirstInvocationARB(value); } |
| 183 |
dvec2 subgroupBroadcastFirst(dvec2 value) { return readFirstInvocationARB(value); } |
| 184 |
dvec3 subgroupBroadcastFirst(dvec3 value) { return readFirstInvocationARB(value); } |
| 185 |
dvec4 subgroupBroadcastFirst(dvec4 value) { return readFirstInvocationARB(value); } |
| 186 |
int subgroupBroadcast(int value, uint id) { return readInvocationARB(value, id); } |
| 187 |
ivec2 subgroupBroadcast(ivec2 value, uint id) { return readInvocationARB(value, id); } |
| 188 |
ivec3 subgroupBroadcast(ivec3 value, uint id) { return readInvocationARB(value, id); } |
| 189 |
ivec4 subgroupBroadcast(ivec4 value, uint id) { return readInvocationARB(value, id); } |
| 190 |
uint subgroupBroadcast(uint value, uint id) { return readInvocationARB(value, id); } |
| 191 |
uvec2 subgroupBroadcast(uvec2 value, uint id) { return readInvocationARB(value, id); } |
| 192 |
uvec3 subgroupBroadcast(uvec3 value, uint id) { return readInvocationARB(value, id); } |
| 193 |
uvec4 subgroupBroadcast(uvec4 value, uint id) { return readInvocationARB(value, id); } |
| 194 |
float subgroupBroadcast(float value, uint id) { return readInvocationARB(value, id); } |
| 195 |
vec2 subgroupBroadcast(vec2 value, uint id) { return readInvocationARB(value, id); } |
| 196 |
vec3 subgroupBroadcast(vec3 value, uint id) { return readInvocationARB(value, id); } |
| 197 |
vec4 subgroupBroadcast(vec4 value, uint id) { return readInvocationARB(value, id); } |
| 198 |
double subgroupBroadcast(double value, uint id) { return readInvocationARB(value, id); } |
| 199 |
dvec2 subgroupBroadcast(dvec2 value, uint id) { return readInvocationARB(value, id); } |
| 200 |
dvec3 subgroupBroadcast(dvec3 value, uint id) { return readInvocationARB(value, id); } |
| 201 |
dvec4 subgroupBroadcast(dvec4 value, uint id) { return readInvocationARB(value, id); } |
| 202 |
#elif defined(GL_NV_shader_thread_shuffle) |
| 203 |
int subgroupBroadcastFirst(int value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 204 |
ivec2 subgroupBroadcastFirst(ivec2 value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 205 |
ivec3 subgroupBroadcastFirst(ivec3 value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 206 |
ivec4 subgroupBroadcastFirst(ivec4 value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 207 |
uint subgroupBroadcastFirst(uint value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 208 |
uvec2 subgroupBroadcastFirst(uvec2 value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 209 |
uvec3 subgroupBroadcastFirst(uvec3 value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 210 |
uvec4 subgroupBroadcastFirst(uvec4 value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 211 |
float subgroupBroadcastFirst(float value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 212 |
vec2 subgroupBroadcastFirst(vec2 value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 213 |
vec3 subgroupBroadcastFirst(vec3 value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 214 |
vec4 subgroupBroadcastFirst(vec4 value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 215 |
double subgroupBroadcastFirst(double value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 216 |
dvec2 subgroupBroadcastFirst(dvec2 value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 217 |
dvec3 subgroupBroadcastFirst(dvec3 value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 218 |
dvec4 subgroupBroadcastFirst(dvec4 value) { return shuffleNV(value, findLSB(ballotThreadNV(true)), gl_WarpSizeNV); } |
| 219 |
int subgroupBroadcast(int value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 220 |
ivec2 subgroupBroadcast(ivec2 value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 221 |
ivec3 subgroupBroadcast(ivec3 value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 222 |
ivec4 subgroupBroadcast(ivec4 value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 223 |
uint subgroupBroadcast(uint value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 224 |
uvec2 subgroupBroadcast(uvec2 value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 225 |
uvec3 subgroupBroadcast(uvec3 value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 226 |
uvec4 subgroupBroadcast(uvec4 value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 227 |
float subgroupBroadcast(float value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 228 |
vec2 subgroupBroadcast(vec2 value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 229 |
vec3 subgroupBroadcast(vec3 value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 230 |
vec4 subgroupBroadcast(vec4 value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 231 |
double subgroupBroadcast(double value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 232 |
dvec2 subgroupBroadcast(dvec2 value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 233 |
dvec3 subgroupBroadcast(dvec3 value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 234 |
dvec4 subgroupBroadcast(dvec4 value, uint id) { return shuffleNV(value, id, gl_WarpSizeNV); } |
| 235 |
#endif |
| 236 |
|
| 237 |
#if defined(GL_KHR_shader_subgroup_ballot) |
| 238 |
#elif defined(GL_NV_shader_thread_group) |
| 239 |
uint subgroupBallotFindLSB(uvec4 value) { return findLSB(value.x); } |
| 240 |
uint subgroupBallotFindMSB(uvec4 value) { return findMSB(value.x); } |
| 241 |
#else |
| 242 |
uint subgroupBallotFindLSB(uvec4 value) |
| 243 |
{ |
| 244 |
int firstLive = findLSB(value.x); |
| 245 |
return uint(firstLive != -1 ? firstLive : (findLSB(value.y) + 32)); |
| 246 |
} |
| 247 |
uint subgroupBallotFindMSB(uvec4 value) |
| 248 |
{ |
| 249 |
int firstLive = findMSB(value.y); |
| 250 |
return uint(firstLive != -1 ? (firstLive + 32) : findMSB(value.x)); |
| 251 |
} |
| 252 |
#endif |
| 253 |
|
| 254 |
#if defined(GL_KHR_shader_subgroup_vote) |
| 255 |
#elif defined(GL_AMD_gcn_shader) |
| 256 |
bool subgroupAll(bool value) { return ballotAMD(value) == ballotAMD(true); } |
| 257 |
bool subgroupAny(bool value) { return ballotAMD(value) != 0ull; } |
| 258 |
bool subgroupAllEqual(bool value) { uint64_t b = ballotAMD(value); return b == 0ull || b == ballotAMD(true); } |
| 259 |
#elif defined(GL_NV_gpu_shader_5) |
| 260 |
bool subgroupAll(bool value) { return allThreadsNV(value); } |
| 261 |
bool subgroupAny(bool value) { return anyThreadNV(value); } |
| 262 |
bool subgroupAllEqual(bool value) { return allThreadsEqualNV(value); } |
| 263 |
#elif defined(GL_ARB_shader_group_vote) |
| 264 |
bool subgroupAll(bool v) { return allInvocationsARB(v); } |
| 265 |
bool subgroupAny(bool v) { return anyInvocationARB(v); } |
| 266 |
bool subgroupAllEqual(bool v) { return allInvocationsEqualARB(v); } |
| 267 |
#endif |
| 268 |
|
| 269 |
#ifndef GL_KHR_shader_subgroup_vote |
| 270 |
#define _SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(type) bool subgroupAllEqual(type value) { return subgroupAllEqual(subgroupBroadcastFirst(value) == value); } |
| 271 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(int) |
| 272 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(ivec2) |
| 273 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(ivec3) |
| 274 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(ivec4) |
| 275 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(uint) |
| 276 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(uvec2) |
| 277 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(uvec3) |
| 278 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(uvec4) |
| 279 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(float) |
| 280 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(vec2) |
| 281 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(vec3) |
| 282 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(vec4) |
| 283 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(double) |
| 284 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(dvec2) |
| 285 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(dvec3) |
| 286 |
_SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND(dvec4) |
| 287 |
#undef _SPIRV_CROSS_SUBGROUP_ALL_EQUAL_WORKAROUND |
| 288 |
#endif |
| 289 |
|
| 290 |
#if defined(GL_KHR_shader_subgroup_ballot) |
| 291 |
#elif defined(GL_NV_shader_thread_group) |
| 292 |
uvec4 subgroupBallot(bool v) { return uvec4(ballotThreadNV(v), 0u, 0u, 0u); } |
| 293 |
#elif defined(GL_ARB_shader_ballot) |
| 294 |
uvec4 subgroupBallot(bool v) { return uvec4(unpackUint2x32(ballotARB(v)), 0u, 0u); } |
| 295 |
#endif |
| 296 |
|
| 297 |
#ifndef GL_KHR_shader_subgroup_basic |
| 298 |
bool subgroupElect() |
| 299 |
{ |
| 300 |
uvec4 activeMask = subgroupBallot(true); |
| 301 |
uint firstLive = subgroupBallotFindLSB(activeMask); |
| 302 |
return gl_SubgroupInvocationID == firstLive; |
| 303 |
} |
| 304 |
#endif |
| 305 |
|
| 306 |
#ifndef GL_KHR_shader_subgroup_basic |
| 307 |
void subgroupBarrier() { memoryBarrierShared(); } |
| 308 |
#endif |
| 309 |
|
| 310 |
#ifndef GL_KHR_shader_subgroup_basic |
| 311 |
void subgroupMemoryBarrier() { groupMemoryBarrier(); } |
| 312 |
void subgroupMemoryBarrierBuffer() { groupMemoryBarrier(); } |
| 313 |
void subgroupMemoryBarrierShared() { memoryBarrierShared(); } |
| 314 |
void subgroupMemoryBarrierImage() { groupMemoryBarrier(); } |
| 315 |
#endif |
| 316 |
|
| 317 |
#ifndef GL_KHR_shader_subgroup_ballot |
| 318 |
bool subgroupInverseBallot(uvec4 value) |
| 319 |
{ |
| 320 |
return any(notEqual(value.xy & gl_SubgroupEqMask.xy, uvec2(0u))); |
| 321 |
} |
| 322 |
uint subgroupBallotInclusiveBitCount(uvec4 value) |
| 323 |
{ |
| 324 |
uvec2 v = value.xy & gl_SubgroupLeMask.xy; |
| 325 |
ivec2 c = bitCount(v); |
| 326 |
#ifdef GL_NV_shader_thread_group |
| 327 |
return uint(c.x); |
| 328 |
#else |
| 329 |
return uint(c.x + c.y); |
| 330 |
#endif |
| 331 |
} |
| 332 |
uint subgroupBallotExclusiveBitCount(uvec4 value) |
| 333 |
{ |
| 334 |
uvec2 v = value.xy & gl_SubgroupLtMask.xy; |
| 335 |
ivec2 c = bitCount(v); |
| 336 |
#ifdef GL_NV_shader_thread_group |
| 337 |
return uint(c.x); |
| 338 |
#else |
| 339 |
return uint(c.x + c.y); |
| 340 |
#endif |
| 341 |
} |
| 342 |
#endif |
| 343 |
|
| 344 |
#ifndef GL_KHR_shader_subgroup_ballot |
| 345 |
uint subgroupBallotBitCount(uvec4 value) |
| 346 |
{ |
| 347 |
ivec2 c = bitCount(value.xy); |
| 348 |
#ifdef GL_NV_shader_thread_group |
| 349 |
return uint(c.x); |
| 350 |
#else |
| 351 |
return uint(c.x + c.y); |
| 352 |
#endif |
| 353 |
} |
| 354 |
#endif |
| 355 |
|
| 356 |
#ifndef GL_KHR_shader_subgroup_ballot |
| 357 |
bool subgroupBallotBitExtract(uvec4 value, uint index) |
| 358 |
{ |
| 359 |
#ifdef GL_NV_shader_thread_group |
| 360 |
uint shifted = value.x >> index; |
| 361 |
#else |
| 362 |
uint shifted = value[index >> 5u] >> (index & 0x1fu); |
| 363 |
#endif |
| 364 |
return (shifted & 1u) != 0u; |
| 365 |
} |
| 366 |
#endif |
| 367 |
|
| 368 |
void main() |
| 369 |
{ |
| 370 |
_9.FragColor = float(gl_NumSubgroups); |
| 371 |
_9.FragColor = float(gl_SubgroupID); |
| 372 |
_9.FragColor = float(gl_SubgroupSize); |
| 373 |
_9.FragColor = float(gl_SubgroupInvocationID); |
| 374 |
subgroupMemoryBarrier(); |
| 375 |
subgroupBarrier(); |
| 376 |
subgroupMemoryBarrier(); |
| 377 |
subgroupMemoryBarrierBuffer(); |
| 378 |
subgroupMemoryBarrierShared(); |
| 379 |
subgroupMemoryBarrierImage(); |
| 380 |
bool elected = subgroupElect(); |
| 381 |
_9.FragColor = vec4(gl_SubgroupEqMask).x; |
| 382 |
_9.FragColor = vec4(gl_SubgroupGeMask).x; |
| 383 |
_9.FragColor = vec4(gl_SubgroupGtMask).x; |
| 384 |
_9.FragColor = vec4(gl_SubgroupLeMask).x; |
| 385 |
_9.FragColor = vec4(gl_SubgroupLtMask).x; |
| 386 |
vec4 broadcasted = subgroupBroadcast(vec4(10.0), 8u); |
| 387 |
vec3 first = subgroupBroadcastFirst(vec3(20.0)); |
| 388 |
uvec4 ballot_value = subgroupBallot(true); |
| 389 |
bool inverse_ballot_value = subgroupInverseBallot(ballot_value); |
| 390 |
bool bit_extracted = subgroupBallotBitExtract(uvec4(10u), 8u); |
| 391 |
uint bit_count = subgroupBallotBitCount(ballot_value); |
| 392 |
uint inclusive_bit_count = subgroupBallotInclusiveBitCount(ballot_value); |
| 393 |
uint exclusive_bit_count = subgroupBallotExclusiveBitCount(ballot_value); |
| 394 |
uint lsb = subgroupBallotFindLSB(ballot_value); |
| 395 |
uint msb = subgroupBallotFindMSB(ballot_value); |
| 396 |
bool has_all = subgroupAll(true); |
| 397 |
bool has_any = subgroupAny(true); |
| 398 |
bool has_equal_bool = subgroupAllEqual(true); |
| 399 |
bool has_equal_T = subgroupAllEqual(uvec3(5u)); |
| 400 |
} |
| 401 |
|