2026-01-12 05:18:12 -05:00
|
|
|
// SPDX-FileCopyrightText: 2002-2026 PCSX2 Dev Team
|
2024-07-30 13:42:36 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0+
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2022-12-28 16:53:37 +10:00
|
|
|
#include "GS/Renderers/Common/GSFunctionMap.h"
|
2023-12-26 21:05:33 +10:00
|
|
|
#include "Memory.h"
|
2022-12-28 16:53:37 +10:00
|
|
|
|
2023-10-10 00:16:15 +10:00
|
|
|
namespace GSCodeReserve
|
2022-12-28 16:53:37 +10:00
|
|
|
{
|
2023-10-10 00:16:15 +10:00
|
|
|
static u8* s_memory_base;
|
|
|
|
|
static u8* s_memory_end;
|
|
|
|
|
static u8* s_memory_ptr;
|
2022-12-28 16:53:37 +10:00
|
|
|
}
|
|
|
|
|
|
2023-10-10 00:16:15 +10:00
|
|
|
void GSCodeReserve::ResetMemory()
|
2022-12-28 16:53:37 +10:00
|
|
|
{
|
2023-10-10 00:16:15 +10:00
|
|
|
s_memory_base = SysMemory::GetSWRec();
|
|
|
|
|
s_memory_end = SysMemory::GetSWRecEnd();
|
|
|
|
|
s_memory_ptr = s_memory_base;
|
2022-12-28 16:53:37 +10:00
|
|
|
}
|
|
|
|
|
|
2023-10-10 00:16:15 +10:00
|
|
|
size_t GSCodeReserve::GetMemoryUsed()
|
2022-12-28 16:53:37 +10:00
|
|
|
{
|
2023-10-10 00:16:15 +10:00
|
|
|
return s_memory_ptr - s_memory_base;
|
2022-12-28 16:53:37 +10:00
|
|
|
}
|
|
|
|
|
|
2023-10-10 00:16:15 +10:00
|
|
|
u8* GSCodeReserve::ReserveMemory(size_t size)
|
2022-12-28 16:53:37 +10:00
|
|
|
{
|
2026-07-30 17:13:43 +02:00
|
|
|
// Null means full, and the caller resets the cache and asks again. This
|
|
|
|
|
// used to be an assert, so a release build walked off the end of the
|
|
|
|
|
// reserve instead, which is the end of the whole code arena.
|
|
|
|
|
if ((s_memory_ptr + size) > s_memory_end)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
2023-10-10 00:16:15 +10:00
|
|
|
return s_memory_ptr;
|
2022-12-28 16:53:37 +10:00
|
|
|
}
|
|
|
|
|
|
2023-10-10 00:16:15 +10:00
|
|
|
void GSCodeReserve::CommitMemory(size_t size)
|
2022-12-28 16:53:37 +10:00
|
|
|
{
|
2023-10-10 00:16:15 +10:00
|
|
|
pxAssert((s_memory_ptr + size) <= s_memory_end);
|
|
|
|
|
s_memory_ptr += size;
|
2022-12-28 16:53:37 +10:00
|
|
|
}
|