blob: e54744a1d46c6c003bc5154df0140b4cae753e9b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
layout(local_size_x=LOCALSIZE) in;
const uint groupSize=LOCALSIZE*BLOCKSIZE;
uniform uint elements;
layout(binding=2, std430) buffer countBuffer
{
uint maxSize;
uint count[];
};
layout(binding=3, std430) buffer globalSumBuffer
{
uint globalSum[];
};
shared uint groupSum[LOCALSIZE];
void main()
{
uint id=gl_LocalInvocationID.x;
uint dataOffset=gl_WorkGroupID.x*groupSize+id;
uint stop=dataOffset+groupSize;
uint sum=0u;
for(uint i=dataOffset; i < stop; i += LOCALSIZE)
sum += count[i];
groupSum[id]=sum;
barrier();
for(uint s=LOCALSIZE/2; s > 0u; s >>= 1u) {
if(id < s)
groupSum[id] += groupSum[id+s];
barrier();
}
if(id == 0u)
globalSum[gl_WorkGroupID.x]=groupSum[0u];
}
|