From d8f753f1e822a97db9562218dbb53d9a7918d2cc Mon Sep 17 00:00:00 2001 From: kd-11 Date: Tue, 9 Jul 2019 21:32:21 +0300 Subject: [PATCH] rsx: Do not allow framebuffer surfaces that exceed their allocated pitch dimensions - Truncate surfaces to forcefully fit inside the declared region --- rpcs3/Emu/RSX/Common/TextureUtils.cpp | 2 +- rpcs3/Emu/RSX/RSXThread.cpp | 29 ++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/RSX/Common/TextureUtils.cpp b/rpcs3/Emu/RSX/Common/TextureUtils.cpp index 4c34dd3159..902a227b74 100644 --- a/rpcs3/Emu/RSX/Common/TextureUtils.cpp +++ b/rpcs3/Emu/RSX/Common/TextureUtils.cpp @@ -798,7 +798,7 @@ size_t get_texture_size(const rsx::vertex_texture &texture) } u32 get_remap_encoding(const std::pair, std::array>& remap) -{ +{ u32 encode = 0; encode |= (remap.first[0] << 0); encode |= (remap.first[1] << 2); diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index d4482199f9..511f0b7a55 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -1110,10 +1110,19 @@ namespace rsx { layout.zeta_address = 0; } + else if (packed_render) + { + layout.actual_zeta_pitch = (layout.width * depth_texel_size); + } else { - // Still exists? Unlikely to get discarded - layout.actual_zeta_pitch = packed_render? (layout.width * depth_texel_size) : layout.zeta_pitch; + const auto packed_zeta_pitch = (layout.width * depth_texel_size); + if (packed_zeta_pitch > layout.zeta_pitch) + { + layout.width = (layout.zeta_pitch / depth_texel_size); + } + + layout.actual_zeta_pitch = layout.zeta_pitch; } for (const auto &index : rsx::utility::get_rtt_indexes(layout.target)) @@ -1159,7 +1168,21 @@ namespace rsx verify(HERE), layout.color_addresses[index]; - layout.actual_color_pitch[index] = packed_render? (layout.width * color_texel_size) : layout.color_pitch[index]; + const auto packed_pitch = (layout.width * color_texel_size); + if (packed_render) + { + layout.actual_color_pitch[index] = packed_pitch; + } + else + { + if (packed_pitch > layout.color_pitch[index]) + { + layout.width = (layout.color_pitch[index] / color_texel_size); + } + + layout.actual_color_pitch[index] = layout.color_pitch[index]; + } + framebuffer_status_valid = true; }