diff options
| author | 2022-01-16 05:05:34 +0100 | |
|---|---|---|
| committer | 2022-03-25 01:51:51 +0100 | |
| commit | 5e982a781201a12c4cee6af2908e4732b4c8d945 (patch) | |
| tree | 480bba2bae6f2618b657e3ddb9729eff65c94c2d /src/video_core/buffer_cache | |
| parent | Garbage Collection: Redesign the algorithm to do a better use of memory. (diff) | |
| download | yuzu-5e982a781201a12c4cee6af2908e4732b4c8d945.tar.gz yuzu-5e982a781201a12c4cee6af2908e4732b4c8d945.tar.xz yuzu-5e982a781201a12c4cee6af2908e4732b4c8d945.zip | |
Buffer Cache: Tune to the levels of the new GC.
Diffstat (limited to 'src/video_core/buffer_cache')
| -rw-r--r-- | src/video_core/buffer_cache/buffer_cache.h | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index 200d792dd..644c6e57e 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h | |||
| @@ -76,8 +76,9 @@ class BufferCache { | |||
| 76 | 76 | ||
| 77 | static constexpr BufferId NULL_BUFFER_ID{0}; | 77 | static constexpr BufferId NULL_BUFFER_ID{0}; |
| 78 | 78 | ||
| 79 | static constexpr u64 EXPECTED_MEMORY = 512_MiB; | 79 | static constexpr s64 DEFAULT_EXPECTED_MEMORY = 512_MiB; |
| 80 | static constexpr u64 CRITICAL_MEMORY = 1_GiB; | 80 | static constexpr s64 DEFAULT_CRITICAL_MEMORY = 1_GiB; |
| 81 | static constexpr s64 TARGET_THRESHOLD = 4_GiB; | ||
| 81 | 82 | ||
| 82 | using Maxwell = Tegra::Engines::Maxwell3D::Regs; | 83 | using Maxwell = Tegra::Engines::Maxwell3D::Regs; |
| 83 | 84 | ||
| @@ -436,6 +437,8 @@ private: | |||
| 436 | Common::LeastRecentlyUsedCache<LRUItemParams> lru_cache; | 437 | Common::LeastRecentlyUsedCache<LRUItemParams> lru_cache; |
| 437 | u64 frame_tick = 0; | 438 | u64 frame_tick = 0; |
| 438 | u64 total_used_memory = 0; | 439 | u64 total_used_memory = 0; |
| 440 | u64 minimum_memory = 0; | ||
| 441 | u64 critical_memory = 0; | ||
| 439 | 442 | ||
| 440 | std::array<BufferId, ((1ULL << 39) >> PAGE_BITS)> page_table; | 443 | std::array<BufferId, ((1ULL << 39) >> PAGE_BITS)> page_table; |
| 441 | }; | 444 | }; |
| @@ -451,11 +454,30 @@ BufferCache<P>::BufferCache(VideoCore::RasterizerInterface& rasterizer_, | |||
| 451 | // Ensure the first slot is used for the null buffer | 454 | // Ensure the first slot is used for the null buffer |
| 452 | void(slot_buffers.insert(runtime, NullBufferParams{})); | 455 | void(slot_buffers.insert(runtime, NullBufferParams{})); |
| 453 | common_ranges.clear(); | 456 | common_ranges.clear(); |
| 457 | |||
| 458 | if (!runtime.CanReportMemoryUsage()) { | ||
| 459 | minimum_memory = DEFAULT_EXPECTED_MEMORY; | ||
| 460 | critical_memory = DEFAULT_CRITICAL_MEMORY; | ||
| 461 | return; | ||
| 462 | } | ||
| 463 | |||
| 464 | const s64 device_memory = static_cast<s64>(runtime.GetDeviceLocalMemory()); | ||
| 465 | const s64 min_spacing_expected = device_memory - 1_GiB - 512_MiB; | ||
| 466 | const s64 min_spacing_critical = device_memory - 1_GiB; | ||
| 467 | const s64 mem_tresshold = std::min(device_memory, TARGET_THRESHOLD); | ||
| 468 | const s64 min_vacancy_expected = (6 * mem_tresshold) / 10; | ||
| 469 | const s64 min_vacancy_critical = (3 * mem_tresshold) / 10; | ||
| 470 | minimum_memory = static_cast<u64>( | ||
| 471 | std::max(std::min(device_memory - min_vacancy_expected, min_spacing_expected), | ||
| 472 | DEFAULT_EXPECTED_MEMORY)); | ||
| 473 | critical_memory = static_cast<u64>( | ||
| 474 | std::max(std::min(device_memory - min_vacancy_critical, min_spacing_critical), | ||
| 475 | DEFAULT_CRITICAL_MEMORY)); | ||
| 454 | } | 476 | } |
| 455 | 477 | ||
| 456 | template <class P> | 478 | template <class P> |
| 457 | void BufferCache<P>::RunGarbageCollector() { | 479 | void BufferCache<P>::RunGarbageCollector() { |
| 458 | const bool aggressive_gc = total_used_memory >= CRITICAL_MEMORY; | 480 | const bool aggressive_gc = total_used_memory >= critical_memory; |
| 459 | const u64 ticks_to_destroy = aggressive_gc ? 60 : 120; | 481 | const u64 ticks_to_destroy = aggressive_gc ? 60 : 120; |
| 460 | int num_iterations = aggressive_gc ? 64 : 32; | 482 | int num_iterations = aggressive_gc ? 64 : 32; |
| 461 | const auto clean_up = [this, &num_iterations](BufferId buffer_id) { | 483 | const auto clean_up = [this, &num_iterations](BufferId buffer_id) { |
| @@ -486,7 +508,11 @@ void BufferCache<P>::TickFrame() { | |||
| 486 | const bool skip_preferred = hits * 256 < shots * 251; | 508 | const bool skip_preferred = hits * 256 < shots * 251; |
| 487 | uniform_buffer_skip_cache_size = skip_preferred ? DEFAULT_SKIP_CACHE_SIZE : 0; | 509 | uniform_buffer_skip_cache_size = skip_preferred ? DEFAULT_SKIP_CACHE_SIZE : 0; |
| 488 | 510 | ||
| 489 | if (total_used_memory >= EXPECTED_MEMORY) { | 511 | // If we can obtain the memory info, use it instead of the estimate. |
| 512 | if (runtime.CanReportMemoryUsage()) { | ||
| 513 | total_used_memory = runtime.GetDeviceMemoryUsage(); | ||
| 514 | } | ||
| 515 | if (total_used_memory >= minimum_memory) { | ||
| 490 | RunGarbageCollector(); | 516 | RunGarbageCollector(); |
| 491 | } | 517 | } |
| 492 | ++frame_tick; | 518 | ++frame_tick; |