mirror of
https://github.com/ran-j/PS2Recomp.git
synced 2026-10-01 18:31:21 -04:00
78ecbae377
feat: wip multi version on dbcman
38 lines
995 B
C++
38 lines
995 B
C++
#pragma once
|
|
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <cstring>
|
|
|
|
namespace GSMem
|
|
{
|
|
class TexturePageCache
|
|
{
|
|
public:
|
|
static constexpr uint32_t kPageSize = 8192u;
|
|
|
|
void Invalidate() noexcept
|
|
{
|
|
m_pageBase = UINT32_MAX;
|
|
}
|
|
|
|
// byteAddress is the wrapped, swizzled VRAM address. The returned
|
|
// pointer is valid only until the next miss or invalidation.
|
|
const uint8_t* Resolve(const uint8_t* vram, uint32_t byteAddress) noexcept
|
|
{
|
|
const uint32_t pageBase = byteAddress & ~(kPageSize - 1u);
|
|
if (m_pageBase != pageBase)
|
|
{
|
|
std::memcpy(m_bytes.data(), vram + pageBase, kPageSize);
|
|
m_pageBase = pageBase;
|
|
}
|
|
return m_bytes.data() + (byteAddress & (kPageSize - 1u));
|
|
}
|
|
|
|
private:
|
|
alignas(64) std::array<uint8_t, kPageSize> m_bytes{};
|
|
uint32_t m_pageBase = UINT32_MAX;
|
|
};
|
|
}
|