2.2 KiB
2.2 KiB
Frame Resources: Per-Frame Command, Sync, and Transient Descriptors
Per-frame struct that owns the command buffer, semaphores/fence, a transient descriptor allocator, and a small deletion queue. Frames are indexed by FRAME_OVERLAP (currently 2) and rotated by _frameNumber in VulkanEngine.
- File:
src/core/frame_resources.h/.cpp
Responsibilities
- Command recording:
_mainCommandBufferallocated from a per-frame_commandPoolwith RESET flag. - Synchronization:
_swapchainSemaphore(image acquired),_renderSemaphore(render finished),_renderFence(CPU wait per frame). - Transient descriptors:
_frameDescriptorsis aDescriptorAllocatorGrowablecleared every frame viaclear_pools(). - Lifetime:
_deletionQueueholds lambdas for transient GPU objects created during the frame (buffers/images) and is flushed at the start of the next frame.
Frame Flow (engine side)
- Start of frame:
- Wait on
_renderFence(previous GPU work for this frame index), flush_deletionQueue, and clear_frameDescriptorspools. - Acquire swapchain image signaling
_swapchainSemaphore. - Reset
_renderFenceand_mainCommandBuffer; begin recording. - Publish
currentFramepointer anddrawExtentonEngineContext.
- Wait on
- Graph build and execute:
- Render Graph is cleared and rebuilt;
ResourceManager::register_upload_pass(...)is added first if there are pending uploads. - Passes record using the published
currentFrameto allocate transient descriptor sets and to enqueue per-frame cleanups.
- Render Graph is cleared and rebuilt;
- Submit and present:
- Submit
cmdwith wait on_swapchainSemaphoreand signal_renderSemaphore, fence_renderFence. - Present waits on
_renderSemaphore.
- Submit
Do/Don’t
- Do use
currentFrame->_frameDescriptorsfor descriptor sets that live only for this frame. - Do push transient resource destruction into
currentFrame->_deletionQueue. - Don’t stash per-frame descriptor sets across frames — they are reset on
clear_pools().
Extending
- If a pass needs additional short-lived command buffers, allocate them from
_commandPooland reset per frame. - If you add frames-in-flight, update
FRAME_OVERLAPand verify fences/semaphores and swapchain image acquisition logic.