summaryrefslogtreecommitdiff
path: root/src/video_core/texture_cache
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2022-01-16 06:34:43 +0100
committerGravatar Fernando Sahmkow2022-03-25 01:51:52 +0100
commit9edbbf2af401f821c0be6a266e65975e3de25fb3 (patch)
tree16bc11bc0097e80e8b39e7cc990a81448f7bf059 /src/video_core/texture_cache
parentBuffer Cache: Tune to the levels of the new GC. (diff)
downloadyuzu-9edbbf2af401f821c0be6a266e65975e3de25fb3.tar.gz
yuzu-9edbbf2af401f821c0be6a266e65975e3de25fb3.tar.xz
yuzu-9edbbf2af401f821c0be6a266e65975e3de25fb3.zip
Garbage Collection: Final tuning.
Diffstat (limited to 'src/video_core/texture_cache')
-rw-r--r--src/video_core/texture_cache/image_base.h10
-rw-r--r--src/video_core/texture_cache/texture_cache.h36
2 files changed, 29 insertions, 17 deletions
diff --git a/src/video_core/texture_cache/image_base.h b/src/video_core/texture_cache/image_base.h
index 279f39269..dd0106432 100644
--- a/src/video_core/texture_cache/image_base.h
+++ b/src/video_core/texture_cache/image_base.h
@@ -29,11 +29,11 @@ enum class ImageFlagBits : u32 {
29 Sparse = 1 << 9, ///< Image has non continous submemory. 29 Sparse = 1 << 9, ///< Image has non continous submemory.
30 30
31 // Garbage Collection Flags 31 // Garbage Collection Flags
32 BadOverlap = 1 << 10, ///< This image overlaps other but doesn't fit, has higher 32 BadOverlap = 1 << 10, ///< This image overlaps other but doesn't fit, has higher
33 ///< garbage collection priority 33 ///< garbage collection priority
34 Alias = 1 << 11, ///< This image has aliases and has priority on garbage 34 Alias = 1 << 11, ///< This image has aliases and has priority on garbage
35 ///< collection 35 ///< collection
36 GCProtected = 1 << 12, ///< Protected from low-tier GC as they are costy to load back. 36 CostlyLoad = 1 << 12, ///< Protected from low-tier GC as it is costly to load back.
37 37
38 // Rescaler 38 // Rescaler
39 Rescaled = 1 << 13, 39 Rescaled = 1 << 13,
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index 7b6bd8697..efc1c4525 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -53,17 +53,16 @@ TextureCache<P>::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface&
53 const s64 device_memory = static_cast<s64>(runtime.GetDeviceLocalMemory()); 53 const s64 device_memory = static_cast<s64>(runtime.GetDeviceLocalMemory());
54 const s64 min_spacing_expected = device_memory - 1_GiB - 512_MiB; 54 const s64 min_spacing_expected = device_memory - 1_GiB - 512_MiB;
55 const s64 min_spacing_critical = device_memory - 1_GiB; 55 const s64 min_spacing_critical = device_memory - 1_GiB;
56 const s64 mem_tresshold = std::min(device_memory, TARGET_THRESHOLD); 56 const s64 mem_threshold = std::min(device_memory, TARGET_THRESHOLD);
57 const s64 min_vacancy_expected = (6 * mem_tresshold) / 10; 57 const s64 min_vacancy_expected = (6 * mem_threshold) / 10;
58 const s64 min_vacancy_critical = (3 * mem_tresshold) / 10; 58 const s64 min_vacancy_critical = (3 * mem_threshold) / 10;
59 expected_memory = static_cast<u64>( 59 expected_memory = static_cast<u64>(
60 std::max(std::min(device_memory - min_vacancy_expected, min_spacing_expected), 60 std::max(std::min(device_memory - min_vacancy_expected, min_spacing_expected),
61 DEFAULT_EXPECTED_MEMORY)); 61 DEFAULT_EXPECTED_MEMORY));
62 critical_memory = static_cast<u64>( 62 critical_memory = static_cast<u64>(
63 std::max(std::min(device_memory - min_vacancy_critical, min_spacing_critical), 63 std::max(std::min(device_memory - min_vacancy_critical, min_spacing_critical),
64 DEFAULT_CRITICAL_MEMORY)); 64 DEFAULT_CRITICAL_MEMORY));
65 minimum_memory = static_cast<u64>((device_memory - mem_tresshold) / 2); 65 minimum_memory = static_cast<u64>((device_memory - mem_threshold) / 2);
66 LOG_CRITICAL(Debug, "Available Memory: {}", device_memory / 1_MiB);
67 } else { 66 } else {
68 expected_memory = DEFAULT_EXPECTED_MEMORY + 512_MiB; 67 expected_memory = DEFAULT_EXPECTED_MEMORY + 512_MiB;
69 critical_memory = DEFAULT_CRITICAL_MEMORY + 1_GiB; 68 critical_memory = DEFAULT_CRITICAL_MEMORY + 1_GiB;
@@ -73,11 +72,12 @@ TextureCache<P>::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface&
73 72
74template <class P> 73template <class P>
75void TextureCache<P>::RunGarbageCollector() { 74void TextureCache<P>::RunGarbageCollector() {
76 const bool high_priority_mode = total_used_memory >= expected_memory; 75 bool high_priority_mode = total_used_memory >= expected_memory;
77 const bool aggressive_mode = total_used_memory >= critical_memory; 76 bool aggressive_mode = total_used_memory >= critical_memory;
78 const u64 ticks_to_destroy = aggressive_mode ? 10ULL : high_priority_mode ? 25ULL : 100ULL; 77 const u64 ticks_to_destroy = aggressive_mode ? 10ULL : high_priority_mode ? 25ULL : 50ULL;
79 size_t num_iterations = aggressive_mode ? 300 : (high_priority_mode ? 50 : 10); 78 size_t num_iterations = aggressive_mode ? 40 : (high_priority_mode ? 20 : 10);
80 const auto clean_up = [this, &num_iterations, high_priority_mode](ImageId image_id) { 79 const auto clean_up = [this, &num_iterations, &high_priority_mode,
80 &aggressive_mode](ImageId image_id) {
81 if (num_iterations == 0) { 81 if (num_iterations == 0) {
82 return true; 82 return true;
83 } 83 }
@@ -85,7 +85,8 @@ void TextureCache<P>::RunGarbageCollector() {
85 auto& image = slot_images[image_id]; 85 auto& image = slot_images[image_id];
86 const bool must_download = 86 const bool must_download =
87 image.IsSafeDownload() && False(image.flags & ImageFlagBits::BadOverlap); 87 image.IsSafeDownload() && False(image.flags & ImageFlagBits::BadOverlap);
88 if (!high_priority_mode && must_download) { 88 if (!high_priority_mode &&
89 (must_download || True(image.flags & ImageFlagBits::CostlyLoad))) {
89 return false; 90 return false;
90 } 91 }
91 if (must_download) { 92 if (must_download) {
@@ -100,6 +101,18 @@ void TextureCache<P>::RunGarbageCollector() {
100 } 101 }
101 UnregisterImage(image_id); 102 UnregisterImage(image_id);
102 DeleteImage(image_id, image.scale_tick > frame_tick + 5); 103 DeleteImage(image_id, image.scale_tick > frame_tick + 5);
104 if (total_used_memory < critical_memory) {
105 if (aggressive_mode) {
106 // Sink the aggresiveness.
107 num_iterations >>= 2;
108 aggressive_mode = false;
109 return false;
110 }
111 if (high_priority_mode && total_used_memory < expected_memory) {
112 num_iterations >>= 1;
113 high_priority_mode = false;
114 }
115 }
103 return false; 116 return false;
104 }; 117 };
105 lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, clean_up); 118 lru_cache.ForEachItemBelow(frame_tick - ticks_to_destroy, clean_up);
@@ -120,7 +133,6 @@ void TextureCache<P>::TickFrame() {
120 runtime.TickFrame(); 133 runtime.TickFrame();
121 critical_gc = 0; 134 critical_gc = 0;
122 ++frame_tick; 135 ++frame_tick;
123 LOG_CRITICAL(Debug, "Current memory: {}", total_used_memory / 1_MiB);
124} 136}
125 137
126template <class P> 138template <class P>