KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
VulkanSynchronization.h
Go to the documentation of this file.
1
14
15#pragma once
16
17#include <vulkan/vulkan.h>
18#include "KarmaTypes.h"
19
20namespace Karma
21{
22 class FVulkanFence;
23 class FVulkanDevice;
24
26 {
27 public:
35 : m_Device(InDevice)
36 {
37 }
38
46
54 void Denit();
55
67 FVulkanFence* AllocateFence(bool bCreateSignaled = false);
68
78 bool WaitForFence(FVulkanFence* Fence);
79
88 void ResetFence(FVulkanFence* Fence);
89
102 void ReleaseFence(FVulkanFence*& Fence);
103
104 protected:
111 void DestroyFence(FVulkanFence* InFence);
112
113 protected:
114 FVulkanDevice& m_Device;
115
123
129 };
130
141 {
142 public:
153 FVulkanFence(FVulkanDevice& InDevice, FVulkanFenceManager& InOwner, bool bCreateSignaled);
154
162 inline bool IsSignaled() const
163 {
164 return m_State == EState::Signaled;
165 }
166
174 inline VkFence GetHandle() const
175 {
176 return m_Handle;
177 }
178
179 protected:
180 VkFence m_Handle;
181
182 enum class EState
183 {
191
198 };
199
200 EState m_State;
201
202 FVulkanFenceManager& m_Owner;
203
204 // Only owner can create and manage fences
206
207 friend FVulkanFenceManager;
208 };
209
210 class FVulkanSemaphore
211 {
212 public:
213 FVulkanSemaphore(FVulkanDevice& InDevice);
214
215 ~FVulkanSemaphore();
216
217 protected:
218 VkSemaphore m_Handle;
219 FVulkanDevice& m_Device;
220 };
221}
This file contains the custom types used in Engine's logic.
Manages Vulkan device resources and operations.
Definition VulkanDevice.h:33
Represents a Vulkan fence used for synchronization between the CPU and GPU.
Definition VulkanSynchronization.h:141
bool IsSignaled() const
Checks if the fence is currently signaled.
Definition VulkanSynchronization.h:162
EState
Definition VulkanSynchronization.h:183
@ NotReady
The fence is not signaled, initial state after reset.
Definition VulkanSynchronization.h:190
@ Signaled
The fence is signaled, indicating that the associated operations have completed.
Definition VulkanSynchronization.h:197
FVulkanFence(FVulkanDevice &InDevice, FVulkanFenceManager &InOwner, bool bCreateSignaled)
Constructor for FVulkanFence.
Definition VulkanSynchronization.cpp:6
VkFence GetHandle() const
Retrieves the Vulkan fence handle.
Definition VulkanSynchronization.h:174
Definition VulkanSynchronization.h:26
KarmaVector< FVulkanFence * > m_UsedFences
Array of fences currently in use by GPU or in-flight work.
Definition VulkanSynchronization.h:128
KarmaVector< FVulkanFence * > m_FreeFences
Array of free fences to be used.
Definition VulkanSynchronization.h:122
void ResetFence(FVulkanFence *Fence)
Resets the given fence to the unsignaled state.
Definition VulkanSynchronization.cpp:95
FVulkanFenceManager(FVulkanDevice &InDevice)
Constructor.
Definition VulkanSynchronization.h:34
FVulkanFence * AllocateFence(bool bCreateSignaled=false)
Allocates fence for use.
Definition VulkanSynchronization.cpp:37
~FVulkanFenceManager()
Makes sure m_UsedFences are zero i.e no fences are currently in use by GPU or inflight-work.
Definition VulkanSynchronization.cpp:32
bool WaitForFence(FVulkanFence *Fence)
Waits for the given fence to be signaled.
Definition VulkanSynchronization.cpp:74
void Denit()
Purpose is two-fold.
Definition VulkanSynchronization.cpp:64
void ReleaseFence(FVulkanFence *&Fence)
Releases the given fence back to the manager.
Definition VulkanSynchronization.cpp:104
void DestroyFence(FVulkanFence *InFence)
Destroys the given fence and releases its resources.
Definition VulkanSynchronization.cpp:24
Karma's std::vector wrapper with additional functionalities.
Definition KarmaTypes.h:243