#version 460
#extension GL_EXT_buffer_reference : enable
#extension GL_EXT_scalar_block_layout : enable

// Issue #37: GPU-resident procedural AABBs. This compute shader is the
// "producer" — it writes the per-box bounding boxes straight into a device
// buffer that Mesh::BuildProcedural / RefitProcedural then consume by device
// address, with no host copy. Here it emits a single unit box [-1,1]^3 (the
// bounding volume the intersection shader turns into a sphere); `time` lets
// the box breathe so a per-frame refit has something to track. A real
// particle system would write one box per particle from simulation state.
//
// The buffer is reached via a buffer_reference (its device address pushed in
// `pc`), so this dispatch needs no descriptor-heap binding for the output.

layout(buffer_reference, scalar) buffer AabbRef {
    float data[];   // 6 floats per box: min.xyz, max.xyz (RTAabb layout)
};

layout(push_constant) uniform PC {
    AabbRef boxes;
    uint    count;
    float   time;
} pc;

layout(local_size_x = 64) in;

void main() {
    uint i = gl_GlobalInvocationID.x;
    if (i >= pc.count) return;

    float r = 1.0 + 0.15 * sin(pc.time);   // gently pulsing radius
    uint b = i * 6u;
    pc.boxes.data[b + 0u] = -r;
    pc.boxes.data[b + 1u] = -r;
    pc.boxes.data[b + 2u] = -r;
    pc.boxes.data[b + 3u] =  r;
    pc.boxes.data[b + 4u] =  r;
    pc.boxes.data[b + 5u] =  r;
}
