From cd335cca85d6a97c8a0a5c6446bf604f206fd45c Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 30 Dec 2019 19:37:35 -0800 Subject: Reworked SemaphoreObject through a more generic ManagedVulkanObject; fixed build error --- Graphics/GraphicsEngineVulkan/CMakeLists.txt | 2 +- .../include/DeviceContextVkImpl.h | 16 ++--- .../include/ManagedVulkanObject.h | 76 ++++++++++++++++++++ .../GraphicsEngineVulkan/include/SemaphoreObject.h | 80 ---------------------- .../GraphicsEngineVulkan/include/SwapChainVkImpl.h | 8 +-- .../GraphicsEngineVulkan/src/SwapChainVkImpl.cpp | 20 ++++-- 6 files changed, 103 insertions(+), 99 deletions(-) create mode 100644 Graphics/GraphicsEngineVulkan/include/ManagedVulkanObject.h delete mode 100644 Graphics/GraphicsEngineVulkan/include/SemaphoreObject.h (limited to 'Graphics/GraphicsEngineVulkan') 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> m_WaitSemaphores; - std::vector m_WaitDstStageMasks; - std::vector> m_SignalSemaphores; + std::vector> m_WaitSemaphores; + std::vector m_WaitDstStageMasks; + std::vector> m_SignalSemaphores; std::vector m_VkWaitSemaphores; std::vector m_VkSignalSemaphores; diff --git a/Graphics/GraphicsEngineVulkan/include/ManagedVulkanObject.h b/Graphics/GraphicsEngineVulkan/include/ManagedVulkanObject.h new file mode 100644 index 00000000..510689c4 --- /dev/null +++ b/Graphics/GraphicsEngineVulkan/include/ManagedVulkanObject.h @@ -0,0 +1,76 @@ +/* Copyright 2019 Diligent Graphics LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. + * + * In no event and under no legal theory, whether in tort (including negligence), + * contract, or otherwise, unless required by applicable law (such as deliberate + * and grossly negligent acts) or agreed to in writing, shall any Contributor be + * liable for any damages, including any direct, indirect, special, incidental, + * or consequential damages of any character arising as a result of this License or + * out of the use or inability to use the software (including but not limited to damages + * for loss of goodwill, work stoppage, computer failure or malfunction, or any and + * all other commercial damages or losses), even if such Contributor has been advised + * of the possibility of such damages. + */ + +#pragma once + +#include "DeviceObjectBase.h" +#include "RenderDeviceVkImpl.h" +#include "VulkanUtilities/VulkanLogicalDevice.h" + +namespace Diligent +{ + +template +class ManagedVulkanObject : public DeviceObjectBase +{ +public: + using TDeviceObjectBase = DeviceObjectBase; + + ManagedVulkanObject(IReferenceCounters* pRefCounters, + RenderDeviceVkImpl* pDevice, + const DeviceObjectAttribs& ObjDesc, + VulkanObjectWrapperType&& ObjectWrapper, + bool bIsDeviceInternal = false) : + TDeviceObjectBase{pRefCounters, pDevice, ObjDesc, bIsDeviceInternal}, + m_VkObject{std::move(ObjectWrapper)} + { + } + + ~ManagedVulkanObject() + { + m_pDevice->SafeReleaseDeviceObject(std::move(m_VkObject), ~Uint64{0}); + } + + static void Create(RenderDeviceVkImpl* pDevice, + VulkanObjectWrapperType&& ObjectWrapper, + const char* Name, + ManagedVulkanObject** ppManagedObject) + { + DeviceObjectAttribs Desc; + Desc.Name = Name; + auto* pObj(NEW_RC_OBJ(GetRawAllocator(), "ManagedVulkanObject instance", ManagedVulkanObject)(pDevice, Desc, std::move(ObjectWrapper))); + pObj->QueryInterface(IID_DeviceObject, reinterpret_cast(ppManagedObject)); + } + + typename VulkanObjectWrapperType::VkObjectType Get() const + { + return m_VkObject; + } + +private: + VulkanObjectWrapperType m_VkObject; +}; + +using ManagedSemaphore = ManagedVulkanObject; + +} // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/include/SemaphoreObject.h b/Graphics/GraphicsEngineVulkan/include/SemaphoreObject.h deleted file mode 100644 index c0dc8b94..00000000 --- a/Graphics/GraphicsEngineVulkan/include/SemaphoreObject.h +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright 2019 Diligent Graphics LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS. - * - * In no event and under no legal theory, whether in tort (including negligence), - * contract, or otherwise, unless required by applicable law (such as deliberate - * and grossly negligent acts) or agreed to in writing, shall any Contributor be - * liable for any damages, including any direct, indirect, special, incidental, - * or consequential damages of any character arising as a result of this License or - * out of the use or inability to use the software (including but not limited to damages - * for loss of goodwill, work stoppage, computer failure or malfunction, or any and - * all other commercial damages or losses), even if such Contributor has been advised - * of the possibility of such damages. - */ - -#pragma once - -#include "DeviceObjectBase.h" -#include "RenderDeviceVkImpl.h" -#include "VulkanUtilities/VulkanObjectWrappers.h" - -namespace Diligent -{ - -struct SemaphoreObjectDesc : DeviceObjectAttribs -{}; - -class SemaphoreObject : public DeviceObjectBase -{ -public: - using TDeviceObjectBase = DeviceObjectBase; - - SemaphoreObject(IReferenceCounters* pRefCounters, - RenderDeviceVkImpl* pDevice, - const SemaphoreObjectDesc& ObjDesc, - bool bIsDeviceInternal = false) : - TDeviceObjectBase{pRefCounters, pDevice, ObjDesc, bIsDeviceInternal} - { - 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() - { - m_pDevice->SafeReleaseDeviceObject(std::move(m_VkSemaphore), ~Uint64{0}); - } - - static void Create(RenderDeviceVkImpl* pDevice, const char* Name, SemaphoreObject** ppSemaphore) - { - SemaphoreObjectDesc Desc; - Desc.Name = Name; - auto* pSemaphoreObj(NEW_RC_OBJ(GetRawAllocator(), "SemaphoreObject instance", SemaphoreObject)(pDevice, Desc)); - pSemaphoreObj->QueryInterface(IID_DeviceObject, reinterpret_cast(ppSemaphore)); - } - - VkSemaphore GetVkSemaphore() const - { - return m_VkSemaphore; - } - -private: - VulkanUtilities::SemaphoreWrapper m_VkSemaphore; -}; - -} // 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> m_ImageAcquiredSemaphores; - std::vector> m_DrawCompleteSemaphores; - std::vector m_ImageAcquiredFences; + std::vector> m_ImageAcquiredSemaphores; + std::vector> m_DrawCompleteSemaphores; + std::vector m_ImageAcquiredFences; std::vector, STDAllocatorRawMem>> 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; -- cgit v1.2.3