[perf][LOW] GetMemoryType returns first match, no preferred/fallback distinction #59

Closed
opened 2026-06-16 16:51:33 +02:00 by jorijnvdgraaf · 0 comments

Subsystem: Device
Location: implementations/Crafter.Graphics-Device.cpp:814-827
Impact: LOW · Effort: Small · Not hot path (allocation sites only)
See also: #89 (upload-strategy helper built on this — once this selects the type, #89 decides direct-map vs staging). Unblocks #58, #65, #72, #73, #74, #75.

Problem

GetMemoryType is first-superset-match with no preference and no fallback (throws). The real defect is the no-fallback behavior, not "first match is suboptimal" (Vulkan orders types so first-match is generally fine).

Proposed fix

Optional preferred flag set distinct from required; iterate preferring matches that also satisfy preferred bits, fall back to required-only.

Correctness caveat

The headline that preferring coherent memory "eliminates the flush" is misleading — the two-arg FlushDevice(cmd,...) also issues a HOST_WRITE->device barrier that is mandatory regardless of coherency. Coherency removes only the cache flush, not the barrier. Do not drop FlushDevice on a coherency assumption.

**Subsystem:** Device **Location:** `implementations/Crafter.Graphics-Device.cpp:814-827` **Impact:** LOW · **Effort:** Small · Not hot path (allocation sites only) **See also:** #89 (upload-strategy helper built on this — once this selects the type, #89 decides direct-map vs staging). Unblocks #58, #65, #72, #73, #74, #75. ### Problem `GetMemoryType` is first-superset-match with no preference and **no fallback** (throws). The real defect is the no-fallback behavior, not "first match is suboptimal" (Vulkan orders types so first-match is generally fine). ### Proposed fix Optional `preferred` flag set distinct from `required`; iterate preferring matches that also satisfy preferred bits, fall back to required-only. ### Correctness caveat The headline that preferring coherent memory "eliminates the flush" is **misleading** — the two-arg `FlushDevice(cmd,...)` also issues a HOST_WRITE->device barrier that is mandatory regardless of coherency. Coherency removes only the cache flush, not the barrier. Do not drop `FlushDevice` on a coherency assumption.
Sign in to join this conversation.
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#59
No description provided.