From 7915dcb23c25267d7e400582a449876ef3528dc2 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Fri, 17 Aug 2018 21:59:56 +0300 Subject: [PATCH] rsx: Do not overflow the program buffer! - Some games overflow the program buffer e.g Resistance games The observed overflow is one instruction longer, likely an engine bug with counting instructions --- rpcs3/Emu/RSX/rsx_methods.cpp | 11 ++++++++++- rpcs3/Emu/RSX/rsx_methods.h | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/RSX/rsx_methods.cpp b/rpcs3/Emu/RSX/rsx_methods.cpp index a9bba45e9c..5dfd17cce4 100644 --- a/rpcs3/Emu/RSX/rsx_methods.cpp +++ b/rpcs3/Emu/RSX/rsx_methods.cpp @@ -348,7 +348,7 @@ namespace rsx if (address >= 468) { // Ignore addresses outside the usable [0, 467] range - LOG_ERROR(RSX, "Invalid transform register index (load=%d, index=%d)", load, index); + LOG_WARNING(RSX, "Invalid transform register index (load=%d, index=%d)", load, index); return; } @@ -367,6 +367,15 @@ namespace rsx { static void impl(thread* rsx, u32 _reg, u32 arg) { + if (rsx::method_registers.transform_program_load() >= 512) + { + // PS3 seems to allow exceeding the program buffer by upto 32 instructions before crashing + // Discard the "excess" instructions to not overflow our transform program buffer + // TODO: Check if the instructions in the overflow area are executed by PS3 + LOG_WARNING(RSX, "Program buffer overflow!"); + return; + } + method_registers.commit_4_transform_program_instructions(index); rsx->m_graphics_state |= rsx::pipeline_state::vertex_program_dirty; } diff --git a/rpcs3/Emu/RSX/rsx_methods.h b/rpcs3/Emu/RSX/rsx_methods.h index e5be47e853..e9d815bcc6 100644 --- a/rpcs3/Emu/RSX/rsx_methods.h +++ b/rpcs3/Emu/RSX/rsx_methods.h @@ -1181,6 +1181,11 @@ namespace rsx return u16(registers[NV308A_SIZE_OUT] & 0xFFFF); } + u32 transform_program_load() + { + return registers[NV4097_SET_TRANSFORM_PROGRAM_LOAD]; + } + void commit_4_transform_program_instructions(u32 index) { u32& load = registers[NV4097_SET_TRANSFORM_PROGRAM_LOAD]; @@ -1194,7 +1199,7 @@ namespace rsx u32 transform_constant_load() { - return decode().transform_constant_load(); + return registers[NV4097_SET_TRANSFORM_CONSTANT_LOAD]; } u32 transform_branch_bits()