[perf] Mesh vertex/index/aabb are HOST_VISIBLE — place device-local (direct on ReBAR, staged otherwise) #73
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Catcrafts/Crafter.Graphics#73
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Subsystem: Mesh / RT geometry
Location:
implementations/Crafter.Graphics-Mesh.cpp:187-188(uncompressed Build),:221-228(compressed Build),:307(procedural aabbBuffer)Impact: Medium-High (conditional, see below) · Effort: Medium
Depends on: #89 (upload-strategy helper), #59 (GetMemoryType preferred/fallback) · Related: #66, #67, #68
Problem
vertexBufferandindexBufferare allocatedHOST_VISIBLE(system RAM, non-coherent — note the explicitFlushDeviceat lines 193-194). ButkVertexUsageBase/kIndexUsageBase(Mesh.cpp:36-40) carrySHADER_DEVICE_ADDRESS_BIT, and the index buffer additionally carriesSTORAGE_BUFFER_BIT. That is the library deliberately exposing geometry for hit-shader fetch (reading per-vertex normals/UVs/indices at hit points) — the dominant RT shading pattern.If an application fetches geometry in closest-hit shaders (the usage flags exist precisely so it can), every
vkCmdTraceRaysKHRreads vertex/index data from system RAM over PCIe, every frame. The buffers are also read as BLAS build inputs (at build, and again on every refit for deforming meshes). Same applies toaabbBuffer(:307).Proposed fix — via the #89 upload-strategy helper (NOT unconditional staging)
Place this geometry in device-local memory, but let #89 decide how:
DEVICE_LOCALheap isHOST_VISIBLE): allocateHOST_VISIBLE|DEVICE_LOCALand keep the existing direct memcpy population. No staging buffer — it would be pure overhead.DEVICE_LOCAL+ aHOST_VISIBLEstaging buffer +vkCmdCopyBuffer.HOST_VISIBLE|DEVICE_LOCALso the CPU can rewrite vertex positions in place each frame (same shape as #65); fall back to staging-per-refit only where the direct type is unavailable.indexBuffertopology is always static (a hardware AS UPDATE cannot change it — see #68), so it can take the staged-once path even for deforming meshes when staging is needed.Caller code reduces to: ask #89's helper for the strategy, then either map-and-write or stage. Ideally the
VulkanBufferupload-intent API from #89 hides this entirely.Correctness caveats
DeferredClear()after recording the copy, and it retires once the submit's frame clears the fence. Same class as #67.HOST_COHERENT, keep the existingFlushDevice(lines 193-194); gate any skip on the chosen type's flags (#60).[perf] Mesh vertex/index/aabb buffers are HOST_VISIBLE — should be DEVICE_LOCAL for GPU readsto [perf] Mesh vertex/index/aabb are HOST_VISIBLE — place device-local (direct on ReBAR, staged otherwise)