diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/gfx/d3d/d3d-util.cpp | 33 | ||||
| -rw-r--r-- | tools/gfx/d3d/d3d-util.h | 2 | ||||
| -rw-r--r-- | tools/gfx/debug-layer/debug-swap-chain.cpp | 6 | ||||
| -rw-r--r-- | tools/gfx/gfx.slang | 4 | ||||
| -rw-r--r-- | tools/gfx/render.cpp | 11 |
5 files changed, 54 insertions, 2 deletions
diff --git a/tools/gfx/d3d/d3d-util.cpp b/tools/gfx/d3d/d3d-util.cpp index dff93810c..05a948773 100644 --- a/tools/gfx/d3d/d3d-util.cpp +++ b/tools/gfx/d3d/d3d-util.cpp @@ -4,6 +4,7 @@ #include <d3d12.h> #include <d3dcompiler.h> #include <dxgi1_4.h> +#include <dxgidebug.h> // We will use the C standard library just for printing error messages. #include <stdio.h> @@ -836,6 +837,38 @@ D3D12_RESOURCE_STATES D3DUtil::getResourceState(ResourceState state) } } +/* static */SlangResult D3DUtil::reportLiveObjects() +{ + static IDXGIDebug* dxgiDebug = nullptr; + + if (!dxgiDebug) + { + HMODULE debugModule = LoadLibraryA("dxgidebug.dll"); + if (debugModule != INVALID_HANDLE_VALUE) + { + auto fun = reinterpret_cast<decltype(&DXGIGetDebugInterface)>(GetProcAddress(debugModule, "DXGIGetDebugInterface")); + if (fun) + { + fun(__uuidof(IDXGIDebug), (void**)&dxgiDebug); + } + } + } + + if (dxgiDebug) + { + const GUID DXGI_DEBUG_ALL_ = { 0xe48ae283, 0xda80, 0x490b, { 0x87, 0xe6, 0x43, 0xe9, 0xa9, 0xcf, 0xda, 0x8 } }; + dxgiDebug->ReportLiveObjects(DXGI_DEBUG_ALL_, DXGI_DEBUG_RLO_ALL); + return SLANG_OK; + } + + return SLANG_E_NOT_AVAILABLE; +} + +Result SLANG_MCALL reportD3DLiveObjects() +{ + return D3DUtil::reportLiveObjects(); +} + /* static */SlangResult D3DUtil::findAdapters(DeviceCheckFlags flags, const AdapterLUID* adapterLUID, IDXGIFactory* dxgiFactory, List<ComPtr<IDXGIAdapter>>& outDxgiAdapters) { outDxgiAdapters.clear(); diff --git a/tools/gfx/d3d/d3d-util.h b/tools/gfx/d3d/d3d-util.h index 4e5880c0a..617ae4af2 100644 --- a/tools/gfx/d3d/d3d-util.h +++ b/tools/gfx/d3d/d3d-util.h @@ -122,6 +122,8 @@ class D3DUtil static uint32_t getSubresourceMipLevel(uint32_t subresourceIndex, uint32_t mipLevelCount); static D3D12_RESOURCE_STATES getResourceState(ResourceState state); + + static SlangResult reportLiveObjects(); }; #if SLANG_GFX_HAS_DXR_SUPPORT diff --git a/tools/gfx/debug-layer/debug-swap-chain.cpp b/tools/gfx/debug-layer/debug-swap-chain.cpp index 3c8058b5c..b1d3bc201 100644 --- a/tools/gfx/debug-layer/debug-swap-chain.cpp +++ b/tools/gfx/debug-layer/debug-swap-chain.cpp @@ -55,8 +55,10 @@ Result DebugSwapchain::resize(GfxCount width, GfxCount height) { if (image->debugGetReferenceCount() != 1) { - GFX_DIAGNOSE_ERROR("all swapchain images must be released before calling resize()."); - return SLANG_FAIL; + // Only warn here because tools like NSight might keep + // an additional reference to swapchain images. + GFX_DIAGNOSE_WARNING("all swapchain images must be released before calling resize()."); + break; } } m_images.clearAndDeallocate(); diff --git a/tools/gfx/gfx.slang b/tools/gfx/gfx.slang index 3d75e3b40..e8750ada7 100644 --- a/tools/gfx/gfx.slang +++ b/tools/gfx/gfx.slang @@ -1957,6 +1957,10 @@ SLANG_GFX_IMPORT Result gfxGetFormatInfo(Format format, FormatInfo *outInfo); /// Given a type returns a function that can construct it, or nullptr if there isn't one SLANG_GFX_IMPORT Result gfxCreateDevice(const DeviceDesc* desc, out Optional<IDevice> outDevice); +/// Reports current set of live objects in gfx. +/// Currently this only calls D3D's ReportLiveObjects. +SLANG_GFX_IMPORT Result gfxReportLiveObjects(); + /// Sets a callback for receiving debug messages. /// The layer does not hold a strong reference to the callback object. /// The user is responsible for holding the callback object alive. diff --git a/tools/gfx/render.cpp b/tools/gfx/render.cpp index 84f537705..048eb8224 100644 --- a/tools/gfx/render.cpp +++ b/tools/gfx/render.cpp @@ -21,6 +21,8 @@ Result SLANG_MCALL getD3D12Adapters(List<AdapterInfo>& outAdapters); Result SLANG_MCALL getVKAdapters(List<AdapterInfo>& outAdapters); Result SLANG_MCALL getCUDAAdapters(List<AdapterInfo>& outAdapters); +Result SLANG_MCALL reportD3DLiveObjects(); + static bool debugLayerEnabled = false; bool isGfxDebugLayerEnabled() { return debugLayerEnabled; } @@ -364,6 +366,15 @@ extern "C" return resultCode; } + SLANG_GFX_API SlangResult SLANG_MCALL + gfxReportLiveObjects() + { +#if SLANG_WINDOWS_FAMILY + SLANG_RETURN_ON_FAIL(reportD3DLiveObjects()); +#endif + return SLANG_OK; + } + SLANG_GFX_API SlangResult SLANG_MCALL gfxSetDebugCallback(IDebugCallback* callback) { _getDebugCallback() = callback; |
