diff options
| author | 2023-11-16 09:17:13 -0500 | |
|---|---|---|
| committer | 2023-11-16 09:17:13 -0500 | |
| commit | d86e88a62253767a58c86017007f362cb675405c (patch) | |
| tree | 9b133456a7632d7b099c9dd4b23f6d5603984d87 /src | |
| 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')
| -rw-r--r-- | src/core/memory.cpp | 25 | ||||
| -rw-r--r-- | src/video_core/fence_manager.h | 5 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/renderer_vulkan.cpp | 14 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_rasterizer.cpp | 12 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_rasterizer.h | 4 |
6 files changed, 32 insertions, 30 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_} { |
diff --git a/src/video_core/fence_manager.h b/src/video_core/fence_manager.h index c0e6471fe..805a89900 100644 --- a/src/video_core/fence_manager.h +++ b/src/video_core/fence_manager.h | |||
| @@ -86,10 +86,7 @@ public: | |||
| 86 | uncommitted_operations.emplace_back(std::move(func)); | 86 | uncommitted_operations.emplace_back(std::move(func)); |
| 87 | } | 87 | } |
| 88 | pending_operations.emplace_back(std::move(uncommitted_operations)); | 88 | pending_operations.emplace_back(std::move(uncommitted_operations)); |
| 89 | { | 89 | QueueFence(new_fence); |
| 90 | std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex}; | ||
| 91 | QueueFence(new_fence); | ||
| 92 | } | ||
| 93 | if (!delay_fence) { | 90 | if (!delay_fence) { |
| 94 | func(); | 91 | func(); |
| 95 | } | 92 | } |
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/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index 7e7a80740..c4c30d807 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp | |||
| @@ -132,16 +132,12 @@ void RendererVulkan::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) { | |||
| 132 | const bool use_accelerated = | 132 | const bool use_accelerated = |
| 133 | rasterizer.AccelerateDisplay(*framebuffer, framebuffer_addr, framebuffer->stride); | 133 | rasterizer.AccelerateDisplay(*framebuffer, framebuffer_addr, framebuffer->stride); |
| 134 | const bool is_srgb = use_accelerated && screen_info.is_srgb; | 134 | const bool is_srgb = use_accelerated && screen_info.is_srgb; |
| 135 | RenderScreenshot(*framebuffer, use_accelerated); | ||
| 135 | 136 | ||
| 136 | { | 137 | Frame* frame = present_manager.GetRenderFrame(); |
| 137 | std::scoped_lock lock{rasterizer.LockCaches()}; | 138 | blit_screen.DrawToSwapchain(frame, *framebuffer, use_accelerated, is_srgb); |
| 138 | RenderScreenshot(*framebuffer, use_accelerated); | 139 | scheduler.Flush(*frame->render_ready); |
| 139 | 140 | present_manager.Present(frame); | |
| 140 | Frame* frame = present_manager.GetRenderFrame(); | ||
| 141 | blit_screen.DrawToSwapchain(frame, *framebuffer, use_accelerated, is_srgb); | ||
| 142 | scheduler.Flush(*frame->render_ready); | ||
| 143 | present_manager.Present(frame); | ||
| 144 | } | ||
| 145 | 141 | ||
| 146 | gpu.RendererFrameEndNotify(); | 142 | gpu.RendererFrameEndNotify(); |
| 147 | rasterizer.TickFrame(); | 143 | rasterizer.TickFrame(); |
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index c0e8431e4..e0ab1eaac 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp | |||
| @@ -199,7 +199,7 @@ void RasterizerVulkan::PrepareDraw(bool is_indexed, Func&& draw_func) { | |||
| 199 | if (!pipeline) { | 199 | if (!pipeline) { |
| 200 | return; | 200 | return; |
| 201 | } | 201 | } |
| 202 | std::scoped_lock lock{LockCaches()}; | 202 | std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex}; |
| 203 | // update engine as channel may be different. | 203 | // update engine as channel may be different. |
| 204 | pipeline->SetEngine(maxwell3d, gpu_memory); | 204 | pipeline->SetEngine(maxwell3d, gpu_memory); |
| 205 | pipeline->Configure(is_indexed); | 205 | pipeline->Configure(is_indexed); |
| @@ -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 | } |
| @@ -710,7 +710,6 @@ void RasterizerVulkan::TiledCacheBarrier() { | |||
| 710 | } | 710 | } |
| 711 | 711 | ||
| 712 | void RasterizerVulkan::FlushCommands() { | 712 | void RasterizerVulkan::FlushCommands() { |
| 713 | std::scoped_lock lock{LockCaches()}; | ||
| 714 | if (draw_counter == 0) { | 713 | if (draw_counter == 0) { |
| 715 | return; | 714 | return; |
| 716 | } | 715 | } |
| @@ -808,7 +807,6 @@ void RasterizerVulkan::FlushWork() { | |||
| 808 | if ((++draw_counter & 7) != 7) { | 807 | if ((++draw_counter & 7) != 7) { |
| 809 | return; | 808 | return; |
| 810 | } | 809 | } |
| 811 | std::scoped_lock lock{LockCaches()}; | ||
| 812 | if (draw_counter < DRAWS_TO_DISPATCH) { | 810 | if (draw_counter < DRAWS_TO_DISPATCH) { |
| 813 | // Send recorded tasks to the worker thread | 811 | // Send recorded tasks to the worker thread |
| 814 | scheduler.DispatchWork(); | 812 | scheduler.DispatchWork(); |
| @@ -1507,7 +1505,7 @@ void RasterizerVulkan::UpdateVertexInput(Tegra::Engines::Maxwell3D::Regs& regs) | |||
| 1507 | void RasterizerVulkan::InitializeChannel(Tegra::Control::ChannelState& channel) { | 1505 | void RasterizerVulkan::InitializeChannel(Tegra::Control::ChannelState& channel) { |
| 1508 | CreateChannel(channel); | 1506 | CreateChannel(channel); |
| 1509 | { | 1507 | { |
| 1510 | std::scoped_lock lock{LockCaches()}; | 1508 | std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex}; |
| 1511 | texture_cache.CreateChannel(channel); | 1509 | texture_cache.CreateChannel(channel); |
| 1512 | buffer_cache.CreateChannel(channel); | 1510 | buffer_cache.CreateChannel(channel); |
| 1513 | } | 1511 | } |
| @@ -1520,7 +1518,7 @@ void RasterizerVulkan::BindChannel(Tegra::Control::ChannelState& channel) { | |||
| 1520 | const s32 channel_id = channel.bind_id; | 1518 | const s32 channel_id = channel.bind_id; |
| 1521 | BindToChannel(channel_id); | 1519 | BindToChannel(channel_id); |
| 1522 | { | 1520 | { |
| 1523 | std::scoped_lock lock{LockCaches()}; | 1521 | std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex}; |
| 1524 | texture_cache.BindToChannel(channel_id); | 1522 | texture_cache.BindToChannel(channel_id); |
| 1525 | buffer_cache.BindToChannel(channel_id); | 1523 | buffer_cache.BindToChannel(channel_id); |
| 1526 | } | 1524 | } |
| @@ -1533,7 +1531,7 @@ void RasterizerVulkan::BindChannel(Tegra::Control::ChannelState& channel) { | |||
| 1533 | void RasterizerVulkan::ReleaseChannel(s32 channel_id) { | 1531 | void RasterizerVulkan::ReleaseChannel(s32 channel_id) { |
| 1534 | EraseChannel(channel_id); | 1532 | EraseChannel(channel_id); |
| 1535 | { | 1533 | { |
| 1536 | std::scoped_lock lock{LockCaches()}; | 1534 | std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex}; |
| 1537 | texture_cache.EraseChannel(channel_id); | 1535 | texture_cache.EraseChannel(channel_id); |
| 1538 | buffer_cache.EraseChannel(channel_id); | 1536 | buffer_cache.EraseChannel(channel_id); |
| 1539 | } | 1537 | } |
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.h b/src/video_core/renderer_vulkan/vk_rasterizer.h index ce3dfbaab..ad069556c 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.h +++ b/src/video_core/renderer_vulkan/vk_rasterizer.h | |||
| @@ -133,10 +133,6 @@ public: | |||
| 133 | 133 | ||
| 134 | void ReleaseChannel(s32 channel_id) override; | 134 | void ReleaseChannel(s32 channel_id) override; |
| 135 | 135 | ||
| 136 | std::scoped_lock<std::recursive_mutex, std::recursive_mutex> LockCaches() { | ||
| 137 | return std::scoped_lock{buffer_cache.mutex, texture_cache.mutex}; | ||
| 138 | } | ||
| 139 | |||
| 140 | private: | 136 | private: |
| 141 | static constexpr size_t MAX_TEXTURES = 192; | 137 | static constexpr size_t MAX_TEXTURES = 192; |
| 142 | static constexpr size_t MAX_IMAGES = 48; | 138 | static constexpr size_t MAX_IMAGES = 48; |