diff --git a/pcsx2/R3000A.h b/pcsx2/R3000A.h index b384a17253..143abc101a 100644 --- a/pcsx2/R3000A.h +++ b/pcsx2/R3000A.h @@ -189,6 +189,9 @@ struct R3000Acpu { s32 (*ExecuteBlock)( s32 eeCycles ); // executes the given number of EE cycles. void (*Clear)(u32 Addr, u32 Size); void (*Shutdown)(); + + uint (*GetCacheReserve)(); + void (*SetCacheReserve)( uint reserveInMegs ); }; extern R3000Acpu *psxCpu; diff --git a/pcsx2/R5900.h b/pcsx2/R5900.h index fa67c562e1..227bc9018f 100644 --- a/pcsx2/R5900.h +++ b/pcsx2/R5900.h @@ -376,6 +376,9 @@ struct R5900cpu // doesn't matter if we're stripping it out soon. ;) // void (*Clear)(u32 Addr, u32 Size); + + uint (*GetCacheReserve)(); + void (*SetCacheReserve)( uint reserveInMegs ); }; extern R5900cpu *Cpu; diff --git a/pcsx2/x86/iR3000A.cpp b/pcsx2/x86/iR3000A.cpp index 2886d53080..83bd77cbea 100644 --- a/pcsx2/x86/iR3000A.cpp +++ b/pcsx2/x86/iR3000A.cpp @@ -1397,12 +1397,26 @@ StartRecomp: s_pCurBlockEx = NULL; } +static void recSetCacheReserve( uint reserveInMegs ) +{ + //m_ConfiguredCacheReserve = reserveInMegs * _1mb; +} + +static uint recGetCacheReserve() +{ + return 0; + //return m_ConfiguredCacheReserve / _1mb; +} + R3000Acpu psxRec = { recReserve, recResetIOP, recExecute, recExecuteBlock, recClearIOP, - recShutdown + recShutdown, + + recGetCacheReserve, + recSetCacheReserve }; diff --git a/pcsx2/x86/ix86-32/iR5900-32.cpp b/pcsx2/x86/ix86-32/iR5900-32.cpp index 3c90e9a28b..d30b998a65 100644 --- a/pcsx2/x86/ix86-32/iR5900-32.cpp +++ b/pcsx2/x86/ix86-32/iR5900-32.cpp @@ -64,6 +64,7 @@ bool g_cpuFlushedPC, g_cpuFlushedCode, g_recompilingDelaySlot, g_maySignalExcept static const int RECCONSTBUF_SIZE = 16384 * 2; // 64 bit consts in 32 bit units static RecompiledCodeReserve* recMem = NULL; +static uptr m_ConfiguredCacheReserve = _64mb; static u32* recConstBuf = NULL; // 64-bit pseudo-immediates static BASEBLOCK *recRAM = NULL; // and the ptr to the blocks here @@ -548,6 +549,42 @@ static void recThrowHardwareDeficiency( const wxChar* extFail ) .SetUserMsg(pxsFmt(_("%s Extensions not found. The R5900-32 recompiler requires a host CPU with MMX, SSE, and SSE2 extensions."), extFail )); } +// This error message is shared by R5900, R3000, and microVU recompilers. It is not used by the +// SuperVU recompiler, since it has its own customized message. +wxString GetMsg_RecVmFailed( const char* recName ) +{ + return pxE( ".Error:Recompiler:VirtualMemoryAlloc", + pxsFmt( + "The %s recompiler was unable to reserve contiguous memory required " + "for internal caches. This problem may be fixable by reducing the default " + "cache sizes for all PCSX2 recompilers, found under Host Settings.", + recName + ) + ); +} + +static void recReserveCache() +{ + if (!recMem) recMem = new RecompiledCodeReserve(L"R5900-32 Recompiler Cache", _1mb * 4); + + recMem->Reserve( m_ConfiguredCacheReserve, HostMemoryMap::EErec ); + + while (!recMem->IsOk() && (m_ConfiguredCacheReserve >= 16)) + { + m_ConfiguredCacheReserve /= 2; + recMem->Reserve( m_ConfiguredCacheReserve * _1mb, HostMemoryMap::EErec ); + } + + if (!recMem->IsOk()) + { + throw Exception::VirtualMemoryMapConflict() + .SetDiagMsg(pxsFmt( L"R5900-32 recompiled code cache could not be mapped." )) + .SetUserMsg(GetMsg_RecVmFailed("R5900-32")); + } + + ProfilerRegisterSource( "EE Rec", *recMem, recMem->GetReserveSizeInBytes() ); +} + static void recReserve() { // Hardware Requirements Check... @@ -561,8 +598,7 @@ static void recReserve() if ( !x86caps.hasStreamingSIMD2Extensions ) recThrowHardwareDeficiency( L"SSE2" ); - recMem = new RecompiledCodeReserve(L"R5900-32 Recompiler Cache", _1mb * 4); - recMem->Reserve( _64mb, HostMemoryMap::EErec ); + recReserveCache(); } static void recAlloc() @@ -595,7 +631,6 @@ static void recAlloc() // No errors.. Proceed with initialization: - ProfilerRegisterSource( "EE Rec", *recMem, recMem->GetReserveSizeInBytes() ); _DynGen_Dispatchers(); x86FpuState = FPU_STATE; @@ -1885,6 +1920,16 @@ static void recThrowException( const BaseException& ex ) #endif } +static void recSetCacheReserve( uint reserveInMegs ) +{ + m_ConfiguredCacheReserve = reserveInMegs * _1mb; +} + +static uint recGetCacheReserve() +{ + return m_ConfiguredCacheReserve / _1mb; +} + R5900cpu recCpu = { recReserve, @@ -1898,4 +1943,7 @@ R5900cpu recCpu = recThrowException, recThrowException, recClear, + + recGetCacheReserve, + recSetCacheReserve, };