Skip to content

LiteFX::Rendering::IGraphicsFactory::beginDefragmentation

Starts a defragmentation process for the resources allocated from the factory.

Synopsis

Declared in <litefx/rendering_api.hpp>

[[dllimport, dllexport]] virtual void beginDefragmentation(
    ICommandQueue const& queue,
    DefragmentationStrategy strategy = DefragmentationStrategy::Balanced,
    UInt64 maxBytesToMove = 0u,
    UInt32 maxAllocationsToMove = 0u) const = 0;

Description

Defragmentation is an iterative process. Calling this method starts defragmentation, which is then advanced by alternating calls to beginDefragmentationPass and endDefragmentationPass. The process ends if endDefragmentationPass returns true.

During a defragmentation pass, a number of resources may get allocated and the memory and filled with memory from resources that will later be destroyed. Each iteration will only create a certain number of such move events, which is mainly influenced by the maxBytesToMove and maxAllocationsToMove parameters, as well as the provided strategy. This way, the number of moves per frame can be limited, which helps with keeping a steady frame rate.

Moving a resource happens by recording copy commands on a command buffer created from queue. If a resource does not need to be copied, for example because it only contains temporary data, you can set the IDeviceMemory::volatileMove property to true. This will only allocate a new resource, but wont copy the contents of the old allocation.

Calling beginDefragmentationPass returns the fence on that queue after which the move commands have been executed. You can either manually wait for the fence (e.g., by calling ICommandQueue::lastCompletedFence) or call endDefragmentationPass directly. Keep in mind that endDefragmentationPass blocks to wait for the last fence to finish, so you might want to consider the alternative approach if you are doing per-frame defragmentation.

Calling this method while another defragmentation process is active will raise an exception.

Exceptions

NameThrown on
RuntimeExceptionThrown, if another defragmentation process is currently running and has not yet finished.

Parameters

NameDescription
queueThe queue to execute the move commands on.
strategyThe strategy to pack the fragmented memory.
maxBytesToMoveThe maximum number of bytes to move during this pass or 0, if no limitation should be imposed.
maxAllocationsToMoveThe maximum number of allocations to move during this pass or 0, if no limitation should be imposed.