From 304dda5ae2f7b47a84ea5a0134912e159698bf6a Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 6 Oct 2018 17:39:10 -0700 Subject: Few minor cosmetic code changes in D3D12 backend --- Graphics/GraphicsEngineD3D12/include/CommandContext.h | 7 ++++++- Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h | 2 +- Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp | 2 +- Graphics/GraphicsEngineD3D12/src/CommandContext.cpp | 6 ------ Graphics/GraphicsEngineD3D12/src/DescriptorHeap.cpp | 7 ++++--- Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp | 3 +++ Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp | 9 +++------ Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') 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 >; 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(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::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}<IdleGPU(true); + pDeviceD3D12->IdleGPU(); if(CreateNew) { -- cgit v1.2.3