From ee1853b139aedf11d2c490cfc719ffd450d9a1b1 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 17 Nov 2016 14:20:25 +0100 Subject: [PATCH] Use versioned root sigs and version 1.1, so we have all relevant data --- .../driver/d3d12/d3d12_command_list_wrap.cpp | 4 +- renderdoc/driver/d3d12/d3d12_commands.cpp | 2 +- renderdoc/driver/d3d12/d3d12_common.h | 42 ++++++- renderdoc/driver/d3d12/d3d12_debug.cpp | 116 ++++++++++++------ renderdoc/driver/d3d12/d3d12_debug.h | 6 +- renderdoc/driver/d3d12/d3d12_replay.cpp | 2 +- 6 files changed, 124 insertions(+), 48 deletions(-) diff --git a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp index df763ff63..f298a60e1 100644 --- a/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_command_list_wrap.cpp @@ -1355,7 +1355,7 @@ void WrappedID3D12GraphicsCommandList::SetComputeRootDescriptorTable( m_ListRecord->MarkResourceFrameReferenced(GetResID(GetWrapped(BaseDescriptor)->nonsamp.heap), eFrameRef_Read); - vector &ranges = + vector &ranges = GetWrapped(m_CurCompRootSig)->sig.params[RootParameterIndex].ranges; D3D12Descriptor *base = GetWrapped(BaseDescriptor); @@ -1855,7 +1855,7 @@ void WrappedID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable( m_ListRecord->MarkResourceFrameReferenced(GetResID(GetWrapped(BaseDescriptor)->nonsamp.heap), eFrameRef_Read); - vector &ranges = + vector &ranges = GetWrapped(m_CurGfxRootSig)->sig.params[RootParameterIndex].ranges; D3D12Descriptor *base = GetWrapped(BaseDescriptor); diff --git a/renderdoc/driver/d3d12/d3d12_commands.cpp b/renderdoc/driver/d3d12/d3d12_commands.cpp index 204c24104..50b780890 100644 --- a/renderdoc/driver/d3d12/d3d12_commands.cpp +++ b/renderdoc/driver/d3d12/d3d12_commands.cpp @@ -1077,7 +1077,7 @@ void D3D12CommandData::AddUsage(D3D12DrawcallTreeNode &drawNode) for(size_t r = 0; r < p.ranges.size(); r++) { - const D3D12_DESCRIPTOR_RANGE &range = p.ranges[r]; + const D3D12_DESCRIPTOR_RANGE1 &range = p.ranges[r]; UINT offset = range.OffsetInDescriptorsFromTableStart; diff --git a/renderdoc/driver/d3d12/d3d12_common.h b/renderdoc/driver/d3d12/d3d12_common.h index 829238430..2758ee6a4 100644 --- a/renderdoc/driver/d3d12/d3d12_common.h +++ b/renderdoc/driver/d3d12/d3d12_common.h @@ -127,9 +127,42 @@ public: } }; -struct D3D12RootSignatureParameter : D3D12_ROOT_PARAMETER +struct D3D12RootSignatureParameter : D3D12_ROOT_PARAMETER1 { - void MakeFrom(const D3D12_ROOT_PARAMETER ¶m, UINT &numSpaces) + D3D12RootSignatureParameter() + { + ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; + ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; + + // copy the POD ones first + Constants.Num32BitValues = 0; + Constants.RegisterSpace = 0; + Constants.ShaderRegister = 0; + } + + D3D12RootSignatureParameter(const D3D12RootSignatureParameter &other) { *this = other; } + D3D12RootSignatureParameter &operator=(const D3D12RootSignatureParameter &other) + { + // copy first + ParameterType = other.ParameterType; + ShaderVisibility = other.ShaderVisibility; + + // copy the POD ones first + Descriptor = other.Descriptor; + Constants = other.Constants; + + ranges = other.ranges; + + // repoint ranges + if(ParameterType == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE) + { + DescriptorTable.NumDescriptorRanges = (UINT)ranges.size(); + DescriptorTable.pDescriptorRanges = &ranges[0]; + } + return *this; + } + + void MakeFrom(const D3D12_ROOT_PARAMETER1 ¶m, UINT &numSpaces) { ParameterType = param.ParameterType; ShaderVisibility = param.ShaderVisibility; @@ -161,13 +194,16 @@ struct D3D12RootSignatureParameter : D3D12_ROOT_PARAMETER } } - vector ranges; + vector ranges; }; struct D3D12RootSignature { D3D12RootSignature() : numSpaces(0) {} uint32_t numSpaces; + uint32_t dwordLength; + + D3D12_ROOT_SIGNATURE_FLAGS Flags; vector params; vector samplers; }; diff --git a/renderdoc/driver/d3d12/d3d12_debug.cpp b/renderdoc/driver/d3d12/d3d12_debug.cpp index beb265307..b727d10b3 100644 --- a/renderdoc/driver/d3d12/d3d12_debug.cpp +++ b/renderdoc/driver/d3d12/d3d12_debug.cpp @@ -290,14 +290,15 @@ D3D12DebugManager::D3D12DebugManager(WrappedID3D12Device *wrapper) m_CacheShaders = true; - vector rootSig; + vector rootSig; - D3D12_ROOT_PARAMETER param = {}; + D3D12_ROOT_PARAMETER1 param = {}; // m_GenericVSCbuffer param.ShaderVisibility = D3D12_SHADER_VISIBILITY_VERTEX; param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV; param.Descriptor.ShaderRegister = 0; + param.Descriptor.Flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE; rootSig.push_back(param); @@ -307,11 +308,21 @@ D3D12DebugManager::D3D12DebugManager(WrappedID3D12Device *wrapper) rootSig.push_back(param); - D3D12_DESCRIPTOR_RANGE srvrange = {}; + ID3DBlob *root = MakeRootSig(rootSig); + + RDCASSERT(root); + + hr = m_WrappedDevice->CreateRootSignature(0, root->GetBufferPointer(), root->GetBufferSize(), + __uuidof(ID3D12RootSignature), (void **)&m_CBOnlyRootSig); + + SAFE_RELEASE(root); + + D3D12_DESCRIPTOR_RANGE1 srvrange = {}; srvrange.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SRV; srvrange.BaseShaderRegister = 0; srvrange.NumDescriptors = 32; srvrange.OffsetInDescriptorsFromTableStart = 0; + srvrange.Flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE; param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; param.DescriptorTable.NumDescriptorRanges = 1; @@ -320,11 +331,12 @@ D3D12DebugManager::D3D12DebugManager(WrappedID3D12Device *wrapper) // SRV rootSig.push_back(param); - D3D12_DESCRIPTOR_RANGE samplerrange = {}; + D3D12_DESCRIPTOR_RANGE1 samplerrange = {}; samplerrange.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER; samplerrange.BaseShaderRegister = 0; samplerrange.NumDescriptors = 2; samplerrange.OffsetInDescriptorsFromTableStart = 0; + samplerrange.Flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE; param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; param.DescriptorTable.NumDescriptorRanges = 1; @@ -333,7 +345,7 @@ D3D12DebugManager::D3D12DebugManager(WrappedID3D12Device *wrapper) // samplers rootSig.push_back(param); - ID3DBlob *root = MakeRootSig(rootSig); + root = MakeRootSig(rootSig); RDCASSERT(root); @@ -349,6 +361,7 @@ D3D12DebugManager::D3D12DebugManager(WrappedID3D12Device *wrapper) param.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV; param.Descriptor.ShaderRegister = 0; + param.Descriptor.Flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE; rootSig.push_back(param); @@ -367,11 +380,12 @@ D3D12DebugManager::D3D12DebugManager(WrappedID3D12Device *wrapper) rootSig.push_back(param); // 3: UAVs - D3D12_DESCRIPTOR_RANGE uavrange = {}; + D3D12_DESCRIPTOR_RANGE1 uavrange = {}; uavrange.RangeType = D3D12_DESCRIPTOR_RANGE_TYPE_UAV; uavrange.BaseShaderRegister = 0; uavrange.NumDescriptors = 3; uavrange.OffsetInDescriptorsFromTableStart = 0; + uavrange.Flags = D3D12_DESCRIPTOR_RANGE_FLAG_NONE; param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE; param.DescriptorTable.NumDescriptorRanges = 1; @@ -472,6 +486,8 @@ D3D12DebugManager::D3D12DebugManager(WrappedID3D12Device *wrapper) RDCERR("Couldn't create m_TexDisplayF32Pipe! 0x%08x", hr); } + pipeDesc.pRootSignature = m_CBOnlyRootSig; + pipeDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; pipeDesc.PS.BytecodeLength = CheckerboardPS->GetBufferSize(); @@ -867,6 +883,7 @@ D3D12DebugManager::D3D12DebugManager(WrappedID3D12Device *wrapper) param.ShaderVisibility = D3D12_SHADER_VISIBILITY_VERTEX; param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV; param.Descriptor.ShaderRegister = 0; + param.Descriptor.Flags = D3D12_ROOT_DESCRIPTOR_FLAG_NONE; rootSig.push_back(param); @@ -1004,6 +1021,7 @@ D3D12DebugManager::~D3D12DebugManager() SAFE_RELEASE(m_TexDisplayF32Pipe); SAFE_RELEASE(m_TexDisplayRootSig); + SAFE_RELEASE(m_CBOnlyRootSig); SAFE_RELEASE(m_CheckerboardPipe); SAFE_RELEASE(m_OutlinePipe); @@ -1114,19 +1132,19 @@ string D3D12DebugManager::GetShaderBlob(const char *source, const char *entry, 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"); + PFN_D3D12_CREATE_VERSIONED_ROOT_SIGNATURE_DESERIALIZER deserializeRootSig = + (PFN_D3D12_CREATE_VERSIONED_ROOT_SIGNATURE_DESERIALIZER)GetProcAddress( + GetModuleHandleA("d3d12.dll"), "D3D12CreateVersionedRootSignatureDeserializer"); if(deserializeRootSig == NULL) { - RDCERR("Can't get D3D12CreateRootSignatureDeserializer"); + RDCERR("Can't get D3D12CreateVersionedRootSignatureDeserializer"); return D3D12RootSignature(); } - ID3D12RootSignatureDeserializer *deser = NULL; - HRESULT hr = - deserializeRootSig(data, dataSize, __uuidof(ID3D12RootSignatureDeserializer), (void **)&deser); + ID3D12VersionedRootSignatureDeserializer *deser = NULL; + HRESULT hr = deserializeRootSig( + data, dataSize, __uuidof(ID3D12VersionedRootSignatureDeserializer), (void **)&deser); if(FAILED(hr)) { @@ -1137,13 +1155,38 @@ D3D12RootSignature D3D12DebugManager::GetRootSig(const void *data, size_t dataSi D3D12RootSignature ret; - const D3D12_ROOT_SIGNATURE_DESC *desc = deser->GetRootSignatureDesc(); + const D3D12_VERSIONED_ROOT_SIGNATURE_DESC *verdesc = NULL; + hr = deser->GetRootSignatureDescAtVersion(D3D_ROOT_SIGNATURE_VERSION_1_1, &verdesc); + if(FAILED(hr)) + { + SAFE_RELEASE(deser); + RDCERR("Can't get descriptor"); + return D3D12RootSignature(); + } + + const D3D12_ROOT_SIGNATURE_DESC1 *desc = &verdesc->Desc_1_1; + + ret.Flags = desc->Flags; ret.params.resize(desc->NumParameters); + ret.dwordLength = 0; + for(size_t i = 0; i < ret.params.size(); i++) + { ret.params[i].MakeFrom(desc->pParameters[i], ret.numSpaces); + // Descriptor tables cost 1 DWORD each. + // Root constants cost 1 DWORD each, since they are 32-bit values. + // Root descriptors (64-bit GPU virtual addresses) cost 2 DWORDs each. + if(desc->pParameters[i].ParameterType == D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE) + ret.dwordLength++; + else if(desc->pParameters[i].ParameterType == D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS) + ret.dwordLength += desc->pParameters[i].Constants.Num32BitValues; + else + ret.dwordLength += 2; + } + if(desc->NumStaticSamplers > 0) { ret.samplers.assign(desc->pStaticSamplers, desc->pStaticSamplers + desc->NumStaticSamplers); @@ -1157,28 +1200,33 @@ D3D12RootSignature D3D12DebugManager::GetRootSig(const void *data, size_t dataSi return ret; } -ID3DBlob *D3D12DebugManager::MakeRootSig(const vector &rootSig) +ID3DBlob *D3D12DebugManager::MakeRootSig(const std::vector params, + D3D12_ROOT_SIGNATURE_FLAGS Flags, UINT NumStaticSamplers, + D3D12_STATIC_SAMPLER_DESC *StaticSamplers) { - PFN_D3D12_SERIALIZE_ROOT_SIGNATURE serializeRootSig = - (PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)GetProcAddress(GetModuleHandleA("d3d12.dll"), - "D3D12SerializeRootSignature"); + PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE serializeRootSig = + (PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE)GetProcAddress( + GetModuleHandleA("d3d12.dll"), "D3D12SerializeVersionedRootSignature"); if(serializeRootSig == NULL) { - RDCERR("Can't get D3D12SerializeRootSignature"); + RDCERR("Can't get D3D12SerializeVersionedRootSignature"); return NULL; } - D3D12_ROOT_SIGNATURE_DESC desc; - desc.Flags = D3D12_ROOT_SIGNATURE_FLAG_NONE; - desc.NumStaticSamplers = 0; - desc.pStaticSamplers = NULL; - desc.NumParameters = (UINT)rootSig.size(); - desc.pParameters = &rootSig[0]; + D3D12_VERSIONED_ROOT_SIGNATURE_DESC verdesc; + verdesc.Version = D3D_ROOT_SIGNATURE_VERSION_1_1; + + D3D12_ROOT_SIGNATURE_DESC1 &desc = verdesc.Desc_1_1; + desc.Flags = Flags; + desc.NumStaticSamplers = NumStaticSamplers; + desc.pStaticSamplers = StaticSamplers; + desc.NumParameters = (UINT)params.size(); + desc.pParameters = ¶ms[0]; ID3DBlob *ret = NULL; ID3DBlob *errBlob = NULL; - HRESULT hr = serializeRootSig(&desc, D3D_ROOT_SIGNATURE_VERSION_1, &ret, &errBlob); + HRESULT hr = serializeRootSig(&verdesc, &ret, &errBlob); if(FAILED(hr)) { @@ -2392,16 +2440,10 @@ void D3D12DebugManager::RenderCheckerboard(Vec3f light, Vec3f dark) list->SetPipelineState(m_CheckerboardPipe); - list->SetGraphicsRootSignature(m_TexDisplayRootSig); - - // Set the descriptor heap containing the texture srv - ID3D12DescriptorHeap *heaps[] = {cbvsrvuavHeap, samplerHeap}; - list->SetDescriptorHeaps(2, heaps); + list->SetGraphicsRootSignature(m_CBOnlyRootSig); list->SetGraphicsRootConstantBufferView(0, m_GenericVSCbuffer->GetGPUVirtualAddress()); list->SetGraphicsRootConstantBufferView(1, m_GenericPSCbuffer->GetGPUVirtualAddress()); - list->SetGraphicsRootDescriptorTable(2, cbvsrvuavHeap->GetGPUDescriptorHandleForHeapStart()); - list->SetGraphicsRootDescriptorTable(3, samplerHeap->GetGPUDescriptorHandleForHeapStart()); float factor[4] = {1.0f, 1.0f, 1.0f, 1.0f}; list->OMSetBlendFactor(factor); @@ -3605,11 +3647,7 @@ ResourceId D3D12DebugManager::RenderOverlay(ResourceId texid, FormatComponentTyp list->SetPipelineState(m_OutlinePipe); - list->SetGraphicsRootSignature(m_TexDisplayRootSig); - - // Set the descriptor heap containing the texture srv - ID3D12DescriptorHeap *heaps[] = {cbvsrvuavHeap, samplerHeap}; - list->SetDescriptorHeaps(2, heaps); + list->SetGraphicsRootSignature(m_CBOnlyRootSig); DebugPixelCBufferData pixelData = {0}; @@ -3626,8 +3664,6 @@ ResourceId D3D12DebugManager::RenderOverlay(ResourceId texid, FormatComponentTyp list->SetGraphicsRootConstantBufferView(0, m_GenericVSCbuffer->GetGPUVirtualAddress()); list->SetGraphicsRootConstantBufferView(1, m_GenericVSCbuffer->GetGPUVirtualAddress()); - list->SetGraphicsRootDescriptorTable(2, cbvsrvuavHeap->GetGPUDescriptorHandleForHeapStart()); - list->SetGraphicsRootDescriptorTable(3, samplerHeap->GetGPUDescriptorHandleForHeapStart()); float factor[4] = {1.0f, 1.0f, 1.0f, 1.0f}; list->OMSetBlendFactor(factor); diff --git a/renderdoc/driver/d3d12/d3d12_debug.h b/renderdoc/driver/d3d12/d3d12_debug.h index ec8ecb1a0..135ace45c 100644 --- a/renderdoc/driver/d3d12/d3d12_debug.h +++ b/renderdoc/driver/d3d12/d3d12_debug.h @@ -101,6 +101,10 @@ public: void FreeRTV(D3D12_CPU_DESCRIPTOR_HANDLE handle); static D3D12RootSignature GetRootSig(const void *data, size_t dataSize); + static ID3DBlob *MakeRootSig(const std::vector params, + D3D12_ROOT_SIGNATURE_FLAGS Flags = D3D12_ROOT_SIGNATURE_FLAG_NONE, + UINT NumStaticSamplers = 0, + D3D12_STATIC_SAMPLER_DESC *StaticSamplers = NULL); private: struct OutputWindow @@ -220,6 +224,7 @@ private: ID3D12RootSignature *m_TexDisplayRootSig; + ID3D12RootSignature *m_CBOnlyRootSig; ID3D12PipelineState *m_CheckerboardPipe; ID3D12PipelineState *m_OutlinePipe; @@ -264,7 +269,6 @@ private: string GetShaderBlob(const char *source, const char *entry, const uint32_t compileFlags, const char *profile, ID3DBlob **srcblob); - static ID3DBlob *MakeRootSig(const vector &rootSig); ID3DBlob *MakeFixedColShader(float overlayConsts[4]); int m_width, m_height; diff --git a/renderdoc/driver/d3d12/d3d12_replay.cpp b/renderdoc/driver/d3d12/d3d12_replay.cpp index 133efe431..3e4cfa0e8 100644 --- a/renderdoc/driver/d3d12/d3d12_replay.cpp +++ b/renderdoc/driver/d3d12/d3d12_replay.cpp @@ -647,7 +647,7 @@ void D3D12Replay::FillRegisterSpaces( for(size_t r = 0; r < p.ranges.size(); r++) { - const D3D12_DESCRIPTOR_RANGE &range = p.ranges[r]; + const D3D12_DESCRIPTOR_RANGE1 &range = p.ranges[r]; UINT shaderReg = range.BaseShaderRegister; UINT regSpace = range.RegisterSpace;