Skip to content

Commit

Permalink
Experiment with aftermath integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Dec 2, 2024
1 parent ea0e1c0 commit 0c29503
Show file tree
Hide file tree
Showing 10 changed files with 902 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ option(GRANITE_VULKAN_SHADER_MANAGER_RUNTIME_COMPILER "Enable Vulkan GLSL runtim
option(GRANITE_VULKAN_FOSSILIZE "Enable support for Fossilize." ON)
option(GRANITE_VULKAN_PROFILES "Enable profiles support." OFF)
option(GRANITE_VULKAN_DXGI_INTEROP "Enable DXGI interop when running on Windows." ON)
option(GRANITE_VULKAN_POST_MORTEM "Add extra support for port-mortem debug." OFF)
option(GRANITE_AUDIO "Enable Audio support." OFF)
option(GRANITE_PLATFORM "Granite Platform" "SDL")
option(GRANITE_HIDDEN "Declare symbols as hidden by default. Useful if you build Granite as a static library and you link to it in your shared library." OFF)
Expand Down
6 changes: 6 additions & 0 deletions vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,9 @@ if (GRANITE_VULKAN_PROFILES)
target_link_libraries(granite-vulkan PRIVATE granite-vulkan-profiles)
target_compile_definitions(granite-vulkan PRIVATE GRANITE_VULKAN_PROFILES)
endif()

if (GRANITE_VULKAN_POST_MORTEM)
add_subdirectory(post-mortem)
target_link_libraries(granite-vulkan PRIVATE granite-vulkan-post-mortem)
target_compile_definitions(granite-vulkan PUBLIC HAVE_GRANITE_VULKAN_POST_MORTEM)
endif()
31 changes: 30 additions & 1 deletion vulkan/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
#include "swappy/swappyVk.h"
#endif

#ifdef HAVE_GRANITE_VULKAN_POST_MORTEM
#include "post_mortem.hpp"
#endif

//#undef VULKAN_DEBUG

#ifdef GRANITE_VULKAN_PROFILES
Expand Down Expand Up @@ -296,6 +300,10 @@ void Context::destroy_device()
SwappyVk_destroyDevice(device);
#endif

#ifdef HAVE_GRANITE_VULKAN_POST_MORTEM
PostMortem::deinit();
#endif

if (owned_device && device != VK_NULL_HANDLE)
{
device_table.vkDestroyDevice(device, nullptr);
Expand Down Expand Up @@ -1610,6 +1618,26 @@ bool Context::create_device(VkPhysicalDevice gpu_, VkSurfaceKHR surface,

device_info.pNext = &pdf2;

#ifdef HAVE_GRANITE_VULKAN_POST_MORTEM
VkPhysicalDeviceDiagnosticsConfigFeaturesNV diagnostic_config_nv;
VkDeviceDiagnosticsConfigCreateInfoNV diagnostic_config_create_nv;
if (has_extension(VK_NV_DEVICE_DIAGNOSTICS_CONFIG_EXTENSION_NAME))
{
enabled_extensions.push_back(VK_NV_DEVICE_DIAGNOSTICS_CONFIG_EXTENSION_NAME);
diagnostic_config_nv = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DIAGNOSTICS_CONFIG_FEATURES_NV };
diagnostic_config_create_nv = { VK_STRUCTURE_TYPE_DEVICE_DIAGNOSTICS_CONFIG_CREATE_INFO_NV };
diagnostic_config_nv.diagnosticsConfig = VK_TRUE;
diagnostic_config_create_nv.flags = VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_AUTOMATIC_CHECKPOINTS_BIT_NV |
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_DEBUG_INFO_BIT_NV |
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_RESOURCE_TRACKING_BIT_NV |
VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_ERROR_REPORTING_BIT_NV;
diagnostic_config_nv.pNext = &diagnostic_config_create_nv;
diagnostic_config_create_nv.pNext = device_info.pNext;
device_info.pNext = &diagnostic_config_nv;
PostMortem::init_nv_aftermath();
}
#endif

// Only need GetPhysicalDeviceProperties2 for Vulkan 1.1-only code, so don't bother getting KHR variant.
VkPhysicalDeviceProperties2 props = { VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 };
// Fallback, query some important Vulkan 1.1 structs if we cannot use core 1.2 method.
Expand Down Expand Up @@ -1649,10 +1677,11 @@ bool Context::create_device(VkPhysicalDevice gpu_, VkSurfaceKHR surface,
if (has_extension(VK_EXT_MESH_SHADER_EXTENSION_NAME))
ADD_CHAIN(ext.mesh_shader_properties, MESH_SHADER_PROPERTIES_EXT);

// Pipeline binaries are currently borked in VVL.
#ifndef HAVE_GRANITE_VULKAN_POST_MORTEM
if ((flags & CONTEXT_CREATION_ENABLE_PIPELINE_BINARY_BIT) != 0 &&
has_extension(VK_KHR_PIPELINE_BINARY_EXTENSION_NAME))
ADD_CHAIN(ext.pipeline_binary_properties, PIPELINE_BINARY_PROPERTIES_KHR);
#endif

vkGetPhysicalDeviceProperties2(gpu, &props);

Expand Down
25 changes: 25 additions & 0 deletions vulkan/post-mortem/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
add_granite_internal_lib(granite-vulkan-post-mortem
post_mortem.cpp post_mortem.hpp)

target_include_directories(granite-vulkan-post-mortem PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(granite-vulkan-post-mortem PRIVATE granite-util)

if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
set(AFTERMATH_ARCH x64)
else()
set(AFTERMATH_ARCH x86)
endif()

find_library(GFSDK_LIBRARY GFSDK_Aftermath_Lib.x64 HINTS ${AFTERMATH_SDK_PATH}/lib/${AFTERMATH_ARCH})

if (GFSDK_LIBRARY)
target_sources(granite-vulkan-post-mortem PRIVATE
NsightAftermathGpuCrashTracker.cpp NsightAftermathGpuCrashTracker.h
NsightAftermathHelpers.h)
target_compile_definitions(granite-vulkan-post-mortem PRIVATE HAVE_AFTERMATH_SDK)
target_link_libraries(granite-vulkan-post-mortem PRIVATE ${GFSDK_LIBRARY} granite-volk-headers)
target_include_directories(granite-vulkan-post-mortem PRIVATE ${AFTERMATH_SDK_PATH}/include)
message("Found Aftermath SDK.")
else()
message("Did not find Aftermath SDK in AFTERMATH_SDK_PATH=${AFTERMATH_SDK_PATH}.")
endif()
Loading

0 comments on commit 0c29503

Please sign in to comment.