From 26fd0510abe11d797d8a16d6ad858e879da9044d Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sat, 6 Dec 2025 14:17:00 +0300 Subject: [PATCH] rsx/fp: Enable CFG passes and emit block epilogues --- .../Passes/FP/RegisterAnnotationPass.h | 2 +- .../RSX/Program/FragmentProgramDecompiler.cpp | 35 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/RSX/Program/Assembler/Passes/FP/RegisterAnnotationPass.h b/rpcs3/Emu/RSX/Program/Assembler/Passes/FP/RegisterAnnotationPass.h index 8856ecb44e..c719a80381 100644 --- a/rpcs3/Emu/RSX/Program/Assembler/Passes/FP/RegisterAnnotationPass.h +++ b/rpcs3/Emu/RSX/Program/Assembler/Passes/FP/RegisterAnnotationPass.h @@ -14,7 +14,7 @@ namespace rsx::assembler::FP class RegisterAnnotationPass : public CFGPass { public: - RegisterAnnotationPass(RSXFragmentProgram& prog) + RegisterAnnotationPass(const RSXFragmentProgram& prog) : m_prog(prog) {} diff --git a/rpcs3/Emu/RSX/Program/FragmentProgramDecompiler.cpp b/rpcs3/Emu/RSX/Program/FragmentProgramDecompiler.cpp index a5a6cd5876..68874272a1 100644 --- a/rpcs3/Emu/RSX/Program/FragmentProgramDecompiler.cpp +++ b/rpcs3/Emu/RSX/Program/FragmentProgramDecompiler.cpp @@ -3,6 +3,11 @@ #include "FragmentProgramDecompiler.h" #include "ProgramStateCache.h" +#include "Assembler/Passes/FP/RegisterAnnotationPass.h" +#include "Assembler/Passes/FP/RegisterDependencyPass.h" + +#include "Emu/system_config.h" + #include namespace rsx @@ -1296,7 +1301,17 @@ bool FragmentProgramDecompiler::handle_tex_srb(u32 opcode) std::string FragmentProgramDecompiler::Decompile() { - const auto graph = deconstruct_fragment_program(m_prog); + auto graph = deconstruct_fragment_program(m_prog); + + if (g_cfg.video.shader_precision != gpu_preset_level::low) + { + FP::RegisterAnnotationPass annotation_pass{ m_prog }; + FP::RegisterDependencyPass dependency_pass{}; + + annotation_pass.run(graph); + dependency_pass.run(graph); + } + m_size = 0; m_location = 0; m_loop_count = 0; @@ -1455,7 +1470,23 @@ std::string FragmentProgramDecompiler::Decompile() if (dst.end) break; } - // TODO: Handle block epilogue if needed + if (block.epilogue.empty()) + { + continue; + } + + AddCode("// Epilogue"); + + for (auto& inst : block.epilogue) + { + m_instruction = &inst; + dst.HEX = inst.bytecode[0]; + src0.HEX = inst.bytecode[1]; + src1.HEX = inst.bytecode[2]; + src2.HEX = inst.bytecode[3]; + + ensure(handle_tex_srb(inst.opcode) || handle_sct_scb(inst.opcode), "Unsupported operation"); + } } while (m_code_level > 1)