summaryrefslogtreecommitdiffstats
path: root/tools/gfx/d3d
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2023-07-18 18:45:38 -0400
committerGitHub <noreply@github.com>2023-07-18 15:45:38 -0700
commit1fe5e83f3dcc8ef0efa2dd083ebdfab5d0f101a9 (patch)
tree9ea88993d0b1f5cad76c21ae3a60ed561bdc3c83 /tools/gfx/d3d
parent4cb3eeb832b5fb29a61f2934b3daa5e42a3d6cde (diff)
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.
Diffstat (limited to 'tools/gfx/d3d')
-rw-r--r--tools/gfx/d3d/d3d-swapchain.h10
-rw-r--r--tools/gfx/d3d/d3d-util.cpp60
-rw-r--r--tools/gfx/d3d/d3d-util.h4
3 files changed, 73 insertions, 1 deletions
diff --git a/tools/gfx/d3d/d3d-swapchain.h b/tools/gfx/d3d/d3d-swapchain.h
index 0d4b3fafb..c9e0de82a 100644
--- a/tools/gfx/d3d/d3d-swapchain.h
+++ b/tools/gfx/d3d/d3d-swapchain.h
@@ -99,7 +99,15 @@ public:
}
virtual SLANG_NO_THROW Result SLANG_MCALL present() override
{
- if (SLANG_FAILED(m_swapChain->Present(m_desc.enableVSync ? 1 : 0, 0)))
+ const auto res = m_swapChain->Present(m_desc.enableVSync ? 1 : 0, 0);
+
+ // We may want to wait for crash dump completion for some kinds of debugging scenarios
+ if (res == DXGI_ERROR_DEVICE_REMOVED || res == DXGI_ERROR_DEVICE_RESET)
+ {
+ D3DUtil::waitForCrashDumpCompletion(res);
+ }
+
+ if (SLANG_FAILED(res))
{
return SLANG_FAIL;
}
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<ComPtr<IDXGIAdapter>>& outDxgiAdapters)
{
outDxgiAdapters.clear();
diff --git a/tools/gfx/d3d/d3d-util.h b/tools/gfx/d3d/d3d-util.h
index a35928f47..ce40ec722 100644
--- a/tools/gfx/d3d/d3d-util.h
+++ b/tools/gfx/d3d/d3d-util.h
@@ -121,6 +121,10 @@ class D3DUtil
static D3D12_RESOURCE_STATES getResourceState(ResourceState state);
static SlangResult reportLiveObjects();
+
+ /// Call after a DXGI_ERROR_DEVICE_REMOVED/DXGI_ERROR_DEVICE_RESET on present, to wait for
+ /// dumping to complete. Will return SLANG_OK if wait happened successfully
+ static SlangResult waitForCrashDumpCompletion(HRESULT res);
};
#if SLANG_GFX_HAS_DXR_SUPPORT