From 01a6f17699e5f4bafb27e40e83f4f3187b3022db Mon Sep 17 00:00:00 2001 From: Morteza Mostajab Date: Fri, 10 Aug 2018 18:14:24 +0200 Subject: [PATCH] !B (CE-17864) (Vulkan) Fixes the crash on startup. Pipeline state destroying is deferred. Copied from Perforce Change: 1835389 --- .../DeviceManager/Vulkan/DevicePSO_Vulkan.cpp | 10 ++-------- .../RenderDll/XRenderD3D9/Vulkan/API/VKDevice.cpp | 18 ++++++++++++++++++ .../RenderDll/XRenderD3D9/Vulkan/API/VKDevice.hpp | 5 +++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Code/CryEngine/RenderDll/XRenderD3D9/DeviceManager/Vulkan/DevicePSO_Vulkan.cpp b/Code/CryEngine/RenderDll/XRenderD3D9/DeviceManager/Vulkan/DevicePSO_Vulkan.cpp index 39422c9cb..6adf6de1a 100644 --- a/Code/CryEngine/RenderDll/XRenderD3D9/DeviceManager/Vulkan/DevicePSO_Vulkan.cpp +++ b/Code/CryEngine/RenderDll/XRenderD3D9/DeviceManager/Vulkan/DevicePSO_Vulkan.cpp @@ -20,10 +20,7 @@ using namespace NCryVulkan; CDeviceGraphicsPSO_Vulkan::~CDeviceGraphicsPSO_Vulkan() { - if (m_pipeline != VK_NULL_HANDLE) - { - vkDestroyPipeline(m_pDevice->GetVkDevice(), m_pipeline, nullptr); - } + GetDevice()->ReleaseLater(m_pipeline, gcpRendD3D->GetRenderFrameID()); } static struct @@ -507,10 +504,7 @@ CDeviceGraphicsPSO::EInitResult CDeviceGraphicsPSO_Vulkan::Init(const CDeviceGra CDeviceComputePSO_Vulkan::~CDeviceComputePSO_Vulkan() { - if (m_pipeline != VK_NULL_HANDLE) - { - vkDestroyPipeline(m_pDevice->GetVkDevice(), m_pipeline, nullptr); - } + GetDevice()->ReleaseLater(m_pipeline, gcpRendD3D->GetRenderFrameID()); } bool CDeviceComputePSO_Vulkan::Init(const CDeviceComputePSODesc& psoDesc) diff --git a/Code/CryEngine/RenderDll/XRenderD3D9/Vulkan/API/VKDevice.cpp b/Code/CryEngine/RenderDll/XRenderD3D9/Vulkan/API/VKDevice.cpp index 00802790a..b8f605326 100644 --- a/Code/CryEngine/RenderDll/XRenderD3D9/Vulkan/API/VKDevice.cpp +++ b/Code/CryEngine/RenderDll/XRenderD3D9/Vulkan/API/VKDevice.cpp @@ -549,11 +549,23 @@ void CDevice::FlushReleaseHeap(const UINT64 (&completedFenceValues)[CMDQUEUE_NUM } } +void CDevice::FlushReleasePSOHeap() threadsafe +{ + while (!m_PSOReleasePair.empty() && m_PSOReleasePair.front().second >= (gcpRendD3D->GetRenderFrameID() + MAX_FRAME_LATENCY)) + { + VkPipeline pipeline = m_PSOReleasePair.front().first; + if (pipeline != VK_NULL_HANDLE) + vkDestroyPipeline(GetVkDevice(), pipeline, nullptr); + m_PSOReleasePair.pop( ); + } +} + void CDevice::FlushReleaseHeaps(const UINT64 (&completedFenceValues)[CMDQUEUE_NUM], const UINT64 (&pruneFenceValues)[CMDQUEUE_NUM]) threadsafe { FlushReleaseHeap(completedFenceValues, pruneFenceValues); FlushReleaseHeap(completedFenceValues, pruneFenceValues); FlushReleaseHeap(completedFenceValues, pruneFenceValues); + FlushReleasePSOHeap (); } //--------------------------------------------------------------------------------------------------------------------- @@ -612,6 +624,12 @@ void CDevice::ReleaseLater(const FVAL64 (&fenceValues)[CMDQUEUE_NUM], CResource* } //--------------------------------------------------------------------------------------------------------------------- +void CDevice::ReleaseLater(VkPipeline pipeline, int frameID) threadsafe +{ + m_PSOReleasePair.push(std::make_pair(pipeline, frameID)); +} + +//--------------------------------------------------------------------------------------------------------------------- // Explicit instantiations template VkResult CDevice::CommitResource(EHeapType HeapHint, CBufferResource* pInputResource) threadsafe; template VkResult CDevice::CommitResource(EHeapType HeapHint, CImageResource * pInputResource) threadsafe; diff --git a/Code/CryEngine/RenderDll/XRenderD3D9/Vulkan/API/VKDevice.hpp b/Code/CryEngine/RenderDll/XRenderD3D9/Vulkan/API/VKDevice.hpp index 54646e93a..b5c2764f0 100644 --- a/Code/CryEngine/RenderDll/XRenderD3D9/Vulkan/API/VKDevice.hpp +++ b/Code/CryEngine/RenderDll/XRenderD3D9/Vulkan/API/VKDevice.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include #include "VKBase.hpp" #include "VKHeap.hpp" @@ -87,7 +88,9 @@ public: template VkResult CreateOrReuseStagingResource(CResource* pInputResource, VkDeviceSize minSize, CBufferResource** ppStagingResource, bool bUpload) threadsafe; template VkResult CreateOrReuseCommittedResource(EHeapType HeapHint, const VkCreateInfo& createInfo, CResource** ppOutputResource) threadsafe; template void ReleaseLater(const FVAL64 (&fenceValues)[CMDQUEUE_NUM], CResource* pObject, bool bReusable = true) threadsafe; + void ReleaseLater(VkPipeline pipeline, int frameID) threadsafe; template void FlushReleaseHeap(const UINT64 (&completedFenceValues)[CMDQUEUE_NUM], const UINT64 (&pruneFenceValues)[CMDQUEUE_NUM]) threadsafe; + void FlushReleasePSOHeap() threadsafe; void FlushReleaseHeaps(const UINT64 (&completedFenceValues)[CMDQUEUE_NUM], const UINT64 (&pruneFenceValues)[CMDQUEUE_NUM]) threadsafe; void FlushAndWaitForGPU(); @@ -149,6 +152,8 @@ private: TReleaseHeap m_ImageReleaseHeap; TRecycleHeap m_ImageRecycleHeap; + std::queue> m_PSOReleasePair; + template TReleaseHeap& GetReleaseHeap(); template TRecycleHeap& GetRecycleHeap(); -- 2.11.4.GIT