]> git.tdb.fi Git - libs/gl.git/blob - source/backends/vulkan/fence.cpp
Initial implementation of Vulkan backend
[libs/gl.git] / source / backends / vulkan / fence.cpp
1 #include <limits>
2 #include "device.h"
3 #include "fence.h"
4 #include "vulkan.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GL {
10
11 Fence::Fence(bool create_signaled):
12         device(Device::get_current())
13 {
14         const VulkanFunctions &vk = device.get_functions();
15
16         VkFenceCreateInfo fence_info = { };
17         fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
18         fence_info.flags = (create_signaled ? VK_FENCE_CREATE_SIGNALED_BIT : 0);
19
20         vk.CreateFence(fence_info, handle);
21 }
22
23 Fence::Fence(Fence &&other):
24         device(other.device),
25         handle(other.handle)
26 {
27         other.handle = 0;
28 }
29
30 Fence::~Fence()
31 {
32         if(handle)
33                 device.get_destroy_queue().destroy(handle);
34 }
35
36 bool Fence::get_status()
37 {
38         const VulkanFunctions &vk = device.get_functions();
39
40         Result result = vk.GetFenceStatus(handle);
41         if(result==VK_NOT_READY)
42                 return false;
43         else
44                 result.check();
45
46         return true;
47 }
48
49 void Fence::reset()
50 {
51         const VulkanFunctions &vk = device.get_functions();
52
53         vk.ResetFences(1, &handle);
54 }
55
56 void Fence::wait()
57 {
58         const VulkanFunctions &vk = device.get_functions();
59
60         vk.WaitForFences(1, &handle, VK_TRUE, numeric_limits<uint64_t>::max());
61 }
62
63 } // namespace GL
64 } // namespace Msp