2019-10-26 23:40:08 -07:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/common_types.h"
|
2021-03-02 16:57:53 -08:00
|
|
|
#include "common/div_ceil.h"
|
2019-10-26 23:40:08 -07:00
|
|
|
#include "core/memory.h"
|
|
|
|
#include "video_core/rasterizer_accelerated.h"
|
|
|
|
|
|
|
|
namespace VideoCore {
|
|
|
|
|
2020-03-31 12:10:44 -07:00
|
|
|
RasterizerAccelerated::RasterizerAccelerated(Core::Memory::Memory& cpu_memory_)
|
2019-11-26 11:10:49 -08:00
|
|
|
: cpu_memory{cpu_memory_} {}
|
2019-10-26 23:40:08 -07:00
|
|
|
|
|
|
|
RasterizerAccelerated::~RasterizerAccelerated() = default;
|
|
|
|
|
|
|
|
void RasterizerAccelerated::UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {
|
2021-03-02 16:57:53 -08:00
|
|
|
const auto page_end = Common::DivCeil(addr + size, Core::Memory::PAGE_SIZE);
|
|
|
|
for (auto page = addr >> Core::Memory::PAGE_BITS; page != page_end; ++page) {
|
2021-05-27 14:47:24 -07:00
|
|
|
auto& count = cached_pages.at(page >> 2).Count(page);
|
2019-10-26 23:40:08 -07:00
|
|
|
|
2021-03-02 17:48:02 -08:00
|
|
|
if (delta > 0) {
|
2021-05-27 14:47:24 -07:00
|
|
|
ASSERT_MSG(count < UINT16_MAX, "Count may overflow!");
|
2021-03-02 17:48:02 -08:00
|
|
|
} else if (delta < 0) {
|
|
|
|
ASSERT_MSG(count > 0, "Count may underflow!");
|
2021-03-02 17:44:02 -08:00
|
|
|
} else {
|
|
|
|
ASSERT_MSG(true, "Delta must be non-zero!");
|
|
|
|
}
|
2019-10-26 23:40:08 -07:00
|
|
|
|
2021-03-12 21:52:49 -08:00
|
|
|
// Adds or subtracts 1, as count is a unsigned 8-bit value
|
2021-05-27 14:47:24 -07:00
|
|
|
count += static_cast<u16>(delta);
|
2019-10-26 23:40:08 -07:00
|
|
|
|
2021-03-02 16:57:53 -08:00
|
|
|
// Assume delta is either -1 or 1
|
|
|
|
if (count == 0) {
|
|
|
|
cpu_memory.RasterizerMarkRegionCached(page << Core::Memory::PAGE_BITS,
|
|
|
|
Core::Memory::PAGE_SIZE, false);
|
|
|
|
} else if (count == 1 && delta > 0) {
|
|
|
|
cpu_memory.RasterizerMarkRegionCached(page << Core::Memory::PAGE_BITS,
|
|
|
|
Core::Memory::PAGE_SIZE, true);
|
2019-10-26 23:40:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace VideoCore
|