blob: 2cb9ed23aacd07870bc216e8d5c1828c164318ba (
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
|
layout(local_size_x=LOCAL_SIZE_X) in;
uniform uint elements;
layout(binding=0, std430) buffer offsetBuffer
{
uint offset[];
};
layout(binding=2, std430) buffer localSumBuffer
{
uint localSum[];
};
void main(void)
{
uint id=gl_GlobalInvocationID.x;
uint m=elements/(gl_WorkGroupSize.x*gl_NumWorkGroups.x);
uint r=elements-m*gl_WorkGroupSize.x*gl_NumWorkGroups.x;
uint row,stop;
if(id < r) {
row=m*id+id;
stop=row+m+1u;
} else {
row=m*id+r;
stop=row+m;
}
uint Sum=offset[row];
offset[elements+row]=Sum;
for(uint i=row+1u; i < stop; ++i) {
Sum += offset[i];
offset[elements+i]=Sum;
}
localSum[id+1u]=Sum;
}
|