diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2019-12-31 03:37:35 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2019-12-31 03:37:35 +0000 |
| commit | cd335cca85d6a97c8a0a5c6446bf604f206fd45c (patch) | |
| tree | 7b6fee761bd2266ff7775ea9ee6629a565178a2f /Graphics/GraphicsEngineVulkan | |
| parent | Vulkan backend: fixed issue with swap chain semaphores being destroyed while ... (diff) | |
| download | DiligentCore-cd335cca85d6a97c8a0a5c6446bf604f206fd45c.tar.gz DiligentCore-cd335cca85d6a97c8a0a5c6446bf604f206fd45c.zip | |
Reworked SemaphoreObject through a more generic ManagedVulkanObject; fixed build error
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h | 16 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/include/ManagedVulkanObject.h (renamed from Graphics/GraphicsEngineVulkan/include/SemaphoreObject.h) | 54 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.h | 8 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp | 20 |
5 files changed, 52 insertions, 48 deletions
diff --git a/Graphics/GraphicsEngineVulkan/CMakeLists.txt b/Graphics/GraphicsEngineVulkan/CMakeLists.txt index a4ac2b92..af3dbcd4 100644 --- a/Graphics/GraphicsEngineVulkan/CMakeLists.txt +++ b/Graphics/GraphicsEngineVulkan/CMakeLists.txt @@ -21,7 +21,7 @@ set(INCLUDE include/RenderPassCache.h include/SamplerVkImpl.h include/ShaderVkImpl.h - include/Semaphore.h + include/ManagedVulkanObject.h include/ShaderResourceBindingVkImpl.h include/ShaderResourceCacheVk.h include/ShaderResourceLayoutVk.h diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h index 9b9531ac..62a72415 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h @@ -41,7 +41,7 @@ #include "TextureVkImpl.h" #include "PipelineStateVkImpl.h" #include "HashUtils.h" -#include "SemaphoreObject.h" +#include "ManagedVulkanObject.h" namespace Diligent { @@ -235,18 +235,18 @@ public: virtual void BufferMemoryBarrier(IBuffer* pBuffer, VkAccessFlags NewAccessFlags) override final; - void AddWaitSemaphore(SemaphoreObject* pWaitSemaphore, VkPipelineStageFlags WaitDstStageMask) + void AddWaitSemaphore(ManagedSemaphore* pWaitSemaphore, VkPipelineStageFlags WaitDstStageMask) { VERIFY_EXPR(pWaitSemaphore != nullptr); m_WaitSemaphores.emplace_back(pWaitSemaphore); - m_VkWaitSemaphores.push_back(pWaitSemaphore->GetVkSemaphore()); + m_VkWaitSemaphores.push_back(pWaitSemaphore->Get()); m_WaitDstStageMasks.push_back(WaitDstStageMask); } - void AddSignalSemaphore(SemaphoreObject* pSignalSemaphore) + void AddSignalSemaphore(ManagedSemaphore* pSignalSemaphore) { VERIFY_EXPR(pSignalSemaphore != nullptr); m_SignalSemaphores.emplace_back(pSignalSemaphore); - m_VkSignalSemaphores.push_back(pSignalSemaphore->GetVkSemaphore()); + m_VkSignalSemaphores.push_back(pSignalSemaphore->Get()); } void UpdateBufferRegion(BufferVkImpl* pBuffVk, @@ -406,9 +406,9 @@ private: FixedBlockMemoryAllocator m_CmdListAllocator; // Semaphores are not owned by the command context - std::vector<RefCntAutoPtr<SemaphoreObject>> m_WaitSemaphores; - std::vector<VkPipelineStageFlags> m_WaitDstStageMasks; - std::vector<RefCntAutoPtr<SemaphoreObject>> m_SignalSemaphores; + std::vector<RefCntAutoPtr<ManagedSemaphore>> m_WaitSemaphores; + std::vector<VkPipelineStageFlags> m_WaitDstStageMasks; + std::vector<RefCntAutoPtr<ManagedSemaphore>> m_SignalSemaphores; std::vector<VkSemaphore> m_VkWaitSemaphores; std::vector<VkSemaphore> m_VkSignalSemaphores; diff --git a/Graphics/GraphicsEngineVulkan/include/SemaphoreObject.h b/Graphics/GraphicsEngineVulkan/include/ManagedVulkanObject.h index c0dc8b94..510689c4 100644 --- a/Graphics/GraphicsEngineVulkan/include/SemaphoreObject.h +++ b/Graphics/GraphicsEngineVulkan/include/ManagedVulkanObject.h @@ -25,56 +25,52 @@ #include "DeviceObjectBase.h" #include "RenderDeviceVkImpl.h" -#include "VulkanUtilities/VulkanObjectWrappers.h" +#include "VulkanUtilities/VulkanLogicalDevice.h" namespace Diligent { -struct SemaphoreObjectDesc : DeviceObjectAttribs -{}; - -class SemaphoreObject : public DeviceObjectBase<IDeviceObject, RenderDeviceVkImpl, SemaphoreObjectDesc> +template <typename VulkanObjectWrapperType> +class ManagedVulkanObject : public DeviceObjectBase<IDeviceObject, RenderDeviceVkImpl, DeviceObjectAttribs> { public: - using TDeviceObjectBase = DeviceObjectBase<IDeviceObject, RenderDeviceVkImpl, SemaphoreObjectDesc>; + using TDeviceObjectBase = DeviceObjectBase<IDeviceObject, RenderDeviceVkImpl, DeviceObjectAttribs>; - SemaphoreObject(IReferenceCounters* pRefCounters, - RenderDeviceVkImpl* pDevice, - const SemaphoreObjectDesc& ObjDesc, - bool bIsDeviceInternal = false) : - TDeviceObjectBase{pRefCounters, pDevice, ObjDesc, bIsDeviceInternal} + ManagedVulkanObject(IReferenceCounters* pRefCounters, + RenderDeviceVkImpl* pDevice, + const DeviceObjectAttribs& ObjDesc, + VulkanObjectWrapperType&& ObjectWrapper, + bool bIsDeviceInternal = false) : + TDeviceObjectBase{pRefCounters, pDevice, ObjDesc, bIsDeviceInternal}, + m_VkObject{std::move(ObjectWrapper)} { - const auto& LogicalDevice = m_pDevice->GetLogicalDevice(); - - VkSemaphoreCreateInfo SemaphoreCI = {}; - - SemaphoreCI.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; - SemaphoreCI.pNext = nullptr; - SemaphoreCI.flags = 0; // reserved for future use - - m_VkSemaphore = LogicalDevice.CreateSemaphore(SemaphoreCI, m_Desc.Name); } - ~SemaphoreObject() + ~ManagedVulkanObject() { - m_pDevice->SafeReleaseDeviceObject(std::move(m_VkSemaphore), ~Uint64{0}); + m_pDevice->SafeReleaseDeviceObject(std::move(m_VkObject), ~Uint64{0}); } - static void Create(RenderDeviceVkImpl* pDevice, const char* Name, SemaphoreObject** ppSemaphore) + static void Create(RenderDeviceVkImpl* pDevice, + VulkanObjectWrapperType&& ObjectWrapper, + const char* Name, + ManagedVulkanObject** ppManagedObject) { - SemaphoreObjectDesc Desc; + DeviceObjectAttribs Desc; Desc.Name = Name; - auto* pSemaphoreObj(NEW_RC_OBJ(GetRawAllocator(), "SemaphoreObject instance", SemaphoreObject)(pDevice, Desc)); - pSemaphoreObj->QueryInterface(IID_DeviceObject, reinterpret_cast<IObject**>(ppSemaphore)); + auto* pObj(NEW_RC_OBJ(GetRawAllocator(), "ManagedVulkanObject instance", ManagedVulkanObject)(pDevice, Desc, std::move(ObjectWrapper))); + pObj->QueryInterface(IID_DeviceObject, reinterpret_cast<IObject**>(ppManagedObject)); } - VkSemaphore GetVkSemaphore() const + typename VulkanObjectWrapperType::VkObjectType Get() const { - return m_VkSemaphore; + return m_VkObject; } private: - VulkanUtilities::SemaphoreWrapper m_VkSemaphore; + VulkanObjectWrapperType m_VkObject; }; +using ManagedSemaphore = ManagedVulkanObject<VulkanUtilities::SemaphoreWrapper>; + } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.h b/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.h index ca3bc981..f1133cad 100644 --- a/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.h @@ -30,7 +30,7 @@ #include "SwapChainBase.h" #include "VulkanUtilities/VulkanInstance.h" #include "VulkanUtilities/VulkanObjectWrappers.h" -#include "SemaphoreObject.h" +#include "ManagedVulkanObject.h" namespace Diligent { @@ -91,9 +91,9 @@ private: VkSwapchainKHR m_VkSwapChain = VK_NULL_HANDLE; VkFormat m_VkColorFormat = VK_FORMAT_UNDEFINED; - std::vector<RefCntAutoPtr<SemaphoreObject>> m_ImageAcquiredSemaphores; - std::vector<RefCntAutoPtr<SemaphoreObject>> m_DrawCompleteSemaphores; - std::vector<VulkanUtilities::FenceWrapper> m_ImageAcquiredFences; + std::vector<RefCntAutoPtr<ManagedSemaphore>> m_ImageAcquiredSemaphores; + std::vector<RefCntAutoPtr<ManagedSemaphore>> m_DrawCompleteSemaphores; + std::vector<VulkanUtilities::FenceWrapper> m_ImageAcquiredFences; std::vector<RefCntAutoPtr<ITextureViewVk>, STDAllocatorRawMem<RefCntAutoPtr<ITextureViewVk>>> m_pBackBufferRTV; diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp index 4fa9a523..e2629f46 100644 --- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp @@ -350,18 +350,26 @@ void SwapChainVkImpl::CreateVulkanSwapChain() m_ImageAcquiredFences.resize(swapchainImageCount); for (uint32_t i = 0; i < swapchainImageCount; ++i) { + VkSemaphoreCreateInfo SemaphoreCI = {}; + + SemaphoreCI.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + SemaphoreCI.pNext = nullptr; + SemaphoreCI.flags = 0; // reserved for future use + { std::stringstream ss; ss << "Swap chain image acquired semaphore " << i; - auto Name = ss.str(); - SemaphoreObject::Create(pRenderDeviceVk, Name.c_str(), &m_ImageAcquiredSemaphores[i]); + auto Name = ss.str(); + auto Semaphore = LogicalDevice.CreateSemaphore(SemaphoreCI, ss.str().c_str()); + ManagedSemaphore::Create(pRenderDeviceVk, std::move(Semaphore), Name.c_str(), &m_ImageAcquiredSemaphores[i]); } { std::stringstream ss; ss << "Swap chain draw complete semaphore " << i; - auto Name = ss.str(); - SemaphoreObject::Create(pRenderDeviceVk, Name.c_str(), &m_DrawCompleteSemaphores[i]); + auto Name = ss.str(); + auto Semaphore = LogicalDevice.CreateSemaphore(SemaphoreCI, ss.str().c_str()); + ManagedSemaphore::Create(pRenderDeviceVk, std::move(Semaphore), Name.c_str(), &m_DrawCompleteSemaphores[i]); } VkFenceCreateInfo FenceCI = {}; @@ -504,7 +512,7 @@ VkResult SwapChainVkImpl::AcquireNextImage(DeviceContextVkImpl* pDeviceCtxVk) } VkFence ImageAcquiredFence = m_ImageAcquiredFences[m_SemaphoreIndex]; - VkSemaphore ImageAcquiredSemaphore = m_ImageAcquiredSemaphores[m_SemaphoreIndex]->GetVkSemaphore(); + VkSemaphore ImageAcquiredSemaphore = m_ImageAcquiredSemaphores[m_SemaphoreIndex]->Get(); auto res = vkAcquireNextImageKHR(LogicalDevice.GetVkDevice(), m_VkSwapChain, UINT64_MAX, ImageAcquiredSemaphore, ImageAcquiredFence, &m_BackBufferIndex); @@ -568,7 +576,7 @@ void SwapChainVkImpl::Present(Uint32 SyncInterval) PresentInfo.pNext = nullptr; PresentInfo.waitSemaphoreCount = 1; // Unlike fences or events, the act of waiting for a semaphore also unsignals that semaphore (6.4.2) - VkSemaphore WaitSemaphore[] = {m_DrawCompleteSemaphores[m_SemaphoreIndex]->GetVkSemaphore()}; + VkSemaphore WaitSemaphore[] = {m_DrawCompleteSemaphores[m_SemaphoreIndex]->Get()}; PresentInfo.pWaitSemaphores = WaitSemaphore; PresentInfo.swapchainCount = 1; PresentInfo.pSwapchains = &m_VkSwapChain; |
