2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

Merge pull request #6372 from bunnei/raster-cache-fix

video_core: rasterizer_cache: Use u16 for cached page count.
This commit is contained in:
bunnei 2021-05-27 15:48:21 -07:00 committed by GitHub
commit 3289abe1cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View file

@ -18,10 +18,10 @@ RasterizerAccelerated::~RasterizerAccelerated() = default;
void RasterizerAccelerated::UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {
const auto page_end = Common::DivCeil(addr + size, Core::Memory::PAGE_SIZE);
for (auto page = addr >> Core::Memory::PAGE_BITS; page != page_end; ++page) {
auto& count = cached_pages.at(page >> 3).Count(page);
auto& count = cached_pages.at(page >> 2).Count(page);
if (delta > 0) {
ASSERT_MSG(count < UINT8_MAX, "Count may overflow!");
ASSERT_MSG(count < UINT16_MAX, "Count may overflow!");
} else if (delta < 0) {
ASSERT_MSG(count > 0, "Count may underflow!");
} else {
@ -29,7 +29,7 @@ void RasterizerAccelerated::UpdatePagesCachedCount(VAddr addr, u64 size, int del
}
// Adds or subtracts 1, as count is a unsigned 8-bit value
count += static_cast<u8>(delta);
count += static_cast<u16>(delta);
// Assume delta is either -1 or 1
if (count == 0) {

View file

@ -29,20 +29,20 @@ private:
public:
CacheEntry() = default;
std::atomic_uint8_t& Count(std::size_t page) {
return values[page & 7];
std::atomic_uint16_t& Count(std::size_t page) {
return values[page & 3];
}
const std::atomic_uint8_t& Count(std::size_t page) const {
return values[page & 7];
const std::atomic_uint16_t& Count(std::size_t page) const {
return values[page & 3];
}
private:
std::array<std::atomic_uint8_t, 8> values{};
std::array<std::atomic_uint16_t, 4> values{};
};
static_assert(sizeof(CacheEntry) == 8, "CacheEntry should be 8 bytes!");
std::array<CacheEntry, 0x800000> cached_pages;
std::array<CacheEntry, 0x1000000> cached_pages;
Core::Memory::Memory& cpu_memory;
};