Add Fence objects (+ use them for sync)
This commit is contained in:
parent
7bf734cdd4
commit
7ba9a33d35
|
|
@ -274,6 +274,11 @@ int main()
|
|||
|
||||
Nz::UInt32 imageCount = vulkanWindow.GetFramebufferCount();
|
||||
std::vector<Nz::Vk::CommandBuffer> renderCmds = cmdPool.AllocateCommandBuffers(imageCount, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
|
||||
|
||||
std::vector<Nz::Vk::Fence> fences(imageCount);
|
||||
for (auto& fence : fences)
|
||||
fence.Create(vulkanDevice.shared_from_this());
|
||||
|
||||
for (Nz::UInt32 i = 0; i < imageCount; ++i)
|
||||
{
|
||||
Nz::Vk::CommandBuffer& renderCmd = renderCmds[i];
|
||||
|
|
@ -317,7 +322,7 @@ int main()
|
|||
1U
|
||||
};
|
||||
|
||||
renderCmd.Begin(VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT);
|
||||
renderCmd.Begin();
|
||||
|
||||
vulkanWindow.BuildPreRenderCommands(i, renderCmd);
|
||||
|
||||
|
|
@ -426,6 +431,9 @@ int main()
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fences[imageIndex].Wait();
|
||||
fences[imageIndex].Reset();
|
||||
|
||||
VkCommandBuffer renderCmdBuffer = renderCmds[imageIndex];
|
||||
VkSemaphore waitSemaphore = vulkanWindow.GetRenderSemaphore();
|
||||
|
||||
|
|
@ -442,7 +450,7 @@ int main()
|
|||
nullptr // const VkSemaphore *pSignalSemaphores
|
||||
};
|
||||
|
||||
if (!graphicsQueue.Submit(submit_info))
|
||||
if (!graphicsQueue.Submit(submit_info, fences[imageIndex]))
|
||||
return false;
|
||||
|
||||
vulkanWindow.Present(imageIndex);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include <Nazara/VulkanRenderer/Wrapper/Device.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DeviceMemory.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Fence.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Framebuffer.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Image.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/ImageView.hpp>
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Nz
|
|||
inline ~CommandBuffer();
|
||||
|
||||
inline bool Begin(const VkCommandBufferBeginInfo& info);
|
||||
inline bool Begin(VkCommandBufferUsageFlags flags);
|
||||
inline bool Begin(VkCommandBufferUsageFlags flags = 0);
|
||||
inline bool Begin(VkCommandBufferUsageFlags flags, const VkCommandBufferInheritanceInfo& inheritanceInfo);
|
||||
inline bool Begin(VkCommandBufferUsageFlags flags, VkRenderPass renderPass, UInt32 subpass, VkFramebuffer framebuffer, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics);
|
||||
inline bool Begin(VkCommandBufferUsageFlags flags, bool occlusionQueryEnable, VkQueryControlFlags queryFlags, VkQueryPipelineStatisticFlags pipelineStatistics);
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ namespace Nz
|
|||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateDescriptorPool);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateDescriptorSetLayout);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateEvent);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateFence);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateFramebuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateGraphicsPipelines);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkCreateImage);
|
||||
|
|
@ -136,6 +137,7 @@ namespace Nz
|
|||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyDescriptorSetLayout);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyDevice);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyEvent);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyFence);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyFramebuffer);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyImage);
|
||||
NAZARA_VULKANRENDERER_DEVICE_FUNCTION(vkDestroyImageView);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_VULKANRENDERER_VKFENCE_HPP
|
||||
#define NAZARA_VULKANRENDERER_VKFENCE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/VulkanRenderer/Wrapper/DeviceObject.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
class Fence : public DeviceObject<Fence, VkFence, VkFenceCreateInfo>
|
||||
{
|
||||
friend DeviceObject;
|
||||
|
||||
public:
|
||||
Fence() = default;
|
||||
Fence(const Fence&) = delete;
|
||||
Fence(Fence&&) = default;
|
||||
~Fence() = default;
|
||||
|
||||
using DeviceObject::Create;
|
||||
inline bool Create(DeviceHandle device, VkFenceCreateFlags flags = 0, const VkAllocationCallbacks* allocator = nullptr);
|
||||
|
||||
inline bool Reset();
|
||||
|
||||
inline bool Wait();
|
||||
inline bool Wait(UInt64 timeout, bool* didTimeout = nullptr);
|
||||
|
||||
Fence& operator=(const Fence&) = delete;
|
||||
Fence& operator=(Fence&&) = delete;
|
||||
|
||||
private:
|
||||
static inline VkResult CreateHelper(const DeviceHandle& device, const VkFenceCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFence* handle);
|
||||
static inline void DestroyHelper(const DeviceHandle& device, VkFence handle, const VkAllocationCallbacks* allocator);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Fence.inl>
|
||||
|
||||
#endif // NAZARA_VULKANRENDERER_VKFENCE_HPP
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
// Copyright (C) 2016 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Vulkan Renderer"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/VulkanRenderer/Wrapper/Fence.hpp>
|
||||
#include <Nazara/VulkanRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
namespace Vk
|
||||
{
|
||||
inline bool Fence::Create(DeviceHandle device, VkFenceCreateFlags flags, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
VkFenceCreateInfo createInfo =
|
||||
{
|
||||
VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
|
||||
nullptr,
|
||||
flags
|
||||
};
|
||||
|
||||
return Create(std::move(device), createInfo, allocator);
|
||||
}
|
||||
|
||||
inline bool Fence::Reset()
|
||||
{
|
||||
m_lastErrorCode = m_device->vkResetFences(*m_device, 1U, &m_handle);
|
||||
if (m_lastErrorCode != VK_SUCCESS)
|
||||
{
|
||||
NazaraError("Failed to reset fence: " + TranslateVulkanError(m_lastErrorCode));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool Fence::Wait()
|
||||
{
|
||||
return Wait(std::numeric_limits<UInt64>::max());
|
||||
}
|
||||
|
||||
inline bool Fence::Wait(UInt64 timeout, bool* didTimeout)
|
||||
{
|
||||
m_lastErrorCode = m_device->vkWaitForFences(*m_device, 1U, &m_handle, VK_TRUE, timeout);
|
||||
if (m_lastErrorCode != VK_SUCCESS && m_lastErrorCode != VK_TIMEOUT)
|
||||
{
|
||||
NazaraError("Failed to wait for fence: " + TranslateVulkanError(m_lastErrorCode));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (didTimeout)
|
||||
*didTimeout = (m_lastErrorCode == VK_TIMEOUT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline VkResult Fence::CreateHelper(const DeviceHandle& device, const VkFenceCreateInfo* createInfo, const VkAllocationCallbacks* allocator, VkFence* handle)
|
||||
{
|
||||
return device->vkCreateFence(*device, createInfo, allocator, handle);
|
||||
}
|
||||
|
||||
inline void Fence::DestroyHelper(const DeviceHandle& device, VkFence handle, const VkAllocationCallbacks* allocator)
|
||||
{
|
||||
return device->vkDestroyFence(*device, handle, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/VulkanRenderer/DebugOff.hpp>
|
||||
|
|
@ -107,6 +107,7 @@ namespace Nz
|
|||
NAZARA_VULKANRENDERER_LOAD_DEVICE(vkCreateDescriptorPool);
|
||||
NAZARA_VULKANRENDERER_LOAD_DEVICE(vkCreateDescriptorSetLayout);
|
||||
NAZARA_VULKANRENDERER_LOAD_DEVICE(vkCreateEvent);
|
||||
NAZARA_VULKANRENDERER_LOAD_DEVICE(vkCreateFence);
|
||||
NAZARA_VULKANRENDERER_LOAD_DEVICE(vkCreateFramebuffer);
|
||||
NAZARA_VULKANRENDERER_LOAD_DEVICE(vkCreateGraphicsPipelines);
|
||||
NAZARA_VULKANRENDERER_LOAD_DEVICE(vkCreateImage);
|
||||
|
|
@ -124,6 +125,7 @@ namespace Nz
|
|||
NAZARA_VULKANRENDERER_LOAD_DEVICE(vkDestroyDescriptorSetLayout);
|
||||
NAZARA_VULKANRENDERER_LOAD_DEVICE(vkDestroyDevice);
|
||||
NAZARA_VULKANRENDERER_LOAD_DEVICE(vkDestroyEvent);
|
||||
NAZARA_VULKANRENDERER_LOAD_DEVICE(vkDestroyFence);
|
||||
NAZARA_VULKANRENDERER_LOAD_DEVICE(vkDestroyFramebuffer);
|
||||
NAZARA_VULKANRENDERER_LOAD_DEVICE(vkDestroyImage);
|
||||
NAZARA_VULKANRENDERER_LOAD_DEVICE(vkDestroyImageView);
|
||||
|
|
|
|||
Loading…
Reference in New Issue