From 907e0fa8c8a4f0f6fc65305788a3b4c7e90b8051 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Thu, 14 Dec 2023 20:26:59 +0100 Subject: [PATCH] Fix fxo dependencies --- rpcs3/Emu/Cell/Modules/cellAudio.cpp | 4 ++++ rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp | 6 ++++++ rpcs3/Emu/Cell/lv2/sys_rsxaudio.h | 2 +- rpcs3/Emu/IPC_socket.cpp | 6 ++++++ rpcs3/Emu/IPC_socket.h | 1 + rpcs3/Emu/Io/usio.cpp | 11 ++++++++--- rpcs3/Emu/RSX/VK/VKGSRender.cpp | 25 +++++++++++++------------ rpcs3/Emu/System.cpp | 7 ++++++- 8 files changed, 45 insertions(+), 17 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellAudio.cpp b/rpcs3/Emu/Cell/Modules/cellAudio.cpp index ec6348ac6c..ab217fa5b0 100644 --- a/rpcs3/Emu/Cell/Modules/cellAudio.cpp +++ b/rpcs3/Emu/Cell/Modules/cellAudio.cpp @@ -4,6 +4,7 @@ #include "Emu/Cell/PPUModule.h" #include "Emu/Cell/lv2/sys_process.h" #include "Emu/Cell/lv2/sys_event.h" +#include "Emu/Cell/Modules/cellAudioOut.h" #include "cellAudio.h" #include "util/video_provider.h" @@ -677,6 +678,9 @@ void cell_audio_thread::reset_counters() cell_audio_thread::cell_audio_thread() { + // Initialize dependencies + g_fxo->need(); + // Initialize loop variables (regardless of provider in order to initialize timestamps) reset_counters(); diff --git a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp index 7058798787..9343b925f5 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp @@ -3,6 +3,7 @@ #include "Emu/IdManager.h" #include "Emu/System.h" #include "Emu/system_config.h" +#include "Emu//Cell/Modules/cellAudioOut.h" #include "util/video_provider.h" #include "sys_process.h" @@ -1305,6 +1306,11 @@ namespace audio rsxaudio_backend_thread::rsxaudio_backend_thread() { + // Initialize dependencies + g_fxo->need(); + + new_emu_cfg = get_emu_cfg(); + const u64 new_vol = g_cfg.audio.volume; callback_cfg.atomic_op([&](callback_config& val) diff --git a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h index bd0a3531fd..fc02a12733 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h +++ b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h @@ -528,7 +528,7 @@ private: u64 start_time = get_system_time(); u64 time_period_idx = 1; - emu_audio_cfg new_emu_cfg{get_emu_cfg()}; + emu_audio_cfg new_emu_cfg{}; bool emu_cfg_changed = true; rsxaudio_state new_ra_state{}; diff --git a/rpcs3/Emu/IPC_socket.cpp b/rpcs3/Emu/IPC_socket.cpp index 6f8341d688..85e3865b96 100644 --- a/rpcs3/Emu/IPC_socket.cpp +++ b/rpcs3/Emu/IPC_socket.cpp @@ -95,6 +95,12 @@ namespace IPC_socket return *this; } + IPC_server_manager::IPC_server_manager(bool enabled) + { + // Enable IPC if needed + set_server_enabled(enabled); + } + void IPC_server_manager::set_server_enabled(bool enabled) { if (enabled) diff --git a/rpcs3/Emu/IPC_socket.h b/rpcs3/Emu/IPC_socket.h index f5ba2935d7..e631c90cbf 100644 --- a/rpcs3/Emu/IPC_socket.h +++ b/rpcs3/Emu/IPC_socket.h @@ -54,6 +54,7 @@ namespace IPC_socket int m_old_port = 0; public: + explicit IPC_server_manager(bool enabled); void set_server_enabled(bool enabled); }; } diff --git a/rpcs3/Emu/Io/usio.cpp b/rpcs3/Emu/Io/usio.cpp index 7584ce53d5..7dea19c8fb 100644 --- a/rpcs3/Emu/Io/usio.cpp +++ b/rpcs3/Emu/Io/usio.cpp @@ -43,6 +43,7 @@ struct usio_memory { std::vector backup_memory; + usio_memory() = default; usio_memory(const usio_memory&) = delete; usio_memory& operator=(const usio_memory&) = delete; @@ -59,6 +60,9 @@ struct usio_memory usb_device_usio::usb_device_usio(const std::array& location) : usb_device_emulated(location) { + // Initialize dependencies + g_fxo->need(); + device = UsbDescriptorNode(USB_DESCRIPTOR_DEVICE, UsbDeviceDescriptor{ .bcdUSB = 0x0110, @@ -141,7 +145,8 @@ extern bool is_input_allowed(); void usb_device_usio::load_backup() { - g_fxo->get().init(); + usio_memory& memory = g_fxo->get(); + memory.init(); fs::file usio_backup_file; @@ -151,7 +156,7 @@ void usb_device_usio::load_backup() return; } - const u64 file_size = g_fxo->get().backup_memory.size(); + const u64 file_size = memory.backup_memory.size(); if (usio_backup_file.size() != file_size) { @@ -159,7 +164,7 @@ void usb_device_usio::load_backup() return; } - usio_backup_file.read(g_fxo->get().backup_memory.data(), file_size); + usio_backup_file.read(memory.backup_memory.data(), file_size); } void usb_device_usio::save_backup() diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.cpp b/rpcs3/Emu/RSX/VK/VKGSRender.cpp index 0cff656119..90e3411680 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.cpp +++ b/rpcs3/Emu/RSX/VK/VKGSRender.cpp @@ -523,17 +523,18 @@ u64 VKGSRender::get_cycles() VKGSRender::VKGSRender(utils::serial* ar) noexcept : GSRender(ar) { - if (m_instance.create("RPCS3")) - { - m_instance.bind(); - } - else + // Initialize dependencies + g_fxo->need(); + + if (!m_instance.create("RPCS3")) { rsx_log.fatal("Could not find a Vulkan compatible GPU driver. Your GPU(s) may not support Vulkan, or you need to install the Vulkan runtime and drivers"); m_device = VK_NULL_HANDLE; return; } + m_instance.bind(); + std::vector& gpus = m_instance.enumerate_devices(); //Actually confirm that the loader found at least one compatible device @@ -890,9 +891,9 @@ VKGSRender::~VKGSRender() vkDeviceWaitIdle(*m_device); // Globals. TODO: Refactor lifetime management - if (backend_config.supports_asynchronous_compute) + if (auto async_scheduler = g_fxo->try_get()) { - g_fxo->get().destroy(); + async_scheduler->destroy(); } // GC cleanup @@ -2412,12 +2413,12 @@ void VKGSRender::close_and_submit_command_buffer(vk::fence* pFence, VkSemaphore primary_submit_info.wait_on(wait_semaphore, pipeline_stage_flags); } - auto& async_scheduler = g_fxo->get(); - if (async_scheduler.is_recording()) + if (auto async_scheduler = g_fxo->try_get(); + async_scheduler && async_scheduler->is_recording()) { - if (async_scheduler.is_host_mode()) + if (async_scheduler->is_host_mode()) { - const VkSemaphore async_sema = *async_scheduler.get_sema(); + const VkSemaphore async_sema = *async_scheduler->get_sema(); secondary_submit_info.queue_signal(async_sema); primary_submit_info.wait_on(async_sema, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); @@ -2425,7 +2426,7 @@ void VKGSRender::close_and_submit_command_buffer(vk::fence* pFence, VkSemaphore vk::get_resource_manager()->push_down_current_scope(); } - async_scheduler.flush(secondary_submit_info, force_flush); + async_scheduler->flush(secondary_submit_info, force_flush); } if (signal_semaphore) diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index fd9394ff69..f6a3fa5d21 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -634,7 +634,12 @@ void Emulator::Init() // Load IPC config g_cfg_ipc.load(); sys_log.notice("Using IPC config:\n%s", g_cfg_ipc.to_string()); - g_fxo->get().set_server_enabled(g_cfg_ipc.get_server_enabled()); + + // Create and start IPC server only if needed + if (g_cfg_ipc.get_server_enabled()) + { + g_fxo->init(true); + } } void Emulator::SetUsr(const std::string& user)