Debian Codegraph @

third_party/spirv-cross/samples/cpp/shared.comp

raw
1 #version 310 es
2 layout(local_size_x = 64) in;
3
4 layout(set = 0, binding = 0, std430) readonly buffer SSBO0
5 {
6 float inputs[];
7 };
8
9 layout(set = 0, binding = 1, std430) writeonly buffer SSBO1
10 {
11 float outputs[];
12 };
13
14 shared float tmp[gl_WorkGroupSize.x];
15
16 void main()
17 {
18 uint local = gl_LocalInvocationIndex;
19 uint work_group = gl_WorkGroupID.x;
20
21 // Does a trivial parallel reduction through shared memory.
22 tmp[local] = inputs[work_group * gl_WorkGroupSize.x * 2u + local] + inputs[work_group * gl_WorkGroupSize.x * 2u + local + gl_WorkGroupSize.x];
23 memoryBarrierShared();
24 barrier();
25
26 for (uint limit = 32u; limit > 1u; limit >>= 1u)
27 {
28 if (local < limit)
29 tmp[local] = tmp[local] + tmp[local + limit];
30 memoryBarrierShared();
31 barrier();
32 }
33
34 if (local == 0u)
35 outputs[work_group] = tmp[0] + tmp[1];
36 }