perf(vulkan-buffer): skip flush/invalidate on coherent memory (#60) #94

Merged
catbot merged 2 commits from claude/issue-60 into master 2026-06-16 19:07:43 +02:00
Member

Summary

VulkanBuffer::FlushDevice / FlushHost called vkFlushMappedMemoryRanges / vkInvalidateMappedMemoryRanges unconditionally, with no record of whether the backing memory is coherent. On HOST_COHERENT memory those calls are pure overhead — host/device writes are mutually visible without an explicit flush.

Fix

  • Record the chosen memory type's propertyFlags at Create time, from the index GetMemoryType actually returns (Device::memoryProperties.memoryTypes[idx].propertyFlags) — not the requested flags. A request lacking the COHERENT bit can still land on a coherent type, and a non-coherent type genuinely needs the flush.
  • FlushDevice() / FlushHost() early-return when the chosen type is HOST_COHERENT.
  • The cmd overload of FlushDevice is unchanged in its barrier behaviour — it still always emits its pipeline barrier; only the redundant host-side flush is gated.
  • Move constructor carries the new field.

Tests

New VulkanBufferFlushGate regression test (pure CPU, no GPU device): stamps memoryPropertyFlagsChosen and verifies the coherent path issues no Vulkan call. Full suite green — 10 passed.

Resolves #60

## Summary `VulkanBuffer::FlushDevice` / `FlushHost` called `vkFlushMappedMemoryRanges` / `vkInvalidateMappedMemoryRanges` unconditionally, with no record of whether the backing memory is coherent. On HOST_COHERENT memory those calls are pure overhead — host/device writes are mutually visible without an explicit flush. ## Fix - Record the **chosen** memory type's `propertyFlags` at `Create` time, from the index `GetMemoryType` actually returns (`Device::memoryProperties.memoryTypes[idx].propertyFlags`) — **not** the requested flags. A request lacking the COHERENT bit can still land on a coherent type, and a non-coherent type genuinely needs the flush. - `FlushDevice()` / `FlushHost()` early-return when the chosen type is `HOST_COHERENT`. - The `cmd` overload of `FlushDevice` is unchanged in its barrier behaviour — it still always emits its pipeline barrier; only the redundant host-side flush is gated. - Move constructor carries the new field. ## Tests New `VulkanBufferFlushGate` regression test (pure CPU, no GPU device): stamps `memoryPropertyFlagsChosen` and verifies the coherent path issues no Vulkan call. Full suite green — 10 passed. Resolves #60
FlushDevice/FlushHost called vkFlushMappedMemoryRanges /
vkInvalidateMappedMemoryRanges unconditionally. Record the chosen
memory type's propertyFlags at Create time (via the index GetMemoryType
returns, not the requested flags) and early-return when HOST_COHERENT.

The cmd overload still always emits its pipeline barrier — only the
redundant host-side flush/invalidate is gated.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
catbot merged commit df51a81db4 into master 2026-06-16 19:07:43 +02:00
catbot deleted branch claude/issue-60 2026-06-16 19:07:43 +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!94
No description provided.