diff options
Diffstat (limited to 'src/core/core.cpp')
| -rw-r--r-- | src/core/core.cpp | 73 |
1 files changed, 21 insertions, 52 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index b14f74976..66f444d39 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -28,7 +28,6 @@ | |||
| 28 | #include "core/file_sys/savedata_factory.h" | 28 | #include "core/file_sys/savedata_factory.h" |
| 29 | #include "core/file_sys/vfs_concat.h" | 29 | #include "core/file_sys/vfs_concat.h" |
| 30 | #include "core/file_sys/vfs_real.h" | 30 | #include "core/file_sys/vfs_real.h" |
| 31 | #include "core/gpu_dirty_memory_manager.h" | ||
| 32 | #include "core/hid/hid_core.h" | 31 | #include "core/hid/hid_core.h" |
| 33 | #include "core/hle/kernel/k_memory_manager.h" | 32 | #include "core/hle/kernel/k_memory_manager.h" |
| 34 | #include "core/hle/kernel/k_process.h" | 33 | #include "core/hle/kernel/k_process.h" |
| @@ -130,11 +129,8 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, | |||
| 130 | 129 | ||
| 131 | struct System::Impl { | 130 | struct System::Impl { |
| 132 | explicit Impl(System& system) | 131 | explicit Impl(System& system) |
| 133 | : kernel{system}, fs_controller{system}, memory{system}, hid_core{}, room_network{}, | 132 | : kernel{system}, fs_controller{system}, hid_core{}, room_network{}, cpu_manager{system}, |
| 134 | cpu_manager{system}, reporter{system}, applet_manager{system}, profile_manager{}, | 133 | reporter{system}, applet_manager{system}, profile_manager{}, time_manager{system} {} |
| 135 | time_manager{system}, gpu_dirty_memory_write_manager{} { | ||
| 136 | memory.SetGPUDirtyManagers(gpu_dirty_memory_write_manager); | ||
| 137 | } | ||
| 138 | 134 | ||
| 139 | void Initialize(System& system) { | 135 | void Initialize(System& system) { |
| 140 | device_memory = std::make_unique<Core::DeviceMemory>(); | 136 | device_memory = std::make_unique<Core::DeviceMemory>(); |
| @@ -241,17 +237,17 @@ struct System::Impl { | |||
| 241 | debugger = std::make_unique<Debugger>(system, port); | 237 | debugger = std::make_unique<Debugger>(system, port); |
| 242 | } | 238 | } |
| 243 | 239 | ||
| 244 | SystemResultStatus SetupForApplicationProcess(System& system, Frontend::EmuWindow& emu_window) { | 240 | void InitializeKernel(System& system) { |
| 245 | LOG_DEBUG(Core, "initialized OK"); | 241 | LOG_DEBUG(Core, "initialized OK"); |
| 246 | 242 | ||
| 247 | // Setting changes may require a full system reinitialization (e.g., disabling multicore). | 243 | // Setting changes may require a full system reinitialization (e.g., disabling multicore). |
| 248 | ReinitializeIfNecessary(system); | 244 | ReinitializeIfNecessary(system); |
| 249 | 245 | ||
| 250 | memory.SetGPUDirtyManagers(gpu_dirty_memory_write_manager); | ||
| 251 | |||
| 252 | kernel.Initialize(); | 246 | kernel.Initialize(); |
| 253 | cpu_manager.Initialize(); | 247 | cpu_manager.Initialize(); |
| 248 | } | ||
| 254 | 249 | ||
| 250 | SystemResultStatus SetupForApplicationProcess(System& system, Frontend::EmuWindow& emu_window) { | ||
| 255 | /// Reset all glue registrations | 251 | /// Reset all glue registrations |
| 256 | arp_manager.ResetAll(); | 252 | arp_manager.ResetAll(); |
| 257 | 253 | ||
| @@ -300,17 +296,9 @@ struct System::Impl { | |||
| 300 | return SystemResultStatus::ErrorGetLoader; | 296 | return SystemResultStatus::ErrorGetLoader; |
| 301 | } | 297 | } |
| 302 | 298 | ||
| 303 | SystemResultStatus init_result{SetupForApplicationProcess(system, emu_window)}; | 299 | InitializeKernel(system); |
| 304 | if (init_result != SystemResultStatus::Success) { | ||
| 305 | LOG_CRITICAL(Core, "Failed to initialize system (Error {})!", | ||
| 306 | static_cast<int>(init_result)); | ||
| 307 | ShutdownMainProcess(); | ||
| 308 | return init_result; | ||
| 309 | } | ||
| 310 | |||
| 311 | telemetry_session->AddInitialInfo(*app_loader, fs_controller, *content_provider); | ||
| 312 | 300 | ||
| 313 | // Create the process. | 301 | // Create the application process. |
| 314 | auto main_process = Kernel::KProcess::Create(system.Kernel()); | 302 | auto main_process = Kernel::KProcess::Create(system.Kernel()); |
| 315 | Kernel::KProcess::Register(system.Kernel(), main_process); | 303 | Kernel::KProcess::Register(system.Kernel(), main_process); |
| 316 | kernel.AppendNewProcess(main_process); | 304 | kernel.AppendNewProcess(main_process); |
| @@ -323,7 +311,18 @@ struct System::Impl { | |||
| 323 | return static_cast<SystemResultStatus>( | 311 | return static_cast<SystemResultStatus>( |
| 324 | static_cast<u32>(SystemResultStatus::ErrorLoader) + static_cast<u32>(load_result)); | 312 | static_cast<u32>(SystemResultStatus::ErrorLoader) + static_cast<u32>(load_result)); |
| 325 | } | 313 | } |
| 314 | |||
| 315 | // Set up the rest of the system. | ||
| 316 | SystemResultStatus init_result{SetupForApplicationProcess(system, emu_window)}; | ||
| 317 | if (init_result != SystemResultStatus::Success) { | ||
| 318 | LOG_CRITICAL(Core, "Failed to initialize system (Error {})!", | ||
| 319 | static_cast<int>(init_result)); | ||
| 320 | ShutdownMainProcess(); | ||
| 321 | return init_result; | ||
| 322 | } | ||
| 323 | |||
| 326 | AddGlueRegistrationForProcess(*app_loader, *main_process); | 324 | AddGlueRegistrationForProcess(*app_loader, *main_process); |
| 325 | telemetry_session->AddInitialInfo(*app_loader, fs_controller, *content_provider); | ||
| 327 | 326 | ||
| 328 | // Initialize cheat engine | 327 | // Initialize cheat engine |
| 329 | if (cheat_engine) { | 328 | if (cheat_engine) { |
| @@ -426,7 +425,6 @@ struct System::Impl { | |||
| 426 | cpu_manager.Shutdown(); | 425 | cpu_manager.Shutdown(); |
| 427 | debugger.reset(); | 426 | debugger.reset(); |
| 428 | kernel.Shutdown(); | 427 | kernel.Shutdown(); |
| 429 | memory.Reset(); | ||
| 430 | Network::RestartSocketOperations(); | 428 | Network::RestartSocketOperations(); |
| 431 | 429 | ||
| 432 | if (auto room_member = room_network.GetRoomMember().lock()) { | 430 | if (auto room_member = room_network.GetRoomMember().lock()) { |
| @@ -507,7 +505,6 @@ struct System::Impl { | |||
| 507 | std::unique_ptr<Tegra::Host1x::Host1x> host1x_core; | 505 | std::unique_ptr<Tegra::Host1x::Host1x> host1x_core; |
| 508 | std::unique_ptr<Core::DeviceMemory> device_memory; | 506 | std::unique_ptr<Core::DeviceMemory> device_memory; |
| 509 | std::unique_ptr<AudioCore::AudioCore> audio_core; | 507 | std::unique_ptr<AudioCore::AudioCore> audio_core; |
| 510 | Core::Memory::Memory memory; | ||
| 511 | Core::HID::HIDCore hid_core; | 508 | Core::HID::HIDCore hid_core; |
| 512 | Network::RoomNetwork room_network; | 509 | Network::RoomNetwork room_network; |
| 513 | 510 | ||
| @@ -567,9 +564,6 @@ struct System::Impl { | |||
| 567 | std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{}; | 564 | std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{}; |
| 568 | std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_cpu{}; | 565 | std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_cpu{}; |
| 569 | 566 | ||
| 570 | std::array<Core::GPUDirtyMemoryManager, Core::Hardware::NUM_CPU_CORES> | ||
| 571 | gpu_dirty_memory_write_manager{}; | ||
| 572 | |||
| 573 | std::deque<std::vector<u8>> user_channel; | 567 | std::deque<std::vector<u8>> user_channel; |
| 574 | }; | 568 | }; |
| 575 | 569 | ||
| @@ -652,29 +646,12 @@ void System::PrepareReschedule(const u32 core_index) { | |||
| 652 | impl->kernel.PrepareReschedule(core_index); | 646 | impl->kernel.PrepareReschedule(core_index); |
| 653 | } | 647 | } |
| 654 | 648 | ||
| 655 | Core::GPUDirtyMemoryManager& System::CurrentGPUDirtyMemoryManager() { | ||
| 656 | const std::size_t core = impl->kernel.GetCurrentHostThreadID(); | ||
| 657 | return impl->gpu_dirty_memory_write_manager[core < Core::Hardware::NUM_CPU_CORES | ||
| 658 | ? core | ||
| 659 | : Core::Hardware::NUM_CPU_CORES - 1]; | ||
| 660 | } | ||
| 661 | |||
| 662 | /// Provides a constant reference to the current gou dirty memory manager. | ||
| 663 | const Core::GPUDirtyMemoryManager& System::CurrentGPUDirtyMemoryManager() const { | ||
| 664 | const std::size_t core = impl->kernel.GetCurrentHostThreadID(); | ||
| 665 | return impl->gpu_dirty_memory_write_manager[core < Core::Hardware::NUM_CPU_CORES | ||
| 666 | ? core | ||
| 667 | : Core::Hardware::NUM_CPU_CORES - 1]; | ||
| 668 | } | ||
| 669 | |||
| 670 | size_t System::GetCurrentHostThreadID() const { | 649 | size_t System::GetCurrentHostThreadID() const { |
| 671 | return impl->kernel.GetCurrentHostThreadID(); | 650 | return impl->kernel.GetCurrentHostThreadID(); |
| 672 | } | 651 | } |
| 673 | 652 | ||
| 674 | void System::GatherGPUDirtyMemory(std::function<void(VAddr, size_t)>& callback) { | 653 | void System::GatherGPUDirtyMemory(std::function<void(VAddr, size_t)>& callback) { |
| 675 | for (auto& manager : impl->gpu_dirty_memory_write_manager) { | 654 | return this->ApplicationProcess()->GatherGPUDirtyMemory(callback); |
| 676 | manager.Gather(callback); | ||
| 677 | } | ||
| 678 | } | 655 | } |
| 679 | 656 | ||
| 680 | PerfStatsResults System::GetAndResetPerfStats() { | 657 | PerfStatsResults System::GetAndResetPerfStats() { |
| @@ -723,20 +700,12 @@ const Kernel::KProcess* System::ApplicationProcess() const { | |||
| 723 | return impl->kernel.ApplicationProcess(); | 700 | return impl->kernel.ApplicationProcess(); |
| 724 | } | 701 | } |
| 725 | 702 | ||
| 726 | ExclusiveMonitor& System::Monitor() { | ||
| 727 | return impl->kernel.GetExclusiveMonitor(); | ||
| 728 | } | ||
| 729 | |||
| 730 | const ExclusiveMonitor& System::Monitor() const { | ||
| 731 | return impl->kernel.GetExclusiveMonitor(); | ||
| 732 | } | ||
| 733 | |||
| 734 | Memory::Memory& System::ApplicationMemory() { | 703 | Memory::Memory& System::ApplicationMemory() { |
| 735 | return impl->memory; | 704 | return impl->kernel.ApplicationProcess()->GetMemory(); |
| 736 | } | 705 | } |
| 737 | 706 | ||
| 738 | const Core::Memory::Memory& System::ApplicationMemory() const { | 707 | const Core::Memory::Memory& System::ApplicationMemory() const { |
| 739 | return impl->memory; | 708 | return impl->kernel.ApplicationProcess()->GetMemory(); |
| 740 | } | 709 | } |
| 741 | 710 | ||
| 742 | Tegra::GPU& System::GPU() { | 711 | Tegra::GPU& System::GPU() { |