summaryrefslogtreecommitdiffstats
path: root/src/video_core/rasterizer_accelerated.cpp
blob: c54b17670395a79a5356d6f1a750475a68914c78 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 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"
#include "common/div_ceil.h"
#include "core/memory.h"
#include "video_core/rasterizer_accelerated.h"

namespace VideoCore {

RasterizerAccelerated::RasterizerAccelerated(Core::Memory::Memory& cpu_memory_)
    : cpu_memory{cpu_memory_} {}

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);

        ASSERT_MSG(count < UINT8_MAX, "Count may exceed UINT8_MAX!");

        count += delta;

        // 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);
        } else {
            ASSERT(count >= 0);
        }
    }
}

} // namespace VideoCore