summaryrefslogtreecommitdiff
path: root/graphics/asymptote/base/shaders/sum1.glsl
blob: f1fa8454b0e0fc3ef83b6d7572f812b297012d3a (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
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)
    offset[elements+i]=Sum += offset[i];

  localSum[id+1u]=Sum;
}