-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.cpp
63 lines (61 loc) · 1.86 KB
/
sync.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// Created by daily on 27-12-23.
//
#include "sync.hpp"
namespace vkinit
{
/**
* @brief Creates a Vulkan semaphore.
*
* Initializes and returns a new semaphore object. Semaphores are used to synchronize operations
* within or across command queues.
*
* @param device The Vulkan logical device_ used to create the semaphore.
* @param debug Flag indicating whether to enable debug logging.
* @return A Vulkan semaphore object, or nullptr if creation fails.
*/
vk::Semaphore make_semaphore(vk::Device device, bool debug)
{
vk::SemaphoreCreateInfo semaphoreInfo = { };
semaphoreInfo.flags = vk::SemaphoreCreateFlags();
try
{
return device.createSemaphore(semaphoreInfo);
}
catch(vk::SystemError &err)
{
if(debug)
{
std::cout << "Failed to create semaphore" << std::endl;
}
return nullptr;
}
}
/**
* @brief Creates a Vulkan fence
*
* Initializes and returns a new semaphore object. Semaphores are used to synchronize operations
* within or across command queues.
*
* @param device The Vulkan logical device_ used to create the semaphore.
* @param debug Flag indicating whether to enable debug logging.
* @return A Vulkan fence object, or nullptr if creation fails.
*/
vk::Fence make_fence(vk::Device device, bool debug)
{
vk::FenceCreateInfo fenceInfo = { };
fenceInfo.flags = vk::FenceCreateFlags() | vk::FenceCreateFlagBits::eSignaled;
try
{
return device.createFence(fenceInfo);
}
catch(vk::SystemError &err)
{
if(debug)
{
std::cout << "Failed to create fence" << std::endl;
}
return nullptr;
}
}
}