[perf][LOW] FlushDevice always flushes even on coherent memory #60

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

Subsystem: VulkanBuffer
Location: interfaces/Crafter.Graphics-VulkanBuffer.cppm:160-168, 194-202
Impact: LOW · Effort: Small · Not hot path (genuine per-frame Vulkan caller is HOST_COHERENT already)

Problem

FlushDevice/FlushHost unconditionally call vkFlushMappedMemoryRanges/Invalidate with no record of whether the memory type is coherent.

Proposed fix

Record the actual chosen memory type's propertyFlags at Create time and early-return when HOST_COHERENT.

Correctness caveat (trap)

Gate on the chosen type's flags via memoryProperties.memoryTypes[idx].propertyFlagsnot the requested flags. The heaps request HOST_VISIBLE|DEVICE_LOCAL (no COHERENT bit) yet may land on a coherent type; conversely a non-coherent type requires the flush. Never remove the barrier in the cmd overload. (Per-frame "hot" examples from the original finding were WebGPU, not this path.)

**Subsystem:** VulkanBuffer **Location:** `interfaces/Crafter.Graphics-VulkanBuffer.cppm:160-168, 194-202` **Impact:** LOW · **Effort:** Small · Not hot path (genuine per-frame Vulkan caller is HOST_COHERENT already) ### Problem `FlushDevice`/`FlushHost` unconditionally call `vkFlushMappedMemoryRanges`/`Invalidate` with no record of whether the memory type is coherent. ### Proposed fix Record the **actual chosen** memory type's `propertyFlags` at Create time and early-return when HOST_COHERENT. ### Correctness caveat (trap) Gate on the **chosen type's** flags via `memoryProperties.memoryTypes[idx].propertyFlags` — **not** the *requested* flags. The heaps request `HOST_VISIBLE|DEVICE_LOCAL` (no COHERENT bit) yet may land on a coherent type; conversely a non-coherent type *requires* the flush. Never remove the barrier in the `cmd` overload. (Per-frame "hot" examples from the original finding were WebGPU, not this path.)
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#60
No description provided.