#version 450 layout(location = 0) in vec4 color; layout(set = 0, binding = 0) uniform mvp { mat4 model; mat4 view; mat4 proj; uint count; } ubo; layout(binding = 1) buffer fragment_buffer { uvec3 fragments[]; }; layout(binding = 2, r32ui) uniform uimage2D head; layout(binding = 3) buffer counter { uint data; }; void main() { const uint idx = atomicAdd(data, 1); if (idx >= ubo.count) { discard; } const uint prev_idx = imageAtomicExchange(head, ivec2(gl_FragCoord.xy), idx); fragments[idx] = uvec3(prev_idx, packUnorm4x8(color), floatBitsToUint(gl_FragCoord.z)); }