perf(mesh): release per-mesh scratch buffer for static BLAS (#66) #104
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Catcrafts/Crafter.Graphics!104
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "claude/issue-66"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Each
Meshkeeps a dedicated DEVICE_LOCAL scratch buffer for its BLAS build, persistent for the mesh's whole lifetime. For static (allowUpdate == false) meshes — the ones that proliferate in many-mesh scenes — the scratch is dead weight the moment the build's GPU work completes: it can never be reused by a refit. That's real, accumulating VRAM waste (not hot-path, no per-frame scratch alloc).Fix
Key the release on
allowUpdate(already recorded atMesh.cpp:196): after recording a fresh build for a static mesh, callscratchBuffer.DeferredClear().The old hazard — "free after build is a use-after-free because the GPU is still building" — is solved by the fence-keyed deferred-deletion queue (#101/#102):
DeferredClear()nulls the handle immediately but retires the allocation only once the build's frame has passed its fence. The build command recorded just above still readsscratchBuffer.addresssafely.allowUpdate == false): scratch released after the build. A laterRefittakes the rebuild fallback, whoseResizesees the nulled handle and re-Creates a fresh scratch.allowUpdate == true): scratch retained exactly as today — an in-place UPDATE reuses it each frame (build scratch >= update scratch, so no resize).!update).Testing
Extended the
BLASBuildOptionshardware test (real headless Vulkan device, RTX 4090) with assertions that allowUpdate meshes retain their scratch, a static mesh releases it after the build, and a static-mesh refit rebuild re-creates then re-releases it.crafter-build test-> 19 passed; BLASBuildOptions reports all 24 checks PASS with 0 Vulkan validation errors (the strongest proof there's no UAF from the early release).Resolves #66