summaryrefslogtreecommitdiff
path: root/src/video_core/texture_cache
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2021-06-17 00:29:48 +0200
committerGravatar Fernando Sahmkow2021-06-17 00:29:48 +0200
commitca6f47c6862a24dfa78f3d25c8b7819636218cdd (patch)
treed45fea664fa1e1d4de04b206289f638ffe1ceedc /src/video_core/texture_cache
parentReaper: Address Feedback. (diff)
downloadyuzu-ca6f47c6862a24dfa78f3d25c8b7819636218cdd.tar.gz
yuzu-ca6f47c6862a24dfa78f3d25c8b7819636218cdd.tar.xz
yuzu-ca6f47c6862a24dfa78f3d25c8b7819636218cdd.zip
Reaper: Change memory restrictions on TC depending on host memory on VK.
Diffstat (limited to 'src/video_core/texture_cache')
-rw-r--r--src/video_core/texture_cache/slot_vector.h2
-rw-r--r--src/video_core/texture_cache/texture_cache.h46
2 files changed, 32 insertions, 16 deletions
diff --git a/src/video_core/texture_cache/slot_vector.h b/src/video_core/texture_cache/slot_vector.h
index 1259e8263..6180b8c0e 100644
--- a/src/video_core/texture_cache/slot_vector.h
+++ b/src/video_core/texture_cache/slot_vector.h
@@ -79,7 +79,7 @@ public:
79 Iterator(SlotVector<T>* slot_vector_, SlotId id_) noexcept 79 Iterator(SlotVector<T>* slot_vector_, SlotId id_) noexcept
80 : slot_vector{slot_vector_}, id{id_} {} 80 : slot_vector{slot_vector_}, id{id_} {}
81 81
82 bool IsValid(const u64* bitset) noexcept { 82 bool IsValid(const u64* bitset) const noexcept {
83 return ((bitset[id.index / 64] >> (id.index % 64)) & 1) != 0; 83 return ((bitset[id.index / 64] >> (id.index % 64)) & 1) != 0;
84 } 84 }
85 85
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index 8ff6f4e01..64b576cbc 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -71,14 +71,16 @@ class TextureCache {
71 static constexpr bool FRAMEBUFFER_BLITS = P::FRAMEBUFFER_BLITS; 71 static constexpr bool FRAMEBUFFER_BLITS = P::FRAMEBUFFER_BLITS;
72 /// True when some copies have to be emulated 72 /// True when some copies have to be emulated
73 static constexpr bool HAS_EMULATED_COPIES = P::HAS_EMULATED_COPIES; 73 static constexpr bool HAS_EMULATED_COPIES = P::HAS_EMULATED_COPIES;
74 /// True when the API can provide info about the memory of the device.
75 static constexpr bool HAS_DEVICE_MEMORY_INFO = P::HAS_DEVICE_MEMORY_INFO;
74 76
75 /// Image view ID for null descriptors 77 /// Image view ID for null descriptors
76 static constexpr ImageViewId NULL_IMAGE_VIEW_ID{0}; 78 static constexpr ImageViewId NULL_IMAGE_VIEW_ID{0};
77 /// Sampler ID for bugged sampler ids 79 /// Sampler ID for bugged sampler ids
78 static constexpr SamplerId NULL_SAMPLER_ID{0}; 80 static constexpr SamplerId NULL_SAMPLER_ID{0};
79 81
80 static constexpr u64 EXPECTED_MEMORY = Common::Size_1_GB; 82 static constexpr u64 DEFAULT_EXPECTED_MEMORY = Common::Size_1_GB;
81 static constexpr u64 CRITICAL_MEMORY = Common::Size_2_GB; 83 static constexpr u64 DEFAULT_CRITICAL_MEMORY = Common::Size_2_GB;
82 84
83 using Runtime = typename P::Runtime; 85 using Runtime = typename P::Runtime;
84 using Image = typename P::Image; 86 using Image = typename P::Image;
@@ -108,6 +110,9 @@ public:
108 /// Notify the cache that a new frame has been queued 110 /// Notify the cache that a new frame has been queued
109 void TickFrame(); 111 void TickFrame();
110 112
113 /// Runs the Garbage Collector.
114 void RunGarbageCollector();
115
111 /// Return a constant reference to the given image view id 116 /// Return a constant reference to the given image view id
112 [[nodiscard]] const ImageView& GetImageView(ImageViewId id) const noexcept; 117 [[nodiscard]] const ImageView& GetImageView(ImageViewId id) const noexcept;
113 118
@@ -339,6 +344,8 @@ private:
339 344
340 bool has_deleted_images = false; 345 bool has_deleted_images = false;
341 u64 total_used_memory = 0; 346 u64 total_used_memory = 0;
347 u64 expected_memory;
348 u64 critical_memory;
342 349
343 SlotVector<Image> slot_images; 350 SlotVector<Image> slot_images;
344 SlotVector<ImageView> slot_image_views; 351 SlotVector<ImageView> slot_image_views;
@@ -382,21 +389,23 @@ TextureCache<P>::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface&
382 void(slot_samplers.insert(runtime, sampler_descriptor)); 389 void(slot_samplers.insert(runtime, sampler_descriptor));
383 390
384 deletion_iterator = slot_images.begin(); 391 deletion_iterator = slot_images.begin();
392
393 if constexpr (HAS_DEVICE_MEMORY_INFO) {
394 const auto device_memory = runtime.GetDeviceLocalMemory();
395 const u64 possible_expected_memory = (device_memory * 3) / 10;
396 const u64 possible_critical_memory = (device_memory * 6) / 10;
397 expected_memory = std::max(possible_expected_memory, DEFAULT_EXPECTED_MEMORY);
398 critical_memory = std::max(possible_critical_memory, DEFAULT_CRITICAL_MEMORY);
399 } else {
400 expected_memory = DEFAULT_EXPECTED_MEMORY;
401 critical_memory = DEFAULT_CRITICAL_MEMORY;
402 }
385} 403}
386 404
387template <class P> 405template <class P>
388void TextureCache<P>::TickFrame() { 406void TextureCache<P>::RunGarbageCollector() {
389 const bool enabled_gc = Settings::values.use_caches_gc.GetValue(); 407 const bool high_priority_mode = total_used_memory >= expected_memory;
390 if (!enabled_gc) { 408 const bool aggressive_mode = total_used_memory >= critical_memory;
391 // @Note(Blinkhawk): compile error with SCOPE_EXIT on msvc.
392 sentenced_images.Tick();
393 sentenced_framebuffers.Tick();
394 sentenced_image_view.Tick();
395 ++frame_tick;
396 return;
397 }
398 const bool high_priority_mode = total_used_memory >= EXPECTED_MEMORY;
399 const bool aggressive_mode = total_used_memory >= CRITICAL_MEMORY;
400 const u64 ticks_to_destroy = high_priority_mode ? 60 : 100; 409 const u64 ticks_to_destroy = high_priority_mode ? 60 : 100;
401 int num_iterations = aggressive_mode ? 256 : (high_priority_mode ? 128 : 64); 410 int num_iterations = aggressive_mode ? 256 : (high_priority_mode ? 128 : 64);
402 for (; num_iterations > 0; --num_iterations) { 411 for (; num_iterations > 0; --num_iterations) {
@@ -451,11 +460,18 @@ void TextureCache<P>::TickFrame() {
451 UnregisterImage(image_id); 460 UnregisterImage(image_id);
452 DeleteImage(image_id); 461 DeleteImage(image_id);
453 if (is_bad_overlap) { 462 if (is_bad_overlap) {
454 num_iterations++; 463 ++num_iterations;
455 } 464 }
456 } 465 }
457 ++deletion_iterator; 466 ++deletion_iterator;
458 } 467 }
468}
469
470template <class P>
471void TextureCache<P>::TickFrame() {
472 if (Settings::values.use_caches_gc.GetValue()) {
473 RunGarbageCollector();
474 }
459 sentenced_images.Tick(); 475 sentenced_images.Tick();
460 sentenced_framebuffers.Tick(); 476 sentenced_framebuffers.Tick();
461 sentenced_image_view.Tick(); 477 sentenced_image_view.Tick();