From 0e232cfdc111d7a3dcbe590acdbd35f7e1f7645d Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Mon, 30 Mar 2020 05:21:59 -0300 Subject: renderer_vulkan: Integrate Nvidia Nsight Aftermath on Windows Adds optional support for Nsight Aftermath. It is enabled through ENABLE_NSIGHT_AFTERMATH in cmake. A path to the SDK has to be provided by the environment variable NSIGHT_AFTERMATH_SDK. Nsight Aftermath allows an application to generate "minidumps" of the GPU state when a device loss happens. By analysing these on Nsight we can know what a game was doing and why it triggered a device loss. The dump is generated inside %APPDATA%\yuzu\log\gpucrash and this directory is deleted every time a new instance is initialized with Nsight enabled. To enable it on yuzu there has a to be a driver and device capable of running Nsight Aftermath on Vulkan. That means only Turing based GPUs on the latest stable driver, beta drivers won't work for now. It is manually enabled in Configuration>Debug>Enable Graphics Debugging because when using all debugging capabilities there is a runtime cost. --- .../renderer_vulkan/nsight_aftermath_tracker.h | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/video_core/renderer_vulkan/nsight_aftermath_tracker.h (limited to 'src/video_core/renderer_vulkan/nsight_aftermath_tracker.h') diff --git a/src/video_core/renderer_vulkan/nsight_aftermath_tracker.h b/src/video_core/renderer_vulkan/nsight_aftermath_tracker.h new file mode 100644 index 000000000..afe7ae99e --- /dev/null +++ b/src/video_core/renderer_vulkan/nsight_aftermath_tracker.h @@ -0,0 +1,87 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include + +#define VK_NO_PROTOTYPES +#include + +#ifdef HAS_NSIGHT_AFTERMATH +#include +#include +#include +#endif + +#include "common/common_types.h" +#include "common/dynamic_library.h" + +namespace Vulkan { + +class NsightAftermathTracker { +public: + NsightAftermathTracker(); + ~NsightAftermathTracker(); + + NsightAftermathTracker(const NsightAftermathTracker&) = delete; + NsightAftermathTracker& operator=(const NsightAftermathTracker&) = delete; + + // Delete move semantics because Aftermath initialization uses a pointer to this. + NsightAftermathTracker(NsightAftermathTracker&&) = delete; + NsightAftermathTracker& operator=(NsightAftermathTracker&&) = delete; + + bool Initialize(); + + void SaveShader(const std::vector& spirv) const; + +private: +#ifdef HAS_NSIGHT_AFTERMATH + static void GpuCrashDumpCallback(const void* gpu_crash_dump, u32 gpu_crash_dump_size, + void* user_data); + + static void ShaderDebugInfoCallback(const void* shader_debug_info, u32 shader_debug_info_size, + void* user_data); + + static void CrashDumpDescriptionCallback( + PFN_GFSDK_Aftermath_AddGpuCrashDumpDescription add_description, void* user_data); + + void OnGpuCrashDumpCallback(const void* gpu_crash_dump, u32 gpu_crash_dump_size); + + void OnShaderDebugInfoCallback(const void* shader_debug_info, u32 shader_debug_info_size); + + void OnCrashDumpDescriptionCallback( + PFN_GFSDK_Aftermath_AddGpuCrashDumpDescription add_description); + + mutable std::mutex mutex; + + std::string dump_dir; + int dump_id = 0; + + bool initialized = false; + + Common::DynamicLibrary dl; + PFN_GFSDK_Aftermath_DisableGpuCrashDumps GFSDK_Aftermath_DisableGpuCrashDumps; + PFN_GFSDK_Aftermath_EnableGpuCrashDumps GFSDK_Aftermath_EnableGpuCrashDumps; + PFN_GFSDK_Aftermath_GetShaderDebugInfoIdentifier GFSDK_Aftermath_GetShaderDebugInfoIdentifier; + PFN_GFSDK_Aftermath_GetShaderHashSpirv GFSDK_Aftermath_GetShaderHashSpirv; + PFN_GFSDK_Aftermath_GpuCrashDump_CreateDecoder GFSDK_Aftermath_GpuCrashDump_CreateDecoder; + PFN_GFSDK_Aftermath_GpuCrashDump_DestroyDecoder GFSDK_Aftermath_GpuCrashDump_DestroyDecoder; + PFN_GFSDK_Aftermath_GpuCrashDump_GenerateJSON GFSDK_Aftermath_GpuCrashDump_GenerateJSON; + PFN_GFSDK_Aftermath_GpuCrashDump_GetJSON GFSDK_Aftermath_GpuCrashDump_GetJSON; +#endif +}; + +#ifndef HAS_NSIGHT_AFTERMATH +inline NsightAftermathTracker::NsightAftermathTracker() = default; +inline NsightAftermathTracker::~NsightAftermathTracker() = default; +inline bool NsightAftermathTracker::Initialize() { + return false; +} +inline void NsightAftermathTracker::SaveShader(const std::vector&) const {} +#endif + +} // namespace Vulkan -- cgit v1.2.3