From 785669c8771c01d57914ec0075315e8ae61b6a31 Mon Sep 17 00:00:00 2001 From: AlexisPollonni <43394202+AlexisPollonni@users.noreply.github.com> Date: Wed, 23 Apr 2025 08:48:44 +0200 Subject: Fixed various queryInterface implementations (#6863) * Fix: Improper implementation in RendererBase::queryInterface In the case an arbitrary uuid was passed to RendererBase::QueryInterface it would return SLANG_OK while the outObject is null. This is improper and unexpected from an IUnkown implementation. Additionally, the function did not call addRef() when concerning an IDevice interface. * Fix: DebugTransientResourceHeap::queryInterface returns wrong interface When trying to query for the transient heap if the debug layer is enabled, queryInterface would set the outObject to the inner api specific heap (ex: vk::TransientResourceImpl) and NOT the debug heap. This causes a side effect when creating a command buffer that debug wrappers would not be used. The debug version will not be returned, and this snowballs causing an access violation when trying to bind a compute pipeline state. After this fix, debug wrappers for transient heaps, command buffers, encoders, etc... wil be used correctly. * fix weird whitespace change --- tools/gfx/debug-layer/debug-transient-heap.cpp | 10 ++++++---- tools/gfx/renderer-shared.cpp | 9 +++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'tools') diff --git a/tools/gfx/debug-layer/debug-transient-heap.cpp b/tools/gfx/debug-layer/debug-transient-heap.cpp index 424a8feb1..5b0219fb7 100644 --- a/tools/gfx/debug-layer/debug-transient-heap.cpp +++ b/tools/gfx/debug-layer/debug-transient-heap.cpp @@ -14,7 +14,11 @@ namespace debug SlangResult DebugTransientResourceHeap::queryInterface(SlangUUID const& uuid, void** outObject) { if (uuid == GfxGUID::IID_ISlangUnknown || uuid == GfxGUID::IID_ITransientResourceHeap) + { *outObject = static_cast(this); + addRef(); + return SLANG_OK; + } if (uuid == GfxGUID::IID_ITransientResourceHeapD3D12) { RefPtr result = new DebugTransientResourceHeapD3D12(); @@ -22,10 +26,8 @@ SlangResult DebugTransientResourceHeap::queryInterface(SlangUUID const& uuid, vo returnComPtr((ITransientResourceHeapD3D12**)outObject, result); return SLANG_OK; } - else - { - return baseObject->queryInterface(uuid, outObject); - } + + return baseObject->queryInterface(uuid, outObject); } Result DebugTransientResourceHeap::synchronizeAndReset() diff --git a/tools/gfx/renderer-shared.cpp b/tools/gfx/renderer-shared.cpp index cb25079fb..d68ce4ee8 100644 --- a/tools/gfx/renderer-shared.cpp +++ b/tools/gfx/renderer-shared.cpp @@ -405,8 +405,13 @@ SlangResult RendererBase::queryInterface(SlangUUID const& uuid, void** outObject return SLANG_OK; } - *outObject = getInterface(uuid); - return SLANG_OK; + if (IDevice* device_ptr = getInterface(uuid)) + { + *outObject = device_ptr; + addRef(); + return SLANG_OK; + } + return SLANG_E_NO_INTERFACE; } IDevice* gfx::RendererBase::getInterface(const Guid& guid) -- cgit v1.2.3