diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-09-22 02:36:08 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-09-22 02:36:08 +0000 |
| commit | cce03c1dc92ee59be7d94e74d3a7b9c439bea68c (patch) | |
| tree | 7e1c8fd1ea31888f8da430dcb526390ff716075c /Graphics/GraphicsEngineVulkan | |
| parent | Fixed linux/mac/iOS build (diff) | |
| download | DiligentCore-cce03c1dc92ee59be7d94e74d3a7b9c439bea68c.tar.gz DiligentCore-cce03c1dc92ee59be7d94e74d3a7b9c439bea68c.zip | |
Unified resource liftime management in D3D12 and Vk backends
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
6 files changed, 38 insertions, 37 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.h b/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.h index 51eff69f..f2503737 100644 --- a/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.h @@ -62,7 +62,7 @@ public: virtual VkQueue GetVkQueue()override final{return m_VkQueue;} - virtual uint32_t GetQueueFamilyIndex()override final { return m_QueueFamilyIndex; } + virtual uint32_t GetQueueFamilyIndex()const override final { return m_QueueFamilyIndex; } virtual Uint64 WaitForIdle()override final; diff --git a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h index aff6fbae..873170fd 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h @@ -44,7 +44,6 @@ #include "FramebufferCache.h" #include "RenderPassCache.h" #include "CommandPoolManager.h" -#include "ResourceReleaseQueue.h" #include "VulkanDynamicHeap.h" /// Namespace for the Direct3D11 implementation of the graphics engine @@ -60,7 +59,8 @@ public: RenderDeviceVkImpl( IReferenceCounters* pRefCounters, IMemoryAllocator& RawMemAllocator, const EngineVkAttribs& CreationAttribs, - ICommandQueueVk* pCmdQueue, + size_t CommandQueueCount, + ICommandQueueVk** pCmdQueues, std::shared_ptr<VulkanUtilities::VulkanInstance> Instance, std::unique_ptr<VulkanUtilities::VulkanPhysicalDevice> PhysicalDevice, std::shared_ptr<VulkanUtilities::VulkanLogicalDevice> LogicalDevice, @@ -89,21 +89,6 @@ public: virtual void CreateBufferFromVulkanResource(VkBuffer vkBuffer, const BufferDesc& BuffDesc, IBuffer** ppBuffer)override final; - virtual Uint64 GetCompletedFenceValue(Uint32 QueueIndex) override final - { - return m_CommandQueues[QueueIndex].CmdQueue->GetCompletedFenceValue(); - } - - virtual Uint64 GetNextFenceValue(Uint32 QueueIndex) override final - { - return m_CommandQueues[QueueIndex].CmdQueue->GetNextFenceValue(); - } - - virtual Bool IsFenceSignaled(Uint32 QueueIndex, Uint64 FenceValue) override final - { - return FenceValue <= GetCompletedFenceValue(QueueIndex); - } - // Idles GPU void IdleGPU(bool ReleaseStaleObjects); // pImmediateCtx parameter is only used to make sure the command buffer is submitted from the immediate context diff --git a/Graphics/GraphicsEngineVulkan/interface/CommandQueueVk.h b/Graphics/GraphicsEngineVulkan/interface/CommandQueueVk.h index df4cfb60..a6175961 100644 --- a/Graphics/GraphicsEngineVulkan/interface/CommandQueueVk.h +++ b/Graphics/GraphicsEngineVulkan/interface/CommandQueueVk.h @@ -60,7 +60,7 @@ public: virtual VkQueue GetVkQueue() = 0; /// Returns vulkan command queue family index - virtual uint32_t GetQueueFamilyIndex() = 0; + virtual uint32_t GetQueueFamilyIndex()const = 0; /// Returns value of the last completed fence virtual Uint64 GetCompletedFenceValue() = 0; diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp index dcad3fbf..c60d9400 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceFactoryVk.cpp @@ -25,6 +25,7 @@ /// Routines that initialize Vulkan-based engine implementation #include "pch.h" +#include <array> #include "RenderDeviceFactoryVk.h" #include "RenderDeviceVkImpl.h" #include "DeviceContextVkImpl.h" @@ -55,7 +56,8 @@ public: void AttachToVulkanDevice(std::shared_ptr<VulkanUtilities::VulkanInstance> Instance, std::unique_ptr<VulkanUtilities::VulkanPhysicalDevice> PhysicalDevice, std::shared_ptr<VulkanUtilities::VulkanLogicalDevice> LogicalDevice, - ICommandQueueVk* pCommandQueue, + size_t CommandQueueCount, + ICommandQueueVk** ppCommandQueues, const EngineVkAttribs& EngineAttribs, IRenderDevice** ppDevice, IDeviceContext** ppContexts, @@ -194,7 +196,8 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk( const EngineVkAttribs& Crea auto &RawMemAllocator = GetRawAllocator(); pCmdQueueVk = NEW_RC_OBJ(RawMemAllocator, "CommandQueueVk instance", CommandQueueVkImpl)(LogicalDevice, QueueInfo.queueFamilyIndex); - AttachToVulkanDevice(Instance, std::move(PhysicalDevice), LogicalDevice, pCmdQueueVk, CreationAttribs, ppDevice, ppContexts, NumDeferredContexts); + std::array<ICommandQueueVk*, 1> CommandQueues = {pCmdQueueVk}; + AttachToVulkanDevice(Instance, std::move(PhysicalDevice), LogicalDevice, CommandQueues.size(), CommandQueues.data(), CreationAttribs, ppDevice, ppContexts, NumDeferredContexts); FenceDesc Desc; Desc.Name = "Command queue fence"; @@ -230,14 +233,15 @@ void EngineFactoryVkImpl::CreateDeviceAndContextsVk( const EngineVkAttribs& Crea void EngineFactoryVkImpl::AttachToVulkanDevice(std::shared_ptr<VulkanUtilities::VulkanInstance> Instance, std::unique_ptr<VulkanUtilities::VulkanPhysicalDevice> PhysicalDevice, std::shared_ptr<VulkanUtilities::VulkanLogicalDevice> LogicalDevice, - ICommandQueueVk* pCommandQueue, + size_t CommandQueueCount, + ICommandQueueVk** ppCommandQueues, const EngineVkAttribs& EngineAttribs, IRenderDevice** ppDevice, IDeviceContext** ppContexts, Uint32 NumDeferredContexts) { - VERIFY( pCommandQueue && ppDevice && ppContexts, "Null pointer provided" ); - if(!LogicalDevice || !pCommandQueue || !ppDevice || !ppContexts ) + VERIFY( ppCommandQueues && ppDevice && ppContexts, "Null pointer provided" ); + if(!LogicalDevice || !ppCommandQueues || !ppDevice || !ppContexts ) return; *ppDevice = nullptr; @@ -246,7 +250,7 @@ void EngineFactoryVkImpl::AttachToVulkanDevice(std::shared_ptr<VulkanUtilities:: try { auto &RawMemAllocator = GetRawAllocator(); - RenderDeviceVkImpl *pRenderDeviceVk( NEW_RC_OBJ(RawMemAllocator, "RenderDeviceVkImpl instance", RenderDeviceVkImpl)(RawMemAllocator, EngineAttribs, pCommandQueue, Instance, std::move(PhysicalDevice), LogicalDevice, NumDeferredContexts ) ); + RenderDeviceVkImpl *pRenderDeviceVk( NEW_RC_OBJ(RawMemAllocator, "RenderDeviceVkImpl instance", RenderDeviceVkImpl)(RawMemAllocator, EngineAttribs, CommandQueueCount, ppCommandQueues, Instance, std::move(PhysicalDevice), LogicalDevice, NumDeferredContexts ) ); pRenderDeviceVk->QueryInterface(IID_RenderDevice, reinterpret_cast<IObject**>(ppDevice) ); std::shared_ptr<GenerateMipsVkHelper> GenerateMipsHelper(new GenerateMipsVkHelper(*pRenderDeviceVk)); diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp index 4da6e760..8d5662e2 100644 --- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp @@ -41,7 +41,8 @@ namespace Diligent RenderDeviceVkImpl :: RenderDeviceVkImpl(IReferenceCounters* pRefCounters, IMemoryAllocator& RawMemAllocator, const EngineVkAttribs& CreationAttribs, - ICommandQueueVk* pCmdQueue, + size_t CommandQueueCount, + ICommandQueueVk** CmdQueues, std::shared_ptr<VulkanUtilities::VulkanInstance> Instance, std::unique_ptr<VulkanUtilities::VulkanPhysicalDevice> PhysicalDevice, std::shared_ptr<VulkanUtilities::VulkanLogicalDevice> LogicalDevice, @@ -50,7 +51,8 @@ RenderDeviceVkImpl :: RenderDeviceVkImpl(IReferenceCounters* { pRefCounters, RawMemAllocator, - 1, + CommandQueueCount, + CmdQueues, NumDeferredContexts, sizeof(TextureVkImpl), sizeof(TextureViewVkImpl), @@ -86,7 +88,7 @@ RenderDeviceVkImpl :: RenderDeviceVkImpl(IReferenceCounters* }, CreationAttribs.MainDescriptorPoolSize.MaxDescriptorSets }, - m_TransientCmdPoolMgr(*m_LogicalVkDevice, pCmdQueue->GetQueueFamilyIndex(), VK_COMMAND_POOL_CREATE_TRANSIENT_BIT), + m_TransientCmdPoolMgr(*m_LogicalVkDevice, CmdQueues[0]->GetQueueFamilyIndex(), VK_COMMAND_POOL_CREATE_TRANSIENT_BIT), m_MemoryMgr("Global resource memory manager", *m_LogicalVkDevice, *m_PhysicalDevice, GetRawAllocator(), CreationAttribs.DeviceLocalMemoryPageSize, CreationAttribs.HostVisibleMemoryPageSize, CreationAttribs.DeviceLocalMemoryReserveSize, CreationAttribs.HostVisibleMemoryReserveSize), m_DynamicMemoryManager { @@ -96,8 +98,6 @@ RenderDeviceVkImpl :: RenderDeviceVkImpl(IReferenceCounters* ~Uint64{0} } { - m_CommandQueues[0].CmdQueue = pCmdQueue; - m_DeviceCaps.DevType = DeviceType::Vulkan; m_DeviceCaps.MajorVersion = 1; m_DeviceCaps.MinorVersion = 0; @@ -199,7 +199,12 @@ void RenderDeviceVkImpl::ExecuteAndDisposeTransientCmdBuff(Uint32 QueueIndex, Vk // // Since transient command buffers do not count as real command buffers, submit them directly to the queue // to avoid interference with the command buffer numbers - Uint64 FenceValue = GetCommandQueue(0).Submit(SubmitInfo); + Uint64 FenceValue = 0; + LockCommandQueue(0, [&](ICommandQueueVk* pCmdQueueVk) + { + FenceValue = pCmdQueueVk->Submit(SubmitInfo); + } + ); // Dispose command pool m_TransientCmdPoolMgr.DisposeCommandPool(std::move(CmdPool), FenceValue); } @@ -249,7 +254,7 @@ Uint64 RenderDeviceVkImpl::ExecuteCommandBuffer(const VkSubmitInfo& SubmitInfo, void RenderDeviceVkImpl::IdleGPU(bool ReleaseStaleObjects) { - IdleCommandQueues(ReleaseStaleObjects, ReleaseStaleObjects); + IdleCommandQueues(ReleaseStaleObjects); m_LogicalVkDevice->WaitIdle(); if (ReleaseStaleObjects) @@ -268,9 +273,6 @@ void RenderDeviceVkImpl::IdleGPU(bool ReleaseStaleObjects) void RenderDeviceVkImpl::FinishFrame(bool ReleaseAllResources) { - // TODO: rework this - auto CompletedFenceValue = ReleaseAllResources ? std::numeric_limits<Uint64>::max() : m_CommandQueues[0].CmdQueue->GetCompletedFenceValue(); - // Discard all remaining objects. This is important to do if there were // no command lists submitted during the frame. All stale resources will // be associated with the submitted fence value and thus will not be released @@ -278,9 +280,14 @@ void RenderDeviceVkImpl::FinishFrame(bool ReleaseAllResources) Uint64 SubmittedFenceValue = 0; Uint64 SubmittedCmdBuffNumber = 0; VkSubmitInfo DummySubmitInfo = {}; + + // TODO: Rework // Submit empty command buffer to set a fence on the GPU - SubmitCommandBuffer(DummySubmitInfo, SubmittedCmdBuffNumber, SubmittedFenceValue, nullptr); + auto CmbBuffInfo = TRenderDeviceBase::SubmitCommandBuffer(0, DummySubmitInfo, true); + // TODO: rework this + auto CompletedFenceValue = ReleaseAllResources ? std::numeric_limits<Uint64>::max() : m_CommandQueues[0].CmdQueue->GetCompletedFenceValue(); + PurgeReleaseQueues(); m_MainDescriptorPool.ReleaseStaleAllocations(CompletedFenceValue); diff --git a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp index 930951f6..21818b6d 100644 --- a/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/SwapChainVkImpl.cpp @@ -454,7 +454,12 @@ void SwapChainVkImpl::Present(Uint32 SyncInterval) PresentInfo.pImageIndices = &m_BackBufferIndex; VkResult Result = VK_SUCCESS; PresentInfo.pResults = &Result; - pDeviceVk->GetCommandQueue(0).Present(PresentInfo); + pDeviceVk->LockCommandQueue(0, + [&PresentInfo](ICommandQueueVk* pCmdQueueVk) + { + pCmdQueueVk->Present(PresentInfo); + } + ); } pImmediateCtxVk->FinishFrame(false); |
