From 7095c663a20e5f5c7ca53e2b83dff5bc791476ce Mon Sep 17 00:00:00 2001 From: baldurk Date: Sun, 31 Jul 2016 15:56:22 +0700 Subject: [PATCH] Track root signature and its contents for matching against root sets --- renderdoc/driver/d3d12/d3d12_command_list.h | 6 ++- .../driver/d3d12/d3d12_command_list_wrap.cpp | 3 ++ renderdoc/driver/d3d12/d3d12_commands.cpp | 2 + renderdoc/driver/d3d12/d3d12_common.h | 31 ++++++++++++++ renderdoc/driver/d3d12/d3d12_debug.cpp | 40 +++++++++++++++++++ renderdoc/driver/d3d12/d3d12_debug.h | 4 +- renderdoc/driver/d3d12/d3d12_device_wrap.cpp | 2 + renderdoc/driver/d3d12/d3d12_resources.h | 2 + 8 files changed, 88 insertions(+), 2 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_command_list.h b/renderdoc/driver/d3d12/d3d12_command_list.h index f991cdd82..8a87b918f 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list.h +++ b/renderdoc/driver/d3d12/d3d12_command_list.h @@ -89,6 +89,8 @@ class WrappedID3D12GraphicsCommandList : public RefCounter12GetChunkName(idx); } D3D12ResourceManager *GetResourceManager() { return m_pDevice->GetResourceManager(); } public: - ALLOCATE_WITH_WRAPPED_POOL(WrappedID3D12GraphicsCommandList); + static const int AllocPoolCount = 8192; + static const int AllocMaxByteSize = 2 * 1024 * 1024; + ALLOCATE_WITH_WRAPPED_POOL(WrappedID3D12GraphicsCommandList, AllocPoolCount, AllocMaxByteSize); WrappedID3D12GraphicsCommandList(ID3D12GraphicsCommandList *real, WrappedID3D12Device *device, Serialiser *serialiser, LogState &state); diff --git a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp index 7f53037e0..5025af2b1 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp @@ -955,6 +955,9 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootSignature(ID3D12RootSignat m_ListRecord->AddChunk(scope.Get()); m_ListRecord->MarkResourceFrameReferenced(GetResID(pRootSignature), eFrameRef_Read); + + // store this so we can look up how many descriptors a given slot references, etc + m_CurRootSig = GetWrapped(pRootSignature); } } diff --git a/renderdoc/driver/d3d12/d3d12_commands.cpp b/renderdoc/driver/d3d12/d3d12_commands.cpp index 38a76f72a..a5a060bfe 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.cpp +++ b/renderdoc/driver/d3d12/d3d12_commands.cpp @@ -505,6 +505,8 @@ WrappedID3D12GraphicsCommandList::WrappedID3D12GraphicsCommandList(ID3D12Graphic m_ListRecord = NULL; m_Cmd = NULL; + m_CurRootSig = NULL; + if(!RenderDoc::Inst().IsReplayApp()) { m_ListRecord = m_pDevice->GetResourceManager()->AddResourceRecord(m_ResourceID); diff --git a/renderdoc/driver/d3d12/d3d12_common.h b/renderdoc/driver/d3d12/d3d12_common.h index 880de1fc4..994aabc61 100644 --- a/renderdoc/driver/d3d12/d3d12_common.h +++ b/renderdoc/driver/d3d12/d3d12_common.h @@ -120,6 +120,37 @@ public: } }; +struct D3D12RootSignatureParameter : D3D12_ROOT_PARAMETER +{ + void MakeFrom(const D3D12_ROOT_PARAMETER ¶m) + { + ParameterType = param.ParameterType; + ShaderVisibility = param.ShaderVisibility; + + // copy the POD ones first + Descriptor = param.Descriptor; + Constants = param.Constants; + + if(ParameterType == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE) + { + ranges.resize(param.DescriptorTable.NumDescriptorRanges); + for(size_t i = 0; i < ranges.size(); i++) + ranges[i] = param.DescriptorTable.pDescriptorRanges[i]; + + DescriptorTable.NumDescriptorRanges = (UINT)ranges.size(); + DescriptorTable.pDescriptorRanges = &ranges[0]; + } + } + + vector ranges; +}; + +struct D3D12RootSignature +{ + vector params; + vector samplers; +}; + #define IMPLEMENT_IUNKNOWN_WITH_REFCOUNTER_CUSTOMQUERY \ ULONG STDMETHODCALLTYPE AddRef() { return RefCounter12::AddRef(); } \ ULONG STDMETHODCALLTYPE Release() { return RefCounter12::Release(); } diff --git a/renderdoc/driver/d3d12/d3d12_debug.cpp b/renderdoc/driver/d3d12/d3d12_debug.cpp index 7ce9bc980..b5cc22ca9 100644 --- a/renderdoc/driver/d3d12/d3d12_debug.cpp +++ b/renderdoc/driver/d3d12/d3d12_debug.cpp @@ -712,6 +712,46 @@ string D3D12DebugManager::GetShaderBlob(const char *source, const char *entry, return errors; } +D3D12RootSignature D3D12DebugManager::GetRootSig(const void *data, size_t dataSize) +{ + PFN_D3D12_CREATE_ROOT_SIGNATURE_DESERIALIZER deserializeRootSig = + (PFN_D3D12_CREATE_ROOT_SIGNATURE_DESERIALIZER)GetProcAddress( + GetModuleHandleA("d3d12.dll"), "D3D12CreateRootSignatureDeserializer"); + + if(deserializeRootSig == NULL) + { + RDCERR("Can't get D3D12CreateRootSignatureDeserializer"); + return D3D12RootSignature(); + } + + ID3D12RootSignatureDeserializer *deser = NULL; + HRESULT hr = + deserializeRootSig(data, dataSize, __uuidof(ID3D12RootSignatureDeserializer), (void **)&deser); + + if(FAILED(hr)) + { + SAFE_RELEASE(deser); + RDCERR("Can't get deserializer"); + return D3D12RootSignature(); + } + + D3D12RootSignature ret; + + const D3D12_ROOT_SIGNATURE_DESC *desc = deser->GetRootSignatureDesc(); + + ret.params.resize(desc->NumParameters); + + for(size_t i = 0; i < ret.params.size(); i++) + ret.params[i].MakeFrom(desc->pParameters[i]); + + if(desc->NumStaticSamplers > 0) + ret.samplers.assign(desc->pStaticSamplers, desc->pStaticSamplers + desc->NumStaticSamplers); + + SAFE_RELEASE(deser); + + return ret; +} + ID3DBlob *D3D12DebugManager::MakeRootSig(const vector &rootSig) { PFN_D3D12_SERIALIZE_ROOT_SIGNATURE serializeRootSig = diff --git a/renderdoc/driver/d3d12/d3d12_debug.h b/renderdoc/driver/d3d12/d3d12_debug.h index be2965d19..a4e1cb169 100644 --- a/renderdoc/driver/d3d12/d3d12_debug.h +++ b/renderdoc/driver/d3d12/d3d12_debug.h @@ -71,6 +71,8 @@ public: D3D12_CPU_DESCRIPTOR_HANDLE AllocRTV(); void FreeRTV(D3D12_CPU_DESCRIPTOR_HANDLE handle); + static D3D12RootSignature GetRootSig(const void *data, size_t dataSize); + private: struct OutputWindow { @@ -168,7 +170,7 @@ private: string GetShaderBlob(const char *source, const char *entry, const uint32_t compileFlags, const char *profile, ID3DBlob **srcblob); - ID3DBlob *MakeRootSig(const vector &rootSig); + static ID3DBlob *MakeRootSig(const vector &rootSig); int m_width, m_height; diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp index 20b1b7e9f..20ea7c50c 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp @@ -544,6 +544,8 @@ HRESULT WrappedID3D12Device::CreateRootSignature(UINT nodeMask, const void *pBlo record->Length = 0; wrapped->SetResourceRecord(record); + wrapped->sig = D3D12DebugManager::GetRootSig(pBlobWithRootSignature, blobLengthInBytes); + record->AddChunk(scope.Get()); } else diff --git a/renderdoc/driver/d3d12/d3d12_resources.h b/renderdoc/driver/d3d12/d3d12_resources.h index 594747cd4..ac01db05e 100644 --- a/renderdoc/driver/d3d12/d3d12_resources.h +++ b/renderdoc/driver/d3d12/d3d12_resources.h @@ -582,6 +582,8 @@ class WrappedID3D12RootSignature : public WrappedDeviceChild12