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