2
3
4
5
6
35
36
48
49
50
51
52
53
54
55
56
57
59 GFSDK_Aftermath_Version_API ,
60 GFSDK_Aftermath_GpuCrashDumpWatchedApiFlags_Vulkan ,
61 GFSDK_Aftermath_GpuCrashDumpFeatureFlags_DeferDebugInfoCallbacks ,
62 GpuCrashDumpCallback ,
63 ShaderDebugInfoCallback ,
64 CrashDumpDescriptionCallback ,
65 ResolveMarkerCallback ,
76 if (!m_GpuCrashTracker)
78 m_GpuCrashTracker = std::make_unique<GpuCrashTracker>();
79 m_GpuCrashTracker->Initialize();
90 constexpr auto tdrTerminationTimeout = std::chrono::seconds(3);
91 const auto tStart = std::chrono::steady_clock::now();
92 auto tElapsed = std::chrono::milliseconds::zero();
94 GFSDK_Aftermath_CrashDump_Status status = GFSDK_Aftermath_CrashDump_Status_Unknown;
97 while (status != GFSDK_Aftermath_CrashDump_Status_CollectingDataFailed &&
98 status != GFSDK_Aftermath_CrashDump_Status_Finished &&
99 tElapsed < tdrTerminationTimeout)
102 std::this_thread::sleep_for(std::chrono::milliseconds(50));
105 auto tEnd = std::chrono::steady_clock::now();
106 tElapsed = std::chrono::duration_cast<std::chrono::milliseconds>(tEnd - tStart);
109 if (status == GFSDK_Aftermath_CrashDump_Status_Finished)
111 std::stringstream ss;
112 ss <<
"Aftermath finished processing the crash dump ";
113 SPICES_CORE_INFO(ss.str());
117 std::stringstream err_msg;
118 err_msg <<
"Unexpected crash dump status: " << status;
119 SPICES_CORE_CRITICAL(err_msg.str().c_str())
132 m_MarkerMap[m_FrameCut].clear();
139 markerId = m_MarkerMap[m_FrameCut].size();
140 m_MarkerMap[m_FrameCut][markerId] = info;
147 std::lock_guard<std::mutex> lock(m_Mutex);
150
151
159 std::lock_guard<std::mutex> lock(m_Mutex);
162
163
164 GFSDK_Aftermath_ShaderDebugInfoIdentifier identifier = {};
166 GFSDK_Aftermath_Version_API ,
168 shaderDebugInfoSize ,
173
174
175
176 std::vector<uint8_t> data(
177 (uint8_t*)pShaderDebugInfo,
178 (uint8_t*)pShaderDebugInfo + shaderDebugInfoSize
180 m_ShaderDebugInfo[identifier].swap(data);
183
184
185 WriteShaderDebugInformationToFile(identifier, pShaderDebugInfo, shaderDebugInfoSize);
188 void GpuCrashTracker::OnDescription(PFN_GFSDK_Aftermath_AddGpuCrashDumpDescription addDescription)
193
194
195
196
197 addDescription(GFSDK_Aftermath_GpuCrashDumpDescriptionKey_ApplicationName ,
"SpicesEngineNsightAftermath");
198 addDescription(GFSDK_Aftermath_GpuCrashDumpDescriptionKey_ApplicationVersion ,
"v1.0");
199 addDescription(GFSDK_Aftermath_GpuCrashDumpDescriptionKey_UserDefined ,
"Aftermath GPU Crash Dump.");
200 addDescription(GFSDK_Aftermath_GpuCrashDumpDescriptionKey_UserDefined + 1 ,
"Engine State: Rendering.");
201 addDescription(GFSDK_Aftermath_GpuCrashDumpDescriptionKey_UserDefined + 2 ,
"More user-defined information...");
205 const void* pMarkerData ,
206 const uint32_t markerDataSize ,
207 void** ppResolvedMarkerData ,
208 uint32_t* pResolvedMarkerDataSize
214
215
216
217 for (
auto& map : m_MarkerMap)
219 const auto& foundMarker = map.find(
reinterpret_cast<uint64_t>(pMarkerData));
220 if (foundMarker != map.end())
222 const std::string& foundMarkerData = foundMarker->second;
225 *ppResolvedMarkerData = (
void*)foundMarkerData.data();
226 *pResolvedMarkerDataSize =
static_cast<uint32_t>(foundMarkerData.length());
237
238
239 GFSDK_Aftermath_GpuCrashDump_Decoder decoder = {};
241 GFSDK_Aftermath_Version_API ,
248
249
250
251 GFSDK_Aftermath_GpuCrashDump_BaseInfo baseInfo = {};
255
256
257
258 uint32_t applicationNameLength = 0;
261 GFSDK_Aftermath_GpuCrashDumpDescriptionKey_ApplicationName ,
262 &applicationNameLength
265 std::vector<
char> applicationName(applicationNameLength,
'\0');
269 GFSDK_Aftermath_GpuCrashDumpDescriptionKey_ApplicationName ,
270 static_cast<uint32_t>(applicationName.size()) ,
271 applicationName.data()
275
276
277
278
279
280 static int count = 0;
281 const std::string baseFileName =
282 std::string(applicationName.data())
284 + std::to_string(baseInfo.pid)
286 + std::to_string(++count);
289
290
294 auto error = time(&timep);
295 p = localtime(&timep);
297 std::stringstream ss;
298 ss << SPICES_GPUCRASHREPORT_PATH <<
303 p->tm_min <<
"00" <<
"/";
304 std::filesystem::create_directories(ss.str());
307
308
309
310 const std::string crashDumpFileName = baseFileName +
".nv-gpudmp";
311 std::ofstream dumpFile(ss.str() + crashDumpFileName, std::ios::out | std::ios::binary);
314 dumpFile.write(
static_cast<
const char*>(pGpuCrashDump), gpuCrashDumpSize);
319
320
321
322 uint32_t jsonSize = 0;
325 GFSDK_Aftermath_GpuCrashDumpDecoderFlags_ALL_INFO ,
326 GFSDK_Aftermath_GpuCrashDumpFormatterFlags_NONE ,
327 ShaderDebugInfoLookupCallback ,
328 ShaderLookupCallback ,
329 ShaderSourceDebugInfoLookupCallback ,
335
336
337 std::vector<
char> json(jsonSize);
340 static_cast<uint32_t>(json.size()) ,
345
346
347 const std::string jsonFileName = crashDumpFileName +
".json";
348 std::ofstream jsonFile(ss.str() + jsonFileName, std::ios::out | std::ios::binary);
352
353
354 jsonFile.write(json.data(), json.size() - 1);
359
360
365 GFSDK_Aftermath_ShaderDebugInfoIdentifier identifier ,
366 const void* pShaderDebugInfo ,
367 const uint32_t shaderDebugInfoSize
373
374
378 auto error = time(&timep);
379 p = localtime(&timep);
381 std::stringstream ss;
382 ss << SPICES_GPUCRASHREPORT_PATH <<
387 p->tm_min <<
"00" <<
"/";
388 std::filesystem::create_directories(ss.str());
391
392
393 const std::string filePath =
"shader-" + std::to_string(identifier) +
".nvdbg";
394 std::ofstream f(ss.str() + filePath, std::ios::out | std::ios::binary);
397 f.write(
static_cast<
const char*>(pShaderDebugInfo), shaderDebugInfoSize);
403 const GFSDK_Aftermath_ShaderDebugInfoIdentifier& identifier ,
404 PFN_GFSDK_Aftermath_SetData setShaderDebugInfo
411
412
413 const auto i_debugInfo = m_ShaderDebugInfo.find(identifier);
414 if (i_debugInfo == m_ShaderDebugInfo.end())
417
418
423
424
425
426 setShaderDebugInfo(i_debugInfo->second.data(),
static_cast<uint32_t>(i_debugInfo->second.size()));
430 const GFSDK_Aftermath_ShaderBinaryHash& shaderHash ,
431 PFN_GFSDK_Aftermath_SetData setShaderBinary
438
439
440 std::vector<uint8_t> shaderBinary;
441 if (!m_ShaderDataBase.FindShaderBinary(shaderHash, shaderBinary))
444
445
450
451
452
453 setShaderBinary(shaderBinary.data(),
static_cast<uint32_t>(shaderBinary.size()));
457 const GFSDK_Aftermath_ShaderDebugName& shaderDebugName ,
458 PFN_GFSDK_Aftermath_SetData setShaderBinary
465
466
467 std::vector<uint8_t> shaderBinary;
468 if (!m_ShaderDataBase.FindShaderBinaryWithDebugData(shaderDebugName, shaderBinary))
471
472
477
478
479
480 setShaderBinary(shaderBinary.data(),
static_cast<uint32_t>(shaderBinary.size()));
484 const void* pGpuCrashDump ,
485 const uint32_t gpuCrashDumpSize ,
496 const void* pShaderDebugInfo ,
497 const uint32_t shaderDebugInfoSize ,
508 PFN_GFSDK_Aftermath_AddGpuCrashDumpDescription addDescription ,
515 pGpuCrashTracker->OnDescription(addDescription);
519 const void* pMarkerData ,
520 const uint32_t markerDataSize ,
522 void** ppResolvedMarkerData ,
523 uint32_t* pResolvedMarkerDataSize
529 pGpuCrashTracker
->OnResolveMarker(pMarkerData
, markerDataSize
, ppResolvedMarkerData
, pResolvedMarkerDataSize
);
533 const GFSDK_Aftermath_ShaderDebugInfoIdentifier* pIdentifier ,
534 PFN_GFSDK_Aftermath_SetData setShaderDebugInfo ,
541 pGpuCrashTracker->OnShaderDebugInfoLookup(*pIdentifier, setShaderDebugInfo);
545 const GFSDK_Aftermath_ShaderBinaryHash* pShaderHash ,
546 PFN_GFSDK_Aftermath_SetData setShaderBinary ,
553 pGpuCrashTracker->OnShaderLookup(*pShaderHash, setShaderBinary);
557 const GFSDK_Aftermath_ShaderDebugName* pShaderDebugName ,
558 PFN_GFSDK_Aftermath_SetData setShaderBinary ,
565 pGpuCrashTracker->OnShaderSourceDebugInfoLookup(*pShaderDebugName, setShaderBinary);
#define AFTERMATH_CHECK_ERROR(FC)
Helper macro for checking Nsight Aftermath results and throwing exception in case of a failure.
#define SPICES_PROFILE_ZONE
static void Init()
Create single instance of this class.
static constexpr unsigned int c_MarkerFrameHistory
keep four frames worth of marker history.
void WriteShaderDebugInformationToFile(GFSDK_Aftermath_ShaderDebugInfoIdentifier identifier, const void *pShaderDebugInfo, const uint32_t shaderDebugInfoSize) const
Helper for writing shader debug information to a file.
void SetMarker(uint64_t &markerId, const std::string &info)
Set Marker.
void OnShaderLookup(const GFSDK_Aftermath_ShaderBinaryHash &shaderHash, PFN_GFSDK_Aftermath_SetData setShaderBinary) const
Handler for shader lookup callbacks. This is used by the JSON decoder for mapping shader instruction ...
void SetFrameCut(uint64_t frameCut)
Set FrameCut.
virtual ~GpuCrashTracker()
Destructor Function.
static void AftermathDeviceLostCheck()
Aftermath handle device lost function.
void OnResolveMarker(const void *pMarkerData, const uint32_t markerDataSize, void **ppResolvedMarkerData, uint32_t *pResolvedMarkerDataSize)
Handler for app-managed marker resolve callback.
std::mutex m_Mutex
For thread-safe access of GPU crash tracker state.
GpuCrashTracker()
Constructor Function.
static std::unique_ptr< GpuCrashTracker > m_GpuCrashTracker
GpuCrashTracker single instance.
static void ShaderDebugInfoCallback(const void *pShaderDebugInfo, const uint32_t shaderDebugInfoSize, void *pUserData)
Shader debug information callback.
bool m_Initialized
Is the GPU crash dump tracker initialized?
uint32_t m_FrameCut
Frame Count cut.
void OnCrashDump(const void *pGpuCrashDump, const uint32_t gpuCrashDumpSize)
Handler for GPU crash dump callbacks from Nsight Aftermath.
void OnShaderDebugInfo(const void *pShaderDebugInfo, const uint32_t shaderDebugInfoSize)
Handler for shader debug information callbacks.
void Initialize()
Initialize the GPU crash dump tracker.
static void GpuCrashDumpCallback(const void *pGpuCrashDump, const uint32_t gpuCrashDumpSize, void *pUserData)
GPU crash dump callback.
void OnShaderSourceDebugInfoLookup(const GFSDK_Aftermath_ShaderDebugName &shaderDebugName, PFN_GFSDK_Aftermath_SetData setShaderBinary) const
Handler for shader source debug info lookup callbacks. This is used by the JSON decoder for mapping s...
void WriteGpuCrashDumpToFile(const void *pGpuCrashDump, const uint32_t gpuCrashDumpSize)
Helper for writing a GPU crash dump to a file.
static void ResolveMarkerCallback(const void *pMarkerData, const uint32_t markerDataSize, void *pUserData, void **ppResolvedMarkerData, uint32_t *pResolvedMarkerDataSize)
App-managed marker resolve callback.
void OnShaderDebugInfoLookup(const GFSDK_Aftermath_ShaderDebugInfoIdentifier &identifier, PFN_GFSDK_Aftermath_SetData setShaderDebugInfo) const
Handler for shader debug information lookup callbacks. This is used by the JSON decoder for mapping s...
Implements GPU crash dump tracking using the Nsight Aftermath API.