example(RTVolume): GPU-written device-buffer procedural AABBs (#37)
A compute shader (aabbs.comp.{glsl,wgsl}) writes the procedural box into a
device buffer that BuildProcedural consumes by device address/handle with no
host copy; the WebGPU path also refits from it each frame so the box breathes.
Verified rendering on both Vulkan (native) and WebGPU (browser).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
8fefb2caef
commit
0d1312ac09
4 changed files with 173 additions and 13 deletions
40
examples/RTVolume/aabbs.comp.glsl
Normal file
40
examples/RTVolume/aabbs.comp.glsl
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue