Add non subgroup based prefix sum
This commit is contained in:
@@ -67,7 +67,8 @@ public class MDICSectionRenderer extends AbstractSectionRenderer<MDICViewport, B
|
|||||||
.compile();
|
.compile();
|
||||||
|
|
||||||
private final Shader prefixSumShader = Shader.make()
|
private final Shader prefixSumShader = Shader.make()
|
||||||
.add(ShaderType.COMPUTE, "voxy:util/prefixsum/inital3.comp")
|
//Use subgroup prefix sum if possible otherwise use dodgy... slow prefix sum
|
||||||
|
.add(ShaderType.COMPUTE, Capabilities.INSTANCE.subgroup?"voxy:util/prefixsum/inital3.comp":"voxy:util/prefixsum/simple.comp")
|
||||||
.define("IO_BUFFER", 0)
|
.define("IO_BUFFER", 0)
|
||||||
.compile();
|
.compile();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
#version 460
|
||||||
|
|
||||||
|
#extension GL_KHR_shader_subgroup_basic : require
|
||||||
|
#extension GL_KHR_shader_subgroup_arithmetic: require
|
||||||
|
|
||||||
|
#define WORK_SIZE 256
|
||||||
|
|
||||||
|
//Does inital parralel prefix sum on batches of WORK_SIZE
|
||||||
|
layout(local_size_x=WORK_SIZE) in;
|
||||||
|
|
||||||
|
layout(binding = IO_BUFFER, std430) buffer InputBuffer {
|
||||||
|
uvec4[] ioCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
shared uint prefixSum[256];
|
||||||
|
|
||||||
|
#define STEP(i) if ((I&(1u<<i))!=0) prefixSum[I] += prefixSum[(I&~((1u<<(i+1))-1))+((1u<<i)-1)];
|
||||||
|
uint prefixSumExclusive(uint value) {
|
||||||
|
uint I = gl_LocalInvocationID.x;
|
||||||
|
prefixSum[I] = value;
|
||||||
|
barrier();
|
||||||
|
STEP(0)
|
||||||
|
barrier();
|
||||||
|
STEP(1)
|
||||||
|
barrier();
|
||||||
|
STEP(2)
|
||||||
|
barrier();
|
||||||
|
STEP(3)
|
||||||
|
barrier();
|
||||||
|
STEP(4)
|
||||||
|
barrier();
|
||||||
|
STEP(5)
|
||||||
|
barrier();
|
||||||
|
STEP(6)
|
||||||
|
barrier();
|
||||||
|
STEP(7)
|
||||||
|
barrier();
|
||||||
|
return prefixSum[I]-value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
uint gid = gl_LocalInvocationID.x;
|
||||||
|
prefixSum[gid] = 0;
|
||||||
|
uvec4 count = uvec4(0);
|
||||||
|
uint sum = 0;
|
||||||
|
{
|
||||||
|
uvec4 dat = ioCount[gid];
|
||||||
|
count.yzw = dat.xyz;
|
||||||
|
count.z += count.y;
|
||||||
|
count.w += count.z;
|
||||||
|
sum = count.w + dat.w;
|
||||||
|
}
|
||||||
|
barrier();
|
||||||
|
count += prefixSumExclusive(sum);
|
||||||
|
ioCount[gid] = count;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user