perf(buffer): capacity-reuse in VulkanBuffer::Resize (#63) #96

Merged
catbot merged 1 commit from claude/issue-63 into master 2026-06-16 20:22:38 +02:00
Member

Problem

VulkanBuffer::Resize always destroyed + reallocated, even when the existing buffer already had room. Per-frame refit paths deliberately skip Resize (UPDATE mode), so this was never a steady-state cost — but capacity-reuse is the safer direction.

Fix

Reuse the existing allocation in place when all of the following hold:

  • the new request fits within the created capacity,
  • the requested usage flags equal the flags the buffer was created with (usage flags are immutable after vkCreateBuffer),
  • the memory type already chosen still satisfies the required property flags ((memoryPropertyFlagsChosen & required) == required).

preferredPropertyFlags is a best-effort perf hint and does not affect correctness, so it is intentionally not part of the guard. On reuse the buffer handle, device address, and mapped pointer are all preserved; only size shrinks to the new logical extent. Any mismatch falls back to the original destroy + recreate path.

VulkanBufferBase now tracks capacity and usageFlagsCreated, set in Create and carried through the move constructor.

Tests

Adds VulkanBufferResizeReuse, a device-free regression test that stamps a fake handle + capacity/flags and drives the reuse guard directly, asserting the in-place path issues no Vulkan call (a real reallocate would fault with no device). Full suite: 14 passed (crafter-build test --jobs=1).

Resolves #63

🤖 Generated with Claude Code

## Problem `VulkanBuffer::Resize` always destroyed + reallocated, even when the existing buffer already had room. Per-frame refit paths deliberately skip Resize (UPDATE mode), so this was never a steady-state cost — but capacity-reuse is the safer direction. ## Fix Reuse the existing allocation in place when **all** of the following hold: - the new request fits within the created `capacity`, - the requested usage flags equal the flags the buffer was created with (usage flags are immutable after `vkCreateBuffer`), - the memory type already chosen still satisfies the required property flags (`(memoryPropertyFlagsChosen & required) == required`). `preferredPropertyFlags` is a best-effort perf hint and does not affect correctness, so it is intentionally not part of the guard. On reuse the buffer handle, device address, and mapped pointer are all preserved; only `size` shrinks to the new logical extent. Any mismatch falls back to the original destroy + recreate path. `VulkanBufferBase` now tracks `capacity` and `usageFlagsCreated`, set in `Create` and carried through the move constructor. ## Tests Adds `VulkanBufferResizeReuse`, a device-free regression test that stamps a fake handle + capacity/flags and drives the reuse guard directly, asserting the in-place path issues no Vulkan call (a real reallocate would fault with no device). Full suite: 14 passed (`crafter-build test --jobs=1`). Resolves #63 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Resize previously always destroyed + reallocated. It now reuses the
existing allocation in place when the new request still fits the created
capacity and the immutable-at-create properties match: usage flags are
fixed at create, and the chosen memory type must still satisfy the
required property flags. preferredPropertyFlags is a best-effort perf
hint and is intentionally not part of the guard. On reuse the buffer
handle, device address and mapped pointer are preserved; only `size`
shrinks to the new logical extent.

Tracks capacity and the created usage flags on VulkanBufferBase, set at
Create and carried through the move constructor.

Adds VulkanBufferResizeReuse, a device-free regression test that drives
the reuse guard directly and asserts the in-place path issues no Vulkan
call.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
catbot merged commit b7500e1fd0 into master 2026-06-16 20:22:38 +02:00
catbot deleted branch claude/issue-63 2026-06-16 20:22:38 +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!96
No description provided.