diff options
Diffstat (limited to 'src/core/memory.cpp')
| -rw-r--r-- | src/core/memory.cpp | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index f126840cb..1c218566f 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -44,8 +44,7 @@ bool AddressSpaceContains(const Common::PageTable& table, const Common::ProcessA | |||
| 44 | // from outside classes. This also allows modification to the internals of the memory | 44 | // from outside classes. This also allows modification to the internals of the memory |
| 45 | // subsystem without needing to rebuild all files that make use of the memory interface. | 45 | // subsystem without needing to rebuild all files that make use of the memory interface. |
| 46 | struct Memory::Impl { | 46 | struct Memory::Impl { |
| 47 | explicit Impl(Core::System& system_) | 47 | explicit Impl(Core::System& system_) : system{system_} {} |
| 48 | : system{system_} {} | ||
| 49 | 48 | ||
| 50 | void SetCurrentPageTable(Kernel::KProcess& process) { | 49 | void SetCurrentPageTable(Kernel::KProcess& process) { |
| 51 | current_page_table = &process.GetPageTable().GetImpl(); | 50 | current_page_table = &process.GetPageTable().GetImpl(); |
| @@ -640,18 +639,6 @@ struct Memory::Impl { | |||
| 640 | LOG_DEBUG(HW_Memory, "Mapping {:016X} onto {:016X}-{:016X}", GetInteger(target), | 639 | LOG_DEBUG(HW_Memory, "Mapping {:016X} onto {:016X}-{:016X}", GetInteger(target), |
| 641 | base * YUZU_PAGESIZE, (base + size) * YUZU_PAGESIZE); | 640 | base * YUZU_PAGESIZE, (base + size) * YUZU_PAGESIZE); |
| 642 | 641 | ||
| 643 | // During boot, current_page_table might not be set yet, in which case we need not flush | ||
| 644 | /*if (system.IsPoweredOn()) { | ||
| 645 | auto& gpu = system.GPU(); | ||
| 646 | for (u64 i = 0; i < size; i++) { | ||
| 647 | const auto page = base + i; | ||
| 648 | if (page_table.pointers[page].Type() == Common::PageType::RasterizerCachedMemory) { | ||
| 649 | |||
| 650 | gpu.FlushAndInvalidateRegion(page << YUZU_PAGEBITS, YUZU_PAGESIZE); | ||
| 651 | } | ||
| 652 | } | ||
| 653 | }*/ | ||
| 654 | |||
| 655 | const auto end = base + size; | 642 | const auto end = base + size; |
| 656 | ASSERT_MSG(end <= page_table.pointers.size(), "out of range mapping at {:016X}", | 643 | ASSERT_MSG(end <= page_table.pointers.size(), "out of range mapping at {:016X}", |
| 657 | base + page_table.pointers.size()); | 644 | base + page_table.pointers.size()); |
| @@ -823,8 +810,7 @@ struct Memory::Impl { | |||
| 823 | } | 810 | } |
| 824 | const size_t core = system.GetCurrentHostThreadID(); | 811 | const size_t core = system.GetCurrentHostThreadID(); |
| 825 | auto& current_area = rasterizer_read_areas[core]; | 812 | auto& current_area = rasterizer_read_areas[core]; |
| 826 | gpu_device_memory->ApplyOpOnPointer( | 813 | gpu_device_memory->ApplyOpOnPointer(p, scratch_buffers[core], [&](DAddr address) { |
| 827 | p, scratch_buffers[core], [&](DAddr address) { | ||
| 828 | const DAddr end_address = address + size; | 814 | const DAddr end_address = address + size; |
| 829 | if (current_area.start_address <= address && end_address <= current_area.end_address) | 815 | if (current_area.start_address <= address && end_address <= current_area.end_address) |
| 830 | [[likely]] { | 816 | [[likely]] { |
| @@ -852,8 +838,7 @@ struct Memory::Impl { | |||
| 852 | sys_core_guard.unlock(); | 838 | sys_core_guard.unlock(); |
| 853 | } | 839 | } |
| 854 | }); | 840 | }); |
| 855 | gpu_device_memory->ApplyOpOnPointer( | 841 | gpu_device_memory->ApplyOpOnPointer(p, scratch_buffers[core], [&](DAddr address) { |
| 856 | p, scratch_buffers[core], [&](DAddr address) { | ||
| 857 | auto& current_area = rasterizer_write_areas[core]; | 842 | auto& current_area = rasterizer_write_areas[core]; |
| 858 | PAddr subaddress = address >> YUZU_PAGEBITS; | 843 | PAddr subaddress = address >> YUZU_PAGEBITS; |
| 859 | bool do_collection = current_area.last_address == subaddress; | 844 | bool do_collection = current_area.last_address == subaddress; |
| @@ -872,12 +857,25 @@ struct Memory::Impl { | |||
| 872 | PAddr last_address; | 857 | PAddr last_address; |
| 873 | }; | 858 | }; |
| 874 | 859 | ||
| 875 | void InvalidateRegion(Common::ProcessAddress dest_addr, size_t size) { | 860 | void InvalidateGPUMemory(u8* p, size_t size) { |
| 876 | system.GPU().InvalidateRegion(GetInteger(dest_addr), size); | 861 | constexpr size_t sys_core = Core::Hardware::NUM_CPU_CORES - 1; |
| 877 | } | 862 | const size_t core = std::min(system.GetCurrentHostThreadID(), |
| 878 | 863 | sys_core); // any other calls threads go to syscore. | |
| 879 | void FlushRegion(Common::ProcessAddress dest_addr, size_t size) { | 864 | if (!gpu_device_memory) [[unlikely]] { |
| 880 | system.GPU().FlushRegion(GetInteger(dest_addr), size); | 865 | gpu_device_memory = &system.Host1x().MemoryManager(); |
| 866 | } | ||
| 867 | // Guard on sys_core; | ||
| 868 | if (core == sys_core) [[unlikely]] { | ||
| 869 | sys_core_guard.lock(); | ||
| 870 | } | ||
| 871 | SCOPE_EXIT({ | ||
| 872 | if (core == sys_core) [[unlikely]] { | ||
| 873 | sys_core_guard.unlock(); | ||
| 874 | } | ||
| 875 | }); | ||
| 876 | auto& gpu = system.GPU(); | ||
| 877 | gpu_device_memory->ApplyOpOnPointer( | ||
| 878 | p, scratch_buffers[core], [&](DAddr address) { gpu.InvalidateRegion(address, size); }); | ||
| 881 | } | 879 | } |
| 882 | 880 | ||
| 883 | Core::System& system; | 881 | Core::System& system; |
| @@ -1081,14 +1079,6 @@ void Memory::MarkRegionDebug(Common::ProcessAddress vaddr, u64 size, bool debug) | |||
| 1081 | impl->MarkRegionDebug(GetInteger(vaddr), size, debug); | 1079 | impl->MarkRegionDebug(GetInteger(vaddr), size, debug); |
| 1082 | } | 1080 | } |
| 1083 | 1081 | ||
| 1084 | void Memory::InvalidateRegion(Common::ProcessAddress dest_addr, size_t size) { | ||
| 1085 | impl->InvalidateRegion(dest_addr, size); | ||
| 1086 | } | ||
| 1087 | |||
| 1088 | void Memory::FlushRegion(Common::ProcessAddress dest_addr, size_t size) { | ||
| 1089 | impl->FlushRegion(dest_addr, size); | ||
| 1090 | } | ||
| 1091 | |||
| 1092 | bool Memory::InvalidateNCE(Common::ProcessAddress vaddr, size_t size) { | 1082 | bool Memory::InvalidateNCE(Common::ProcessAddress vaddr, size_t size) { |
| 1093 | [[maybe_unused]] bool mapped = true; | 1083 | [[maybe_unused]] bool mapped = true; |
| 1094 | [[maybe_unused]] bool rasterizer = false; | 1084 | [[maybe_unused]] bool rasterizer = false; |
| @@ -1100,10 +1090,10 @@ bool Memory::InvalidateNCE(Common::ProcessAddress vaddr, size_t size) { | |||
| 1100 | GetInteger(vaddr)); | 1090 | GetInteger(vaddr)); |
| 1101 | mapped = false; | 1091 | mapped = false; |
| 1102 | }, | 1092 | }, |
| 1103 | [&] { | 1093 | [&] { rasterizer = true; }); |
| 1104 | impl->system.GPU().InvalidateRegion(GetInteger(vaddr), size); | 1094 | if (rasterizer) { |
| 1105 | rasterizer = true; | 1095 | impl->InvalidateGPUMemory(ptr, size); |
| 1106 | }); | 1096 | } |
| 1107 | 1097 | ||
| 1108 | #ifdef __linux__ | 1098 | #ifdef __linux__ |
| 1109 | if (!rasterizer && mapped) { | 1099 | if (!rasterizer && mapped) { |