perf(rt): place SBT in device-local memory via upload-strategy helper (#72) #107

Merged
catbot merged 1 commit from claude/issue-72 into master 2026-06-17 19:42:02 +02:00
Member

Summary

The shader binding table (sbtBuffer) was allocated plain HOST_VISIBLE (system RAM). It is written once at pipeline creation and read by the GPU on every vkCmdTraceRaysKHR for the pipeline's lifetime — a textbook write-once/read-many buffer that was paying a PCIe read on every trace dispatch.

This routes the SBT allocation through Device::PreferDirectDeviceWrite (#89):

  • A DEVICE_LOCAL|HOST_VISIBLE type exists (ReBAR/UMA, or a BAR window — the SBT is tiny so the window budget is never the constraint): prefer DEVICE_LOCAL on top of the required HOST_VISIBLE. GPU reads hit local VRAM; the one-time memcpy goes write-combined over PCIe (write-only, sequential — ideal WC).
  • No combined type exists (no spec guarantee): PreferDirectDeviceWrite returns false, the preferred hint is dropped, and GetMemoryType (#59) falls back to plain HOST_VISIBLE — current behaviour, the cheaper fallback the issue blesses while staging isn't wired here.

Correctness

  • The buffer stays mapped, so the write-once memcpy path is unchanged.
  • The existing FlushDevice gates its flush on the chosen memory type's flags (#60), so a direct-write type lacking HOST_COHERENT is still flushed correctly.
  • The SBT is tiny, so BAR-window pressure (#58) is negligible when a combined type exists.

Testing

crafter-build test19 passed (includes UploadStrategy, BLASBuildOptions, TLASHighWaterMark, MemoryTypeFallback). Backend perf change with no visible output, so no screenshot.

Resolves #72

## Summary The shader binding table (`sbtBuffer`) was allocated plain `HOST_VISIBLE` (system RAM). It is written **once** at pipeline creation and read by the GPU on **every** `vkCmdTraceRaysKHR` for the pipeline's lifetime — a textbook write-once/read-many buffer that was paying a PCIe read on every trace dispatch. This routes the SBT allocation through `Device::PreferDirectDeviceWrite` (#89): - **A `DEVICE_LOCAL|HOST_VISIBLE` type exists** (ReBAR/UMA, or a BAR window — the SBT is tiny so the window budget is never the constraint): prefer `DEVICE_LOCAL` on top of the required `HOST_VISIBLE`. GPU reads hit local VRAM; the one-time `memcpy` goes write-combined over PCIe (write-only, sequential — ideal WC). - **No combined type exists** (no spec guarantee): `PreferDirectDeviceWrite` returns false, the preferred hint is dropped, and `GetMemoryType` (#59) falls back to plain `HOST_VISIBLE` — current behaviour, the cheaper fallback the issue blesses while staging isn't wired here. ### Correctness - The buffer stays mapped, so the write-once `memcpy` path is unchanged. - The existing `FlushDevice` gates its flush on the **chosen** memory type's flags (#60), so a direct-write type lacking `HOST_COHERENT` is still flushed correctly. - The SBT is tiny, so BAR-window pressure (#58) is negligible when a combined type exists. ## Testing `crafter-build test` — **19 passed** (includes `UploadStrategy`, `BLASBuildOptions`, `TLASHighWaterMark`, `MemoryTypeFallback`). Backend perf change with no visible output, so no screenshot. Resolves #72
The shader binding table is written once at pipeline creation and read by
the GPU on every vkCmdTraceRaysKHR thereafter, yet it was allocated plain
HOST_VISIBLE (system RAM) — so every trace dispatch read raygen/miss/hit
records over PCIe.

Route the SBT allocation through Device::PreferDirectDeviceWrite (#89):
when a DEVICE_LOCAL|HOST_VISIBLE type exists, prefer DEVICE_LOCAL on top
of the required HOST_VISIBLE so the buffer lands in mappable device
memory (GPU reads hit local VRAM; the one-time memcpy goes write-combined
over PCIe). When no combined type exists, the preferred hint is dropped
and GetMemoryType (#59) falls back to plain HOST_VISIBLE — current
behaviour. The SBT is tiny so a small BAR window's budget is never the
constraint.

The buffer stays mapped and the existing FlushDevice gates on the chosen
memory type's coherency flags (#60), so a direct-write type lacking
HOST_COHERENT is still flushed correctly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
catbot merged commit 87264bb2ec into master 2026-06-17 19:42:02 +02:00
catbot deleted branch claude/issue-72 2026-06-17 19:42:03 +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!107
No description provided.