From 9fe08de5b5708dbfd455b0fccaa4f8a992b14eb2 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Thu, 6 Apr 2017 12:25:39 -0700 Subject: Fixed D3D12 warnings, updated copyright notice --- .../GraphicsEngineD3D12/include/BufferD3D12Impl.h | 2 +- .../include/BufferViewD3D12Impl.h | 2 +- .../GraphicsEngineD3D12/include/CommandContext.h | 4 +- .../include/CommandListD3D12Impl.h | 2 +- .../include/CommandListManager.h | 2 +- .../include/D3D12ResourceBase.h | 2 +- .../include/D3D12TypeConversions.h | 2 +- .../include/D3D12TypeDefinitions.h | 2 +- Graphics/GraphicsEngineD3D12/include/D3D12Utils.h | 2 +- .../GraphicsEngineD3D12/include/DescriptorHeap.h | 193 ++++++++++++++++++--- .../include/DeviceContextD3D12Impl.h | 2 +- .../include/DynamicUploadHeap.h | 5 +- .../GraphicsEngineD3D12/include/GenerateMips.h | 2 +- .../include/PipelineStateD3D12Impl.h | 2 +- .../include/RenderDeviceD3D12Impl.h | 2 +- .../GraphicsEngineD3D12/include/RootSignature.h | 2 +- .../GraphicsEngineD3D12/include/SamplerD3D12Impl.h | 2 +- .../GraphicsEngineD3D12/include/ShaderD3D12Impl.h | 2 +- .../include/ShaderResourceBindingD3D12Impl.h | 2 +- .../include/ShaderResourceCacheD3D12.h | 2 +- .../include/ShaderResourceLayoutD3D12.h | 2 +- .../include/ShaderResourcesD3D12.h | 2 +- .../include/SwapChainD3D12Impl.h | 2 +- .../GraphicsEngineD3D12/include/TextureD3D12Impl.h | 2 +- .../include/TextureViewD3D12Impl.h | 2 +- Graphics/GraphicsEngineD3D12/include/pch.h | 2 +- .../GraphicsEngineD3D12/interface/BufferD3D12.h | 2 +- .../interface/BufferViewD3D12.h | 2 +- .../interface/PipelineStateD3D12.h | 2 +- .../interface/RenderDeviceD3D12.h | 2 +- .../interface/RenderDeviceFactoryD3D12.h | 2 +- .../GraphicsEngineD3D12/interface/SamplerD3D12.h | 2 +- .../GraphicsEngineD3D12/interface/ShaderD3D12.h | 2 +- .../interface/ShaderResourceBindingD3D12.h | 2 +- .../GraphicsEngineD3D12/interface/SwapChainD3D12.h | 2 +- .../GraphicsEngineD3D12/interface/TextureD3D12.h | 2 +- .../interface/TextureViewD3D12.h | 2 +- .../GraphicsEngineD3D12/src/BufferD3D12Impl.cpp | 6 +- .../src/BufferViewD3D12Impl.cpp | 2 +- .../GraphicsEngineD3D12/src/CommandContext.cpp | 4 +- .../GraphicsEngineD3D12/src/CommandListManager.cpp | 2 +- .../GraphicsEngineD3D12/src/D3D12ResourceBase.cpp | 2 +- .../src/D3D12TypeConversions.cpp | 2 +- Graphics/GraphicsEngineD3D12/src/D3D12Utils.cpp | 2 +- Graphics/GraphicsEngineD3D12/src/DLLMain.cpp | 2 +- .../GraphicsEngineD3D12/src/DescriptorHeap.cpp | 71 ++++++-- .../src/DeviceContextD3D12Impl.cpp | 2 +- .../GraphicsEngineD3D12/src/DynamicUploadHeap.cpp | 2 +- Graphics/GraphicsEngineD3D12/src/GenerateMips.cpp | 17 +- .../src/PipelineStateD3D12Impl.cpp | 2 +- .../src/RenderDeviceD3D12Impl.cpp | 2 +- .../src/RenderDeviceFactoryD3D12.cpp | 2 +- Graphics/GraphicsEngineD3D12/src/RootSignature.cpp | 4 +- .../GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp | 2 +- .../GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp | 2 +- .../src/ShaderResourceBindingD3D12Impl.cpp | 2 +- .../src/ShaderResourceCacheD3D12.cpp | 2 +- .../src/ShaderResourceLayoutD3D12.cpp | 2 +- .../src/ShaderResourcesD3D12.cpp | 2 +- .../GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp | 7 +- .../GraphicsEngineD3D12/src/TextureD3D12Impl.cpp | 6 +- .../src/TextureViewD3D12Impl.cpp | 2 +- Graphics/GraphicsEngineD3D12/src/pch.cpp | 2 +- 63 files changed, 312 insertions(+), 111 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h index 9ee4e25d..15406bc8 100644 --- a/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/BufferD3D12Impl.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/BufferViewD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/BufferViewD3D12Impl.h index f5aff0ab..743be25c 100644 --- a/Graphics/GraphicsEngineD3D12/include/BufferViewD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/BufferViewD3D12Impl.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/CommandContext.h b/Graphics/GraphicsEngineD3D12/include/CommandContext.h index 71482511..d1512b62 100644 --- a/Graphics/GraphicsEngineD3D12/include/CommandContext.h +++ b/Graphics/GraphicsEngineD3D12/include/CommandContext.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -83,8 +83,6 @@ public: // Submit the command buffer and reset it. This is encouraged to keep the GPU busy and reduce latency. // Taking too long to build command lists and submit them can idle the GPU. - // Returns a fence value to verify completion. (Use it with the CommandListManager.) - ID3D12GraphicsCommandList* Close(ID3D12CommandAllocator **ppAllocator); void Reset( CommandListManager& CmdListManager ); diff --git a/Graphics/GraphicsEngineD3D12/include/CommandListD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/CommandListD3D12Impl.h index 00e5fcaa..e73e36d1 100644 --- a/Graphics/GraphicsEngineD3D12/include/CommandListD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/CommandListD3D12Impl.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/CommandListManager.h b/Graphics/GraphicsEngineD3D12/include/CommandListManager.h index a9b79650..9b0faa4f 100644 --- a/Graphics/GraphicsEngineD3D12/include/CommandListManager.h +++ b/Graphics/GraphicsEngineD3D12/include/CommandListManager.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/D3D12ResourceBase.h b/Graphics/GraphicsEngineD3D12/include/D3D12ResourceBase.h index e8faa4a3..84629c48 100644 --- a/Graphics/GraphicsEngineD3D12/include/D3D12ResourceBase.h +++ b/Graphics/GraphicsEngineD3D12/include/D3D12ResourceBase.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/D3D12TypeConversions.h b/Graphics/GraphicsEngineD3D12/include/D3D12TypeConversions.h index d909bd42..d8741573 100644 --- a/Graphics/GraphicsEngineD3D12/include/D3D12TypeConversions.h +++ b/Graphics/GraphicsEngineD3D12/include/D3D12TypeConversions.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/D3D12TypeDefinitions.h b/Graphics/GraphicsEngineD3D12/include/D3D12TypeDefinitions.h index 892de4aa..761f750b 100644 --- a/Graphics/GraphicsEngineD3D12/include/D3D12TypeDefinitions.h +++ b/Graphics/GraphicsEngineD3D12/include/D3D12TypeDefinitions.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/D3D12Utils.h b/Graphics/GraphicsEngineD3D12/include/D3D12Utils.h index 64ee7c40..13dbd204 100644 --- a/Graphics/GraphicsEngineD3D12/include/D3D12Utils.h +++ b/Graphics/GraphicsEngineD3D12/include/D3D12Utils.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/DescriptorHeap.h b/Graphics/GraphicsEngineD3D12/include/DescriptorHeap.h index b96977e6..91c27495 100644 --- a/Graphics/GraphicsEngineD3D12/include/DescriptorHeap.h +++ b/Graphics/GraphicsEngineD3D12/include/DescriptorHeap.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ #include #include #include "ObjectBase.h" -#include "FreeBlockListManagerGPU.h" +#include "VariableSizeGPUAllocationsManager.h" namespace Diligent { @@ -41,14 +41,24 @@ class RenderDeviceD3D12Impl; class IDescriptorAllocator { public: + // Allocate Count descriptors virtual DescriptorHeapAllocation Allocate( uint32_t Count ) = 0; virtual void Free(DescriptorHeapAllocation&& Allocation) = 0; virtual Uint32 GetDescriptorSize()const = 0; }; +// The class represents descriptor heap allocation (continuous descriptor range in a descriptor heap) +// +// m_FirstCpuHandle +// | +// | ~ ~ ~ ~ ~ X X X X X X X ~ ~ ~ ~ ~ ~ | D3D12 Descriptor Heap +// | +// m_FirstGpuHandle +// class DescriptorHeapAllocation { public: + // Creates null allocation DescriptorHeapAllocation() : m_NumHandles(1), // One null descriptor handle m_pDescriptorHeap(nullptr), @@ -58,20 +68,13 @@ public: m_FirstGpuHandle.ptr = 0; } - DescriptorHeapAllocation( IDescriptorAllocator *pAllocator, ID3D12DescriptorHeap *pHeap, D3D12_CPU_DESCRIPTOR_HANDLE CpuHandle, Uint32 NHandles ) : - m_FirstCpuHandle(CpuHandle), - m_pAllocator(pAllocator), - m_pDescriptorHeap(pHeap), - m_NumHandles(NHandles) - { - m_FirstGpuHandle.ptr = 0; - VERIFY_EXPR(m_pAllocator != nullptr && m_pDescriptorHeap != nullptr); - auto DescriptorSize = m_pAllocator->GetDescriptorSize(); - VERIFY(DescriptorSize < std::numeric_limits::max(), "DescriptorSize exceeds allowed limit") - m_DescriptorSize = static_cast( DescriptorSize ); - } - - DescriptorHeapAllocation( IDescriptorAllocator *pAllocator, ID3D12DescriptorHeap *pHeap, D3D12_CPU_DESCRIPTOR_HANDLE CpuHandle, D3D12_GPU_DESCRIPTOR_HANDLE GpuHandle, Uint32 NHandles, Uint16 AllocationManagerId = static_cast(-1) ) : + // Initializes non-null allocation + DescriptorHeapAllocation( IDescriptorAllocator *pAllocator, + ID3D12DescriptorHeap *pHeap, + D3D12_CPU_DESCRIPTOR_HANDLE CpuHandle, + D3D12_GPU_DESCRIPTOR_HANDLE GpuHandle, + Uint32 NHandles, + Uint16 AllocationManagerId = static_cast(-1) ) : m_FirstCpuHandle(CpuHandle), m_FirstGpuHandle(GpuHandle), m_pAllocator(pAllocator), @@ -85,6 +88,7 @@ public: m_DescriptorSize = static_cast( DescriptorSize ); } + // Move constructor (copy is not allowed) DescriptorHeapAllocation(DescriptorHeapAllocation &&Allocation) : m_FirstCpuHandle(Allocation.m_FirstCpuHandle), m_FirstGpuHandle(Allocation.m_FirstGpuHandle), @@ -103,6 +107,7 @@ public: Allocation.m_AllocationManagerId = static_cast(-1); } + // Move assignment (assignment is not allowed) DescriptorHeapAllocation& operator = (DescriptorHeapAllocation &&Allocation) { m_FirstCpuHandle = Allocation.m_FirstCpuHandle; @@ -124,12 +129,16 @@ public: return *this; } + // Destructor automatically releases this allocation through the allocator ~DescriptorHeapAllocation() { if(!IsNull() && m_pAllocator) m_pAllocator->Free(std::move(*this)); + // Allocation must be disposed by the allocator + VERIFY(IsNull(), "Non-null descriptor is being destroyed") } + // Returns CPU descriptor handle at the specified offset D3D12_CPU_DESCRIPTOR_HANDLE GetCpuHandle(Uint32 Offset = 0) const { VERIFY_EXPR(Offset >= 0 && Offset < m_NumHandles); @@ -142,6 +151,7 @@ public: return CPUHandle; } + // Returns GPU descriptor handle at the specified offset D3D12_GPU_DESCRIPTOR_HANDLE GetGpuHandle(Uint32 Offset = 0) const { VERIFY_EXPR(Offset >= 0 && Offset < m_NumHandles); @@ -153,9 +163,10 @@ public: return GPUHandle; } + // Returns pointer to the descriptor heap that contains this allocation ID3D12DescriptorHeap *GetDescriptorHeap(){return m_pDescriptorHeap;} - size_t GetNumHandles(){return m_NumHandles;} + size_t GetNumHandles()const{return m_NumHandles;} bool IsNull() const { return m_FirstCpuHandle.ptr == 0; } bool IsShaderVisible() const { return m_FirstGpuHandle.ptr != 0; } @@ -163,29 +174,59 @@ public: UINT GetDescriptorSize()const{return m_DescriptorSize;} private: + // No copies, only moves are allowed DescriptorHeapAllocation(const DescriptorHeapAllocation&) = delete; DescriptorHeapAllocation& operator= (const DescriptorHeapAllocation&) = delete; + // First CPU descriptor handle in this allocation D3D12_CPU_DESCRIPTOR_HANDLE m_FirstCpuHandle = {0}; + + // First GPU descriptor handle in this allocation D3D12_GPU_DESCRIPTOR_HANDLE m_FirstGpuHandle = {0}; - // Keep strong reference to the parent heap to make sure it is alive while allocation is alive + + // Keep strong reference to the parent heap to make sure it is alive while allocation is alive - TOO EXPENSIVE //RefCntAutoPtr m_pAllocator; + + // Pointer to the descriptor heap allocator that created this allocation IDescriptorAllocator* m_pAllocator = nullptr; + + // Pointer to the D3D12 descriptor heap that contains descriptors in this allocation ID3D12DescriptorHeap* m_pDescriptorHeap = nullptr; + + // Number of descriptors in the allocation Uint32 m_NumHandles = 0; + + // Allocation manager ID. One allocator may support several + // allocation managers. This field is required to identify + // the manager within the allocator that was used to create + // this allocation Uint16 m_AllocationManagerId = static_cast(-1); + + // Descriptor size Uint16 m_DescriptorSize = 0; }; +// The class performs suballocations within one D3D12 descriptor heap. +// It uses VariableSizeGPUAllocationsManager to manage free space in the heap +// +// | X X X X O O O X X O O X O O O O | D3D12 descriptor heap +// +// X - used descriptor +// O - available descriptor +// class DescriptorHeapAllocationManager { public: + // Creates a new D3D12 descriptor heap DescriptorHeapAllocationManager(IMemoryAllocator &Allocator, RenderDeviceD3D12Impl *pDeviceD3D12Impl, IDescriptorAllocator *pParentAllocator, size_t ThisManagerId, const D3D12_DESCRIPTOR_HEAP_DESC &HeapDesc); + + // Uses subrange of descriptors in the existing D3D12 descriptor heap + // that starts at offset FirstDescriptor and uses NumDescriptors descriptors DescriptorHeapAllocationManager(IMemoryAllocator &Allocator, RenderDeviceD3D12Impl *pDeviceD3D12Impl, IDescriptorAllocator *pParentAllocator, @@ -220,36 +261,78 @@ public: rhs.m_ThisManagerId = static_cast(-1); } + // No copies or move-assignments DescriptorHeapAllocationManager& operator = (DescriptorHeapAllocationManager&& rhs) = delete; DescriptorHeapAllocationManager(const DescriptorHeapAllocationManager&) = delete; DescriptorHeapAllocationManager& operator = (const DescriptorHeapAllocationManager&) = delete; ~DescriptorHeapAllocationManager(); + // Allocates Count descriptors DescriptorHeapAllocation Allocate( uint32_t Count ); + + // Releases descriptor heap allocation. + // Note that the allocation is not released immediately, but + // added to the release queue in the allocations manager void Free(DescriptorHeapAllocation&& Allocation); + + // Releases all stale allocation from completed frames void ReleaseStaleAllocations(Uint64 NumCompletedFrames); + size_t GetNumAvailableDescriptors()const{return m_FreeBlockManager.GetFreeSize();} private: - FreeBlockListManagerGPU m_FreeBlockManager; + // Allocations manager used to handle descriptor allocations within the heap + VariableSizeGPUAllocationsManager m_FreeBlockManager; + + // Heap description D3D12_DESCRIPTOR_HEAP_DESC m_HeapDesc; + + // Strong reference to D3D12 descriptor heap object CComPtr m_pd3d12DescriptorHeap; + + // First CPU descriptor handle in the available descriptor range D3D12_CPU_DESCRIPTOR_HANDLE m_FirstCPUHandle = {0}; + + // First GPU descriptor handle in the available descriptor range D3D12_GPU_DESCRIPTOR_HANDLE m_FirstGPUHandle = {0}; + UINT m_DescriptorSize = 0; + + // Number of descriptors in the allocation. + // If this manager was initialized as a subrange in the existing heap, + // this value may be different from m_HeapDesc.NumDescriptors Uint32 m_NumDescriptorsInAllocation = 0; + std::mutex m_AllocationMutex; RenderDeviceD3D12Impl *m_pDeviceD3D12Impl = nullptr; IDescriptorAllocator *m_pParentAllocator = nullptr; + + // External ID assigned to this descriptor allocations manager size_t m_ThisManagerId = static_cast(-1); }; -// This is an unbounded resource descriptor heap. It is intended to provide space for CPU-visible resource descriptors -// as resources are created as well as for static and mutable shader descriptor tables. +// CPU descriptor heap is intended to provide storage for resource view descriptor handles +// It contains a pool of DescriptorHeapAllocationManager object instances, where every instance manages +// its own CPU-only D3D12 descriptor heap: +// +// m_AvailableHeaps[0] m_AvailableHeaps[1] m_AvailableHeaps[2] +// | X X X X X X X X |, | X X X O O X X O |, | X O O O O O O O | +// +// X - used descriptor +// O - available descriptor +// +// Allocation routine goes through the list of managers that have available descriptors and tries to process +// the request using every manager. If there are no available managers or no manager was able to handle the request, +// the function creates a new descriptor heap manager and lets it handle the request +// +// Render device contains four CPUDescriptorHeap object instances (one for each D3D12 heap type). The heaps are accessed +// when a texture or a buffer view is created. +// class CPUDescriptorHeap : public IDescriptorAllocator { public: + // Initializes the heap CPUDescriptorHeap(IMemoryAllocator &Allocator, RenderDeviceD3D12Impl *pDeviceD3D12Impl, Uint32 NumDescriptorsInHeap, @@ -271,7 +354,9 @@ public: protected: + // Pool of descriptor heap managers std::vector > m_HeapPool; + // Indices of available descriptor heap managers std::set, STDAllocatorRawMem > m_AvailableHeaps; IMemoryAllocator &m_MemAllocator; @@ -280,11 +365,51 @@ protected: D3D12_DESCRIPTOR_HEAP_DESC m_HeapDesc; UINT m_DescriptorSize; RenderDeviceD3D12Impl *m_pDeviceD3D12Impl; - Uint32 m_MaxHeapSize = 0; + + // Maximum heap size during the application lifetime - for statistic purposes + Uint32 m_MaxHeapSize = 0; Uint32 m_CurrentSize = 0; // This size does not count stale allocation }; - +// GPU descriptor heap provides storage for shader-visible descriptors +// The heap contains single D3D12 descriptor heap that is broken into two parts. +// The first part stores static and mutable resource descriptor handles. +// The second part is intended to provide temporary storage for dynamic resources +// Space for dynamic resources is allocated in chunks, and then descriptors are suballocated within every +// chunk. DynamicSuballocationsManager facilitates this process +// +// +// static and mutable handles || dynamic space +// || chunk 0 chunk 1 chunk 2 unused +// | X O O X X O X O O O O X X X X O || | X X X O | | X X O O | | O O O O | O O O O || +// | | +// suballocation suballocation +// within chunk 0 within chunk 1 +// +// Render device contains two GPUDescriptorHeap instances (CBV_SRV_UAV and SAMPLER). The heaps +// are used to allocate GPU-visible descriptors for shader resource binding objects. The heaps +// are also used by command contexts (through DynamicSuballocationsManager to allocated dynamic descriptors) +// +// _______________________________________________________________________________________________________________________________ +// | Render Device | +// | | +// | m_CPUDescriptorHeaps[CBV_SRV_UAV] | X X X X X X X X |, | X X X X X X X X |, | X O O X O O O O | | +// | m_CPUDescriptorHeaps[SAMPLER] | X X X X O O O X |, | X O O X O O O O | | +// | m_CPUDescriptorHeaps[RTV] | X X X O O O O O |, | O O O O O O O O | | +// | m_CPUDescriptorHeaps[DSV] | X X X O X O X O | | +// | ctx1 ctx2 | +// | m_GPUDescriptorHeaps[CBV_SRV_UAV] | X O O X X O X O O O O X X X X O || | X X X O | | X X O O | | O O O O | O O O O || | +// | m_GPUDescriptorHeaps[SAMPLER] | X X O O X O X X X O O X O O O O || | X X O O | | X O O O | | O O O O | O O O O || | +// | | +// |_______________________________________________________________________________________________________________________________| +// +// ________________________________________________ ________________________________________________ +// |Device Context 1 | |Device Context 2 | +// | | | | +// | m_DynamicGPUDescriptorAllocator[CBV_SRV_UAV] | | m_DynamicGPUDescriptorAllocator[CBV_SRV_UAV] | +// | m_DynamicGPUDescriptorAllocator[SAMPLER] | | m_DynamicGPUDescriptorAllocator[SAMPLER] | +// |________________________________________________| |________________________________________________| +// class GPUDescriptorHeap : public IDescriptorAllocator { public: @@ -310,29 +435,42 @@ public: void ReleaseStaleAllocations(Uint64 NumCompletedFrames); - D3D12_DESCRIPTOR_HEAP_DESC &GetHeapDesc(){return m_HeapDesc;} + const D3D12_DESCRIPTOR_HEAP_DESC &GetHeapDesc()const{return m_HeapDesc;} protected: D3D12_DESCRIPTOR_HEAP_DESC m_HeapDesc; CComPtr m_pd3d12DescriptorHeap; - UINT m_DescriptorSize = 0; - std::mutex m_Mutex; + std::mutex m_AllocMutex, m_DynAllocMutex; + // Allocation manager for static/mutable part DescriptorHeapAllocationManager m_HeapAllocationManager; + + // Allocation manager for dynamic part DescriptorHeapAllocationManager m_DynamicAllocationsManager; RenderDeviceD3D12Impl *m_pDeviceD3D12; Uint32 m_CurrentSize = 0; + // Maximum static/mutable part size during the application lifetime - for statistic purposes Uint32 m_MaxHeapSize = 0; Uint32 m_CurrentDynamicSize = 0; + // Maximum dynamic part size during the application lifetime - for statistic purposes Uint32 m_MaxDynamicSize = 0; }; +// The class facilitates allocation of dynamic descriptor handles. It requests a chunk of heap +// from the master GPU descriptor heap and then performs linear suballocation within the chunk +// At the end of the frame all allocations are disposed. +// static and mutable handles || dynamic space +// || chunk 0 chunk 2 +// | || | X X X O | | O O O O | || GPU Descriptor Heap +// | | +// m_Suballocations[0] m_Suballocations[1] +// class DynamicSuballocationsManager : public IDescriptorAllocator { public: @@ -351,11 +489,14 @@ public: virtual Uint32 GetDescriptorSize()const override{return m_ParentGPUHeap.GetDescriptorSize();} private: + // List of chunks allocated from the master GPU descriptor heap. All chunks are disposed at the end + // of the frame std::vector > m_Suballocations; Uint32 m_CurrentSuballocationOffset = 0; Uint32 m_DynamicChunkSize = 0; + // Parent GPU descriptor heap that is used to allocate chunks GPUDescriptorHeap &m_ParentGPUHeap; }; diff --git a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h index ffe8598a..14555715 100644 --- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/DynamicUploadHeap.h b/Graphics/GraphicsEngineD3D12/include/DynamicUploadHeap.h index a4799ded..56b17284 100644 --- a/Graphics/GraphicsEngineD3D12/include/DynamicUploadHeap.h +++ b/Graphics/GraphicsEngineD3D12/include/DynamicUploadHeap.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -125,6 +125,9 @@ public: private: const bool m_bIsCPUAccessible; + // When a chunk of dynamic memory is requested, the heap first tries to allocate the memory in the largest GPU buffer. + // If allocation fails, it a new ring buffer is created that provides enough space and requests memory from that buffer. + // Only the largest buffer is used for allocation and all other buffers are released when GPU is done with corresponding frames std::vector > m_RingBuffers; IMemoryAllocator &m_Allocator; RenderDeviceD3D12Impl* m_pDeviceD3D12 = nullptr; diff --git a/Graphics/GraphicsEngineD3D12/include/GenerateMips.h b/Graphics/GraphicsEngineD3D12/include/GenerateMips.h index 22e81589..109858a9 100644 --- a/Graphics/GraphicsEngineD3D12/include/GenerateMips.h +++ b/Graphics/GraphicsEngineD3D12/include/GenerateMips.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h index 1ac6564f..84e2fb09 100644 --- a/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h index 0294a8b8..db601579 100644 --- a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/RootSignature.h b/Graphics/GraphicsEngineD3D12/include/RootSignature.h index 750b2b9d..eb2a20ba 100644 --- a/Graphics/GraphicsEngineD3D12/include/RootSignature.h +++ b/Graphics/GraphicsEngineD3D12/include/RootSignature.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/SamplerD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/SamplerD3D12Impl.h index 11226b64..fc920441 100644 --- a/Graphics/GraphicsEngineD3D12/include/SamplerD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/SamplerD3D12Impl.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h index b39c70d6..79ef7fec 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderD3D12Impl.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h index 025db186..b5824b17 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceBindingD3D12Impl.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.h b/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.h index aed6d32e..601e28e1 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceCacheD3D12.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h b/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h index 90d1ba27..b29e7ea4 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourcesD3D12.h b/Graphics/GraphicsEngineD3D12/include/ShaderResourcesD3D12.h index f58ce20d..940a1350 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourcesD3D12.h +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourcesD3D12.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h index e7e8f312..197ccd68 100644 --- a/Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/SwapChainD3D12Impl.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.h index 039de70f..3bee0851 100644 --- a/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/TextureViewD3D12Impl.h b/Graphics/GraphicsEngineD3D12/include/TextureViewD3D12Impl.h index 6256ca0a..e07446a5 100644 --- a/Graphics/GraphicsEngineD3D12/include/TextureViewD3D12Impl.h +++ b/Graphics/GraphicsEngineD3D12/include/TextureViewD3D12Impl.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/include/pch.h b/Graphics/GraphicsEngineD3D12/include/pch.h index f2f0b7f4..225f72b4 100644 --- a/Graphics/GraphicsEngineD3D12/include/pch.h +++ b/Graphics/GraphicsEngineD3D12/include/pch.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/interface/BufferD3D12.h b/Graphics/GraphicsEngineD3D12/interface/BufferD3D12.h index f3e69a13..823965a9 100644 --- a/Graphics/GraphicsEngineD3D12/interface/BufferD3D12.h +++ b/Graphics/GraphicsEngineD3D12/interface/BufferD3D12.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/interface/BufferViewD3D12.h b/Graphics/GraphicsEngineD3D12/interface/BufferViewD3D12.h index 7d9e45c9..a388e4c6 100644 --- a/Graphics/GraphicsEngineD3D12/interface/BufferViewD3D12.h +++ b/Graphics/GraphicsEngineD3D12/interface/BufferViewD3D12.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/interface/PipelineStateD3D12.h b/Graphics/GraphicsEngineD3D12/interface/PipelineStateD3D12.h index c31ea4cc..e978c014 100644 --- a/Graphics/GraphicsEngineD3D12/interface/PipelineStateD3D12.h +++ b/Graphics/GraphicsEngineD3D12/interface/PipelineStateD3D12.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/interface/RenderDeviceD3D12.h b/Graphics/GraphicsEngineD3D12/interface/RenderDeviceD3D12.h index 309d355e..3d37c0a8 100644 --- a/Graphics/GraphicsEngineD3D12/interface/RenderDeviceD3D12.h +++ b/Graphics/GraphicsEngineD3D12/interface/RenderDeviceD3D12.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h b/Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h index f3aa45f4..2a81cf76 100644 --- a/Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h +++ b/Graphics/GraphicsEngineD3D12/interface/RenderDeviceFactoryD3D12.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/interface/SamplerD3D12.h b/Graphics/GraphicsEngineD3D12/interface/SamplerD3D12.h index 4359fdc5..f8d98e69 100644 --- a/Graphics/GraphicsEngineD3D12/interface/SamplerD3D12.h +++ b/Graphics/GraphicsEngineD3D12/interface/SamplerD3D12.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/interface/ShaderD3D12.h b/Graphics/GraphicsEngineD3D12/interface/ShaderD3D12.h index 50aa22aa..c8bca697 100644 --- a/Graphics/GraphicsEngineD3D12/interface/ShaderD3D12.h +++ b/Graphics/GraphicsEngineD3D12/interface/ShaderD3D12.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/interface/ShaderResourceBindingD3D12.h b/Graphics/GraphicsEngineD3D12/interface/ShaderResourceBindingD3D12.h index 6038b88b..27162053 100644 --- a/Graphics/GraphicsEngineD3D12/interface/ShaderResourceBindingD3D12.h +++ b/Graphics/GraphicsEngineD3D12/interface/ShaderResourceBindingD3D12.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/interface/SwapChainD3D12.h b/Graphics/GraphicsEngineD3D12/interface/SwapChainD3D12.h index eacc0ef4..ab936019 100644 --- a/Graphics/GraphicsEngineD3D12/interface/SwapChainD3D12.h +++ b/Graphics/GraphicsEngineD3D12/interface/SwapChainD3D12.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/interface/TextureD3D12.h b/Graphics/GraphicsEngineD3D12/interface/TextureD3D12.h index 2fe585ce..449f2692 100644 --- a/Graphics/GraphicsEngineD3D12/interface/TextureD3D12.h +++ b/Graphics/GraphicsEngineD3D12/interface/TextureD3D12.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/interface/TextureViewD3D12.h b/Graphics/GraphicsEngineD3D12/interface/TextureViewD3D12.h index 967d28a1..f9c83a61 100644 --- a/Graphics/GraphicsEngineD3D12/interface/TextureViewD3D12.h +++ b/Graphics/GraphicsEngineD3D12/interface/TextureViewD3D12.h @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp index c7470492..4d9ef799 100644 --- a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ #include "GraphicsUtilities.h" #include "DXGITypeConversions.h" #include "EngineMemory.h" +#include "StringTools.h" namespace Diligent { @@ -109,6 +110,9 @@ BufferD3D12Impl :: BufferD3D12Impl(FixedBlockMemoryAllocator &BufferObjMemAlloca if(FAILED(hr)) LOG_ERROR_AND_THROW("Failed to create D3D12 buffer") + if( *m_Desc.Name != 0) + m_pd3d12Resource->SetName(WidenString(m_Desc.Name).c_str()); + if( bInitializeBuffer ) { D3D12_HEAP_PROPERTIES UploadHeapProps; diff --git a/Graphics/GraphicsEngineD3D12/src/BufferViewD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BufferViewD3D12Impl.cpp index e27c91ea..f0f7b2d7 100644 --- a/Graphics/GraphicsEngineD3D12/src/BufferViewD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/BufferViewD3D12Impl.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp index c123993f..72531286 100644 --- a/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp +++ b/Graphics/GraphicsEngineD3D12/src/CommandContext.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -243,7 +243,7 @@ void CommandContext::TransitionResource(D3D12ResourceBase& Resource, IDeviceObje D3D12_RESOURCE_STATES OldState = Resource.GetState(); // Check if required state is already set - if ( (OldState & NewState) != NewState ) + if ( (OldState & NewState) != NewState || NewState == 0 && OldState != 0 ) { // If both old state and new state are read-only states, combine the two if( (OldState & D3D12_RESOURCE_STATE_GENERIC_READ) == OldState && diff --git a/Graphics/GraphicsEngineD3D12/src/CommandListManager.cpp b/Graphics/GraphicsEngineD3D12/src/CommandListManager.cpp index 8ffc64ce..77c72d08 100644 --- a/Graphics/GraphicsEngineD3D12/src/CommandListManager.cpp +++ b/Graphics/GraphicsEngineD3D12/src/CommandListManager.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/D3D12ResourceBase.cpp b/Graphics/GraphicsEngineD3D12/src/D3D12ResourceBase.cpp index b2e9f431..0744fda7 100644 --- a/Graphics/GraphicsEngineD3D12/src/D3D12ResourceBase.cpp +++ b/Graphics/GraphicsEngineD3D12/src/D3D12ResourceBase.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/D3D12TypeConversions.cpp b/Graphics/GraphicsEngineD3D12/src/D3D12TypeConversions.cpp index 738fbc98..68082795 100644 --- a/Graphics/GraphicsEngineD3D12/src/D3D12TypeConversions.cpp +++ b/Graphics/GraphicsEngineD3D12/src/D3D12TypeConversions.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/D3D12Utils.cpp b/Graphics/GraphicsEngineD3D12/src/D3D12Utils.cpp index a1f82e1c..c2428e16 100644 --- a/Graphics/GraphicsEngineD3D12/src/D3D12Utils.cpp +++ b/Graphics/GraphicsEngineD3D12/src/D3D12Utils.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/DLLMain.cpp b/Graphics/GraphicsEngineD3D12/src/DLLMain.cpp index fff890c0..94065164 100644 --- a/Graphics/GraphicsEngineD3D12/src/DLLMain.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DLLMain.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/DescriptorHeap.cpp b/Graphics/GraphicsEngineD3D12/src/DescriptorHeap.cpp index 02ea8384..7ba3d2bc 100644 --- a/Graphics/GraphicsEngineD3D12/src/DescriptorHeap.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DescriptorHeap.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ namespace Diligent { - +// Creates a new descriptor heap and reference the entire heap DescriptorHeapAllocationManager::DescriptorHeapAllocationManager(IMemoryAllocator &Allocator, RenderDeviceD3D12Impl *pDeviceD3D12Impl, IDescriptorAllocator *pParentAllocator, @@ -54,6 +54,8 @@ DescriptorHeapAllocationManager::DescriptorHeapAllocationManager(IMemoryAllocato m_FirstGPUHandle = m_pd3d12DescriptorHeap->GetGPUDescriptorHandleForHeapStart(); } +// Uses subrange of descriptors in the existing D3D12 descriptor heap +// that starts at offset FirstDescriptor and uses NumDescriptors descriptors DescriptorHeapAllocationManager::DescriptorHeapAllocationManager(IMemoryAllocator &Allocator, RenderDeviceD3D12Impl *pDeviceD3D12Impl, IDescriptorAllocator *pParentAllocator, @@ -90,39 +92,47 @@ DescriptorHeapAllocationManager::~DescriptorHeapAllocationManager() DescriptorHeapAllocation DescriptorHeapAllocationManager::Allocate(uint32_t Count) { std::lock_guard LockGuard(m_AllocationMutex); + // Methods of VariableSizeGPUAllocationsManager class are not thread safe! + // Use variable-size GPU allocations manager to allocate the requested number of descriptors auto DescriptorHandleOffset = m_FreeBlockManager.Allocate(Count); - if (DescriptorHandleOffset == FreeBlockListManagerGPU::InvalidOffset) + if (DescriptorHandleOffset == VariableSizeGPUAllocationsManager::InvalidOffset) { return DescriptorHeapAllocation(); } + // Compute the first CPU and GPU descriptor handles in the allocation by + // offseting the first CPU and GPU descriptor handle in the range auto CPUHandle = m_FirstCPUHandle; CPUHandle.ptr += DescriptorHandleOffset * m_DescriptorSize; - auto GPUHandle = m_FirstGPUHandle; + auto GPUHandle = m_FirstGPUHandle; // Will be null if the heap is not GPU-visible if(m_HeapDesc.Flags & D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE) GPUHandle.ptr += DescriptorHandleOffset * m_DescriptorSize; - VERIFY(m_ThisManagerId < std::numeric_limits::max(), "ManagerID exceed allowed limit"); - DescriptorHeapAllocation Allocation( m_pParentAllocator, m_pd3d12DescriptorHeap, CPUHandle, GPUHandle, Count, static_cast(m_ThisManagerId)); - - return Allocation; + VERIFY(m_ThisManagerId < std::numeric_limits::max(), "ManagerID exceeds 16-bit range"); + return DescriptorHeapAllocation( m_pParentAllocator, m_pd3d12DescriptorHeap, CPUHandle, GPUHandle, Count, static_cast(m_ThisManagerId)); } void DescriptorHeapAllocationManager::Free(DescriptorHeapAllocation&& Allocation) { std::lock_guard LockGuard(m_AllocationMutex); + // Methods of VariableSizeGPUAllocationsManager class are not thread safe! VERIFY(Allocation.GetAllocationManagerId() == m_ThisManagerId, "Invalid descriptor heap manager Id") auto DescriptorOffset = (Allocation.GetCpuHandle().ptr - m_FirstCPUHandle.ptr) / m_DescriptorSize; + // Note that the allocation is not released immediately, but added to the release queue in the allocations manager m_FreeBlockManager.Free(DescriptorOffset, Allocation.GetNumHandles(), m_pDeviceD3D12Impl->GetCurrentFrame()); + // Clear the allocation Allocation = DescriptorHeapAllocation(); } void DescriptorHeapAllocationManager::ReleaseStaleAllocations(Uint64 NumCompletedFrames) { + std::lock_guard LockGuard(m_AllocationMutex); + // Methods of VariableSizeGPUAllocationsManager class are not thread safe! + m_FreeBlockManager.ReleaseCompletedFrames(NumCompletedFrames); } @@ -163,21 +173,37 @@ DescriptorHeapAllocation CPUDescriptorHeap::Allocate( uint32_t Count ) { std::lock_guard LockGuard(m_AllocationMutex); DescriptorHeapAllocation Allocation; + // Go through all descriptor heap managers that have free descriptors for (auto AvailableHeapIt = m_AvailableHeaps.begin(); AvailableHeapIt != m_AvailableHeaps.end(); ++AvailableHeapIt) { + // Try to allocate descriptor using the current descriptor heap manager Allocation = m_HeapPool[*AvailableHeapIt].Allocate(Count); + // Remove the manager from the pool if it has no more available descriptors if(m_HeapPool[*AvailableHeapIt].GetNumAvailableDescriptors() == 0) m_AvailableHeaps.erase(*AvailableHeapIt); + // Terminate the loop if descriptor was successfully allocated, otherwise + // go to the next manager if(Allocation.GetCpuHandle().ptr != 0) break; } + // If there were no available descriptor heap managers or no manager was able + // to suffice the allocation request, create a new manager if(Allocation.GetCpuHandle().ptr == 0) { + // Make sure the heap is large enough to accomodate the requested number of descriptors + if(Count > m_HeapDesc.NumDescriptors) + { + LOG_WARNING_MESSAGE("Number of requested descriptors exceeds the descriptor heap size. Increasing the number of descriptors in the heap") + } + m_HeapDesc.NumDescriptors = std::max(m_HeapDesc.NumDescriptors, static_cast(Count)); + // Create a new descriptor heap manager. Note that this constructor creates a new D3D12 descriptor + // heap and references the entire heap. Pool index is used as manager ID m_HeapPool.emplace_back(m_MemAllocator, m_pDeviceD3D12Impl, this, m_HeapPool.size(), m_HeapDesc); auto NewHeapIt = m_AvailableHeaps.insert(m_HeapPool.size()-1); + // Use the new manager to allocate descriptor handles Allocation = m_HeapPool[*NewHeapIt.first].Allocate(Count); } @@ -201,6 +227,7 @@ void CPUDescriptorHeap::ReleaseStaleAllocations(Uint64 NumCompletedFrames) for (size_t HeapManagerInd = 0; HeapManagerInd < m_HeapPool.size(); ++HeapManagerInd) { m_HeapPool[HeapManagerInd].ReleaseStaleAllocations(NumCompletedFrames); + // Return the manager to the pool of available managers if it has available descriptors if(m_HeapPool[HeapManagerInd].GetNumAvailableDescriptors() > 0) m_AvailableHeaps.insert(HeapManagerInd); } @@ -241,7 +268,7 @@ GPUDescriptorHeap::~GPUDescriptorHeap() DescriptorHeapAllocation GPUDescriptorHeap::Allocate(uint32_t Count) { - std::lock_guard LockGuard(m_Mutex); + std::lock_guard LockGuard(m_AllocMutex); DescriptorHeapAllocation Allocation = m_HeapAllocationManager.Allocate(Count); m_CurrentSize += (Allocation.GetCpuHandle().ptr != 0) ? Count : 0; @@ -252,7 +279,7 @@ DescriptorHeapAllocation GPUDescriptorHeap::Allocate(uint32_t Count) DescriptorHeapAllocation GPUDescriptorHeap::AllocateDynamic(uint32_t Count) { - std::lock_guard LockGuard(m_Mutex); + std::lock_guard LockGuard(m_DynAllocMutex); DescriptorHeapAllocation Allocation = m_DynamicAllocationsManager.Allocate(Count); m_CurrentDynamicSize += (Allocation.GetCpuHandle().ptr != 0) ? Count : 0; @@ -266,15 +293,15 @@ void GPUDescriptorHeap::Free(DescriptorHeapAllocation&& Allocation) auto MgrId = Allocation.GetAllocationManagerId(); VERIFY(MgrId == 0 || MgrId == 1, "Unexpected allocation manager ID"); - std::lock_guard LockGuard(m_Mutex); - if(MgrId == 0) { + std::lock_guard LockGuard(m_AllocMutex); m_CurrentSize -= static_cast(Allocation.GetNumHandles()); m_HeapAllocationManager.Free(std::move(Allocation)); } else { + std::lock_guard LockGuard(m_DynAllocMutex); m_CurrentDynamicSize -= static_cast(Allocation.GetNumHandles()); m_DynamicAllocationsManager.Free(std::move(Allocation)); } @@ -282,8 +309,15 @@ void GPUDescriptorHeap::Free(DescriptorHeapAllocation&& Allocation) void GPUDescriptorHeap::ReleaseStaleAllocations(Uint64 NumCompletedFrames) { - m_HeapAllocationManager.ReleaseStaleAllocations(NumCompletedFrames); - m_DynamicAllocationsManager.ReleaseStaleAllocations(NumCompletedFrames); + { + std::lock_guard LockGuard(m_AllocMutex); + m_HeapAllocationManager.ReleaseStaleAllocations(NumCompletedFrames); + } + + { + std::lock_guard LockGuard(m_DynAllocMutex); + m_DynamicAllocationsManager.ReleaseStaleAllocations(NumCompletedFrames); + } } @@ -299,14 +333,20 @@ DynamicSuballocationsManager::DynamicSuballocationsManager(IMemoryAllocator &All void DynamicSuballocationsManager::DiscardAllocations(Uint64 FrameNumber) { + // Clear the list and dispose all allocated chunks of GPU descriptor heap. m_Suballocations.clear(); } DescriptorHeapAllocation DynamicSuballocationsManager::Allocate(Uint32 Count) { + // This method is intentionally lock-free as it is expected to + // be called through device context from single thread only + + // Check if there are no chunks or the last chunk does not have enough space if( m_Suballocations.empty() || m_CurrentSuballocationOffset + Count > m_Suballocations.back().GetNumHandles() ) { + // Request a new chunk from the GPU descriptor heap auto SuballocationSize = std::max(m_DynamicChunkSize, Count); auto NewDynamicSubAllocation = m_ParentGPUHeap.AllocateDynamic(SuballocationSize); if (NewDynamicSubAllocation.GetCpuHandle().ptr == 0) @@ -318,6 +358,7 @@ DescriptorHeapAllocation DynamicSuballocationsManager::Allocate(Uint32 Count) m_CurrentSuballocationOffset = 0; } + // Perform suballocation from the last chunk auto &CurrentSuballocation = m_Suballocations.back(); auto ManagerId = CurrentSuballocation.GetAllocationManagerId(); @@ -335,7 +376,7 @@ DescriptorHeapAllocation DynamicSuballocationsManager::Allocate(Uint32 Count) void DynamicSuballocationsManager::Free(DescriptorHeapAllocation&& Allocation) { - // Do nothing + // Do nothing. Dynamic allocations are not disposed individually, but as whole chunks at the end of the frame Allocation = DescriptorHeapAllocation(); } diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index 5ebfb4b4..258e6ebf 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/DynamicUploadHeap.cpp b/Graphics/GraphicsEngineD3D12/src/DynamicUploadHeap.cpp index c747a731..292957cb 100644 --- a/Graphics/GraphicsEngineD3D12/src/DynamicUploadHeap.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DynamicUploadHeap.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/GenerateMips.cpp b/Graphics/GraphicsEngineD3D12/src/GenerateMips.cpp index ee382930..5ef672d4 100644 --- a/Graphics/GraphicsEngineD3D12/src/GenerateMips.cpp +++ b/Graphics/GraphicsEngineD3D12/src/GenerateMips.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -166,14 +166,19 @@ namespace Diligent // TODO: Shouldn't we transition top mip to shader resource state? D3D12_CPU_DESCRIPTOR_HANDLE DstDescriptorRange = DescriptorAlloc.GetCpuHandle(); - UINT DstRangeSize = 1+NumMips; + const Uint32 MaxMipsHandledByCS = 4; // Max number of mip levels processed by one CS shader invocation + UINT DstRangeSize = 1 + MaxMipsHandledByCS; D3D12_CPU_DESCRIPTOR_HANDLE SrcDescriptorRanges[5] = {}; SrcDescriptorRanges[0] = SRVDescriptorHandle; UINT SrcRangeSizes[5] = {1,1,1,1,1}; - for(Uint32 u=0; u < NumMips; ++u) - SrcDescriptorRanges[1+u] = pTexD3D12->GetUAVDescriptorHandle(TopMip+u+1, 0); - - pd3d12Device->CopyDescriptors(1, &DstDescriptorRange, &DstRangeSize, 1+NumMips, SrcDescriptorRanges, SrcRangeSizes, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); + // On Resource Binding Tier 2 hardware, all descriptor tables of type CBV and UAV declared in the set + // Root Signature must be populated and initialized, even if the shaders do not need the descriptor. + // So we must populate all 4 slots even though we may actually process less than 4 mip levels + // Copy top mip level UAV descriptor handle to all unused slots + for(Uint32 u=0; u < MaxMipsHandledByCS; ++u) + SrcDescriptorRanges[1+u] = pTexD3D12->GetUAVDescriptorHandle( std::min( TopMip+u+1, TexDesc.MipLevels-1), 0); + + pd3d12Device->CopyDescriptors(1, &DstDescriptorRange, &DstRangeSize, 1+MaxMipsHandledByCS, SrcDescriptorRanges, SrcRangeSizes, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); ComputeCtx.Dispatch((DstWidth+7)/8, (DstHeight+7)/8); diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index c2ed2d83..d52c3383 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp index 51c89306..c2576e8f 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp index 762e8a03..17ce22ae 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceFactoryD3D12.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp index 272895af..3fc4f814 100644 --- a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -449,6 +449,8 @@ void RootSignature::Finalize(ID3D12Device *pd3d12Device) hr = pd3d12Device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), __uuidof(m_pd3d12RootSignature), reinterpret_cast( static_cast(&m_pd3d12RootSignature))); CHECK_D3D_RESULT_THROW(hr, "Failed to create root signature") + //if( *m_Desc.Name != 0) + // m_pd3d12RootSignature->SetName(WidenString(m_Desc.Name).c_str()); bool bHasDynamicResources = m_TotalSrvCbvUavSlots[SHADER_VARIABLE_TYPE_DYNAMIC]!=0 || m_TotalSamplerSlots[SHADER_VARIABLE_TYPE_DYNAMIC]!=0; if(bHasDynamicResources) diff --git a/Graphics/GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp index e6e95bac..0d443e85 100644 --- a/Graphics/GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/SamplerD3D12Impl.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp index fd43fa49..84a4df8e 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp index 118707a2..6287695e 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceBindingD3D12Impl.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp index 700b49b5..25eefe9e 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp index 924131e4..c870b5f0 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp index e7543ce6..c42f663e 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp index e1be6145..2e42ca44 100644 --- a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -125,6 +125,9 @@ void SwapChainD3D12Impl::InitBuffersAndViews() if(FAILED(hr)) LOG_ERROR_AND_THROW("Failed to get back buffer ", backbuff," from the swap chain"); + hr = pBackBuffer->SetName(L"Main back buffer"); + VERIFY_EXPR(SUCCEEDED(hr)); + TextureDesc BackBufferDesc; BackBufferDesc.Format = m_SwapChainDesc.ColorBufferFormat; String Name = "Main back buffer "; @@ -152,7 +155,7 @@ void SwapChainD3D12Impl::InitBuffersAndViews() DepthBufferDesc.ClearValue.Format = DepthBufferDesc.Format; DepthBufferDesc.ClearValue.DepthStencil.Depth = m_SwapChainDesc.DefaultDepthValue; DepthBufferDesc.ClearValue.DepthStencil.Stencil = m_SwapChainDesc.DefaultStencilValue; - String Name = "Main depth buffer"; + DepthBufferDesc.Name = "Main depth buffer"; RefCntAutoPtr pDepthBufferTex; m_pRenderDevice->CreateTexture(DepthBufferDesc, TextureData(), static_cast(&pDepthBufferTex) ); m_pDepthBufferDSV = pDepthBufferTex->GetDefaultView(TEXTURE_VIEW_DEPTH_STENCIL); diff --git a/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp index d59f1947..8361421f 100644 --- a/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ #include "DXGITypeConversions.h" #include "d3dx12_win.h" #include "EngineMemory.h" +#include "StringTools.h" using namespace Diligent; @@ -142,6 +143,9 @@ TextureD3D12Impl :: TextureD3D12Impl(FixedBlockMemoryAllocator &TexObjAllocator, if(FAILED(hr)) LOG_ERROR_AND_THROW("Failed to create D3D12 texture") + if( *m_Desc.Name != 0) + m_pd3d12Resource->SetName(WidenString(m_Desc.Name).c_str()); + if(bInitializeTexture) { Uint32 ExpectedNumSubresources = static_cast(Desc.MipLevels * (Desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? 1 : Desc.DepthOrArraySize) ); diff --git a/Graphics/GraphicsEngineD3D12/src/TextureViewD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/TextureViewD3D12Impl.cpp index 0b93926b..57749298 100644 --- a/Graphics/GraphicsEngineD3D12/src/TextureViewD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/TextureViewD3D12Impl.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Graphics/GraphicsEngineD3D12/src/pch.cpp b/Graphics/GraphicsEngineD3D12/src/pch.cpp index 997e0f4a..d5f45c6a 100644 --- a/Graphics/GraphicsEngineD3D12/src/pch.cpp +++ b/Graphics/GraphicsEngineD3D12/src/pch.cpp @@ -1,4 +1,4 @@ -/* Copyright 2015-2016 Egor Yusov +/* Copyright 2015-2017 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. -- cgit v1.2.3