diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-10-07 00:39:10 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-10-07 00:39:10 +0000 |
| commit | 304dda5ae2f7b47a84ea5a0134912e159698bf6a (patch) | |
| tree | 3a7a14a803d2668c1604449ef85128b8282a49c5 /Graphics/GraphicsEngineD3D12 | |
| parent | Re-enabled idling GPU in VulkanDynamicMemoryManager::AllocateMasterBlock() si... (diff) | |
| download | DiligentCore-304dda5ae2f7b47a84ea5a0134912e159698bf6a.tar.gz DiligentCore-304dda5ae2f7b47a84ea5a0134912e159698bf6a.zip | |
Few minor cosmetic code changes in D3D12 backend
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
8 files changed, 19 insertions, 19 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/CommandContext.h b/Graphics/GraphicsEngineD3D12/include/CommandContext.h index c3b0d6f7..a766c56f 100644 --- a/Graphics/GraphicsEngineD3D12/include/CommandContext.h +++ b/Graphics/GraphicsEngineD3D12/include/CommandContext.h @@ -116,7 +116,12 @@ public: void SetID(const Char* ID) { m_ID = ID; } ID3D12GraphicsCommandList *GetCommandList(){return m_pCommandList;} - DescriptorHeapAllocation AllocateDynamicGPUVisibleDescriptor( D3D12_DESCRIPTOR_HEAP_TYPE Type, UINT Count = 1 ); + DescriptorHeapAllocation AllocateDynamicGPUVisibleDescriptor( D3D12_DESCRIPTOR_HEAP_TYPE Type, UINT Count = 1 ) + { + VERIFY(m_DynamicGPUDescriptorAllocators != nullptr, "Dynamic GPU descriptor llocators have not been initialized. Did you forget to call SetDynamicGPUDescriptorAllocators() after resetting the context?"); + VERIFY(Type >= D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV && Type <= D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, "Invalid heap type"); + return m_DynamicGPUDescriptorAllocators[Type].Allocate(Count); + } void InsertUAVBarrier(D3D12ResourceBase& Resource, IDeviceObject &Object, bool FlushImmediate = false); diff --git a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h index 64978ea0..b0d6ba05 100644 --- a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h @@ -78,7 +78,7 @@ public: DescriptorHeapAllocation AllocateDescriptor( D3D12_DESCRIPTOR_HEAP_TYPE Type, UINT Count = 1 ); DescriptorHeapAllocation AllocateGPUDescriptors( D3D12_DESCRIPTOR_HEAP_TYPE Type, UINT Count = 1 ); - void IdleGPU(bool ReleaseStaleObjects); + void IdleGPU(); using PooledCommandContext = std::unique_ptr<CommandContext, STDDeleterRawMem<CommandContext> >; PooledCommandContext AllocateCommandContext(const Char *ID = ""); diff --git a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp index 3c6ca015..5d11cdf9 100644 --- a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp @@ -328,7 +328,7 @@ void BufferD3D12Impl :: Map(IDeviceContext* pContext, MAP_TYPE MapType, Uint32 M LOG_WARNING_MESSAGE_ONCE("Mapping CPU buffer for reading on D3D12 currently requires flushing context and idling GPU"); pDeviceContextD3D12->Flush(); auto *pDeviceD3D12 = ValidatedCast<RenderDeviceD3D12Impl>(GetDevice()); - pDeviceD3D12->IdleGPU(false); + pDeviceD3D12->IdleGPU(); VERIFY(m_Desc.Usage == USAGE_CPU_ACCESSIBLE, "Buffer must be created as USAGE_CPU_ACCESSIBLE to be mapped for reading"); D3D12_RANGE MapRange; diff --git a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp index c0236a4a..05419ac2 100644 --- a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp +++ b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp @@ -290,10 +290,4 @@ void CommandContext::InsertAliasBarrier(D3D12ResourceBase& Before, D3D12Resource FlushResourceBarriers(); } -DescriptorHeapAllocation CommandContext::AllocateDynamicGPUVisibleDescriptor( D3D12_DESCRIPTOR_HEAP_TYPE Type, UINT Count ) -{ - VERIFY(Type >= D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV && Type <= D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER, "Invalid heap type"); - return m_DynamicGPUDescriptorAllocators[Type].Allocate(Count); -} - } diff --git a/Graphics/GraphicsEngineD3D12/src/DescriptorHeap.cpp b/Graphics/GraphicsEngineD3D12/src/DescriptorHeap.cpp index d17e88a0..cd9ac42a 100644 --- a/Graphics/GraphicsEngineD3D12/src/DescriptorHeap.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DescriptorHeap.cpp @@ -403,7 +403,8 @@ DynamicSuballocationsManager::~DynamicSuballocationsManager() void DynamicSuballocationsManager::ReleaseAllocations(Uint64 CmdQueueMask) { // Clear the list and dispose all allocated chunks of GPU descriptor heap. - // The chunks will be added to the release queue in the allocations manager + // The chunks will be added to release queues and eventually returned to the + // parent GPU heap. for(auto& Allocation : m_Suballocations) { m_ParentGPUHeap.Free(std::move(Allocation), CmdQueueMask); @@ -425,7 +426,7 @@ DescriptorHeapAllocation DynamicSuballocationsManager::Allocate(Uint32 Count) // Request a new chunk from the parent GPU descriptor heap auto SuballocationSize = std::max(m_DynamicChunkSize, Count); auto NewDynamicSubAllocation = m_ParentGPUHeap.AllocateDynamic(SuballocationSize); - if (NewDynamicSubAllocation.GetCpuHandle().ptr == 0) + if (NewDynamicSubAllocation.IsNull()) { LOG_ERROR_MESSAGE("Failed to suballocate region for dynamic descriptors"); return DescriptorHeapAllocation(); @@ -438,7 +439,7 @@ DescriptorHeapAllocation DynamicSuballocationsManager::Allocate(Uint32 Count) } // Perform suballocation from the last chunk - auto &CurrentSuballocation = m_Suballocations.back(); + auto& CurrentSuballocation = m_Suballocations.back(); auto ManagerId = CurrentSuballocation.GetAllocationManagerId(); VERIFY(ManagerId < std::numeric_limits<Uint16>::max(), "ManagerID exceed allowed limit"); diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index c9aa0f6a..263e4ecd 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -578,8 +578,11 @@ namespace Diligent { VERIFY_EXPR(m_bIsDeferred || m_SubmittedBuffersCmdQueueMask == (Uint64{1}<<m_CommandQueueId)); + // Released pages are returned to the global dynamic memory manager hosted by render device. m_DynamicHeap.ReleaseAllocatedPages(m_SubmittedBuffersCmdQueueMask); + // Dynamic GPU descriptor allocations are returned to the global GPU descriptor heap + // hosted by the render device. for(size_t i=0; i < _countof(m_DynamicGPUDescriptorAllocator); ++i) m_DynamicGPUDescriptorAllocator[i].ReleaseAllocations(m_SubmittedBuffersCmdQueueMask); diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp index bf4fd7e4..cfe7e24c 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp @@ -89,7 +89,7 @@ RenderDeviceD3D12Impl :: RenderDeviceD3D12Impl(IReferenceCounters* pRef RenderDeviceD3D12Impl::~RenderDeviceD3D12Impl() { // Wait for the GPU to complete all its operations - IdleGPU(true); + IdleGPU(); ReleaseStaleResources(true); #ifdef DEVELOPMENT @@ -193,12 +193,9 @@ Uint64 RenderDeviceD3D12Impl::CloseAndExecuteCommandContext(Uint32 QueueIndex, P } -void RenderDeviceD3D12Impl::IdleGPU(bool ReleaseStaleObjects) +void RenderDeviceD3D12Impl::IdleGPU() { - // Do not wait until the end of the frame and force deletion. - // It is necessary to release outstanding references to the - // swap chain buffers when it is resized in the middle of the frame. - IdleCommandQueues(ReleaseStaleObjects); + IdleCommandQueues(true); } void RenderDeviceD3D12Impl::FlushStaleResources(Uint32 CmdQueueIndex) diff --git a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp index 423d73ce..4fcf8df9 100644 --- a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp @@ -172,7 +172,7 @@ void SwapChainD3D12Impl::UpdateSwapChain(bool CreateNew) // This will release references to D3D12 swap chain buffers hold by // m_pBackBufferRTV[] - pDeviceD3D12->IdleGPU(true); + pDeviceD3D12->IdleGPU(); if(CreateNew) { |
