Revision control
Copy as Markdown
#version 430
// Same as dispatch_indirect_consume.comp, but additionally reads the dispatch
// arguments through a read-only storage binding, so that the indirect buffer is
// shader-read in the very dispatch that also sources its work group counts from
// it.
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(std430, binding = 0) buffer OutputBuffer
{
uint values[];
} outBuf;
struct DispatchIndirectCommand
{
uint x;
uint y;
uint z;
};
layout(std430, binding = 1) readonly buffer IndirectDispatchBuffer
{
DispatchIndirectCommand cmd;
} args;
void main()
{
uint idx = gl_WorkGroupID.x
+ gl_WorkGroupID.y * 16u
+ gl_WorkGroupID.z * 16u * 16u;
// Folded in so the read cannot be optimized away. Top bit flags stale args.
uint flag = (args.cmd.x != 0u && args.cmd.y != 0u && args.cmd.z != 0u) ? 0u : 0x80000000u;
outBuf.values[idx] = (gl_WorkGroupID.z << 20)
| (gl_WorkGroupID.y << 10)
| gl_WorkGroupID.x
| flag;
}