1 module gfx.vulkan.sync;
2 
3 package:
4 
5 import core.time : dur, Duration;
6 
7 import gfx.bindings.vulkan;
8 
9 import gfx.core.rc;
10 import gfx.graal.sync;
11 import gfx.vulkan.device;
12 
13 class VulkanSemaphore : VulkanDevObj!(VkSemaphore, "DestroySemaphore"), Semaphore
14 {
15     mixin(atomicRcCode);
16 
17     this(VkSemaphore vkObj, VulkanDevice dev) {
18         super(vkObj, dev);
19     }
20 
21     override @property Device device() {
22         return dev;
23     }
24 }
25 
26 class VulkanFence : VulkanDevObj!(VkFence, "DestroyFence"), Fence
27 {
28     mixin(atomicRcCode);
29 
30     this (VkFence vkObj, VulkanDevice dev) {
31         super(vkObj, dev);
32     }
33 
34     override @property Device device() {
35         return dev;
36     }
37 
38     override @property bool signaled() {
39         return vk.GetFenceStatus(vkDev, vkObj) == VK_SUCCESS;
40     }
41 
42     override void reset()
43     {
44         auto vkF = vkObj;
45         vulkanEnforce(
46             vk.ResetFences(vkDev, 1, &vkF),
47             "Could not reset Vulkan fence"
48         );
49     }
50 
51     override void wait(Duration timeout=dur!"seconds"(-1))
52     {
53         const nsecs = timeout.total!"nsecs";
54         const vkTimeout = nsecs < 0 ? ulong.max : cast(ulong)nsecs;
55         auto vkF = vkObj;
56 
57         vulkanEnforce(
58             vk.WaitForFences(vkDev, 1, &vkF, VK_TRUE, vkTimeout),
59             "Could not wait for Vulkan fence"
60         );
61     }
62 }