diff options
author | bunnei <bunneidev@gmail.com> | 2018-04-21 20:40:51 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2018-04-24 23:49:20 +0200 |
commit | 10c6d891190e407cf4fbcf6eb8ce2506ddf388ec (patch) | |
tree | 3ba8d73cf1906252012a4810be6f5b0b5bc9ca80 | |
parent | memory_manager: Make GpuToCpuAddress return an optional. (diff) | |
download | yuzu-10c6d891190e407cf4fbcf6eb8ce2506ddf388ec.tar yuzu-10c6d891190e407cf4fbcf6eb8ce2506ddf388ec.tar.gz yuzu-10c6d891190e407cf4fbcf6eb8ce2506ddf388ec.tar.bz2 yuzu-10c6d891190e407cf4fbcf6eb8ce2506ddf388ec.tar.lz yuzu-10c6d891190e407cf4fbcf6eb8ce2506ddf388ec.tar.xz yuzu-10c6d891190e407cf4fbcf6eb8ce2506ddf388ec.tar.zst yuzu-10c6d891190e407cf4fbcf6eb8ce2506ddf388ec.zip |
-rw-r--r-- | src/video_core/memory_manager.cpp | 17 | ||||
-rw-r--r-- | src/video_core/memory_manager.h | 10 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp index 9bbbb7e65..25984439d 100644 --- a/src/video_core/memory_manager.cpp +++ b/src/video_core/memory_manager.cpp @@ -38,6 +38,9 @@ GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, u64 size) { PageSlot(*gpu_addr + offset) = cpu_addr + offset; } + MappedRegion region{cpu_addr, *gpu_addr, size}; + mapped_regions.push_back(region); + return *gpu_addr; } @@ -49,6 +52,9 @@ GPUVAddr MemoryManager::MapBufferEx(VAddr cpu_addr, GPUVAddr gpu_addr, u64 size) PageSlot(gpu_addr + offset) = cpu_addr + offset; } + MappedRegion region{cpu_addr, gpu_addr, size}; + mapped_regions.push_back(region); + return gpu_addr; } @@ -84,6 +90,17 @@ boost::optional<VAddr> MemoryManager::GpuToCpuAddress(GPUVAddr gpu_addr) { return base_addr + (gpu_addr & PAGE_MASK); } +std::vector<GPUVAddr> MemoryManager::CpuToGpuAddress(VAddr cpu_addr) const { + std::vector<GPUVAddr> results; + for (const auto& region : mapped_regions) { + if (cpu_addr >= region.cpu_addr && cpu_addr < (region.cpu_addr + region.size)) { + u64 offset = cpu_addr - region.cpu_addr; + results.push_back(region.gpu_addr + offset); + } + } + return results; +} + bool MemoryManager::IsPageMapped(GPUVAddr gpu_addr) { return PageSlot(gpu_addr) != static_cast<u64>(PageStatus::Unmapped); } diff --git a/src/video_core/memory_manager.h b/src/video_core/memory_manager.h index 246c8fb7e..7d745101f 100644 --- a/src/video_core/memory_manager.h +++ b/src/video_core/memory_manager.h @@ -6,6 +6,7 @@ #include <array> #include <memory> +#include <vector> #include <boost/optional.hpp> @@ -26,6 +27,7 @@ public: GPUVAddr MapBufferEx(VAddr cpu_addr, u64 size); GPUVAddr MapBufferEx(VAddr cpu_addr, GPUVAddr gpu_addr, u64 size); boost::optional<VAddr> GpuToCpuAddress(GPUVAddr gpu_addr); + std::vector<GPUVAddr> CpuToGpuAddress(VAddr cpu_addr) const; static constexpr u64 PAGE_BITS = 16; static constexpr u64 PAGE_SIZE = 1 << PAGE_BITS; @@ -51,6 +53,14 @@ private: using PageBlock = std::array<VAddr, PAGE_BLOCK_SIZE>; std::array<std::unique_ptr<PageBlock>, PAGE_TABLE_SIZE> page_table{}; + + struct MappedRegion { + VAddr cpu_addr; + GPUVAddr gpu_addr; + u64 size; + }; + + std::vector<MappedRegion> mapped_regions; }; } // namespace Tegra |