FrameContext& fc = frames[currentFrameIndex];
// Wait until GPU has reached the value when this frame's resources were last retired
if (fc.retireValue != 0) {
auto waitInfo = vk::SemaphoreWaitInfo{
.semaphoreCount = 1,
.pSemaphores = &(*timeline),
.pValues = &fc.retireValue
};
device.waitSemaphores(waitInfo, /*timeoutNs=*/UINT64_C(1'000'000'000)); // 1s timeout
}
// Record & submit this frame
recordCommands(fc.cmd /*, ... */);
// Define the value that represents "this frame complete"
const uint64_t frameComplete = nextSubmitValue++;
vk::SemaphoreSubmitInfo signalInfo{
.semaphore = *timeline,
.value = frameComplete,
.stageMask = vk::PipelineStageFlagBits2::eAllCommands
};
vk::CommandBufferSubmitInfo cmdInfo{ .commandBuffer = *fc.cmd };
vk::SubmitInfo2 submit{
.commandBufferInfoCount = 1,
.pCommandBufferInfos = &cmdInfo,
.signalSemaphoreInfoCount= 1,
.pSignalSemaphoreInfos = &signalInfo
};
graphicsQueue.submit2(submit);
// Tag this frame's resources with the value at which they're safe to reuse
fc.retireValue = frameComplete;