X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbackends%2Fvulkan%2Ffence.cpp;fp=source%2Fbackends%2Fvulkan%2Ffence.cpp;h=f5b754423371824e89c7a9845c6c492c90555b82;hb=99ca354f18119f82f1adeca100cd665a8f640317;hp=0000000000000000000000000000000000000000;hpb=4cd245dafe6a7ee5c93edca5aee2d146f1155309;p=libs%2Fgl.git diff --git a/source/backends/vulkan/fence.cpp b/source/backends/vulkan/fence.cpp new file mode 100644 index 00000000..f5b75442 --- /dev/null +++ b/source/backends/vulkan/fence.cpp @@ -0,0 +1,64 @@ +#include +#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::max()); +} + +} // namespace GL +} // namespace Msp