summaryrefslogtreecommitdiff
path: root/src/video_core/buffer_cache
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/buffer_cache')
-rw-r--r--src/video_core/buffer_cache/buffer_cache.h27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h
index ecb7d3dee..b4fa85c5b 100644
--- a/src/video_core/buffer_cache/buffer_cache.h
+++ b/src/video_core/buffer_cache/buffer_cache.h
@@ -65,6 +65,9 @@ class BufferCache {
65 65
66 static constexpr BufferId NULL_BUFFER_ID{0}; 66 static constexpr BufferId NULL_BUFFER_ID{0};
67 67
68 static constexpr u64 expected_memory = 512ULL * 1024ULL * 1024ULL;
69 static constexpr u64 critical_memory = 1024ULL * 1024ULL * 1024ULL;
70
68 using Maxwell = Tegra::Engines::Maxwell3D::Regs; 71 using Maxwell = Tegra::Engines::Maxwell3D::Regs;
69 72
70 using Runtime = typename P::Runtime; 73 using Runtime = typename P::Runtime;
@@ -327,6 +330,7 @@ private:
327 330
328 typename SlotVector<Buffer>::Iterator deletion_iterator; 331 typename SlotVector<Buffer>::Iterator deletion_iterator;
329 u64 frame_tick = 0; 332 u64 frame_tick = 0;
333 u64 total_used_memory = 0;
330 334
331 std::array<BufferId, ((1ULL << 39) >> PAGE_BITS)> page_table; 335 std::array<BufferId, ((1ULL << 39) >> PAGE_BITS)> page_table;
332}; 336};
@@ -346,6 +350,10 @@ BufferCache<P>::BufferCache(VideoCore::RasterizerInterface& rasterizer_,
346 350
347template <class P> 351template <class P>
348void BufferCache<P>::TickFrame() { 352void BufferCache<P>::TickFrame() {
353 SCOPE_EXIT({
354 ++frame_tick;
355 delayed_destruction_ring.Tick();
356 });
349 // Calculate hits and shots and move hit bits to the right 357 // Calculate hits and shots and move hit bits to the right
350 const u32 hits = std::reduce(uniform_cache_hits.begin(), uniform_cache_hits.end()); 358 const u32 hits = std::reduce(uniform_cache_hits.begin(), uniform_cache_hits.end());
351 const u32 shots = std::reduce(uniform_cache_shots.begin(), uniform_cache_shots.end()); 359 const u32 shots = std::reduce(uniform_cache_shots.begin(), uniform_cache_shots.end());
@@ -359,8 +367,13 @@ void BufferCache<P>::TickFrame() {
359 const bool skip_preferred = hits * 256 < shots * 251; 367 const bool skip_preferred = hits * 256 < shots * 251;
360 uniform_buffer_skip_cache_size = skip_preferred ? DEFAULT_SKIP_CACHE_SIZE : 0; 368 uniform_buffer_skip_cache_size = skip_preferred ? DEFAULT_SKIP_CACHE_SIZE : 0;
361 369
362 static constexpr u64 ticks_to_destroy = 120; 370 const bool activate_gc = total_used_memory >= expected_memory;
363 int num_iterations = 32; 371 if (!activate_gc) {
372 return;
373 }
374 const bool agressive_gc = total_used_memory >= critical_memory;
375 const u64 ticks_to_destroy = agressive_gc ? 60 : 120;
376 int num_iterations = agressive_gc ? 64 : 32;
364 for (; num_iterations > 0; --num_iterations) { 377 for (; num_iterations > 0; --num_iterations) {
365 if (deletion_iterator == slot_buffers.end()) { 378 if (deletion_iterator == slot_buffers.end()) {
366 deletion_iterator = slot_buffers.begin(); 379 deletion_iterator = slot_buffers.begin();
@@ -375,8 +388,6 @@ void BufferCache<P>::TickFrame() {
375 DeleteBuffer(buffer_id); 388 DeleteBuffer(buffer_id);
376 } 389 }
377 } 390 }
378 delayed_destruction_ring.Tick();
379 ++frame_tick;
380} 391}
381 392
382template <class P> 393template <class P>
@@ -1115,8 +1126,14 @@ template <class P>
1115template <bool insert> 1126template <bool insert>
1116void BufferCache<P>::ChangeRegister(BufferId buffer_id) { 1127void BufferCache<P>::ChangeRegister(BufferId buffer_id) {
1117 const Buffer& buffer = slot_buffers[buffer_id]; 1128 const Buffer& buffer = slot_buffers[buffer_id];
1129 const auto size = buffer.SizeBytes();
1130 if (insert) {
1131 total_used_memory += Common::AlignUp(size, 1024);
1132 } else {
1133 total_used_memory -= Common::AlignUp(size, 1024);
1134 }
1118 const VAddr cpu_addr_begin = buffer.CpuAddr(); 1135 const VAddr cpu_addr_begin = buffer.CpuAddr();
1119 const VAddr cpu_addr_end = cpu_addr_begin + buffer.SizeBytes(); 1136 const VAddr cpu_addr_end = cpu_addr_begin + size;
1120 const u64 page_begin = cpu_addr_begin / PAGE_SIZE; 1137 const u64 page_begin = cpu_addr_begin / PAGE_SIZE;
1121 const u64 page_end = Common::DivCeil(cpu_addr_end, PAGE_SIZE); 1138 const u64 page_end = Common::DivCeil(cpu_addr_end, PAGE_SIZE);
1122 for (u64 page = page_begin; page != page_end; ++page) { 1139 for (u64 page = page_begin; page != page_end; ++page) {