summaryrefslogtreecommitdiff
path: root/src/video_core/buffer_cache
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2020-12-30 02:25:23 -0300
committerGravatar ReinUsesLisp2020-12-30 03:38:50 -0300
commit9764c13d6d2977903f407761b27d847c0056e1c4 (patch)
treef6f5d6d6379b0404147969e7d1f548ed3d49ca01 /src/video_core/buffer_cache
parentvideo_core: Add a delayed destruction ring abstraction (diff)
downloadyuzu-9764c13d6d2977903f407761b27d847c0056e1c4.tar.gz
yuzu-9764c13d6d2977903f407761b27d847c0056e1c4.tar.xz
yuzu-9764c13d6d2977903f407761b27d847c0056e1c4.zip
video_core: Rewrite the texture cache
The current texture cache has several points that hurt maintainability and performance. It's easy to break unrelated parts of the cache when doing minor changes. The cache can easily forget valuable information about the cached textures by CPU writes or simply by its normal usage.The current texture cache has several points that hurt maintainability and performance. It's easy to break unrelated parts of the cache when doing minor changes. The cache can easily forget valuable information about the cached textures by CPU writes or simply by its normal usage. This commit aims to address those issues.
Diffstat (limited to 'src/video_core/buffer_cache')
-rw-r--r--src/video_core/buffer_cache/buffer_cache.h19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h
index 38961f3fd..83b9ee871 100644
--- a/src/video_core/buffer_cache/buffer_cache.h
+++ b/src/video_core/buffer_cache/buffer_cache.h
@@ -118,20 +118,17 @@ public:
118 /// Prepares the buffer cache for data uploading 118 /// Prepares the buffer cache for data uploading
119 /// @param max_size Maximum number of bytes that will be uploaded 119 /// @param max_size Maximum number of bytes that will be uploaded
120 /// @return True when a stream buffer invalidation was required, false otherwise 120 /// @return True when a stream buffer invalidation was required, false otherwise
121 bool Map(std::size_t max_size) { 121 void Map(std::size_t max_size) {
122 std::lock_guard lock{mutex}; 122 std::lock_guard lock{mutex};
123 123
124 bool invalidated; 124 std::tie(buffer_ptr, buffer_offset_base) = stream_buffer.Map(max_size, 4);
125 std::tie(buffer_ptr, buffer_offset_base, invalidated) = stream_buffer->Map(max_size, 4);
126 buffer_offset = buffer_offset_base; 125 buffer_offset = buffer_offset_base;
127
128 return invalidated;
129 } 126 }
130 127
131 /// Finishes the upload stream 128 /// Finishes the upload stream
132 void Unmap() { 129 void Unmap() {
133 std::lock_guard lock{mutex}; 130 std::lock_guard lock{mutex};
134 stream_buffer->Unmap(buffer_offset - buffer_offset_base); 131 stream_buffer.Unmap(buffer_offset - buffer_offset_base);
135 } 132 }
136 133
137 /// Function called at the end of each frame, inteded for deferred operations 134 /// Function called at the end of each frame, inteded for deferred operations
@@ -261,9 +258,9 @@ public:
261protected: 258protected:
262 explicit BufferCache(VideoCore::RasterizerInterface& rasterizer_, 259 explicit BufferCache(VideoCore::RasterizerInterface& rasterizer_,
263 Tegra::MemoryManager& gpu_memory_, Core::Memory::Memory& cpu_memory_, 260 Tegra::MemoryManager& gpu_memory_, Core::Memory::Memory& cpu_memory_,
264 std::unique_ptr<StreamBuffer> stream_buffer_) 261 StreamBuffer& stream_buffer_)
265 : rasterizer{rasterizer_}, gpu_memory{gpu_memory_}, cpu_memory{cpu_memory_}, 262 : rasterizer{rasterizer_}, gpu_memory{gpu_memory_}, cpu_memory{cpu_memory_},
266 stream_buffer{std::move(stream_buffer_)}, stream_buffer_handle{stream_buffer->Handle()} {} 263 stream_buffer{stream_buffer_} {}
267 264
268 ~BufferCache() = default; 265 ~BufferCache() = default;
269 266
@@ -441,7 +438,7 @@ private:
441 438
442 buffer_ptr += size; 439 buffer_ptr += size;
443 buffer_offset += size; 440 buffer_offset += size;
444 return BufferInfo{stream_buffer->Handle(), uploaded_offset, stream_buffer->Address()}; 441 return BufferInfo{stream_buffer.Handle(), uploaded_offset, stream_buffer.Address()};
445 } 442 }
446 443
447 void AlignBuffer(std::size_t alignment) { 444 void AlignBuffer(std::size_t alignment) {
@@ -567,9 +564,7 @@ private:
567 VideoCore::RasterizerInterface& rasterizer; 564 VideoCore::RasterizerInterface& rasterizer;
568 Tegra::MemoryManager& gpu_memory; 565 Tegra::MemoryManager& gpu_memory;
569 Core::Memory::Memory& cpu_memory; 566 Core::Memory::Memory& cpu_memory;
570 567 StreamBuffer& stream_buffer;
571 std::unique_ptr<StreamBuffer> stream_buffer;
572 BufferType stream_buffer_handle;
573 568
574 u8* buffer_ptr = nullptr; 569 u8* buffer_ptr = nullptr;
575 u64 buffer_offset = 0; 570 u64 buffer_offset = 0;