From 5e4c2433c1924f4c47309ae9dd380c3ee7d0ac7b Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sat, 13 Dec 2025 14:35:31 +0300 Subject: [PATCH] vk/gl: Mark unused FP outputs as unused --- rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp | 15 +++++++++++++-- rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp | 18 ++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp b/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp index 4cbd92eecd..0879e5e987 100644 --- a/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp +++ b/rpcs3/Emu/RSX/GL/GLFragmentProgram.cpp @@ -103,8 +103,19 @@ void GLFragmentDecompilerThread::insertOutputs(std::stringstream & OS) const auto reg_type = float_type ? "vec4" : getHalfTypeName(4); for (uint i = 0; i < std::size(table); ++i) { - if (m_parr.HasParam(PF_PARAM_NONE, reg_type, table[i].second)) - OS << "layout(location=" << i << ") out vec4 " << table[i].first << ";\n"; + if (!m_parr.HasParam(PF_PARAM_NONE, reg_type, table[i].second)) + { + continue; + } + + if (i >= m_prog.mrt_buffers_count) + { + // Dead writes. Declare as temp variables for DCE to clean up. + OS << "vec4 " << table[i].first << "; // Unused\n"; + continue; + } + + OS << "layout(location=" << i << ") out vec4 " << table[i].first << ";\n"; } } diff --git a/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp b/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp index ea9d7cd0f1..ecca27f0df 100644 --- a/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp +++ b/rpcs3/Emu/RSX/VK/VKFragmentProgram.cpp @@ -150,17 +150,27 @@ void VKFragmentDecompilerThread::insertOutputs(std::stringstream & OS) { "ocol3", m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS ? "r4" : "h8" }, }; - //NOTE: We do not skip outputs, the only possible combinations are a(0), b(0), ab(0,1), abc(0,1,2), abcd(0,1,2,3) + // NOTE: We do not skip outputs, the only possible combinations are a(0), b(0), ab(0,1), abc(0,1,2), abcd(0,1,2,3) u8 output_index = 0; const bool float_type = (m_ctrl & CELL_GCM_SHADER_CONTROL_32_BITS_EXPORTS) || !device_props.has_native_half_support; const auto reg_type = float_type ? "vec4" : getHalfTypeName(4); for (uint i = 0; i < std::size(table); ++i) { - if (m_parr.HasParam(PF_PARAM_NONE, reg_type, table[i].second)) + if (!m_parr.HasParam(PF_PARAM_NONE, reg_type, table[i].second)) { - OS << "layout(location=" << std::to_string(output_index++) << ") " << "out vec4 " << table[i].first << ";\n"; - vk_prog->output_color_masks[i] = -1; + continue; } + + if (i >= m_prog.mrt_buffers_count) + { + // Dead writes. Declare as temp variables for DCE to clean up. + OS << "vec4 " << table[i].first << "; // Unused\n"; + vk_prog->output_color_masks[i] = 0; + continue; + } + + OS << "layout(location=" << std::to_string(output_index++) << ") " << "out vec4 " << table[i].first << ";\n"; + vk_prog->output_color_masks[i] = -1; } }