Skip to content

Implement resource defragmentation.#192

Merged
crud89 merged 10 commits intomainfrom
dev/resource-defragmentation
Oct 28, 2025
Merged

Implement resource defragmentation.#192
crud89 merged 10 commits intomainfrom
dev/resource-defragmentation

Conversation

@crud89
Copy link
Copy Markdown
Owner

@crud89 crud89 commented Oct 28, 2025

Describe the pull request

This PR implements support for resource defragmentation. This is mostly done on the IGraphicsFactory, but also on buffers and images directly. The graphics factory now exposes a set of methods to invoke the defragmentation process. For an example implementation, a sample is provided.

Resources (i.e., objects that implement IDeviceMemory) are potentially moved during defragmentation. As this implies a re-creation of the resource itself, bindings may get invalidated. To react to such a move, there are two events that can be subscribed to. The IDeviceMemory::moving event occurs after a move has been recorded, but before it has been finished. It provides the command queue and a fence value on that queue that signals if the move has finished. On the other hand, the IDeviceMemory::moved event is more straightforward and is executed after a resource has been relocated and can be rebound.

Currently render targets aren't affected by defragmentation, as they are often times implicitly transitioned during rendering and moving them mandates some form state tracking to properly barrier them. The way this is implemented is by checking if an image has the ResourceUsage::RenderTarget flag set during a defragmentation pass and if so, it is ignored. This is sub-optimal and ideally, render targets should be allocated from a separate pool instead. If this ever becomes a problem, we can address it this way.

Related issues

@crud89 crud89 added this to the Alpha #05 milestone Oct 28, 2025
@crud89 crud89 self-assigned this Oct 28, 2025
@crud89 crud89 added this to LiteFX Oct 28, 2025
@crud89 crud89 added Vulkan πŸŒ‹ The issue involves the Vulkan backend. DX12 ❎ The issue involves the DX12 backend. labels Oct 28, 2025
@crud89 crud89 moved this to In Progress in LiteFX Oct 28, 2025
@crud89
Copy link
Copy Markdown
Owner Author

crud89 commented Oct 28, 2025

Run: checks

@crud89 crud89 merged commit 02a98fa into main Oct 28, 2025
9 checks passed
@crud89 crud89 deleted the dev/resource-defragmentation branch October 28, 2025 17:19
@crud89 crud89 moved this from In Progress to v0.5.1 in LiteFX Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DX12 ❎ The issue involves the DX12 backend. Vulkan πŸŒ‹ The issue involves the Vulkan backend.

Projects

Status: v0.5.1

Development

Successfully merging this pull request may close these issues.

Add support for resource defragmentation.

1 participant