diff options
author | ameerj <52414509+ameerj@users.noreply.github.com> | 2021-12-31 08:07:59 +0100 |
---|---|---|
committer | ameerj <52414509+ameerj@users.noreply.github.com> | 2021-12-31 23:04:02 +0100 |
commit | 285b6dbc3932be87abfb7b044a083186152d1cac (patch) | |
tree | 38cc972b87093beace828275386a829fbcb886a2 /src/video_core | |
parent | video_core/memory_manager: Deduplicate Read/WriteBlock (diff) | |
download | yuzu-285b6dbc3932be87abfb7b044a083186152d1cac.tar yuzu-285b6dbc3932be87abfb7b044a083186152d1cac.tar.gz yuzu-285b6dbc3932be87abfb7b044a083186152d1cac.tar.bz2 yuzu-285b6dbc3932be87abfb7b044a083186152d1cac.tar.lz yuzu-285b6dbc3932be87abfb7b044a083186152d1cac.tar.xz yuzu-285b6dbc3932be87abfb7b044a083186152d1cac.tar.zst yuzu-285b6dbc3932be87abfb7b044a083186152d1cac.zip |
Diffstat (limited to 'src/video_core')
-rw-r--r-- | src/video_core/memory_manager.cpp | 22 | ||||
-rw-r--r-- | src/video_core/texture_cache/texture_cache.h | 4 |
2 files changed, 12 insertions, 14 deletions
diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp index 055c79a8e..4ff3fa268 100644 --- a/src/video_core/memory_manager.cpp +++ b/src/video_core/memory_manager.cpp @@ -73,12 +73,12 @@ void MemoryManager::Unmap(GPUVAddr gpu_addr, std::size_t size) { } const auto submapped_ranges = GetSubmappedRange(gpu_addr, size); - for (const auto& map : submapped_ranges) { + for (const auto& [map_addr, map_size] : submapped_ranges) { // Flush and invalidate through the GPU interface, to be asynchronous if possible. - const std::optional<VAddr> cpu_addr = GpuToCpuAddress(map.first); + const std::optional<VAddr> cpu_addr = GpuToCpuAddress(map_addr); ASSERT(cpu_addr); - rasterizer->UnmapMemory(*cpu_addr, map.second); + rasterizer->UnmapMemory(*cpu_addr, map_size); } UpdateRange(gpu_addr, PageEntry::State::Unmapped, size); @@ -274,8 +274,8 @@ void MemoryManager::ReadBlockImpl(GPUVAddr gpu_src_addr, void* dest_buffer, std: while (remaining_size > 0) { const std::size_t copy_amount{ std::min(static_cast<std::size_t>(page_size) - page_offset, remaining_size)}; - - if (const auto page_addr{GpuToCpuAddress(page_index << page_bits)}; page_addr) { + const auto page_addr{GpuToCpuAddress(page_index << page_bits)}; + if (page_addr && *page_addr != 0) { const auto src_addr{*page_addr + page_offset}; if (is_safe) { // Flush must happen on the rasterizer interface, such that memory is always @@ -313,8 +313,8 @@ void MemoryManager::WriteBlockImpl(GPUVAddr gpu_dest_addr, const void* src_buffe while (remaining_size > 0) { const std::size_t copy_amount{ std::min(static_cast<std::size_t>(page_size) - page_offset, remaining_size)}; - - if (const auto page_addr{GpuToCpuAddress(page_index << page_bits)}; page_addr) { + const auto page_addr{GpuToCpuAddress(page_index << page_bits)}; + if (page_addr && *page_addr != 0) { const auto dest_addr{*page_addr + page_offset}; if (is_safe) { @@ -415,15 +415,15 @@ std::vector<std::pair<GPUVAddr, std::size_t>> MemoryManager::GetSubmappedRange( size_t page_offset{gpu_addr & page_mask}; std::optional<std::pair<GPUVAddr, std::size_t>> last_segment{}; std::optional<VAddr> old_page_addr{}; - const auto extend_size = [this, &last_segment, &page_index](std::size_t bytes) { + const auto extend_size = [&last_segment, &page_index, &page_offset](std::size_t bytes) { if (!last_segment) { - GPUVAddr new_base_addr = page_index << page_bits; + const GPUVAddr new_base_addr = (page_index << page_bits) + page_offset; last_segment = {new_base_addr, bytes}; } else { last_segment->second += bytes; } }; - const auto split = [this, &last_segment, &result] { + const auto split = [&last_segment, &result] { if (last_segment) { result.push_back(*last_segment); last_segment = std::nullopt; @@ -432,7 +432,7 @@ std::vector<std::pair<GPUVAddr, std::size_t>> MemoryManager::GetSubmappedRange( while (remaining_size > 0) { const size_t num_bytes{std::min(page_size - page_offset, remaining_size)}; const auto page_addr{GpuToCpuAddress(page_index << page_bits)}; - if (!page_addr) { + if (!page_addr || *page_addr == 0) { split(); } else if (old_page_addr) { if (*old_page_addr + page_size != *page_addr) { diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index b494152b8..198bb0cfb 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h @@ -1376,9 +1376,7 @@ void TextureCache<P>::ForEachSparseSegment(ImageBase& image, Func&& func) { using FuncReturn = typename std::invoke_result<Func, GPUVAddr, VAddr, size_t>::type; static constexpr bool RETURNS_BOOL = std::is_same_v<FuncReturn, bool>; const auto segments = gpu_memory.GetSubmappedRange(image.gpu_addr, image.guest_size_bytes); - for (auto& segment : segments) { - const auto gpu_addr = segment.first; - const auto size = segment.second; + for (const auto& [gpu_addr, size] : segments) { std::optional<VAddr> cpu_addr = gpu_memory.GpuToCpuAddress(gpu_addr); ASSERT(cpu_addr); if constexpr (RETURNS_BOOL) { |