From 96aa1b3a08a6a240ff2a34f58e5baf94c5664bc1 Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Sat, 6 Jan 2024 22:49:32 -0800 Subject: [PATCH] memory: Fix order of checks in PhysicalToVirtualAddressForRasterizer. (#7328) --- src/core/memory.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/memory.cpp b/src/core/memory.cpp index fa616b9ed0..eb4ab42d44 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -691,12 +691,7 @@ std::vector MemorySystem::PhysicalToVirtualAddressForRasterizer(PAddr add if (addr >= VRAM_PADDR && addr < VRAM_PADDR_END) { return {addr - VRAM_PADDR + VRAM_VADDR}; } - if (addr >= FCRAM_PADDR && addr < FCRAM_PADDR_END) { - return {addr - FCRAM_PADDR + LINEAR_HEAP_VADDR, addr - FCRAM_PADDR + NEW_LINEAR_HEAP_VADDR}; - } - if (addr >= FCRAM_PADDR_END && addr < FCRAM_N3DS_PADDR_END) { - return {addr - FCRAM_PADDR + NEW_LINEAR_HEAP_VADDR}; - } + // NOTE: Order matters here. auto plg_ldr = Service::PLGLDR::GetService(impl->system); if (plg_ldr) { auto fb_addr = plg_ldr->GetPluginFBAddr(); @@ -704,6 +699,12 @@ std::vector MemorySystem::PhysicalToVirtualAddressForRasterizer(PAddr add return {addr - fb_addr + PLUGIN_3GX_FB_VADDR}; } } + if (addr >= FCRAM_PADDR && addr < FCRAM_PADDR_END) { + return {addr - FCRAM_PADDR + LINEAR_HEAP_VADDR, addr - FCRAM_PADDR + NEW_LINEAR_HEAP_VADDR}; + } + if (addr >= FCRAM_PADDR_END && addr < FCRAM_N3DS_PADDR_END) { + return {addr - FCRAM_PADDR + NEW_LINEAR_HEAP_VADDR}; + } // While the physical <-> virtual mapping is 1:1 for the regions supported by the cache, // some games (like Pokemon Super Mystery Dungeon) will try to use textures that go beyond // the end address of VRAM, causing the Virtual->Physical translation to fail when flushing