diff options
| author | Yong He <yonghe@outlook.com> | 2022-10-12 14:51:13 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-12 14:51:13 -0700 |
| commit | 344898b091867e5450a3fa432a207d75255df77a (patch) | |
| tree | e9779a112e371ad141d1f6d9b8778acb4207179b | |
| parent | d96250bcc2e8fedb485df3ed0fdc28f89f6d23c8 (diff) | |
Add gfx debug layer trampoline for D3D12 interfaces. (#2445)
Co-authored-by: Yong He <yhe@nvidia.com>
| -rw-r--r-- | slang-gfx.h | 4 | ||||
| -rw-r--r-- | tools/gfx/d3d12/d3d12-transient-heap.cpp | 4 | ||||
| -rw-r--r-- | tools/gfx/d3d12/d3d12-transient-heap.h | 2 | ||||
| -rw-r--r-- | tools/gfx/debug-layer/debug-command-buffer.cpp | 33 | ||||
| -rw-r--r-- | tools/gfx/debug-layer/debug-command-buffer.h | 5 | ||||
| -rw-r--r-- | tools/gfx/debug-layer/debug-helper-functions.cpp | 2 | ||||
| -rw-r--r-- | tools/gfx/debug-layer/debug-helper-functions.h | 39 | ||||
| -rw-r--r-- | tools/gfx/debug-layer/debug-transient-heap.cpp | 48 | ||||
| -rw-r--r-- | tools/gfx/debug-layer/debug-transient-heap.h | 20 | ||||
| -rw-r--r-- | tools/gfx/renderer-shared.cpp | 2 | ||||
| -rw-r--r-- | tools/gfx/renderer-shared.h | 2 |
11 files changed, 136 insertions, 25 deletions
diff --git a/slang-gfx.h b/slang-gfx.h index b4ab50517..2acb8bf1a 100644 --- a/slang-gfx.h +++ b/slang-gfx.h @@ -1995,7 +1995,7 @@ public: 0xcd48bd29, 0xee72, 0x41b8, { 0xbc, 0xff, 0xa, 0x2b, 0x3a, 0xaa, 0x6d, 0xeb } \ } -class ID3D12TransientResourceHeap : public ISlangUnknown +class ITransientResourceHeapD3D12 : public ISlangUnknown { public: enum class DescriptorType @@ -2008,7 +2008,7 @@ public: Offset& outDescriptorOffset, void** outD3DDescriptorHeapHandle) = 0; }; -#define SLANG_UUID_ID3D12TransientResourceHeap \ +#define SLANG_UUID_ITransientResourceHeapD3D12 \ { \ 0x9bc6a8bc, 0x5f7a, 0x454a, { 0x93, 0xef, 0x3b, 0x10, 0x5b, 0xb7, 0x63, 0x7e } \ } diff --git a/tools/gfx/d3d12/d3d12-transient-heap.cpp b/tools/gfx/d3d12/d3d12-transient-heap.cpp index e33aa473c..11b03dc12 100644 --- a/tools/gfx/d3d12/d3d12-transient-heap.cpp +++ b/tools/gfx/d3d12/d3d12-transient-heap.cpp @@ -81,9 +81,9 @@ D3D12DescriptorHeap& TransientResourceHeapImpl::getCurrentSamplerHeap() Result TransientResourceHeapImpl::queryInterface(SlangUUID const& uuid, void** outObject) { - if (uuid == GfxGUID::IID_ID3D12TransientResourceHeap) + if (uuid == GfxGUID::IID_ITransientResourceHeapD3D12) { - *outObject = static_cast<ID3D12TransientResourceHeap*>(this); + *outObject = static_cast<ITransientResourceHeapD3D12*>(this); addRef(); return SLANG_OK; } diff --git a/tools/gfx/d3d12/d3d12-transient-heap.h b/tools/gfx/d3d12/d3d12-transient-heap.h index 8d9ac261a..6b05367e8 100644 --- a/tools/gfx/d3d12/d3d12-transient-heap.h +++ b/tools/gfx/d3d12/d3d12-transient-heap.h @@ -12,7 +12,7 @@ using namespace Slang; class TransientResourceHeapImpl : public TransientResourceHeapBaseImpl<DeviceImpl, BufferResourceImpl> - , public ID3D12TransientResourceHeap + , public ITransientResourceHeapD3D12 { private: typedef TransientResourceHeapBaseImpl<DeviceImpl, BufferResourceImpl> Super; diff --git a/tools/gfx/debug-layer/debug-command-buffer.cpp b/tools/gfx/debug-layer/debug-command-buffer.cpp index aa9c6b8b8..f3c71cb77 100644 --- a/tools/gfx/debug-layer/debug-command-buffer.cpp +++ b/tools/gfx/debug-layer/debug-command-buffer.cpp @@ -22,6 +22,15 @@ DebugCommandBuffer::DebugCommandBuffer() m_rayTracingCommandEncoder.commandBuffer = this; } +ICommandBuffer* DebugCommandBuffer::getInterface(const Slang::Guid& guid) +{ + if (guid == GfxGUID::IID_ICommandBuffer || guid == GfxGUID::IID_ISlangUnknown) + return (DebugObject<ICommandBuffer>*)this; + if (guid == GfxGUID::IID_ICommandBufferD3D12) + return static_cast<ICommandBufferD3D12*>(this); + return nullptr; +} + void DebugCommandBuffer::encodeRenderCommands( IRenderPassLayout* renderPass, IFramebuffer* framebuffer, @@ -127,6 +136,30 @@ Result DebugCommandBuffer::getNativeHandle(InteropHandle* outHandle) return baseObject->getNativeHandle(outHandle); } +void DebugCommandBuffer::invalidateDescriptorHeapBinding() +{ + SLANG_GFX_API_FUNC; + ComPtr<ICommandBufferD3D12> cmdBuf; + if (SLANG_FAILED(baseObject->queryInterface(SlangUUID SLANG_UUID_ICommandBufferD3D12, (void**)cmdBuf.writeRef()))) + { + GFX_DIAGNOSE_ERROR("The current command buffer implementation does not provide ICommandBufferD3D12 interface."); + return; + } + return cmdBuf->invalidateDescriptorHeapBinding(); +} + +void DebugCommandBuffer::ensureInternalDescriptorHeapsBound() +{ + SLANG_GFX_API_FUNC; + ComPtr<ICommandBufferD3D12> cmdBuf; + if (SLANG_FAILED(baseObject->queryInterface(SlangUUID SLANG_UUID_ICommandBufferD3D12, (void**)cmdBuf.writeRef()))) + { + GFX_DIAGNOSE_ERROR("The current command buffer implementation does not provide ICommandBufferD3D12 interface."); + return; + } + return cmdBuf->ensureInternalDescriptorHeapsBound(); +} + void DebugCommandBuffer::checkEncodersClosedBeforeNewEncoder() { if (m_renderCommandEncoder.isOpen || m_resourceCommandEncoder.isOpen || diff --git a/tools/gfx/debug-layer/debug-command-buffer.h b/tools/gfx/debug-layer/debug-command-buffer.h index d7633960b..33709fb2c 100644 --- a/tools/gfx/debug-layer/debug-command-buffer.h +++ b/tools/gfx/debug-layer/debug-command-buffer.h @@ -12,14 +12,13 @@ using namespace Slang; namespace debug { -class DebugCommandBuffer : public DebugObject<ICommandBuffer> +class DebugCommandBuffer : public DebugObject<ICommandBuffer>, ICommandBufferD3D12 { public: SLANG_COM_OBJECT_IUNKNOWN_ALL; public: DebugTransientResourceHeap* m_transientHeap; - private: DebugRenderCommandEncoder m_renderCommandEncoder; DebugComputeCommandEncoder m_computeCommandEncoder; @@ -41,6 +40,8 @@ public: encodeRayTracingCommands(IRayTracingCommandEncoder** outEncoder) override; virtual SLANG_NO_THROW void SLANG_MCALL close() override; virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outHandle) override; + virtual SLANG_NO_THROW void SLANG_MCALL invalidateDescriptorHeapBinding() override; + virtual SLANG_NO_THROW void SLANG_MCALL ensureInternalDescriptorHeapsBound() override; private: void checkEncodersClosedBeforeNewEncoder(); diff --git a/tools/gfx/debug-layer/debug-helper-functions.cpp b/tools/gfx/debug-layer/debug-helper-functions.cpp index 0d2c1d110..10dcedf2a 100644 --- a/tools/gfx/debug-layer/debug-helper-functions.cpp +++ b/tools/gfx/debug-layer/debug-helper-functions.cpp @@ -13,7 +13,6 @@ thread_local const char* _currentFunctionName = nullptr; SLANG_GFX_DEBUG_GET_INTERFACE_IMPL(Device) SLANG_GFX_DEBUG_GET_INTERFACE_IMPL_PARENT(BufferResource, Resource) SLANG_GFX_DEBUG_GET_INTERFACE_IMPL_PARENT(TextureResource, Resource) -SLANG_GFX_DEBUG_GET_INTERFACE_IMPL(CommandBuffer) SLANG_GFX_DEBUG_GET_INTERFACE_IMPL(CommandQueue) SLANG_GFX_DEBUG_GET_INTERFACE_IMPL(Framebuffer) SLANG_GFX_DEBUG_GET_INTERFACE_IMPL(FramebufferLayout) @@ -25,7 +24,6 @@ SLANG_GFX_DEBUG_GET_INTERFACE_IMPL(SamplerState) SLANG_GFX_DEBUG_GET_INTERFACE_IMPL(ShaderObject) SLANG_GFX_DEBUG_GET_INTERFACE_IMPL(ShaderProgram) SLANG_GFX_DEBUG_GET_INTERFACE_IMPL(Swapchain) -SLANG_GFX_DEBUG_GET_INTERFACE_IMPL(TransientResourceHeap) SLANG_GFX_DEBUG_GET_INTERFACE_IMPL(QueryPool) SLANG_GFX_DEBUG_GET_INTERFACE_IMPL_PARENT(AccelerationStructure, ResourceView) SLANG_GFX_DEBUG_GET_INTERFACE_IMPL(Fence) diff --git a/tools/gfx/debug-layer/debug-helper-functions.h b/tools/gfx/debug-layer/debug-helper-functions.h index 1842cf458..f2edd0d84 100644 --- a/tools/gfx/debug-layer/debug-helper-functions.h +++ b/tools/gfx/debug-layer/debug-helper-functions.h @@ -131,13 +131,30 @@ void _gfxDiagnoseImpl(DebugMessageType type, const char* format, TArgs... args) // Utility conversion functions to get Debug* object or the inner object from a user provided // pointer. -#define SLANG_GFX_DEBUG_GET_OBJ_IMPL(type) \ - inline Debug##type* getDebugObj(I##type* ptr) { return static_cast<Debug##type*>(ptr); } \ - inline I##type* getInnerObj(I##type* ptr) \ - { \ - if (!ptr) return nullptr; \ - auto debugObj = getDebugObj(ptr); \ - return debugObj->baseObject; \ +#define SLANG_GFX_DEBUG_GET_OBJ_IMPL(type) \ + inline Debug##type* getDebugObj(I##type* ptr) \ + { \ + return static_cast<Debug##type*>(static_cast<DebugObject<I##type>*>(ptr)); \ + } \ + inline I##type* getInnerObj(I##type* ptr) \ + { \ + if (!ptr) \ + return nullptr; \ + auto debugObj = getDebugObj(ptr); \ + return debugObj->baseObject; \ + } + +#define SLANG_GFX_DEBUG_GET_OBJ_IMPL_UNOWNED(type) \ + inline Debug##type* getDebugObj(I##type* ptr) \ + { \ + return static_cast<Debug##type*>(static_cast<UnownedDebugObject<I##type>*>(ptr)); \ + } \ + inline I##type* getInnerObj(I##type* ptr) \ + { \ + if (!ptr) \ + return nullptr; \ + auto debugObj = getDebugObj(ptr); \ + return debugObj->baseObject; \ } SLANG_GFX_DEBUG_GET_OBJ_IMPL(Device) @@ -145,10 +162,10 @@ SLANG_GFX_DEBUG_GET_OBJ_IMPL(BufferResource) SLANG_GFX_DEBUG_GET_OBJ_IMPL(TextureResource) SLANG_GFX_DEBUG_GET_OBJ_IMPL(CommandBuffer) SLANG_GFX_DEBUG_GET_OBJ_IMPL(CommandQueue) -SLANG_GFX_DEBUG_GET_OBJ_IMPL(ComputeCommandEncoder) -SLANG_GFX_DEBUG_GET_OBJ_IMPL(RenderCommandEncoder) -SLANG_GFX_DEBUG_GET_OBJ_IMPL(ResourceCommandEncoder) -SLANG_GFX_DEBUG_GET_OBJ_IMPL(RayTracingCommandEncoder) +SLANG_GFX_DEBUG_GET_OBJ_IMPL_UNOWNED(ComputeCommandEncoder) +SLANG_GFX_DEBUG_GET_OBJ_IMPL_UNOWNED(RenderCommandEncoder) +SLANG_GFX_DEBUG_GET_OBJ_IMPL_UNOWNED(ResourceCommandEncoder) +SLANG_GFX_DEBUG_GET_OBJ_IMPL_UNOWNED(RayTracingCommandEncoder) SLANG_GFX_DEBUG_GET_OBJ_IMPL(Framebuffer) SLANG_GFX_DEBUG_GET_OBJ_IMPL(FramebufferLayout) SLANG_GFX_DEBUG_GET_OBJ_IMPL(InputLayout) diff --git a/tools/gfx/debug-layer/debug-transient-heap.cpp b/tools/gfx/debug-layer/debug-transient-heap.cpp index 91e575742..84861297a 100644 --- a/tools/gfx/debug-layer/debug-transient-heap.cpp +++ b/tools/gfx/debug-layer/debug-transient-heap.cpp @@ -12,6 +12,23 @@ using namespace Slang; namespace debug { +SlangResult DebugTransientResourceHeap::queryInterface(SlangUUID const& uuid, void** outObject) +{ + if (uuid == GfxGUID::IID_ISlangUnknown || uuid == GfxGUID::IID_ITransientResourceHeap) + *outObject = static_cast<ITransientResourceHeap*>(this); + if (uuid == GfxGUID::IID_ITransientResourceHeapD3D12) + { + RefPtr<DebugTransientResourceHeapD3D12> result = new DebugTransientResourceHeapD3D12(); + baseObject->queryInterface(uuid, (void**)result->baseObject.writeRef()); + returnComPtr((ITransientResourceHeapD3D12**)outObject, result); + return SLANG_OK; + } + else + { + return baseObject->queryInterface(uuid, outObject); + } +} + Result DebugTransientResourceHeap::synchronizeAndReset() { SLANG_GFX_API_FUNC; @@ -32,9 +49,38 @@ Result DebugTransientResourceHeap::createCommandBuffer(ICommandBuffer** outComma auto result = baseObject->createCommandBuffer(outObject->baseObject.writeRef()); if (SLANG_FAILED(result)) return result; - returnComPtr(outCommandBuffer, outObject); + outObject->queryInterface(SlangUUID SLANG_UUID_ICommandBuffer, (void**)outCommandBuffer); return result; } +SlangResult DebugTransientResourceHeapD3D12::queryInterface(SlangUUID const& uuid, void** outObject) +{ + if (uuid == GfxGUID::IID_ISlangUnknown || uuid == GfxGUID::IID_ITransientResourceHeapD3D12) + *outObject = static_cast<ITransientResourceHeapD3D12*>(this); + if (uuid == GfxGUID::IID_ITransientResourceHeap) + { + RefPtr<DebugTransientResourceHeap> result = new DebugTransientResourceHeap(); + baseObject->queryInterface(uuid, (void**)result->baseObject.writeRef()); + returnComPtr((ITransientResourceHeap**)outObject, result); + return SLANG_OK; + } + else + { + return baseObject->queryInterface(uuid, outObject); + } +} + +Result DebugTransientResourceHeapD3D12::allocateTransientDescriptorTable( + DescriptorType type, + GfxCount count, + Offset& outDescriptorOffset, + void** outD3DDescriptorHeapHandle) +{ + SLANG_GFX_API_FUNC; + + return baseObject->allocateTransientDescriptorTable( + type, count, outDescriptorOffset, outD3DDescriptorHeapHandle); +} + } // namespace debug } // namespace gfx diff --git a/tools/gfx/debug-layer/debug-transient-heap.h b/tools/gfx/debug-layer/debug-transient-heap.h index dd89d8a21..60430228d 100644 --- a/tools/gfx/debug-layer/debug-transient-heap.h +++ b/tools/gfx/debug-layer/debug-transient-heap.h @@ -12,15 +12,31 @@ namespace debug class DebugTransientResourceHeap : public DebugObject<ITransientResourceHeap> { public: - SLANG_COM_OBJECT_IUNKNOWN_ALL; + SLANG_COM_OBJECT_IUNKNOWN_ADD_REF; + SLANG_COM_OBJECT_IUNKNOWN_RELEASE; public: - ITransientResourceHeap* getInterface(const Slang::Guid& guid); + virtual SLANG_NO_THROW SlangResult SLANG_MCALL queryInterface(SlangUUID const& uuid, void** outObject) override; + virtual SLANG_NO_THROW Result SLANG_MCALL synchronizeAndReset() override; virtual SLANG_NO_THROW Result SLANG_MCALL finish() override; virtual SLANG_NO_THROW Result SLANG_MCALL createCommandBuffer(ICommandBuffer** outCommandBuffer) override; }; +class DebugTransientResourceHeapD3D12 : public DebugObject<ITransientResourceHeapD3D12> +{ +public: + SLANG_COM_OBJECT_IUNKNOWN_ADD_REF; + SLANG_COM_OBJECT_IUNKNOWN_RELEASE; +public: + virtual SLANG_NO_THROW SlangResult SLANG_MCALL queryInterface(SlangUUID const& uuid, void** outObject) override; + virtual SLANG_NO_THROW Result SLANG_MCALL allocateTransientDescriptorTable( + DescriptorType type, + GfxCount count, + Offset& outDescriptorOffset, + void** outD3DDescriptorHeapHandle) override; +}; + } // namespace debug } // namespace gfx diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp index 8ed776776..f76fa2325 100644 --- a/tools/gfx/renderer-shared.cpp +++ b/tools/gfx/renderer-shared.cpp @@ -46,7 +46,7 @@ const Slang::Guid GfxGUID::IID_IAccelerationStructure = SLANG_UUID_IAcceleration const Slang::Guid GfxGUID::IID_IFence = SLANG_UUID_IFence; const Slang::Guid GfxGUID::IID_IShaderTable = SLANG_UUID_IShaderTable; const Slang::Guid GfxGUID::IID_IPipelineCreationAPIDispatcher = SLANG_UUID_IPipelineCreationAPIDispatcher; -const Slang::Guid GfxGUID::IID_ID3D12TransientResourceHeap = SLANG_UUID_ID3D12TransientResourceHeap; +const Slang::Guid GfxGUID::IID_ITransientResourceHeapD3D12 = SLANG_UUID_ITransientResourceHeapD3D12; StageType translateStage(SlangStage slangStage) diff --git a/tools/gfx/renderer-shared.h b/tools/gfx/renderer-shared.h index a753fe017..b140e1f40 100644 --- a/tools/gfx/renderer-shared.h +++ b/tools/gfx/renderer-shared.h @@ -43,7 +43,7 @@ struct GfxGUID static const Slang::Guid IID_IFence; static const Slang::Guid IID_IShaderTable; static const Slang::Guid IID_IPipelineCreationAPIDispatcher; - static const Slang::Guid IID_ID3D12TransientResourceHeap; + static const Slang::Guid IID_ITransientResourceHeapD3D12; }; bool isGfxDebugLayerEnabled(); |
