feat(device): runtime upload-strategy helper PreferDirectDeviceWrite (#89) #95

Merged
catbot merged 1 commit from claude/issue-89 into master 2026-06-16 19:23:59 +02:00
Member

Summary

Adds Device::PreferDirectDeviceWrite(VkDeviceSize size), the runtime upload-strategy helper that unifies the memory-placement cluster. For a CPU-written, GPU-read buffer it decides — at runtime, from Device::memoryProperties — whether to:

  • true → allocate HOST_VISIBLE | DEVICE_LOCAL, map, write straight into device memory (no staging).
  • false → allocate pure DEVICE_LOCAL and feed it from a HOST_VISIBLE staging buffer + vkCmdCopyBuffer.

Logic

  1. No DEVICE_LOCAL | HOST_VISIBLE type (no resizable BAR) → false (staging mandatory).
  2. ReBAR / UMA — BAR heap ≥ 90% of the largest DEVICE_LOCAL heap → true (staging would be pure overhead).
  3. Small BAR window — BAR heap ≪ VRAM → true only for buffers within a per-window budget (1/8 of the window); large buffers stage so they don't exhaust the window (#58).

Notes

  • Complements GetMemoryType (#59): #59 selects the memory type, this selects the strategy.
  • Upload-only (CPU-write → GPU-read). Readback (#74) wants HOST_CACHED and stays a separate path.
  • A VK_EXT_memory_budget-driven remaining-space check (rather than total window size) is documented as a follow-up; the extension isn't currently enabled.

Testing

crafter-build test — all green (13 passed). New tests/UploadStrategy drives the helper over synthetic ReBAR / UMA / small-window / no-BAR layouts (pure CPU, no GPU device), mirroring MemoryTypeFallback.

Unblocks #65, #72, #73, #75.

Resolves #89

🤖 Generated with Claude Code

## Summary Adds `Device::PreferDirectDeviceWrite(VkDeviceSize size)`, the runtime upload-strategy helper that unifies the memory-placement cluster. For a CPU-written, GPU-read buffer it decides — at runtime, from `Device::memoryProperties` — whether to: - **`true`** → allocate `HOST_VISIBLE | DEVICE_LOCAL`, map, write straight into device memory (no staging). - **`false`** → allocate pure `DEVICE_LOCAL` and feed it from a `HOST_VISIBLE` staging buffer + `vkCmdCopyBuffer`. ### Logic 1. No `DEVICE_LOCAL | HOST_VISIBLE` type (no resizable BAR) → `false` (staging mandatory). 2. ReBAR / UMA — BAR heap ≥ 90% of the largest `DEVICE_LOCAL` heap → `true` (staging would be pure overhead). 3. Small BAR window — BAR heap ≪ VRAM → `true` only for buffers within a per-window budget (1/8 of the window); large buffers stage so they don't exhaust the window (#58). ### Notes - Complements `GetMemoryType` (#59): #59 selects the memory *type*, this selects the *strategy*. - Upload-only (CPU-write → GPU-read). Readback (#74) wants `HOST_CACHED` and stays a separate path. - A `VK_EXT_memory_budget`-driven *remaining*-space check (rather than total window size) is documented as a follow-up; the extension isn't currently enabled. ## Testing `crafter-build test` — all green (13 passed). New `tests/UploadStrategy` drives the helper over synthetic ReBAR / UMA / small-window / no-BAR layouts (pure CPU, no GPU device), mirroring `MemoryTypeFallback`. Unblocks #65, #72, #73, #75. Resolves #89 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Add Device::PreferDirectDeviceWrite(size) so the memory-placement cluster
(#65/#72/#73/#75) no longer re-derives where a CPU-written, GPU-read buffer
should live. It picks the strategy at runtime from Device::memoryProperties:

  - No DEVICE_LOCAL|HOST_VISIBLE type (no resizable BAR) -> false (must stage).
  - ReBAR/UMA (BAR heap >= 90% of largest DEVICE_LOCAL heap) -> true: map and
    write directly; a staging copy would be pure overhead.
  - Small BAR window (BAR heap << VRAM) -> true only for buffers within a
    per-window budget (1/8 of the window); large buffers stage so they don't
    exhaust the window (#58).

Complements GetMemoryType (#59): #59 picks the memory *type*, this picks the
*strategy*. Upload-only — readback (#74) wants HOST_CACHED and stays separate.
A VK_EXT_memory_budget-driven remaining-space check is noted as a follow-up.

Tested by tests/UploadStrategy (pure CPU over synthetic ReBAR / UMA /
small-window / no-BAR layouts, no GPU device needed), mirroring
MemoryTypeFallback.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
catbot merged commit 69641f1c44 into master 2026-06-16 19:23:59 +02:00
catbot deleted branch claude/issue-89 2026-06-16 19:23:59 +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!95
No description provided.