From 3c0ea1855641bf98325498351e804d9d0303be50 Mon Sep 17 00:00:00 2001 From: Vinicius Rangel Date: Sun, 8 Dec 2024 15:46:59 -0300 Subject: [PATCH] devtools: shader editing load patch even with config disabled --- src/core/debug_state.cpp | 4 ++-- src/core/debug_state.h | 7 ++++--- src/core/devtools/widget/shader_list.cpp | 8 +++++--- src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | 9 ++++----- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/core/debug_state.cpp b/src/core/debug_state.cpp index 8123c0b38..649624924 100644 --- a/src/core/debug_state.cpp +++ b/src/core/debug_state.cpp @@ -179,8 +179,8 @@ void DebugStateImpl::PushRegsDump(uintptr_t base_addr, uintptr_t header_addr, void DebugStateImpl::CollectShader(const std::string& name, vk::ShaderModule module, std::span spv, std::span raw_code, - std::span patch_spv) { + std::span patch_spv, bool is_patched) { shader_dump_list.emplace_back(name, module, std::vector{spv.begin(), spv.end()}, std::vector{raw_code.begin(), raw_code.end()}, - std::vector{patch_spv.begin(), patch_spv.end()}); + std::vector{patch_spv.begin(), patch_spv.end()}, is_patched); } diff --git a/src/core/debug_state.h b/src/core/debug_state.h index 4f47eaf08..fa2e5cd9d 100644 --- a/src/core/debug_state.h +++ b/src/core/debug_state.h @@ -91,9 +91,9 @@ struct ShaderDump { std::string cache_patch_disasm{}; ShaderDump(std::string name, vk::ShaderModule module, std::vector spv, - std::vector isa, std::vector patch_spv) + std::vector isa, std::vector patch_spv, bool is_patched) : name(std::move(name)), module(module), spv(std::move(spv)), isa(std::move(isa)), - patch_spv(std::move(patch_spv)) {} + patch_spv(std::move(patch_spv)), is_patched(is_patched) {} ShaderDump(const ShaderDump& other) = delete; ShaderDump(ShaderDump&& other) noexcept @@ -204,7 +204,8 @@ public: const AmdGpu::Liverpool::Regs& regs, bool is_compute = false); void CollectShader(const std::string& name, vk::ShaderModule module, std::span spv, - std::span raw_code, std::span patch_spv); + std::span raw_code, std::span patch_spv, + bool is_patched); }; } // namespace DebugStateType diff --git a/src/core/devtools/widget/shader_list.cpp b/src/core/devtools/widget/shader_list.cpp index be743fa8e..80c939718 100644 --- a/src/core/devtools/widget/shader_list.cpp +++ b/src/core/devtools/widget/shader_list.cpp @@ -232,10 +232,12 @@ void ShaderList::Draw() { int i = 0; for (const auto& shader : DebugState.shader_dump_list) { char name[128]; - if (shader.patch_spv.empty()) { - snprintf(name, sizeof(name), "%s", shader.name.c_str()); + if (shader.is_patched) { + snprintf(name, sizeof(name), "%s (PATCH ON)", shader.name.c_str()); + } else if (!shader.patch_spv.empty()) { + snprintf(name, sizeof(name), "%s (PATCH OFF)", shader.name.c_str()); } else { - snprintf(name, sizeof(name), "%s (PATCH)", shader.name.c_str()); + snprintf(name, sizeof(name), "%s", shader.name.c_str()); } if (ButtonEx(name, {width, 20.0f}, ImGuiButtonFlags_NoHoveredOnFocus)) { open_shaders.emplace_back(i); diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 32c5b5671..276e4ef29 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp @@ -434,7 +434,8 @@ vk::ShaderModule PipelineCache::CompileModule(Shader::Info& info, vk::ShaderModule module; auto patch = GetShaderPatch(info.pgm_hash, info.stage, perm_idx, "spv"); - if (patch) { + const bool is_patched = patch && Config::patchShaders(); + if (is_patched) { LOG_INFO(Loader, "Loaded patch for {} shader {:#x}", info.stage, info.pgm_hash); module = CompileSPV(*patch, instance.GetDevice()); } else { @@ -444,7 +445,8 @@ vk::ShaderModule PipelineCache::CompileModule(Shader::Info& info, const auto name = fmt::format("{}_{:#018x}_{}", info.stage, info.pgm_hash, perm_idx); Vulkan::SetObjectName(instance.GetDevice(), module, name); if (Config::collectShadersForDebug()) { - DebugState.CollectShader(name, module, spv, code, patch ? *patch : std::span{}); + DebugState.CollectShader(name, module, spv, code, patch ? *patch : std::span{}, + is_patched); } return module; } @@ -533,9 +535,6 @@ void PipelineCache::DumpShader(std::span code, u64 hash, Shader::Stag std::optional> PipelineCache::GetShaderPatch(u64 hash, Shader::Stage stage, size_t perm_idx, std::string_view ext) { - if (!Config::patchShaders()) { - return {}; - } using namespace Common::FS; const auto patch_dir = GetUserPath(PathType::ShaderDir) / "patch";