From ff821b25c812a6070219f700781ecbc405f514e5 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 20 Feb 2024 15:48:50 +0000 Subject: [PATCH] Create fake descriptor storage objects for GL and D3D11 --- renderdoc/api/replay/replay_enums.h | 10 +++++ renderdoc/driver/d3d11/d3d11_context.cpp | 25 ++++++++---- renderdoc/driver/d3d11/d3d11_context.h | 39 +++++++++++++++++-- renderdoc/driver/d3d11/d3d11_device.cpp | 16 ++++++-- renderdoc/driver/d3d11/d3d11_replay.cpp | 18 ++++++++- renderdoc/driver/d3d12/d3d12_device_wrap.cpp | 2 +- renderdoc/driver/gl/gl_driver.cpp | 10 +++++ renderdoc/driver/gl/gl_driver.h | 2 + renderdoc/driver/gl/gl_replay.cpp | 18 ++++++++- renderdoc/driver/gl/gl_resources.h | 1 + .../vulkan/wrappers/vk_descriptor_funcs.cpp | 2 +- 11 files changed, 123 insertions(+), 20 deletions(-) diff --git a/renderdoc/api/replay/replay_enums.h b/renderdoc/api/replay/replay_enums.h index 8a8d070e0..7ed3692ad 100644 --- a/renderdoc/api/replay/replay_enums.h +++ b/renderdoc/api/replay/replay_enums.h @@ -662,6 +662,14 @@ API-specific concepts. A structure used to carry implementation-defined spatial partitioning data and related information, used to accelerate geometry intersection queries (e.g. for ray tracing). + +.. data:: DescriptorStore + + A descriptor store, either driver or application managed. For example a Vulkan descriptor set or + a D3D12 descriptor heap. + + APIs without an explicit concept of descriptor storage will have virtual objects corresponding to + temporary bindings. )"); enum class ResourceType : uint32_t { @@ -690,6 +698,8 @@ enum class ResourceType : uint32_t Pool, AccelerationStructure, + + DescriptorStore, }; DECLARE_REFLECTION_ENUM(ResourceType); diff --git a/renderdoc/driver/d3d11/d3d11_context.cpp b/renderdoc/driver/d3d11/d3d11_context.cpp index ec3cba9b0..15dced7c6 100644 --- a/renderdoc/driver/d3d11/d3d11_context.cpp +++ b/renderdoc/driver/d3d11/d3d11_context.cpp @@ -69,6 +69,12 @@ HRESULT STDMETHODCALLTYPE WrappedID3DUserDefinedAnnotation::QueryInterface(REFII extern uint32_t NullCBOffsets[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT]; extern uint32_t NullCBCounts[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT]; +D3DDescriptorStore::D3DDescriptorStore(WrappedID3D11Device *device) +{ + m_ID = ResourceIDGen::GetNewUniqueID(); + device->GetResourceManager()->AddCurrentResource(GetResourceID(), this); +} + WrappedID3D11DeviceContext::WrappedID3D11DeviceContext(WrappedID3D11Device *realDevice, ID3D11DeviceContext *context) : m_pDevice(realDevice), @@ -138,10 +144,16 @@ WrappedID3D11DeviceContext::WrappedID3D11DeviceContext(WrappedID3D11Device *real if(RenderDoc::Inst().IsReplayApp()) { m_State = CaptureState::LoadingReplaying; + + m_DescriptorStore = new D3DDescriptorStore(m_pDevice); + m_pDevice->GetResourceManager()->AddLiveResource(m_DescriptorStore->GetResourceID(), + m_DescriptorStore); } else { m_State = CaptureState::BackgroundCapturing; + + m_DescriptorStore = NULL; } // create a temporary and grab its resource ID @@ -210,8 +222,6 @@ WrappedID3D11DeviceContext::WrappedID3D11DeviceContext(WrappedID3D11Device *real m_SuccessfulCapture = false; } } - - ReplayFakeContext(ResourceId()); } WrappedID3D11DeviceContext::~WrappedID3D11DeviceContext() @@ -222,6 +232,12 @@ WrappedID3D11DeviceContext::~WrappedID3D11DeviceContext() if(m_pRealContext && GetType() != D3D11_DEVICE_CONTEXT_IMMEDIATE) m_pDevice->RemoveDeferredContext(this); + // if this context is being destroyed by the resource manager the descriptor store may already be + // "removed" + if(m_DescriptorStore && GetResourceManager()->HasLiveResource(m_DescriptorStore->GetResourceID())) + GetResourceManager()->EraseLiveResource(m_DescriptorStore->GetResourceID()); + SAFE_DELETE(m_DescriptorStore); + SAFE_DELETE(m_FrameReader); SAFE_RELEASE(m_WrappedVideo.m_pReal); @@ -1217,11 +1233,6 @@ const APIEvent &WrappedID3D11DeviceContext::GetEvent(uint32_t eventId) const return m_Events[RDCMIN(idx, m_Events.size() - 1)]; } -void WrappedID3D11DeviceContext::ReplayFakeContext(ResourceId id) -{ - m_FakeContext = id; -} - RDResult WrappedID3D11DeviceContext::ReplayLog(CaptureState readType, uint32_t startEventID, uint32_t endEventID, bool partial) { diff --git a/renderdoc/driver/d3d11/d3d11_context.h b/renderdoc/driver/d3d11/d3d11_context.h index 0471628a3..16d916af2 100644 --- a/renderdoc/driver/d3d11/d3d11_context.h +++ b/renderdoc/driver/d3d11/d3d11_context.h @@ -93,6 +93,36 @@ enum CaptureFailReason CaptureFailed_UncappedCmdlist, }; +// a fake device child to be able to register a resource without needing a wrapper +struct D3DDescriptorStore : public ID3D11DeviceChild +{ +private: + ResourceId m_ID; + +public: + D3DDescriptorStore(WrappedID3D11Device *device); + virtual ~D3DDescriptorStore() {} + + ResourceId GetResourceID() { return m_ID; } + + ULONG STDMETHODCALLTYPE AddRef() { return 1; } + ULONG STDMETHODCALLTYPE Release() { return 1; } + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) { return E_NOTIMPL; } + void STDMETHODCALLTYPE GetDevice(ID3D11Device **ppDevice) {} + HRESULT STDMETHODCALLTYPE GetPrivateData(REFGUID guid, UINT *pDataSize, void *pData) + { + return E_NOTIMPL; + } + HRESULT STDMETHODCALLTYPE SetPrivateData(REFGUID guid, UINT DataSize, const void *pData) + { + return E_NOTIMPL; + } + HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(REFGUID guid, const IUnknown *pData) + { + return E_NOTIMPL; + } +}; + class WrappedID3D11DeviceContext : public ID3D11DeviceContext4 { private: @@ -145,6 +175,7 @@ private: std::set m_StringDB; ResourceId m_CurContextId; + D3DDescriptorStore *m_DescriptorStore; StreamReader *m_FrameReader = NULL; @@ -168,8 +199,6 @@ private: RenderDoc::Inst().AddActiveDriver(RDCDriver::D3D11, false); } - ResourceId m_FakeContext; - bool m_DoStateVerify; D3D11RenderState *m_CurrentPipelineState; @@ -266,6 +295,11 @@ public: void VerifyState(); + ResourceId GetDescriptorsID() + { + return m_DescriptorStore ? m_DescriptorStore->GetResourceID() : ResourceId(); + } + void BeginFrame(); void EndFrame(); @@ -300,7 +334,6 @@ public: bool IsFL11_1(); bool ProcessChunk(ReadSerialiser &ser, D3D11Chunk chunk); - void ReplayFakeContext(ResourceId id); RDResult ReplayLog(CaptureState readType, uint32_t startEventID, uint32_t endEventID, bool partial); void SetFrameReader(StreamReader *reader) { m_FrameReader = reader; } void MarkResourceReferenced(ResourceId id, FrameRefType refType); diff --git a/renderdoc/driver/d3d11/d3d11_device.cpp b/renderdoc/driver/d3d11/d3d11_device.cpp index f9d5a1ad3..e8bfed085 100644 --- a/renderdoc/driver/d3d11/d3d11_device.cpp +++ b/renderdoc/driver/d3d11/d3d11_device.cpp @@ -1032,11 +1032,19 @@ bool WrappedID3D11Device::ProcessChunk(ReadSerialiser &ser, D3D11Chunk context) m_pImmediateContext->AddRef(); m_ResourceManager->AddLiveResource(ImmediateContext, m_pImmediateContext); + ResourceId descId = m_pImmediateContext->GetDescriptorsID(); + AddResource(descId, ResourceType::DescriptorStore, ""); + AddResource(ImmediateContext, ResourceType::Queue, ""); - ResourceDescription &desc = GetReplay()->GetResourceDesc(ImmediateContext); - desc.autogeneratedName = false; - desc.name = "Immediate Context"; - desc.initialisationChunks.clear(); + ResourceDescription &ctxdesc = GetReplay()->GetResourceDesc(ImmediateContext); + ctxdesc.SetCustomName("Immediate Context"); + ctxdesc.initialisationChunks.clear(); + + ResourceDescription &bindsdesc = GetReplay()->GetResourceDesc(descId); + bindsdesc.SetCustomName("Immediate Context Bindings"); + bindsdesc.initialisationChunks.clear(); + ctxdesc.derivedResources.push_back(descId); + bindsdesc.parentResources.push_back(ImmediateContext); } return true; diff --git a/renderdoc/driver/d3d11/d3d11_replay.cpp b/renderdoc/driver/d3d11/d3d11_replay.cpp index b036e4a74..1c2ce5963 100644 --- a/renderdoc/driver/d3d11/d3d11_replay.cpp +++ b/renderdoc/driver/d3d11/d3d11_replay.cpp @@ -1667,10 +1667,17 @@ void D3D11Replay::SavePipelineState(uint32_t eventId) rdcarray D3D11Replay::GetDescriptors(ResourceId descriptorStore, const rdcarray &ranges) { + rdcarray ret; + + if(descriptorStore != m_pImmediateContext->GetDescriptorsID()) + { + RDCERR("Descriptors query for invalid descriptor store on fixed bindings API (D3D11)"); + return ret; + } + size_t count = 0; for(const DescriptorRange &r : ranges) count += r.count; - rdcarray ret; ret.resize(count); return ret; } @@ -1678,10 +1685,17 @@ rdcarray D3D11Replay::GetDescriptors(ResourceId descriptorStore, rdcarray D3D11Replay::GetSamplerDescriptors(ResourceId descriptorStore, const rdcarray &ranges) { + rdcarray ret; + + if(descriptorStore != m_pImmediateContext->GetDescriptorsID()) + { + RDCERR("Descriptors query for invalid descriptor store on fixed bindings API (D3D11)"); + return ret; + } + size_t count = 0; for(const DescriptorRange &r : ranges) count += r.count; - rdcarray ret; ret.resize(count); return ret; } diff --git a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp index 35a7f83b8..b28b0b061 100644 --- a/renderdoc/driver/d3d12/d3d12_device_wrap.cpp +++ b/renderdoc/driver/d3d12/d3d12_device_wrap.cpp @@ -962,7 +962,7 @@ bool WrappedID3D12Device::Serialise_CreateDescriptorHeap( GetResourceManager()->AddLiveResource(pHeap, ret); - AddResource(pHeap, ResourceType::ShaderBinding, "Descriptor Heap"); + AddResource(pHeap, ResourceType::DescriptorStore, "Descriptor Heap"); } } diff --git a/renderdoc/driver/gl/gl_driver.cpp b/renderdoc/driver/gl/gl_driver.cpp index c16d96dea..9ab7ad24c 100644 --- a/renderdoc/driver/gl/gl_driver.cpp +++ b/renderdoc/driver/gl/gl_driver.cpp @@ -695,6 +695,16 @@ WrappedOpenGL::WrappedOpenGL(GLPlatform &platform) m_DeviceRecord = m_ContextRecord = NULL; ResourceIDGen::SetReplayResourceIDs(); + + m_DescriptorsID = GetResourceManager()->RegisterResource( + GLResource(NULL, eResSpecial, eSpecialResDescriptorStorage)); + + GetResourceManager()->AddLiveResource( + m_DescriptorsID, GLResource(NULL, eResSpecial, eSpecialResDescriptorStorage)); + + AddResource(m_DescriptorsID, ResourceType::DescriptorStore, ""); + GetReplay()->GetResourceDesc(m_DescriptorsID).SetCustomName("Context Bindings"); + GetReplay()->GetResourceDesc(m_DescriptorsID).initialisationChunks.clear(); } rdcspv::Init(); diff --git a/renderdoc/driver/gl/gl_driver.h b/renderdoc/driver/gl/gl_driver.h index 3ece0f645..57d5eb666 100644 --- a/renderdoc/driver/gl/gl_driver.h +++ b/renderdoc/driver/gl/gl_driver.h @@ -220,6 +220,8 @@ private: ResourceId m_ContextResourceID; GLResourceRecord *m_ContextRecord; + ResourceId m_DescriptorsID; + GLResourceManager *m_ResourceManager; uint64_t m_TimeBase = 0; diff --git a/renderdoc/driver/gl/gl_replay.cpp b/renderdoc/driver/gl/gl_replay.cpp index 559a8ee65..2f13adf9d 100644 --- a/renderdoc/driver/gl/gl_replay.cpp +++ b/renderdoc/driver/gl/gl_replay.cpp @@ -2123,10 +2123,17 @@ void GLReplay::SavePipelineState(uint32_t eventId) rdcarray GLReplay::GetDescriptors(ResourceId descriptorStore, const rdcarray &ranges) { + rdcarray ret; + + if(descriptorStore != m_pDriver->m_DescriptorsID) + { + RDCERR("Descriptors query for invalid descriptor store on fixed bindings API (OpenGL)"); + return ret; + } + size_t count = 0; for(const DescriptorRange &r : ranges) count += r.count; - rdcarray ret; ret.resize(count); return ret; } @@ -2134,10 +2141,17 @@ rdcarray GLReplay::GetDescriptors(ResourceId descriptorStore, rdcarray GLReplay::GetSamplerDescriptors(ResourceId descriptorStore, const rdcarray &ranges) { + rdcarray ret; + + if(descriptorStore != m_pDriver->m_DescriptorsID) + { + RDCERR("Descriptors query for invalid descriptor store on fixed bindings API (OpenGL)"); + return ret; + } + size_t count = 0; for(const DescriptorRange &r : ranges) count += r.count; - rdcarray ret; ret.resize(count); return ret; } diff --git a/renderdoc/driver/gl/gl_resources.h b/renderdoc/driver/gl/gl_resources.h index 6ed9ba74c..2a8f33836 100644 --- a/renderdoc/driver/gl/gl_resources.h +++ b/renderdoc/driver/gl/gl_resources.h @@ -93,6 +93,7 @@ enum GLSpecialResource { eSpecialResDevice = 0, eSpecialResContext = 0, + eSpecialResDescriptorStorage = 0, }; enum NullInitialiser diff --git a/renderdoc/driver/vulkan/wrappers/vk_descriptor_funcs.cpp b/renderdoc/driver/vulkan/wrappers/vk_descriptor_funcs.cpp index d55e1d56f..d1c30c1ce 100644 --- a/renderdoc/driver/vulkan/wrappers/vk_descriptor_funcs.cpp +++ b/renderdoc/driver/vulkan/wrappers/vk_descriptor_funcs.cpp @@ -502,7 +502,7 @@ bool WrappedVulkan::Serialise_vkAllocateDescriptorSets(SerialiserType &ser, VkDe variableDescriptorAlloc); } - AddResource(DescriptorSet, ResourceType::ShaderBinding, "Descriptor Set"); + AddResource(DescriptorSet, ResourceType::DescriptorStore, "Descriptor Set"); DerivedResource(device, DescriptorSet); DerivedResource(AllocateInfo.pSetLayouts[0], DescriptorSet); DerivedResource(AllocateInfo.descriptorPool, DescriptorSet);