diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap5.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap5.cpp index c02b076bb..b2d977933 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap5.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap5.cpp @@ -161,7 +161,7 @@ bool WrappedID3D12Device::Serialise_CreateStateObject(SerialiserType &ser, wrapped->exports = new D3D12ShaderExportDatabase( pStateObject, GetResourceManager()->GetRaytracingResourceAndUtilHandler(), - wrapped->GetProperties()); + GetShaderCache(), wrapped->GetProperties()); wrapped->exports->PopulateDatabase(Descriptor.NumSubobjects, subs); @@ -229,7 +229,7 @@ WrappedID3D12Device::CreateStateObject(const D3D12_STATE_OBJECT_DESC *pDesc, REF wrapped->exports = new D3D12ShaderExportDatabase( wrapped->GetResourceID(), GetResourceManager()->GetRaytracingResourceAndUtilHandler(), - wrapped->GetProperties()); + GetShaderCache(), wrapped->GetProperties()); wrapped->exports->PopulateDatabase(pDesc->NumSubobjects, pDesc->pSubobjects); diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap7.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap7.cpp index 166e3488a..16452773e 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap7.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap7.cpp @@ -117,7 +117,7 @@ bool WrappedID3D12Device::Serialise_AddToStateObject(SerialiserType &ser, wrapped->exports = new D3D12ShaderExportDatabase( pNewStateObject, GetResourceManager()->GetRaytracingResourceAndUtilHandler(), - wrapped->GetProperties()); + GetShaderCache(), wrapped->GetProperties()); wrapped->exports->GrowFrom(((WrappedID3D12StateObject *)pStateObjectToGrowFrom)->exports); wrapped->exports->PopulateDatabase(Addition.NumSubobjects, subs); @@ -189,7 +189,7 @@ HRESULT STDMETHODCALLTYPE WrappedID3D12Device::AddToStateObject( wrapped->exports = new D3D12ShaderExportDatabase( wrapped->GetResourceID(), GetResourceManager()->GetRaytracingResourceAndUtilHandler(), - wrapped->GetProperties()); + GetShaderCache(), wrapped->GetProperties()); wrapped->exports->GrowFrom(((WrappedID3D12StateObject *)pStateObjectToGrowFrom)->exports); wrapped->exports->PopulateDatabase(pAddition->NumSubobjects, pAddition->pSubobjects); diff --git a/renderdoc/driver/d3d12/d3d12_resources.cpp b/renderdoc/driver/d3d12/d3d12_resources.cpp index 2f7d92d96..1e72de672 100644 --- a/renderdoc/driver/d3d12/d3d12_resources.cpp +++ b/renderdoc/driver/d3d12/d3d12_resources.cpp @@ -24,6 +24,7 @@ #include "d3d12_resources.h" #include "driver/shaders/dxbc/dxbc_reflect.h" +#include "driver/shaders/dxil/dxil_metadata.h" #include "d3d12_command_list.h" #include "d3d12_command_queue.h" #include "d3d12_shader_cache.h" @@ -839,8 +840,13 @@ void WrappedID3D12PipelineState::ProcessDescriptorAccess() D3D12ShaderExportDatabase::D3D12ShaderExportDatabase(ResourceId id, D3D12RaytracingResourceAndUtilHandler *rayManager, + D3D12ShaderCache *cache, ID3D12StateObjectProperties *obj) - : RefCounter12(NULL), objectOriginalId(id), m_RayManager(rayManager), m_StateObjectProps(obj) + : RefCounter12(NULL), + objectOriginalId(id), + m_RayManager(rayManager), + m_ShaderCache(cache), + m_StateObjectProps(obj) { m_RayManager->RegisterExportDatabase(this); } @@ -863,6 +869,7 @@ void D3D12ShaderExportDatabase::PopulateDatabase(size_t NumSubobjects, bool unassocDefaultValid = false; bool explicitDefault = false; bool unassocDXILDefaultValid = false; + bool explicitDXILDefault = false; uint32_t dxilDefaultRoot = ~0U; rdcarray> explicitRootSigAssocs; @@ -902,6 +909,11 @@ void D3D12ShaderExportDatabase::PopulateDatabase(size_t NumSubobjects, { D3D12_DXIL_LIBRARY_DESC *dxil = (D3D12_DXIL_LIBRARY_DESC *)subobjects[i].pDesc; + DXBC::DXBCContainer container( + bytebuf((byte *)dxil->DXILLibrary.pShaderBytecode, dxil->DXILLibrary.BytecodeLength), + rdcstr(), GraphicsAPI::D3D12, ~0U, ~0U); + + rdcarray exports; if(dxil->NumExports > 0) { for(UINT e = 0; e < dxil->NumExports; e++) @@ -909,23 +921,57 @@ void D3D12ShaderExportDatabase::PopulateDatabase(size_t NumSubobjects, // Name is always the name used for exports - if renaming then the renamed-from name // is only used to lookup in the dxil library and not for any associations-by-name AddExport(StringFormat::Wide2UTF8(dxil->pExports[e].Name)); + exports.push_back(StringFormat::Wide2UTF8(dxil->pExports[e].Name)); } } else { // hard part, we need to parse the DXIL to get the entry points - DXBC::DXBCContainer container( - bytebuf((byte *)dxil->DXILLibrary.pShaderBytecode, dxil->DXILLibrary.BytecodeLength), - rdcstr(), GraphicsAPI::D3D12, ~0U, ~0U); - rdcarray entries = container.GetEntryPoints(); for(const ShaderEntryPoint &e : entries) AddExport(e.name); } - // TODO: register local root signature subobjects into dxilLocalRootSigs. Override - // anything in there, unlike the import from a collection below. + // import local root signature subobjects + DXIL::RDATData rdat; + rdcarray localRSs; + if(container.GetRuntimeData(rdat)) + { + for(const DXIL::RDATData::SubobjectInfo &sub : rdat.subobjectsInfo) + { + if(sub.type == DXIL::RDATData::SubobjectInfo::SubobjectType::LocalRS) + { + if(exports.contains(sub.name) || exports.empty()) + { + localRSs.push_back(sub.name); + dxilLocalRootSigs[sub.name] = m_RayManager->RegisterLocalRootSig( + m_ShaderCache->GetRootSig(sub.rs.data.data(), sub.rs.data.size())); + + // ignore these if an explicit default association has been made + if(!explicitDXILDefault) + { + // if multiple root signatures are defined, then there can't be an unspecified default + unassocDXILDefaultValid = explicitDefaultDxilAssocs.empty(); + dxilDefaultRoot = dxilLocalRootSigs[sub.assoc.subobject]; + } + } + } + else if(sub.type == DXIL::RDATData::SubobjectInfo::SubobjectType::SubobjectToExportsAssoc) + { + // only care about local RS associations + if(localRSs.contains(sub.assoc.subobject)) + { + if(sub.assoc.exports.empty()) + { + explicitDXILDefault = true; + // TODO do we need a different level of priority for this vs an explicit default in code? + explicitDefaultDxilAssocs.push_back(sub.assoc.subobject); + } + } + } + } + } } else if(subobjects[i].Type == D3D12_STATE_SUBOBJECT_TYPE_EXISTING_COLLECTION) { diff --git a/renderdoc/driver/d3d12/d3d12_resources.h b/renderdoc/driver/d3d12/d3d12_resources.h index 3d81d6b4c..b93d08e91 100644 --- a/renderdoc/driver/d3d12/d3d12_resources.h +++ b/renderdoc/driver/d3d12/d3d12_resources.h @@ -1025,7 +1025,7 @@ struct D3D12ShaderExportDatabase : public RefCounter12 { public: D3D12ShaderExportDatabase(ResourceId id, D3D12RaytracingResourceAndUtilHandler *rayManager, - ID3D12StateObjectProperties *obj); + D3D12ShaderCache *cache, ID3D12StateObjectProperties *obj); ~D3D12ShaderExportDatabase(); ResourceId GetResourceId() { return objectOriginalId; } @@ -1073,6 +1073,7 @@ private: ID3D12StateObjectProperties *m_StateObjectProps = NULL; D3D12RaytracingResourceAndUtilHandler *m_RayManager = NULL; + D3D12ShaderCache *m_ShaderCache = NULL; struct ExportLookup {