summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorameerj <52414509+ameerj@users.noreply.github.com>2021-12-31 05:36:00 +0100
committerameerj <52414509+ameerj@users.noreply.github.com>2021-12-31 08:08:22 +0100
commit2428214c4be289b86faa5424ca030f4d2959dba2 (patch)
treef06a6a8cab8a3af79d44bda0c6068b01f22f6d4f
parentMerge pull request #7647 from german77/toad (diff)
downloadyuzu-2428214c4be289b86faa5424ca030f4d2959dba2.tar
yuzu-2428214c4be289b86faa5424ca030f4d2959dba2.tar.gz
yuzu-2428214c4be289b86faa5424ca030f4d2959dba2.tar.bz2
yuzu-2428214c4be289b86faa5424ca030f4d2959dba2.tar.lz
yuzu-2428214c4be289b86faa5424ca030f4d2959dba2.tar.xz
yuzu-2428214c4be289b86faa5424ca030f4d2959dba2.tar.zst
yuzu-2428214c4be289b86faa5424ca030f4d2959dba2.zip
Diffstat (limited to '')
-rw-r--r--src/video_core/memory_manager.cpp74
-rw-r--r--src/video_core/memory_manager.h5
2 files changed, 32 insertions, 47 deletions
diff --git a/src/video_core/memory_manager.cpp b/src/video_core/memory_manager.cpp
index dce00e829..055c79a8e 100644
--- a/src/video_core/memory_manager.cpp
+++ b/src/video_core/memory_manager.cpp
@@ -265,7 +265,8 @@ size_t MemoryManager::BytesToMapEnd(GPUVAddr gpu_addr) const noexcept {
return it->second - (gpu_addr - it->first);
}
-void MemoryManager::ReadBlock(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size) const {
+void MemoryManager::ReadBlockImpl(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size,
+ bool is_safe) const {
std::size_t remaining_size{size};
std::size_t page_index{gpu_src_addr >> page_bits};
std::size_t page_offset{gpu_src_addr & page_mask};
@@ -276,11 +277,15 @@ void MemoryManager::ReadBlock(GPUVAddr gpu_src_addr, void* dest_buffer, std::siz
if (const auto page_addr{GpuToCpuAddress(page_index << page_bits)}; page_addr) {
const auto src_addr{*page_addr + page_offset};
-
- // Flush must happen on the rasterizer interface, such that memory is always synchronous
- // when it is read (even when in asynchronous GPU mode). Fixes Dead Cells title menu.
- rasterizer->FlushRegion(src_addr, copy_amount);
+ if (is_safe) {
+ // Flush must happen on the rasterizer interface, such that memory is always
+ // synchronous when it is read (even when in asynchronous GPU mode).
+ // Fixes Dead Cells title menu.
+ rasterizer->FlushRegion(src_addr, copy_amount);
+ }
system.Memory().ReadBlockUnsafe(src_addr, dest_buffer, copy_amount);
+ } else {
+ std::memset(dest_buffer, 0, copy_amount);
}
page_index++;
@@ -290,31 +295,17 @@ void MemoryManager::ReadBlock(GPUVAddr gpu_src_addr, void* dest_buffer, std::siz
}
}
+void MemoryManager::ReadBlock(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size) const {
+ ReadBlockImpl(gpu_src_addr, dest_buffer, size, true);
+}
+
void MemoryManager::ReadBlockUnsafe(GPUVAddr gpu_src_addr, void* dest_buffer,
const std::size_t size) const {
- std::size_t remaining_size{size};
- std::size_t page_index{gpu_src_addr >> page_bits};
- std::size_t page_offset{gpu_src_addr & page_mask};
-
- 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 src_addr{*page_addr + page_offset};
- system.Memory().ReadBlockUnsafe(src_addr, dest_buffer, copy_amount);
- } else {
- std::memset(dest_buffer, 0, copy_amount);
- }
-
- page_index++;
- page_offset = 0;
- dest_buffer = static_cast<u8*>(dest_buffer) + copy_amount;
- remaining_size -= copy_amount;
- }
+ ReadBlockImpl(gpu_src_addr, dest_buffer, size, false);
}
-void MemoryManager::WriteBlock(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size) {
+void MemoryManager::WriteBlockImpl(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size,
+ bool is_safe) {
std::size_t remaining_size{size};
std::size_t page_index{gpu_dest_addr >> page_bits};
std::size_t page_offset{gpu_dest_addr & page_mask};
@@ -326,9 +317,11 @@ void MemoryManager::WriteBlock(GPUVAddr gpu_dest_addr, const void* src_buffer, s
if (const auto page_addr{GpuToCpuAddress(page_index << page_bits)}; page_addr) {
const auto dest_addr{*page_addr + page_offset};
- // Invalidate must happen on the rasterizer interface, such that memory is always
- // synchronous when it is written (even when in asynchronous GPU mode).
- rasterizer->InvalidateRegion(dest_addr, copy_amount);
+ if (is_safe) {
+ // Invalidate must happen on the rasterizer interface, such that memory is always
+ // synchronous when it is written (even when in asynchronous GPU mode).
+ rasterizer->InvalidateRegion(dest_addr, copy_amount);
+ }
system.Memory().WriteBlockUnsafe(dest_addr, src_buffer, copy_amount);
}
@@ -339,26 +332,13 @@ void MemoryManager::WriteBlock(GPUVAddr gpu_dest_addr, const void* src_buffer, s
}
}
+void MemoryManager::WriteBlock(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size) {
+ WriteBlockImpl(gpu_dest_addr, src_buffer, size, true);
+}
+
void MemoryManager::WriteBlockUnsafe(GPUVAddr gpu_dest_addr, const void* src_buffer,
std::size_t size) {
- std::size_t remaining_size{size};
- std::size_t page_index{gpu_dest_addr >> page_bits};
- std::size_t page_offset{gpu_dest_addr & page_mask};
-
- 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 dest_addr{*page_addr + page_offset};
- system.Memory().WriteBlockUnsafe(dest_addr, src_buffer, copy_amount);
- }
-
- page_index++;
- page_offset = 0;
- src_buffer = static_cast<const u8*>(src_buffer) + copy_amount;
- remaining_size -= copy_amount;
- }
+ WriteBlockImpl(gpu_dest_addr, src_buffer, size, false);
}
void MemoryManager::FlushRegion(GPUVAddr gpu_addr, size_t size) const {
diff --git a/src/video_core/memory_manager.h b/src/video_core/memory_manager.h
index 99d13e7f6..38d8d9d74 100644
--- a/src/video_core/memory_manager.h
+++ b/src/video_core/memory_manager.h
@@ -155,6 +155,11 @@ private:
void FlushRegion(GPUVAddr gpu_addr, size_t size) const;
+ void ReadBlockImpl(GPUVAddr gpu_src_addr, void* dest_buffer, std::size_t size,
+ bool is_safe) const;
+ void WriteBlockImpl(GPUVAddr gpu_dest_addr, const void* src_buffer, std::size_t size,
+ bool is_safe);
+
[[nodiscard]] static constexpr std::size_t PageEntryIndex(GPUVAddr gpu_addr) {
return (gpu_addr >> page_bits) & page_table_mask;
}