diff options
| author | 2023-11-16 09:17:13 -0500 | |
|---|---|---|
| committer | 2023-11-16 09:17:13 -0500 | |
| commit | d86e88a62253767a58c86017007f362cb675405c (patch) | |
| tree | 9b133456a7632d7b099c9dd4b23f6d5603984d87 /src/core/memory.cpp | |
| parent | Merge pull request #12038 from german77/no_implement (diff) | |
| parent | Memory: Fix invalidation handling from the CPU/Services (diff) | |
| download | yuzu-d86e88a62253767a58c86017007f362cb675405c.tar.gz yuzu-d86e88a62253767a58c86017007f362cb675405c.tar.xz yuzu-d86e88a62253767a58c86017007f362cb675405c.zip | |
Merge pull request #11995 from FernandoS27/you-dont-need-the-new-iphone
Revert PR #11806 and do a proper fix to the memory handling.
Diffstat (limited to 'src/core/memory.cpp')
| -rw-r--r-- | src/core/memory.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 84b60a928..a3431772a 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -1,8 +1,10 @@ | |||
| 1 | // SPDX-FileCopyrightText: 2015 Citra Emulator Project | 1 | // SPDX-FileCopyrightText: 2015 Citra Emulator Project |
| 2 | // SPDX-FileCopyrightText: 2018 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 3 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 4 | ||
| 4 | #include <algorithm> | 5 | #include <algorithm> |
| 5 | #include <cstring> | 6 | #include <cstring> |
| 7 | #include <mutex> | ||
| 6 | #include <span> | 8 | #include <span> |
| 7 | 9 | ||
| 8 | #include "common/assert.h" | 10 | #include "common/assert.h" |
| @@ -10,6 +12,7 @@ | |||
| 10 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 11 | #include "common/logging/log.h" | 13 | #include "common/logging/log.h" |
| 12 | #include "common/page_table.h" | 14 | #include "common/page_table.h" |
| 15 | #include "common/scope_exit.h" | ||
| 13 | #include "common/settings.h" | 16 | #include "common/settings.h" |
| 14 | #include "common/swap.h" | 17 | #include "common/swap.h" |
| 15 | #include "core/core.h" | 18 | #include "core/core.h" |
| @@ -318,7 +321,7 @@ struct Memory::Impl { | |||
| 318 | [&](const Common::ProcessAddress current_vaddr, const std::size_t copy_amount, | 321 | [&](const Common::ProcessAddress current_vaddr, const std::size_t copy_amount, |
| 319 | u8* const host_ptr) { | 322 | u8* const host_ptr) { |
| 320 | if constexpr (!UNSAFE) { | 323 | if constexpr (!UNSAFE) { |
| 321 | system.GPU().InvalidateRegion(GetInteger(current_vaddr), copy_amount); | 324 | HandleRasterizerWrite(GetInteger(current_vaddr), copy_amount); |
| 322 | } | 325 | } |
| 323 | std::memcpy(host_ptr, src_buffer, copy_amount); | 326 | std::memcpy(host_ptr, src_buffer, copy_amount); |
| 324 | }, | 327 | }, |
| @@ -351,7 +354,7 @@ struct Memory::Impl { | |||
| 351 | }, | 354 | }, |
| 352 | [&](const Common::ProcessAddress current_vaddr, const std::size_t copy_amount, | 355 | [&](const Common::ProcessAddress current_vaddr, const std::size_t copy_amount, |
| 353 | u8* const host_ptr) { | 356 | u8* const host_ptr) { |
| 354 | system.GPU().InvalidateRegion(GetInteger(current_vaddr), copy_amount); | 357 | HandleRasterizerWrite(GetInteger(current_vaddr), copy_amount); |
| 355 | std::memset(host_ptr, 0, copy_amount); | 358 | std::memset(host_ptr, 0, copy_amount); |
| 356 | }, | 359 | }, |
| 357 | [](const std::size_t copy_amount) {}); | 360 | [](const std::size_t copy_amount) {}); |
| @@ -420,7 +423,7 @@ struct Memory::Impl { | |||
| 420 | const std::size_t block_size) { | 423 | const std::size_t block_size) { |
| 421 | // dc cvac: Store to point of coherency | 424 | // dc cvac: Store to point of coherency |
| 422 | // CPU flush -> GPU invalidate | 425 | // CPU flush -> GPU invalidate |
| 423 | system.GPU().InvalidateRegion(GetInteger(current_vaddr), block_size); | 426 | HandleRasterizerWrite(GetInteger(current_vaddr), block_size); |
| 424 | }; | 427 | }; |
| 425 | return PerformCacheOperation(dest_addr, size, on_rasterizer); | 428 | return PerformCacheOperation(dest_addr, size, on_rasterizer); |
| 426 | } | 429 | } |
| @@ -430,7 +433,7 @@ struct Memory::Impl { | |||
| 430 | const std::size_t block_size) { | 433 | const std::size_t block_size) { |
| 431 | // dc civac: Store to point of coherency, and invalidate from cache | 434 | // dc civac: Store to point of coherency, and invalidate from cache |
| 432 | // CPU flush -> GPU invalidate | 435 | // CPU flush -> GPU invalidate |
| 433 | system.GPU().InvalidateRegion(GetInteger(current_vaddr), block_size); | 436 | HandleRasterizerWrite(GetInteger(current_vaddr), block_size); |
| 434 | }; | 437 | }; |
| 435 | return PerformCacheOperation(dest_addr, size, on_rasterizer); | 438 | return PerformCacheOperation(dest_addr, size, on_rasterizer); |
| 436 | } | 439 | } |
| @@ -767,7 +770,18 @@ struct Memory::Impl { | |||
| 767 | } | 770 | } |
| 768 | 771 | ||
| 769 | void HandleRasterizerWrite(VAddr address, size_t size) { | 772 | void HandleRasterizerWrite(VAddr address, size_t size) { |
| 770 | const size_t core = system.GetCurrentHostThreadID(); | 773 | constexpr size_t sys_core = Core::Hardware::NUM_CPU_CORES - 1; |
| 774 | const size_t core = std::min(system.GetCurrentHostThreadID(), | ||
| 775 | sys_core); // any other calls threads go to syscore. | ||
| 776 | // Guard on sys_core; | ||
| 777 | if (core == sys_core) [[unlikely]] { | ||
| 778 | sys_core_guard.lock(); | ||
| 779 | } | ||
| 780 | SCOPE_EXIT({ | ||
| 781 | if (core == sys_core) [[unlikely]] { | ||
| 782 | sys_core_guard.unlock(); | ||
| 783 | } | ||
| 784 | }); | ||
| 771 | auto& current_area = rasterizer_write_areas[core]; | 785 | auto& current_area = rasterizer_write_areas[core]; |
| 772 | VAddr subaddress = address >> YUZU_PAGEBITS; | 786 | VAddr subaddress = address >> YUZU_PAGEBITS; |
| 773 | bool do_collection = current_area.last_address == subaddress; | 787 | bool do_collection = current_area.last_address == subaddress; |
| @@ -799,6 +813,7 @@ struct Memory::Impl { | |||
| 799 | rasterizer_read_areas{}; | 813 | rasterizer_read_areas{}; |
| 800 | std::array<GPUDirtyState, Core::Hardware::NUM_CPU_CORES> rasterizer_write_areas{}; | 814 | std::array<GPUDirtyState, Core::Hardware::NUM_CPU_CORES> rasterizer_write_areas{}; |
| 801 | std::span<Core::GPUDirtyMemoryManager> gpu_dirty_managers; | 815 | std::span<Core::GPUDirtyMemoryManager> gpu_dirty_managers; |
| 816 | std::mutex sys_core_guard; | ||
| 802 | }; | 817 | }; |
| 803 | 818 | ||
| 804 | Memory::Memory(Core::System& system_) : system{system_} { | 819 | Memory::Memory(Core::System& system_) : system{system_} { |