From 1fe5e83f3dcc8ef0efa2dd083ebdfab5d0f101a9 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 18 Jul 2023 18:45:38 -0400 Subject: nsight Aftermath crash example (#2984) * Small fixes and improvements around reflection tool. * Make PrettyWriter printing a class. * Aftermath crash demo WIP. * Enable aftermath in test project. * Setting failCount. * Dumping out of source maps. * Improve comments. Simplify handling of compile products. * Other small fixes to aftermath example. * Added Emit SourceLocType. Track sourcemap association meaning. Improved documentation. * Small improvements. * Capture debug information for D3D11/D3D12/Vulkan. * Enable debug info. * Small improvements. * Improve aftermath example README.md. --- tools/gfx/d3d/d3d-util.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'tools/gfx/d3d/d3d-util.cpp') diff --git a/tools/gfx/d3d/d3d-util.cpp b/tools/gfx/d3d/d3d-util.cpp index e1ffc0efc..34d615744 100644 --- a/tools/gfx/d3d/d3d-util.cpp +++ b/tools/gfx/d3d/d3d-util.cpp @@ -14,6 +14,14 @@ #include "core/slang-basic.h" #include "core/slang-platform.h" +#ifdef GFX_NV_AFTERMATH +# include "GFSDK_Aftermath.h" +# include "GFSDK_Aftermath_Defines.h" +# include "GFSDK_Aftermath_GpuCrashDump.h" + +# include "core/slang-process.h" +#endif + namespace gfx { using namespace Slang; @@ -870,6 +878,58 @@ Result SLANG_MCALL reportD3DLiveObjects() return D3DUtil::reportLiveObjects(); } + +/* static */SlangResult D3DUtil::waitForCrashDumpCompletion(HRESULT res) +{ + // If it's not a device remove/reset then theres nothing to wait for + if (!(res == DXGI_ERROR_DEVICE_REMOVED || res == DXGI_ERROR_DEVICE_RESET)) + { + return SLANG_OK; + } + +#if GFX_NV_AFTERMATH + { + GFSDK_Aftermath_CrashDump_Status status = GFSDK_Aftermath_CrashDump_Status_Unknown; + if (GFSDK_Aftermath_GetCrashDumpStatus(&status) != GFSDK_Aftermath_Result_Success) + { + return SLANG_FAIL; + } + + const auto startTick = Process::getClockTick(); + const auto frequency = Process::getClockFrequency(); + + float timeOutInSecs = 1.0f; + + uint64_t timeOutTicks = uint64_t(frequency * timeOutInSecs) + 1; + + // Loop while Aftermath crash dump data collection has not finished or + // the application is still processing the crash dump data. + while (status != GFSDK_Aftermath_CrashDump_Status_CollectingDataFailed && + status != GFSDK_Aftermath_CrashDump_Status_Finished && + Process::getClockTick() - startTick < timeOutTicks) + { + // Sleep a couple of milliseconds and poll the status again. + Process::sleepCurrentThread(50); + if (GFSDK_Aftermath_GetCrashDumpStatus(&status) != GFSDK_Aftermath_Result_Success) + { + return SLANG_FAIL; + } + } + + if (status == GFSDK_Aftermath_CrashDump_Status_Finished) + { + return SLANG_OK; + } + else + { + return SLANG_E_TIME_OUT; + } + } +#endif + + return SLANG_OK; +} + /* static */SlangResult D3DUtil::findAdapters(DeviceCheckFlags flags, const AdapterLUID* adapterLUID, IDXGIFactory* dxgiFactory, List>& outDxgiAdapters) { outDxgiAdapters.clear(); -- cgit v1.2.3