summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/video_core/memory_manager.cpp23
-rw-r--r--src/video_core/memory_manager.h6
2 files changed, 27 insertions, 2 deletions
diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp
index f5cdf548e..c841f3cd7 100644
--- a/src/video_core/memory_manager.cpp
+++ b/src/video_core/memory_manager.cpp
@@ -4,6 +4,7 @@
4 4
5#include "common/alignment.h" 5#include "common/alignment.h"
6#include "common/assert.h" 6#include "common/assert.h"
7#include "common/logging/log.h"
7#include "core/core.h" 8#include "core/core.h"
8#include "core/hle/kernel/memory/page_table.h" 9#include "core/hle/kernel/memory/page_table.h"
9#include "core/hle/kernel/process.h" 10#include "core/hle/kernel/process.h"
@@ -38,6 +39,12 @@ GPUVAddr MemoryManager::UpdateRange(GPUVAddr gpu_addr, PageEntry page_entry, std
38} 39}
39 40
40GPUVAddr MemoryManager::Map(VAddr cpu_addr, GPUVAddr gpu_addr, std::size_t size) { 41GPUVAddr MemoryManager::Map(VAddr cpu_addr, GPUVAddr gpu_addr, std::size_t size) {
42 const auto it = std::ranges::lower_bound(map_ranges, gpu_addr, {}, &MapRange::first);
43 if (it != map_ranges.end() && it->first == gpu_addr) {
44 it->second = size;
45 } else {
46 map_ranges.insert(it, MapRange{gpu_addr, size});
47 }
41 return UpdateRange(gpu_addr, cpu_addr, size); 48 return UpdateRange(gpu_addr, cpu_addr, size);
42} 49}
43 50
@@ -52,10 +59,16 @@ GPUVAddr MemoryManager::MapAllocate32(VAddr cpu_addr, std::size_t size) {
52} 59}
53 60
54void MemoryManager::Unmap(GPUVAddr gpu_addr, std::size_t size) { 61void MemoryManager::Unmap(GPUVAddr gpu_addr, std::size_t size) {
55 if (!size) { 62 if (size == 0) {
56 return; 63 return;
57 } 64 }
58 65 const auto it = std::ranges::lower_bound(map_ranges, gpu_addr, {}, &MapRange::first);
66 if (it != map_ranges.end()) {
67 ASSERT(it->first == gpu_addr);
68 map_ranges.erase(it);
69 } else {
70 UNREACHABLE_MSG("Unmapping non-existent GPU address=0x{:x}", gpu_addr);
71 }
59 // Flush and invalidate through the GPU interface, to be asynchronous if possible. 72 // Flush and invalidate through the GPU interface, to be asynchronous if possible.
60 const std::optional<VAddr> cpu_addr = GpuToCpuAddress(gpu_addr); 73 const std::optional<VAddr> cpu_addr = GpuToCpuAddress(gpu_addr);
61 ASSERT(cpu_addr); 74 ASSERT(cpu_addr);
@@ -218,6 +231,12 @@ const u8* MemoryManager::GetPointer(GPUVAddr gpu_addr) const {
218 return system.Memory().GetPointer(*address); 231 return system.Memory().GetPointer(*address);
219} 232}
220 233
234size_t MemoryManager::BytesToMapEnd(GPUVAddr gpu_addr) const noexcept {
235 auto it = std::ranges::upper_bound(map_ranges, gpu_addr, {}, &MapRange::first);
236 --it;
237 return it->second - (gpu_addr - it->first);
238}
239
221void MemoryManager::ReadBlock(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size) const { 240void MemoryManager::ReadBlock(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size) const {
222 std::size_t remaining_size{size}; 241 std::size_t remaining_size{size};
223 std::size_t page_index{gpu_src_addr >> page_bits}; 242 std::size_t page_index{gpu_src_addr >> page_bits};
diff --git a/src/video_core/memory_manager.h b/src/video_core/memory_manager.h
index a52fbbd8c..b468a67de 100644
--- a/src/video_core/memory_manager.h
+++ b/src/video_core/memory_manager.h
@@ -85,6 +85,9 @@ public:
85 [[nodiscard]] u8* GetPointer(GPUVAddr addr); 85 [[nodiscard]] u8* GetPointer(GPUVAddr addr);
86 [[nodiscard]] const u8* GetPointer(GPUVAddr addr) const; 86 [[nodiscard]] const u8* GetPointer(GPUVAddr addr) const;
87 87
88 /// Returns the number of bytes until the end of the memory map containing the given GPU address
89 [[nodiscard]] size_t BytesToMapEnd(GPUVAddr gpu_addr) const noexcept;
90
88 /** 91 /**
89 * ReadBlock and WriteBlock are full read and write operations over virtual 92 * ReadBlock and WriteBlock are full read and write operations over virtual
90 * GPU Memory. It's important to use these when GPU memory may not be continuous 93 * GPU Memory. It's important to use these when GPU memory may not be continuous
@@ -151,6 +154,9 @@ private:
151 VideoCore::RasterizerInterface* rasterizer = nullptr; 154 VideoCore::RasterizerInterface* rasterizer = nullptr;
152 155
153 std::vector<PageEntry> page_table; 156 std::vector<PageEntry> page_table;
157
158 using MapRange = std::pair<GPUVAddr, size_t>;
159 std::vector<MapRange> map_ranges;
154}; 160};
155 161
156} // namespace Tegra 162} // namespace Tegra