Crafter.Graphics/examples/VulkanTriangle
catbot 4e42d663a6 WebGPU RT: wavefront tracer core (GENERATE/PREP/TRACE/SHADE/RESOLVE)
Replace the megakernel @compute entry with five wavefront kernels sharing
one module, connected by GPU ray/hit/payload buffers and a GPU-driven
indirect bounce loop:

  GENERATE -> (PREP -> TRACE -> SHADE) x maxDepth -> RESOLVE

- TRACE contains zero user code (pure _rtwTraverseTlas/Blas, opaque-only).
- PREP publishes dispatchWorkgroupsIndirect args from the live ray count;
  the indirect-args buffer lives in its own bind group so it is never
  bound read-write in the same dispatch that consumes it as INDIRECT.
- New emit/accumulate API: rtEmitPrimaryRay / rtEmitRay / rtAccumulate,
  plus an optional user Resolve stage (tonemap hook; identity by default).
- Per-pass WfParams via a dynamic-offset uniform ring (curIsA/bounce vary
  between passes within one submit).
- Payload-typed wfPayload binding emitted in the codegen region after the
  user's struct Payload; payload travels with each ray (2*W*H slots).
- Request maxBufferSize / maxStorageBufferBindingSize / maxComputeWorkgroups
  PerDimension so the W*H-sized work buffers fit past the 128MB baseline.

VulkanTriangle ported to the new API and renders bit-identical to the
megakernel baseline at maxDepth=1.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-31 16:24:41 +00:00
..
closesthit.glsl vulkan triangle 2026-01-29 19:18:47 +01:00
closesthit.wgsl WebGPU RT: wavefront tracer core (GENERATE/PREP/TRACE/SHADE/RESOLVE) 2026-05-31 16:24:41 +00:00
main.cpp webgpu triangle 2026-05-18 18:43:30 +02:00
miss.glsl vulkan triangle 2026-01-29 19:18:47 +01:00
miss.wgsl WebGPU RT: wavefront tracer core (GENERATE/PREP/TRACE/SHADE/RESOLVE) 2026-05-31 16:24:41 +00:00
project.cpp webgpu triangle 2026-05-18 18:43:30 +02:00
raygen.glsl webgpu triangle 2026-05-18 18:43:30 +02:00
raygen.wgsl WebGPU RT: wavefront tracer core (GENERATE/PREP/TRACE/SHADE/RESOLVE) 2026-05-31 16:24:41 +00:00
README.md animated example 2026-05-02 00:03:24 +02:00

VulkanTriangle

The minimal ray-traced example. Renders a single static triangle through vkCmdTraceRaysKHR. No UI.

What it shows

  • Device::Initialize() + Window + swapchain bring-up.
  • A DescriptorHeapVulkan sized for one image + one buffer slot, with slot ranges allocated via the bump-allocator API (AllocateImageSlots, AllocateBufferSlots).
  • A PipelineRTVulkan built from raygen / miss / closesthit SPIR-V shaders compiled at build time.
  • Mesh::Build constructing a BLAS and RenderingElement3D::BuildTLAS the per-frame TLAS.
  • Direct descriptor writes via vkWriteResourceDescriptorsEXT for the swapchain views and TLAS device addresses.
  • RTPass{&pipeline} plugged into window.passes — the canonical way to add ray tracing to a window in this library.

It's the smallest sensible test of the bindless VK_EXT_descriptor_heap

  • ray-tracing path.

Run

cd examples/VulkanTriangle
crafter-build -r

You should see a 1280×720 window with a triangle filling roughly the centre.

Notes

raygen.glsl's traceRayEXT call is currently commented out — the example exercises the dispatch and imageStore paths only. Uncomment it to actually trace into the BLAS.