1#version 450 2#extension GL_KHR_shader_subgroup_basic : require 3#extension GL_KHR_shader_subgroup_ballot : require 4#extension GL_KHR_shader_subgroup_vote : require 5#extension GL_KHR_shader_subgroup_shuffle : require 6#extension GL_KHR_shader_subgroup_shuffle_relative : require 7#extension GL_KHR_shader_subgroup_arithmetic : require 8#extension GL_KHR_shader_subgroup_clustered : require 9#extension GL_KHR_shader_subgroup_quad : require 10layout(local_size_x = 1) in; 11 12layout(std430, binding = 0) buffer SSBO 13{ 14 float FragColor; 15}; 16 17void main() 18{ 19 // basic 20 FragColor = float(gl_NumSubgroups); 21 FragColor = float(gl_SubgroupID); 22 FragColor = float(gl_SubgroupSize); 23 FragColor = float(gl_SubgroupInvocationID); 24 subgroupBarrier(); 25 subgroupMemoryBarrier(); 26 subgroupMemoryBarrierBuffer(); 27 subgroupMemoryBarrierShared(); 28 subgroupMemoryBarrierImage(); 29 bool elected = subgroupElect(); 30 31 // ballot 32 FragColor = float(gl_SubgroupEqMask); 33 FragColor = float(gl_SubgroupGeMask); 34 FragColor = float(gl_SubgroupGtMask); 35 FragColor = float(gl_SubgroupLeMask); 36 FragColor = float(gl_SubgroupLtMask); 37 vec4 broadcasted = subgroupBroadcast(vec4(10.0), 8u); 38 bvec2 broadcasted_bool = subgroupBroadcast(bvec2(true), 8u); 39 vec3 first = subgroupBroadcastFirst(vec3(20.0)); 40 bvec4 first_bool = subgroupBroadcastFirst(bvec4(false)); 41 uvec4 ballot_value = subgroupBallot(true); 42 bool inverse_ballot_value = subgroupInverseBallot(ballot_value); 43 bool bit_extracted = subgroupBallotBitExtract(uvec4(10u), 8u); 44 uint bit_count = subgroupBallotBitCount(ballot_value); 45 uint inclusive_bit_count = subgroupBallotInclusiveBitCount(ballot_value); 46 uint exclusive_bit_count = subgroupBallotExclusiveBitCount(ballot_value); 47 uint lsb = subgroupBallotFindLSB(ballot_value); 48 uint msb = subgroupBallotFindMSB(ballot_value); 49 50 // shuffle 51 uint shuffled = subgroupShuffle(10u, 8u); 52 bool shuffled_bool = subgroupShuffle(true, 9u); 53 uint shuffled_xor = subgroupShuffleXor(30u, 8u); 54 bool shuffled_xor_bool = subgroupShuffleXor(false, 9u); 55 56 // shuffle relative 57 uint shuffled_up = subgroupShuffleUp(20u, 4u); 58 bool shuffled_up_bool = subgroupShuffleUp(true, 4u); 59 uint shuffled_down = subgroupShuffleDown(20u, 4u); 60 bool shuffled_down_bool = subgroupShuffleDown(false, 4u); 61 62 // vote 63 bool has_all = subgroupAll(true); 64 bool has_any = subgroupAny(true); 65 bool has_equal = subgroupAllEqual(0); 66 has_equal = subgroupAllEqual(true); 67 has_equal = subgroupAllEqual(vec3(0.0, 1.0, 2.0)); 68 has_equal = subgroupAllEqual(bvec4(true, true, false, true)); 69 70 // arithmetic 71 vec4 added = subgroupAdd(vec4(20.0)); 72 ivec4 iadded = subgroupAdd(ivec4(20)); 73 vec4 multiplied = subgroupMul(vec4(20.0)); 74 ivec4 imultiplied = subgroupMul(ivec4(20)); 75 vec4 lo = subgroupMin(vec4(20.0)); 76 vec4 hi = subgroupMax(vec4(20.0)); 77 ivec4 slo = subgroupMin(ivec4(20)); 78 ivec4 shi = subgroupMax(ivec4(20)); 79 uvec4 ulo = subgroupMin(uvec4(20)); 80 uvec4 uhi = subgroupMax(uvec4(20)); 81 uvec4 anded = subgroupAnd(ballot_value); 82 uvec4 ored = subgroupOr(ballot_value); 83 uvec4 xored = subgroupXor(ballot_value); 84 85 added = subgroupInclusiveAdd(added); 86 iadded = subgroupInclusiveAdd(iadded); 87 multiplied = subgroupInclusiveMul(multiplied); 88 imultiplied = subgroupInclusiveMul(imultiplied); 89 //lo = subgroupInclusiveMin(lo); // FIXME: Unsupported by Metal 90 //hi = subgroupInclusiveMax(hi); 91 //slo = subgroupInclusiveMin(slo); 92 //shi = subgroupInclusiveMax(shi); 93 //ulo = subgroupInclusiveMin(ulo); 94 //uhi = subgroupInclusiveMax(uhi); 95 //anded = subgroupInclusiveAnd(anded); 96 //ored = subgroupInclusiveOr(ored); 97 //xored = subgroupInclusiveXor(ored); 98 //added = subgroupExclusiveAdd(lo); 99 100 added = subgroupExclusiveAdd(multiplied); 101 multiplied = subgroupExclusiveMul(multiplied); 102 iadded = subgroupExclusiveAdd(imultiplied); 103 imultiplied = subgroupExclusiveMul(imultiplied); 104 //lo = subgroupExclusiveMin(lo); // FIXME: Unsupported by Metal 105 //hi = subgroupExclusiveMax(hi); 106 //ulo = subgroupExclusiveMin(ulo); 107 //uhi = subgroupExclusiveMax(uhi); 108 //slo = subgroupExclusiveMin(slo); 109 //shi = subgroupExclusiveMax(shi); 110 //anded = subgroupExclusiveAnd(anded); 111 //ored = subgroupExclusiveOr(ored); 112 //xored = subgroupExclusiveXor(ored); 113 114 // clustered 115 added = subgroupClusteredAdd(added, 4u); 116 multiplied = subgroupClusteredMul(multiplied, 4u); 117 iadded = subgroupClusteredAdd(iadded, 4u); 118 imultiplied = subgroupClusteredMul(imultiplied, 4u); 119 lo = subgroupClusteredMin(lo, 4u); 120 hi = subgroupClusteredMax(hi, 4u); 121 ulo = subgroupClusteredMin(ulo, 4u); 122 uhi = subgroupClusteredMax(uhi, 4u); 123 slo = subgroupClusteredMin(slo, 4u); 124 shi = subgroupClusteredMax(shi, 4u); 125 anded = subgroupClusteredAnd(anded, 4u); 126 ored = subgroupClusteredOr(ored, 4u); 127 xored = subgroupClusteredXor(xored, 4u); 128 129 // quad 130 vec4 swap_horiz = subgroupQuadSwapHorizontal(vec4(20.0)); 131 bvec4 swap_horiz_bool = subgroupQuadSwapHorizontal(bvec4(true)); 132 vec4 swap_vertical = subgroupQuadSwapVertical(vec4(20.0)); 133 bvec4 swap_vertical_bool = subgroupQuadSwapVertical(bvec4(true)); 134 vec4 swap_diagonal = subgroupQuadSwapDiagonal(vec4(20.0)); 135 bvec4 swap_diagonal_bool = subgroupQuadSwapDiagonal(bvec4(true)); 136 vec4 quad_broadcast = subgroupQuadBroadcast(vec4(20.0), 3u); 137 bvec4 quad_broadcast_bool = subgroupQuadBroadcast(bvec4(true), 3u); 138} 139