perf(webgpu): range-flush only live TLAS metadata slots (#130) #149

Merged
catbot merged 1 commit from claude/issue-130 into master 2026-06-18 15:56:46 +02:00
Member

Problem

implementations/Crafter.Graphics-RenderingElement3D-WebGPU.cpp:162 flushed the TLAS metadata mirror with metadataBuffer.FlushDevice(). That buffer is padded to kNPadded = 65536 slots, but only primitiveCount entries are ever live — so every frame wgpuWriteBuffer pushed all 256 KB through the WASM→JS staging path (~100–250× waste for a few-hundred-instance scene). The Vulkan parallel already sizes its flush to primitiveCount, so this was WebGPU-specific.

Fix

Switch to the existing FlushDeviceRange(0, 0, primitiveCount * sizeof(std::uint32_t)) overload — the same one the instanceBuffer partial-write loop directly above already uses — so only the live slots are uploaded.

Testing

  • Native build: green.
  • WASM build (--target=wasm32-wasip1): the WebGPU implementation file compiles cleanly.
  • crafter-build test --jobs=1: 24 passed. (Parallel runs hit unrelated git-pull contention on the shared external-dep cache; serializing avoids it.)

Resolves #130

## Problem `implementations/Crafter.Graphics-RenderingElement3D-WebGPU.cpp:162` flushed the TLAS metadata mirror with `metadataBuffer.FlushDevice()`. That buffer is padded to `kNPadded = 65536` slots, but only `primitiveCount` entries are ever live — so every frame `wgpuWriteBuffer` pushed all 256 KB through the WASM→JS staging path (~100–250× waste for a few-hundred-instance scene). The Vulkan parallel already sizes its flush to `primitiveCount`, so this was WebGPU-specific. ## Fix Switch to the existing `FlushDeviceRange(0, 0, primitiveCount * sizeof(std::uint32_t))` overload — the same one the `instanceBuffer` partial-write loop directly above already uses — so only the live slots are uploaded. ## Testing - Native build: green. - WASM build (`--target=wasm32-wasip1`): the WebGPU implementation file compiles cleanly. - `crafter-build test --jobs=1`: 24 passed. (Parallel runs hit unrelated git-pull contention on the shared external-dep cache; serializing avoids it.) Resolves #130
The metadata mirror is padded to kNPadded (65536) but only primitiveCount
slots are live. metadataBuffer.FlushDevice() wgpuWriteBuffer'd all 256 KB
through the WASM->JS staging path every frame (~100-250x waste for a
few-hundred-instance scene). Switch to the existing FlushDeviceRange
overload — the same one the instanceBuffer loop directly above uses —
sized to primitiveCount * sizeof(uint32_t). The Vulkan parallel already
sizes its flush to primitiveCount, so this was WebGPU-specific.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
catbot merged commit 77bc6f7aec into master 2026-06-18 15:56:46 +02:00
catbot deleted branch claude/issue-130 2026-06-18 15:56:46 +02:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Catcrafts/Crafter.Graphics!149
No description provided.