• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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	bvec4 anded_b = subgroupAnd(equal(ballot_value, uvec4(42)));
85	bvec4 ored_b = subgroupOr(equal(ballot_value, uvec4(42)));
86	bvec4 xored_b = subgroupXor(equal(ballot_value, uvec4(42)));
87
88	added = subgroupInclusiveAdd(added);
89	iadded = subgroupInclusiveAdd(iadded);
90	multiplied = subgroupInclusiveMul(multiplied);
91	imultiplied = subgroupInclusiveMul(imultiplied);
92	//lo = subgroupInclusiveMin(lo);  // FIXME: Unsupported by Metal
93	//hi = subgroupInclusiveMax(hi);
94	//slo = subgroupInclusiveMin(slo);
95	//shi = subgroupInclusiveMax(shi);
96	//ulo = subgroupInclusiveMin(ulo);
97	//uhi = subgroupInclusiveMax(uhi);
98	//anded = subgroupInclusiveAnd(anded);
99	//ored = subgroupInclusiveOr(ored);
100	//xored = subgroupInclusiveXor(ored);
101	//added = subgroupExclusiveAdd(lo);
102
103	added = subgroupExclusiveAdd(multiplied);
104	multiplied = subgroupExclusiveMul(multiplied);
105	iadded = subgroupExclusiveAdd(imultiplied);
106	imultiplied = subgroupExclusiveMul(imultiplied);
107	//lo = subgroupExclusiveMin(lo);  // FIXME: Unsupported by Metal
108	//hi = subgroupExclusiveMax(hi);
109	//ulo = subgroupExclusiveMin(ulo);
110	//uhi = subgroupExclusiveMax(uhi);
111	//slo = subgroupExclusiveMin(slo);
112	//shi = subgroupExclusiveMax(shi);
113	//anded = subgroupExclusiveAnd(anded);
114	//ored = subgroupExclusiveOr(ored);
115	//xored = subgroupExclusiveXor(ored);
116
117	// clustered
118	added = subgroupClusteredAdd(added, 4u);
119	multiplied = subgroupClusteredMul(multiplied, 4u);
120	iadded = subgroupClusteredAdd(iadded, 4u);
121	imultiplied = subgroupClusteredMul(imultiplied, 4u);
122	lo = subgroupClusteredMin(lo, 4u);
123	hi = subgroupClusteredMax(hi, 4u);
124	ulo = subgroupClusteredMin(ulo, 4u);
125	uhi = subgroupClusteredMax(uhi, 4u);
126	slo = subgroupClusteredMin(slo, 4u);
127	shi = subgroupClusteredMax(shi, 4u);
128	anded = subgroupClusteredAnd(anded, 4u);
129	ored = subgroupClusteredOr(ored, 4u);
130	xored = subgroupClusteredXor(xored, 4u);
131
132	anded_b = subgroupClusteredAnd(equal(anded, uvec4(2u)), 4u);
133	ored_b = subgroupClusteredOr(equal(ored, uvec4(3u)), 4u);
134	xored_b = subgroupClusteredXor(equal(xored, uvec4(4u)), 4u);
135
136	// quad
137	vec4 swap_horiz = subgroupQuadSwapHorizontal(vec4(20.0));
138	bvec4 swap_horiz_bool = subgroupQuadSwapHorizontal(bvec4(true));
139	vec4 swap_vertical = subgroupQuadSwapVertical(vec4(20.0));
140	bvec4 swap_vertical_bool = subgroupQuadSwapVertical(bvec4(true));
141	vec4 swap_diagonal = subgroupQuadSwapDiagonal(vec4(20.0));
142	bvec4 swap_diagonal_bool = subgroupQuadSwapDiagonal(bvec4(true));
143	vec4 quad_broadcast = subgroupQuadBroadcast(vec4(20.0), 3u);
144	bvec4 quad_broadcast_bool = subgroupQuadBroadcast(bvec4(true), 3u);
145}
146