Crimson Engine 1.0.0
A high-performance C++20 game engine prototype showcasing a custom ECS, Vulkan renderer, and ImGui editor.
Loading...
Searching...
No Matches
VulkanFrameSync.hpp
Go to the documentation of this file.
1#pragma once
2#include <vulkan/vulkan.h>
3#include <vector>
4#include <stdexcept>
5
11public:
15 VulkanFrameSync() = default;
20
23
29 void create(VkDevice device, uint32_t maxFramesInFlight = 2);
33 void destroy();
34
49 VkFence getInFlightFence() const { return inFlightFences[currentFrame]; }
50
58 void nextFrame();
59
64 uint32_t getCurrentFrameIndex() const { return currentFrame; }
65
66private:
68 VkDevice device = VK_NULL_HANDLE;
70 uint32_t maxFrames = 0;
72 uint32_t currentFrame = 0;
73
75 std::vector<VkSemaphore> imageAvailableSemaphores;
77 std::vector<VkSemaphore> renderFinishedSemaphores;
79 std::vector<VkFence> inFlightFences;
80};
std::vector< VkFence > inFlightFences
Fences waiting for queue work execution completion.
Definition VulkanFrameSync.hpp:79
VulkanFrameSync & operator=(const VulkanFrameSync &)=delete
std::vector< VkSemaphore > renderFinishedSemaphores
Semaphores waiting for render passes to complete.
Definition VulkanFrameSync.hpp:77
VulkanFrameSync()=default
Construct a new Vulkan Frame Sync object.
void create(VkDevice device, uint32_t maxFramesInFlight=2)
Allocates synchronization semaphores and fences.
Definition VulkanFrameSync.cpp:33
void nextFrame()
Progresses the frame index counter.
Definition VulkanFrameSync.cpp:68
VkSemaphore getRenderFinishedSemaphore() const
Gets render completion semaphore.
Definition VulkanFrameSync.hpp:44
VulkanFrameSync(const VulkanFrameSync &)=delete
void destroy()
Safely destroys synchronization primitives.
Definition VulkanFrameSync.cpp:13
VkFence getInFlightFence() const
Gets current in-flight queue submission fence.
Definition VulkanFrameSync.hpp:49
~VulkanFrameSync()
Destroy the Vulkan Frame Sync object and release sync objects.
Definition VulkanFrameSync.cpp:6
uint32_t getCurrentFrameIndex() const
Gets current active double-buffered index.
Definition VulkanFrameSync.hpp:64
uint32_t currentFrame
Active frame index.
Definition VulkanFrameSync.hpp:72
void waitForCurrentFrame()
Blocks host execution until current frame fence is signaled, then resets it.
Definition VulkanFrameSync.cpp:60
VkSemaphore getImageAvailableSemaphore() const
Gets image acquisition semaphore.
Definition VulkanFrameSync.hpp:39
VkDevice device
Reference to logical device.
Definition VulkanFrameSync.hpp:68
uint32_t maxFrames
Max frames allowed in flight.
Definition VulkanFrameSync.hpp:70
std::vector< VkSemaphore > imageAvailableSemaphores
Semaphores waiting for image availability.
Definition VulkanFrameSync.hpp:75