From bd04112dd490c94abf13aa3e2154230b8eaef76b Mon Sep 17 00:00:00 2001 From: Steve Karolewics Date: Tue, 4 Feb 2020 00:48:00 -0500 Subject: [PATCH] Add a non-shader-visible heap to D3D12ViewCreator for clearing UAVs --- util/test/demos/d3d12/d3d12_helpers.cpp | 5 +++-- util/test/demos/d3d12/d3d12_helpers.h | 9 +++++++-- util/test/demos/d3d12/d3d12_test.cpp | 4 ++++ util/test/demos/d3d12/d3d12_test.h | 10 +++++----- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/util/test/demos/d3d12/d3d12_helpers.cpp b/util/test/demos/d3d12/d3d12_helpers.cpp index c2efb387d..b9b79ec33 100644 --- a/util/test/demos/d3d12/d3d12_helpers.cpp +++ b/util/test/demos/d3d12/d3d12_helpers.cpp @@ -376,8 +376,9 @@ D3D12TextureCreator::operator ID3D12ResourcePtr() const } D3D12ViewCreator::D3D12ViewCreator(D3D12GraphicsTest *test, ID3D12DescriptorHeap *heap, - ViewType viewType, ID3D12Resource *res) - : m_Test(test), m_Type(viewType), m_Heap(heap), m_Res(res) + ID3D12DescriptorHeap *clearHeap, ViewType viewType, + ID3D12Resource *res) + : m_Test(test), m_Type(viewType), m_Heap(heap), m_ClearHeap(clearHeap), m_Res(res) { D3D12_RESOURCE_DESC resdesc = res->GetDesc(); D3D12_RESOURCE_DIMENSION dim = resdesc.Dimension; diff --git a/util/test/demos/d3d12/d3d12_helpers.h b/util/test/demos/d3d12/d3d12_helpers.h index 5272cef84..0c0a1bbeb 100644 --- a/util/test/demos/d3d12/d3d12_helpers.h +++ b/util/test/demos/d3d12/d3d12_helpers.h @@ -170,8 +170,8 @@ protected: class D3D12ViewCreator { public: - D3D12ViewCreator(D3D12GraphicsTest *test, ID3D12DescriptorHeap *heap, ViewType viewType, - ID3D12Resource *res); + D3D12ViewCreator(D3D12GraphicsTest *test, ID3D12DescriptorHeap *heap, + ID3D12DescriptorHeap *clearHeap, ViewType viewType, ID3D12Resource *res); // common params D3D12ViewCreator &Format(DXGI_FORMAT format); @@ -209,6 +209,10 @@ public: { return CreateGPU(m_Heap, descriptor); } + D3D12_CPU_DESCRIPTOR_HANDLE CreateClearCPU(uint32_t descriptor) + { + return CreateCPU(m_ClearHeap, descriptor); + } private: void SetupDescriptors(ViewType viewType, ResourceType resType); @@ -216,6 +220,7 @@ private: D3D12GraphicsTest *m_Test; ID3D12Resource *m_Res; ID3D12DescriptorHeap *m_Heap; + ID3D12DescriptorHeap *m_ClearHeap; ViewType m_Type; // instead of a huge mess trying to auto populate the actual descriptors from saved values, as diff --git a/util/test/demos/d3d12/d3d12_test.cpp b/util/test/demos/d3d12/d3d12_test.cpp index 9ecf92a83..612b4d1cb 100644 --- a/util/test/demos/d3d12/d3d12_test.cpp +++ b/util/test/demos/d3d12/d3d12_test.cpp @@ -335,6 +335,10 @@ bool D3D12GraphicsTest::Init() CHECK_HR(dev->CreateDescriptorHeap(&desc, __uuidof(ID3D12DescriptorHeap), (void **)&m_CBVUAVSRV)); m_CBVUAVSRV->SetName(L"CBV/UAV/SRV heap"); + + desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE; + CHECK_HR(dev->CreateDescriptorHeap(&desc, __uuidof(ID3D12DescriptorHeap), (void **)&m_Clear)); + m_CBVUAVSRV->SetName(L"UAV clear heap"); } { diff --git a/util/test/demos/d3d12/d3d12_test.h b/util/test/demos/d3d12/d3d12_test.h index 5b049a832..b5167cef4 100644 --- a/util/test/demos/d3d12/d3d12_test.h +++ b/util/test/demos/d3d12/d3d12_test.h @@ -107,22 +107,22 @@ struct D3D12GraphicsTest : public GraphicsTest template D3D12ViewCreator MakeSRV(T res) { - return D3D12ViewCreator(this, m_CBVUAVSRV, ViewType::SRV, res); + return D3D12ViewCreator(this, m_CBVUAVSRV, NULL, ViewType::SRV, res); } template D3D12ViewCreator MakeRTV(T res) { - return D3D12ViewCreator(this, m_RTV, ViewType::RTV, res); + return D3D12ViewCreator(this, m_RTV, NULL, ViewType::RTV, res); } template D3D12ViewCreator MakeDSV(T res) { - return D3D12ViewCreator(this, m_DSV, ViewType::DSV, res); + return D3D12ViewCreator(this, m_DSV, NULL, ViewType::DSV, res); } template D3D12ViewCreator MakeUAV(T res) { - return D3D12ViewCreator(this, m_CBVUAVSRV, ViewType::UAV, res); + return D3D12ViewCreator(this, m_CBVUAVSRV, m_Clear, ViewType::UAV, res); } std::vector GetBufferData(ID3D12ResourcePtr buffer, D3D12_RESOURCE_STATES state, @@ -201,7 +201,7 @@ struct D3D12GraphicsTest : public GraphicsTest ID3D12DevicePtr dev; - ID3D12DescriptorHeapPtr m_RTV, m_DSV, m_CBVUAVSRV, m_Sampler; + ID3D12DescriptorHeapPtr m_RTV, m_DSV, m_CBVUAVSRV, m_Clear, m_Sampler; ID3D12CommandAllocatorPtr m_Alloc; ID3D12GraphicsCommandListPtr m_DebugList;