]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/vulkan/fence.cpp
Initial implementation of Vulkan backend
[libs/gl.git] / source / backends / vulkan / fence.cpp
diff --git a/source/backends/vulkan/fence.cpp b/source/backends/vulkan/fence.cpp
new file mode 100644 (file)
index 0000000..f5b7544
--- /dev/null
@@ -0,0 +1,64 @@
+#include <limits>
+#include "device.h"
+#include "fence.h"
+#include "vulkan.h"
+
+using namespace std;
+
+namespace Msp {
+namespace GL {
+
+Fence::Fence(bool create_signaled):
+       device(Device::get_current())
+{
+       const VulkanFunctions &vk = device.get_functions();
+
+       VkFenceCreateInfo fence_info = { };
+       fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
+       fence_info.flags = (create_signaled ? VK_FENCE_CREATE_SIGNALED_BIT : 0);
+
+       vk.CreateFence(fence_info, handle);
+}
+
+Fence::Fence(Fence &&other):
+       device(other.device),
+       handle(other.handle)
+{
+       other.handle = 0;
+}
+
+Fence::~Fence()
+{
+       if(handle)
+               device.get_destroy_queue().destroy(handle);
+}
+
+bool Fence::get_status()
+{
+       const VulkanFunctions &vk = device.get_functions();
+
+       Result result = vk.GetFenceStatus(handle);
+       if(result==VK_NOT_READY)
+               return false;
+       else
+               result.check();
+
+       return true;
+}
+
+void Fence::reset()
+{
+       const VulkanFunctions &vk = device.get_functions();
+
+       vk.ResetFences(1, &handle);
+}
+
+void Fence::wait()
+{
+       const VulkanFunctions &vk = device.get_functions();
+
+       vk.WaitForFences(1, &handle, VK_TRUE, numeric_limits<uint64_t>::max());
+}
+
+} // namespace GL
+} // namespace Msp