mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-21 08:08:56 +02:00
[buffer_cache] Add batching support for memory tracker updates (#3288)
I added a batching/ coalescing of ranges in WordManager to reduce calls per pages in UpdatePagesCachedCount, also a test to verify if FlushCachedWrites coalesced (reduces callings to UpdatePagesCachedCount) callings and register each of them to inspect them. Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3288 Reviewed-by: Maufeat <sahyno1996@gmail.com> Reviewed-by: DraVee <dravee@eden-emu.dev> Co-authored-by: CamilleLaVey <camillelavey99@gmail.com> Co-committed-by: CamilleLaVey <camillelavey99@gmail.com>
This commit is contained in:
parent
51cc1bc6be
commit
1a9b4b37e1
4 changed files with 155 additions and 6 deletions
|
|
@ -4,11 +4,15 @@
|
|||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <unordered_map>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "video_core/buffer_cache/memory_tracker_base.h"
|
||||
#include "core/device_memory.h"
|
||||
#include "video_core/host1x/gpu_device_memory_manager.h"
|
||||
|
||||
namespace {
|
||||
using Range = std::pair<u64, u64>;
|
||||
|
|
@ -23,6 +27,8 @@ constexpr VAddr c = 16 * HIGH_PAGE_SIZE;
|
|||
class RasterizerInterface {
|
||||
public:
|
||||
void UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {
|
||||
++update_calls;
|
||||
calls.emplace_back(addr, size, delta);
|
||||
const u64 page_start{addr >> Core::DEVICE_PAGEBITS};
|
||||
const u64 page_end{(addr + size + Core::DEVICE_PAGESIZE - 1) >> Core::DEVICE_PAGEBITS};
|
||||
for (u64 page = page_start; page < page_end; ++page) {
|
||||
|
|
@ -36,6 +42,9 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t UpdateCalls() const noexcept { return update_calls; }
|
||||
[[nodiscard]] const std::vector<std::tuple<VAddr, u64, int>>& UpdateCallsList() const noexcept { return calls; }
|
||||
|
||||
[[nodiscard]] int Count(VAddr addr) const noexcept {
|
||||
const auto it = page_table.find(addr >> Core::DEVICE_PAGEBITS);
|
||||
return it == page_table.end() ? 0 : it->second;
|
||||
|
|
@ -51,7 +60,10 @@ public:
|
|||
|
||||
private:
|
||||
std::unordered_map<u64, int> page_table;
|
||||
std::vector<std::tuple<VAddr, u64, int>> calls;
|
||||
size_t update_calls = 0;
|
||||
};
|
||||
|
||||
} // Anonymous namespace
|
||||
|
||||
using MemoryTracker = VideoCommon::MemoryTrackerBase<RasterizerInterface>;
|
||||
|
|
@ -544,3 +556,34 @@ TEST_CASE("MemoryTracker: Cached write downloads") {
|
|||
memory_track->MarkRegionAsCpuModified(c, WORD);
|
||||
REQUIRE(rasterizer.Count() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("MemoryTracker: FlushCachedWrites batching") {
|
||||
RasterizerInterface rasterizer;
|
||||
std::unique_ptr<MemoryTracker> memory_track(std::make_unique<MemoryTracker>(rasterizer));
|
||||
memory_track->UnmarkRegionAsCpuModified(c, WORD * 2);
|
||||
memory_track->CachedCpuWrite(c + PAGE, PAGE);
|
||||
memory_track->CachedCpuWrite(c + PAGE * 2, PAGE);
|
||||
memory_track->CachedCpuWrite(c + PAGE * 4, PAGE);
|
||||
REQUIRE(rasterizer.UpdateCalls() == 0);
|
||||
memory_track->FlushCachedWrites();
|
||||
// Now we expect a single batch call (coalesced ranges) to the device memory manager
|
||||
REQUIRE(rasterizer.UpdateCalls() == 1);
|
||||
const auto& calls = rasterizer.UpdateCallsList();
|
||||
REQUIRE(std::get<0>(calls[0]) == c + PAGE);
|
||||
REQUIRE(std::get<1>(calls[0]) == PAGE * 3);
|
||||
}
|
||||
|
||||
TEST_CASE("DeviceMemoryManager: UpdatePagesCachedBatch basic") {
|
||||
Core::DeviceMemory device_memory;
|
||||
Tegra::MaxwellDeviceMemoryManager manager(device_memory);
|
||||
// empty should be a no-op
|
||||
std::vector<std::pair<Core::DAddr, size_t>> empty;
|
||||
manager.UpdatePagesCachedBatch(empty, 1);
|
||||
|
||||
// small ranges should be accepted and not crash
|
||||
std::vector<std::pair<Core::DAddr, size_t>> ranges;
|
||||
ranges.emplace_back(0, Core::Memory::YUZU_PAGESIZE);
|
||||
ranges.emplace_back(Core::Memory::YUZU_PAGESIZE, Core::Memory::YUZU_PAGESIZE);
|
||||
manager.UpdatePagesCachedBatch(ranges, 1);
|
||||
SUCCEED("UpdatePagesCachedBatch executed without error");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue