summaryrefslogtreecommitdiffstats
path: root/tools/gfx/debug-layer
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-10-12 14:51:13 -0700
committerGitHub <noreply@github.com>2022-10-12 14:51:13 -0700
commit344898b091867e5450a3fa432a207d75255df77a (patch)
treee9779a112e371ad141d1f6d9b8778acb4207179b /tools/gfx/debug-layer
parentd96250bcc2e8fedb485df3ed0fdc28f89f6d23c8 (diff)
Add gfx debug layer trampoline for D3D12 interfaces. (#2445)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tools/gfx/debug-layer')
-rw-r--r--tools/gfx/debug-layer/debug-command-buffer.cpp33
-rw-r--r--tools/gfx/debug-layer/debug-command-buffer.h5
-rw-r--r--tools/gfx/debug-layer/debug-helper-functions.cpp2
-rw-r--r--tools/gfx/debug-layer/debug-helper-functions.h39
-rw-r--r--tools/gfx/debug-layer/debug-transient-heap.cpp48
-rw-r--r--tools/gfx/debug-layer/debug-transient-heap.h20
6 files changed, 129 insertions, 18 deletions
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