CPU/CodeCache: Fix currently-invalidated blocks breaking memory states

This commit is contained in:
Connor McLaughlin 2022-01-06 22:46:54 +10:00
parent 30a53fbb3c
commit 541947c6f8

View file

@ -649,6 +649,9 @@ recompile:
AddBlockToHostCodeMap(block);
#endif
// block is valid again
block->invalidated = false;
// re-insert into the block map since we removed it earlier.
s_blocks.emplace(block->key.bits, block);
return true;
@ -836,7 +839,7 @@ void InvalidCodeFunction()
#endif
static void InvalidateBlock(CodeBlock* block)
static void InvalidateBlock(CodeBlock* block, bool allow_frame_invalidation)
{
// Invalidate forces the block to be checked again.
Log_DebugPrintf("Invalidating block at 0x%08X", block->GetPC());
@ -845,6 +848,8 @@ static void InvalidateBlock(CodeBlock* block)
if (block->can_link)
{
const u32 frame_number = System::GetFrameNumber();
if (allow_frame_invalidation)
{
const u32 frame_diff = frame_number - block->invalidate_frame_number;
if (frame_diff <= INVALIDATE_THRESHOLD_TO_DISABLE_LINKING)
{
@ -857,6 +862,12 @@ static void InvalidateBlock(CodeBlock* block)
block->invalidate_frame_number = frame_number;
}
}
else
{
// don't trigger frame number based invalidation for this block (e.g. memory save states)
block->invalidate_frame_number = frame_number - INVALIDATE_THRESHOLD_TO_DISABLE_LINKING - 1;
}
}
UnlinkBlock(block);
@ -870,7 +881,7 @@ void InvalidateBlocksWithPageIndex(u32 page_index)
DebugAssert(page_index < Bus::RAM_8MB_CODE_PAGE_COUNT);
auto& blocks = m_ram_block_map[page_index];
for (CodeBlock* block : blocks)
InvalidateBlock(block);
InvalidateBlock(block, true);
// Block will be re-added next execution.
blocks.clear();
@ -883,7 +894,7 @@ void InvalidateAll()
{
CodeBlock* block = it.second;
if (block && !block->invalidated)
InvalidateBlock(block);
InvalidateBlock(block, false);
}
Bus::ClearRAMCodePageFlags();