morton_swizzle: Move out of bounds texture check out of the decode loop
* Running relative expensive checks like this on a hot path causes small but measurable performance loss. Tested SMD wit this and it doesn't crash
This commit is contained in:
@ -398,6 +398,33 @@ bool MemorySystem::IsValidPhysicalAddress(const PAddr paddr) const {
|
||||
return GetPhysicalPointer(paddr) != nullptr;
|
||||
}
|
||||
|
||||
PAddr MemorySystem::ClampPhysicalAddress(PAddr base, PAddr address) const {
|
||||
struct MemoryArea {
|
||||
PAddr paddr_base;
|
||||
u32 size;
|
||||
};
|
||||
|
||||
constexpr std::array memory_areas = {
|
||||
MemoryArea{VRAM_PADDR, VRAM_SIZE},
|
||||
MemoryArea{DSP_RAM_PADDR, DSP_RAM_SIZE},
|
||||
MemoryArea{FCRAM_PADDR, FCRAM_N3DS_SIZE},
|
||||
MemoryArea{N3DS_EXTRA_RAM_PADDR, N3DS_EXTRA_RAM_SIZE},
|
||||
};
|
||||
|
||||
const auto area =
|
||||
std::ranges::find_if(memory_areas, [&](const MemoryArea& area) {
|
||||
return base >= area.paddr_base && base <= area.paddr_base + area.size;
|
||||
});
|
||||
|
||||
if (area == memory_areas.end()) {
|
||||
LOG_ERROR(HW_Memory, "Unknown base address used for clamping {:#08X} at PC {:#08X}", base,
|
||||
Core::GetRunningCore().GetPC());
|
||||
return address;
|
||||
}
|
||||
|
||||
return std::clamp(address, area->paddr_base, area->paddr_base + area->size);
|
||||
}
|
||||
|
||||
u8* MemorySystem::GetPointer(const VAddr vaddr) {
|
||||
u8* page_pointer = impl->current_page_table->pointers[vaddr >> PAGE_BITS];
|
||||
if (page_pointer) {
|
||||
@ -457,22 +484,22 @@ MemoryRef MemorySystem::GetPhysicalRef(PAddr address) const {
|
||||
u32 size;
|
||||
};
|
||||
|
||||
static constexpr MemoryArea memory_areas[] = {
|
||||
{VRAM_PADDR, VRAM_SIZE},
|
||||
{DSP_RAM_PADDR, DSP_RAM_SIZE},
|
||||
{FCRAM_PADDR, FCRAM_N3DS_SIZE},
|
||||
{N3DS_EXTRA_RAM_PADDR, N3DS_EXTRA_RAM_SIZE},
|
||||
constexpr std::array memory_areas = {
|
||||
MemoryArea{VRAM_PADDR, VRAM_SIZE},
|
||||
MemoryArea{DSP_RAM_PADDR, DSP_RAM_SIZE},
|
||||
MemoryArea{FCRAM_PADDR, FCRAM_N3DS_SIZE},
|
||||
MemoryArea{N3DS_EXTRA_RAM_PADDR, N3DS_EXTRA_RAM_SIZE},
|
||||
};
|
||||
|
||||
const auto area =
|
||||
std::find_if(std::begin(memory_areas), std::end(memory_areas), [&](const auto& area) {
|
||||
std::ranges::find_if(memory_areas, [&](const MemoryArea& area) {
|
||||
// Note: the region end check is inclusive because the user can pass in an address that
|
||||
// represents an open right bound
|
||||
return address >= area.paddr_base && address <= area.paddr_base + area.size;
|
||||
});
|
||||
|
||||
if (area == std::end(memory_areas)) {
|
||||
LOG_ERROR(HW_Memory, "unknown GetPhysicalPointer @ 0x{:08X} at PC 0x{:08X}", address,
|
||||
if (area == memory_areas.end()) {
|
||||
LOG_ERROR(HW_Memory, "Unknown GetPhysicalPointer @ {:#08X} at PC {:#08X}", address,
|
||||
Core::GetRunningCore().GetPC());
|
||||
return nullptr;
|
||||
}
|
||||
|
Reference in New Issue
Block a user