diff options
| author | 2023-11-10 16:43:56 +0100 | |
|---|---|---|
| committer | 2023-11-12 14:10:40 +0100 | |
| commit | f1806d237f57f2c0944f6ae4721ac9497de5b4cf (patch) | |
| tree | f717cadc5f074b2732323b2e3371bac4aedc3ec1 | |
| parent | Revert "renderer_vulkan: add locks to avoid scheduler flushes from CPU" (diff) | |
| download | yuzu-f1806d237f57f2c0944f6ae4721ac9497de5b4cf.tar.gz yuzu-f1806d237f57f2c0944f6ae4721ac9497de5b4cf.tar.xz yuzu-f1806d237f57f2c0944f6ae4721ac9497de5b4cf.zip | |
Memory: Fix invalidation handling from the CPU/Services
Diffstat (limited to '')
| -rw-r--r-- | src/core/memory.cpp | 25 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_rasterizer.cpp | 2 |
3 files changed, 22 insertions, 7 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index fa5273402..9f4883afc 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_} { |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 27e2de1bf..9995b6dd4 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -555,7 +555,7 @@ void RasterizerOpenGL::OnCacheInvalidation(VAddr addr, u64 size) { | |||
| 555 | } | 555 | } |
| 556 | { | 556 | { |
| 557 | std::scoped_lock lock{buffer_cache.mutex}; | 557 | std::scoped_lock lock{buffer_cache.mutex}; |
| 558 | buffer_cache.CachedWriteMemory(addr, size); | 558 | buffer_cache.WriteMemory(addr, size); |
| 559 | } | 559 | } |
| 560 | shader_cache.InvalidateRegion(addr, size); | 560 | shader_cache.InvalidateRegion(addr, size); |
| 561 | } | 561 | } |
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 3bfaabc49..e0ab1eaac 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp | |||
| @@ -621,7 +621,7 @@ void RasterizerVulkan::OnCacheInvalidation(VAddr addr, u64 size) { | |||
| 621 | } | 621 | } |
| 622 | { | 622 | { |
| 623 | std::scoped_lock lock{buffer_cache.mutex}; | 623 | std::scoped_lock lock{buffer_cache.mutex}; |
| 624 | buffer_cache.CachedWriteMemory(addr, size); | 624 | buffer_cache.WriteMemory(addr, size); |
| 625 | } | 625 | } |
| 626 | pipeline_cache.InvalidateRegion(addr, size); | 626 | pipeline_cache.InvalidateRegion(addr, size); |
| 627 | } | 627 | } |