nsight_aftermath_tracker: Report used shaders to Nsight Aftermath

This commit is contained in:
ReinUsesLisp 2021-04-11 02:50:30 -03:00 committed by ameerj
parent 106764a6d5
commit 479ca00071
6 changed files with 20 additions and 16 deletions

View File

@ -206,6 +206,7 @@ VKComputePass::VKComputePass(const Device& device, VKDescriptorPool& descriptor_
.codeSize = static_cast<u32>(code.size_bytes()), .codeSize = static_cast<u32>(code.size_bytes()),
.pCode = code.data(), .pCode = code.data(),
}); });
device.SaveShader(code);
pipeline = device.GetLogical().CreateComputePipeline({ pipeline = device.GetLogical().CreateComputePipeline({
.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
.pNext = nullptr, .pNext = nullptr,

View File

@ -770,6 +770,7 @@ std::unique_ptr<GraphicsPipeline> PipelineCache::CreateGraphicsPipeline(
const Shader::Profile profile{MakeProfile(key, program.stage)}; const Shader::Profile profile{MakeProfile(key, program.stage)};
const std::vector<u32> code{EmitSPIRV(profile, program, binding)}; const std::vector<u32> code{EmitSPIRV(profile, program, binding)};
device.SaveShader(code);
modules[stage_index] = BuildShader(device, code); modules[stage_index] = BuildShader(device, code);
if (device.HasDebuggingToolAttached()) { if (device.HasDebuggingToolAttached()) {
const std::string name{fmt::format("{:016x}{:016x}", key.unique_hashes[index][0], const std::string name{fmt::format("{:016x}{:016x}", key.unique_hashes[index][0],
@ -846,7 +847,8 @@ std::unique_ptr<ComputePipeline> PipelineCache::CreateComputePipeline(
Shader::Maxwell::Flow::CFG cfg{env, pools.flow_block, env.StartAddress()}; Shader::Maxwell::Flow::CFG cfg{env, pools.flow_block, env.StartAddress()};
Shader::IR::Program program{TranslateProgram(pools.inst, pools.block, env, cfg)}; Shader::IR::Program program{TranslateProgram(pools.inst, pools.block, env, cfg)};
u32 binding{0}; u32 binding{0};
std::vector<u32> code{EmitSPIRV(base_profile, program, binding)}; const std::vector<u32> code{EmitSPIRV(base_profile, program, binding)};
device.SaveShader(code);
vk::ShaderModule spv_module{BuildShader(device, code)}; vk::ShaderModule spv_module{BuildShader(device, code)};
if (device.HasDebuggingToolAttached()) { if (device.HasDebuggingToolAttached()) {
const auto name{fmt::format("{:016x}{:016x}", key.unique_hash[0], key.unique_hash[1])}; const auto name{fmt::format("{:016x}{:016x}", key.unique_hash[0], key.unique_hash[1])};

View File

@ -73,12 +73,11 @@ NsightAftermathTracker::~NsightAftermathTracker() {
} }
} }
void NsightAftermathTracker::SaveShader(const std::vector<u32>& spirv) const { void NsightAftermathTracker::SaveShader(std::span<const u32> spirv) const {
if (!initialized) { if (!initialized) {
return; return;
} }
std::vector<u32> spirv_copy(spirv.begin(), spirv.end());
std::vector<u32> spirv_copy = spirv;
GFSDK_Aftermath_SpirvCode shader; GFSDK_Aftermath_SpirvCode shader;
shader.pData = spirv_copy.data(); shader.pData = spirv_copy.data();
shader.size = static_cast<u32>(spirv_copy.size() * 4); shader.size = static_cast<u32>(spirv_copy.size() * 4);

View File

@ -6,6 +6,7 @@
#include <filesystem> #include <filesystem>
#include <mutex> #include <mutex>
#include <span>
#include <string> #include <string>
#include <vector> #include <vector>
@ -33,7 +34,7 @@ public:
NsightAftermathTracker(NsightAftermathTracker&&) = delete; NsightAftermathTracker(NsightAftermathTracker&&) = delete;
NsightAftermathTracker& operator=(NsightAftermathTracker&&) = delete; NsightAftermathTracker& operator=(NsightAftermathTracker&&) = delete;
void SaveShader(const std::vector<u32>& spirv) const; void SaveShader(std::span<const u32> spirv) const;
private: private:
#ifdef HAS_NSIGHT_AFTERMATH #ifdef HAS_NSIGHT_AFTERMATH
@ -61,21 +62,21 @@ private:
bool initialized = false; bool initialized = false;
Common::DynamicLibrary dl; Common::DynamicLibrary dl;
PFN_GFSDK_Aftermath_DisableGpuCrashDumps GFSDK_Aftermath_DisableGpuCrashDumps; PFN_GFSDK_Aftermath_DisableGpuCrashDumps GFSDK_Aftermath_DisableGpuCrashDumps{};
PFN_GFSDK_Aftermath_EnableGpuCrashDumps GFSDK_Aftermath_EnableGpuCrashDumps; PFN_GFSDK_Aftermath_EnableGpuCrashDumps GFSDK_Aftermath_EnableGpuCrashDumps{};
PFN_GFSDK_Aftermath_GetShaderDebugInfoIdentifier GFSDK_Aftermath_GetShaderDebugInfoIdentifier; PFN_GFSDK_Aftermath_GetShaderDebugInfoIdentifier GFSDK_Aftermath_GetShaderDebugInfoIdentifier{};
PFN_GFSDK_Aftermath_GetShaderHashSpirv GFSDK_Aftermath_GetShaderHashSpirv; PFN_GFSDK_Aftermath_GetShaderHashSpirv GFSDK_Aftermath_GetShaderHashSpirv{};
PFN_GFSDK_Aftermath_GpuCrashDump_CreateDecoder GFSDK_Aftermath_GpuCrashDump_CreateDecoder; PFN_GFSDK_Aftermath_GpuCrashDump_CreateDecoder GFSDK_Aftermath_GpuCrashDump_CreateDecoder{};
PFN_GFSDK_Aftermath_GpuCrashDump_DestroyDecoder GFSDK_Aftermath_GpuCrashDump_DestroyDecoder; PFN_GFSDK_Aftermath_GpuCrashDump_DestroyDecoder GFSDK_Aftermath_GpuCrashDump_DestroyDecoder{};
PFN_GFSDK_Aftermath_GpuCrashDump_GenerateJSON GFSDK_Aftermath_GpuCrashDump_GenerateJSON; PFN_GFSDK_Aftermath_GpuCrashDump_GenerateJSON GFSDK_Aftermath_GpuCrashDump_GenerateJSON{};
PFN_GFSDK_Aftermath_GpuCrashDump_GetJSON GFSDK_Aftermath_GpuCrashDump_GetJSON; PFN_GFSDK_Aftermath_GpuCrashDump_GetJSON GFSDK_Aftermath_GpuCrashDump_GetJSON{};
#endif #endif
}; };
#ifndef HAS_NSIGHT_AFTERMATH #ifndef HAS_NSIGHT_AFTERMATH
inline NsightAftermathTracker::NsightAftermathTracker() = default; inline NsightAftermathTracker::NsightAftermathTracker() = default;
inline NsightAftermathTracker::~NsightAftermathTracker() = default; inline NsightAftermathTracker::~NsightAftermathTracker() = default;
inline void NsightAftermathTracker::SaveShader(const std::vector<u32>&) const {} inline void NsightAftermathTracker::SaveShader(std::span<const u32>) const {}
#endif #endif
} // namespace Vulkan } // namespace Vulkan

View File

@ -493,7 +493,7 @@ void Device::ReportLoss() const {
std::this_thread::sleep_for(std::chrono::seconds{15}); std::this_thread::sleep_for(std::chrono::seconds{15});
} }
void Device::SaveShader(const std::vector<u32>& spirv) const { void Device::SaveShader(std::span<const u32> spirv) const {
if (nsight_aftermath_tracker) { if (nsight_aftermath_tracker) {
nsight_aftermath_tracker->SaveShader(spirv); nsight_aftermath_tracker->SaveShader(spirv);
} }

View File

@ -7,6 +7,7 @@
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <unordered_map> #include <unordered_map>
#include <span>
#include <vector> #include <vector>
#include "common/common_types.h" #include "common/common_types.h"
@ -43,7 +44,7 @@ public:
void ReportLoss() const; void ReportLoss() const;
/// Reports a shader to Nsight Aftermath. /// Reports a shader to Nsight Aftermath.
void SaveShader(const std::vector<u32>& spirv) const; void SaveShader(std::span<const u32> spirv) const;
/// Returns the name of the VkDriverId reported from Vulkan. /// Returns the name of the VkDriverId reported from Vulkan.
std::string GetDriverName() const; std::string GetDriverName() const;