summaryrefslogtreecommitdiffstats
path: root/tools/gfx/d3d12
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/d3d12
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/d3d12')
-rw-r--r--tools/gfx/d3d12/d3d12-device.cpp50
-rw-r--r--tools/gfx/d3d12/d3d12-device.h2
2 files changed, 49 insertions, 3 deletions
diff --git a/tools/gfx/d3d12/d3d12-device.cpp b/tools/gfx/d3d12/d3d12-device.cpp
index 863326a94..68078b445 100644
--- a/tools/gfx/d3d12/d3d12-device.cpp
+++ b/tools/gfx/d3d12/d3d12-device.cpp
@@ -28,6 +28,12 @@
# include "../nvapi/nvapi-include.h"
#endif
+#ifdef GFX_NV_AFTERMATH
+# include "GFSDK_Aftermath.h"
+# include "GFSDK_Aftermath_Defines.h"
+# include "GFSDK_Aftermath_GpuCrashDump.h"
+#endif
+
namespace gfx
{
namespace d3d12
@@ -37,6 +43,13 @@ using namespace Slang;
static const uint32_t D3D_FEATURE_LEVEL_12_2 = 0xc200;
+
+#if GFX_NV_AFTERMATH
+/* static */const bool DeviceImpl::g_isAftermathEnabled = true;
+#else
+/* static */const bool DeviceImpl::g_isAftermathEnabled = false;
+#endif
+
struct ShaderModelInfo
{
D3D_SHADER_MODEL shaderModel;
@@ -286,7 +299,7 @@ Result DeviceImpl::_createDevice(
D3D_FEATURE_LEVEL featureLevel,
D3D12DeviceInfo& outDeviceInfo)
{
- if (m_dxDebug && (deviceCheckFlags & DeviceCheckFlag::UseDebug))
+ if (m_dxDebug && (deviceCheckFlags & DeviceCheckFlag::UseDebug) && !g_isAftermathEnabled)
{
m_dxDebug->EnableDebugLayer();
}
@@ -319,7 +332,7 @@ Result DeviceImpl::_createDevice(
return SLANG_FAIL;
}
- if (m_dxDebug && (deviceCheckFlags & DeviceCheckFlag::UseDebug))
+ if (m_dxDebug && (deviceCheckFlags & DeviceCheckFlag::UseDebug) && !g_isAftermathEnabled)
{
ComPtr<ID3D12InfoQueue> infoQueue;
if (SLANG_SUCCEEDED(device->QueryInterface(infoQueue.writeRef())))
@@ -373,6 +386,35 @@ Result DeviceImpl::_createDevice(
}
}
+
+#ifdef GFX_NV_AFTERMATH
+ {
+ if ((deviceCheckFlags & DeviceCheckFlag::UseDebug) && g_isAftermathEnabled)
+ {
+ // Initialize Nsight Aftermath for this device.
+ // This combination of flags is not necessarily appropraite for real world usage
+ const uint32_t aftermathFlags =
+ GFSDK_Aftermath_FeatureFlags_EnableMarkers | // Enable event marker tracking.
+ GFSDK_Aftermath_FeatureFlags_CallStackCapturing | // Enable automatic call stack event markers.
+ GFSDK_Aftermath_FeatureFlags_EnableResourceTracking | // Enable tracking of resources.
+ GFSDK_Aftermath_FeatureFlags_GenerateShaderDebugInfo | // Generate debug information for shaders.
+ GFSDK_Aftermath_FeatureFlags_EnableShaderErrorReporting; // Enable additional runtime shader error reporting.
+
+ auto initResult = GFSDK_Aftermath_DX12_Initialize(
+ GFSDK_Aftermath_Version_API,
+ aftermathFlags,
+ device);
+
+ if ( initResult != GFSDK_Aftermath_Result_Success)
+ {
+ SLANG_ASSERT_FAILURE("Unable to initialize aftermath");
+ // Unable to initialize
+ return SLANG_FAIL;
+ }
+ }
+ }
+#endif
+
// Get the descs
{
adapter->GetDesc(&outDeviceInfo.m_desc);
@@ -474,7 +516,9 @@ Result DeviceImpl::initialize(const Desc& desc)
}
#endif
- if (ENABLE_DEBUG_LAYER || isGfxDebugLayerEnabled())
+
+ // If Aftermath is enabled, we can't enable the D3D12 debug layer as well
+ if (ENABLE_DEBUG_LAYER || isGfxDebugLayerEnabled() && !g_isAftermathEnabled)
{
m_D3D12GetDebugInterface =
(PFN_D3D12_GET_DEBUG_INTERFACE)loadProc(d3dModule, "D3D12GetDebugInterface");
diff --git a/tools/gfx/d3d12/d3d12-device.h b/tools/gfx/d3d12/d3d12-device.h
index 975ba419b..6bbdde9d0 100644
--- a/tools/gfx/d3d12/d3d12-device.h
+++ b/tools/gfx/d3d12/d3d12-device.h
@@ -56,6 +56,8 @@ public:
ComPtr<ID3D12Debug> m_dxDebug;
+ static const bool g_isAftermathEnabled;
+
D3D12DeviceInfo m_deviceInfo;
ID3D12Device* m_device = nullptr;
ID3D12Device5* m_device5 = nullptr;