From 5f9c5e8765366672bd795fec066c85309e9dfe82 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 26 Sep 2019 18:32:31 +0300 Subject: [PATCH] Use g_fxo for rsx::thread --- rpcs3/Emu/Memory/vm.cpp | 4 +-- .../Emu/RSX/Overlays/overlay_perf_metrics.cpp | 6 +---- rpcs3/Emu/RSX/RSXThread.cpp | 14 +++++----- rpcs3/Emu/RSX/RSXThread.h | 10 ++++++- rpcs3/Emu/RSX/rsx_utils.h | 8 ------ rpcs3/Emu/System.cpp | 7 ++--- rpcs3/Emu/System.h | 2 +- rpcs3/main_application.cpp | 26 +++++++++++++++---- 8 files changed, 42 insertions(+), 35 deletions(-) diff --git a/rpcs3/Emu/Memory/vm.cpp b/rpcs3/Emu/Memory/vm.cpp index 5582815959..6ceb0f82ef 100644 --- a/rpcs3/Emu/Memory/vm.cpp +++ b/rpcs3/Emu/Memory/vm.cpp @@ -346,7 +346,7 @@ namespace vm // Notify rsx that range has become valid // Note: This must be done *before* memory gets mapped while holding the vm lock, otherwise // the RSX might try to invalidate memory that got unmapped and remapped - if (const auto rsxthr = fxm::check_unlocked()) + if (const auto rsxthr = g_fxo->get()) { rsxthr->on_notify_memory_mapped(addr, size); } @@ -483,7 +483,7 @@ namespace vm // Notify rsx to invalidate range // Note: This must be done *before* memory gets unmapped while holding the vm lock, otherwise // the RSX might try to call VirtualProtect on memory that is already unmapped - if (const auto rsxthr = fxm::check_unlocked()) + if (const auto rsxthr = g_fxo->get()) { rsxthr->on_notify_memory_unmapped(addr, size); } diff --git a/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp b/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp index a6137ea618..c192727d09 100644 --- a/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp +++ b/rpcs3/Emu/RSX/Overlays/overlay_perf_metrics.cpp @@ -244,7 +244,7 @@ namespace rsx f32 rsx_usage{0}; u32 rsx_load{0}; - std::shared_ptr rsx_thread; + const auto rsx_thread = g_fxo->get(); std::string perf_text; @@ -255,7 +255,6 @@ namespace rsx { frametime = m_force_update ? 0 : std::max(0.0, elapsed / m_frames); - rsx_thread = fxm::get(); rsx_load = rsx_thread->get_load(); total_threads = CPUStats::get_thread_count(); @@ -274,9 +273,6 @@ namespace rsx spu_cycles += thread_ctrl::get_cycles(spu); }); - if (!rsx_thread) - rsx_thread = fxm::get(); - rsx_cycles += rsx_thread->get_cycles(); total_cycles = ppu_cycles + spu_cycles + rsx_cycles; diff --git a/rpcs3/Emu/RSX/RSXThread.cpp b/rpcs3/Emu/RSX/RSXThread.cpp index 0c27accec7..f4c04b9386 100644 --- a/rpcs3/Emu/RSX/RSXThread.cpp +++ b/rpcs3/Emu/RSX/RSXThread.cpp @@ -42,7 +42,7 @@ extern thread_local std::string(*g_tls_log_prefix)(); namespace rsx { std::function g_access_violation_handler; - thread* g_current_renderer = nullptr; + dma_manager g_dma_manager; u32 get_address(u32 offset, u32 location) @@ -258,9 +258,13 @@ namespace rsx } } + thread::~thread() + { + g_access_violation_handler = nullptr; + } + thread::thread() { - g_current_renderer = this; g_access_violation_handler = [this](u32 address, bool is_writing) { return on_access_violation(address, is_writing); @@ -278,12 +282,6 @@ namespace rsx } } - thread::~thread() - { - g_access_violation_handler = nullptr; - g_current_renderer = nullptr; - } - void thread::capture_frame(const std::string &name) { frame_trace_data::draw_state draw_state = {}; diff --git a/rpcs3/Emu/RSX/RSXThread.h b/rpcs3/Emu/RSX/RSXThread.h index 5e1621fedc..9051c0099b 100644 --- a/rpcs3/Emu/RSX/RSXThread.h +++ b/rpcs3/Emu/RSX/RSXThread.h @@ -20,6 +20,7 @@ #include "Capture/rsx_replay.h" #include "Emu/Cell/lv2/sys_rsx.h" +#include "Emu/IdManager.h" extern u64 get_guest_system_time(); extern u64 get_system_time(); @@ -599,10 +600,12 @@ namespace rsx void operator()(); virtual u64 get_cycles() = 0; + virtual ~thread(); + + static constexpr auto thread_name = "rsx::thread"sv; protected: thread(); - virtual ~thread(); virtual void on_task(); virtual void on_exit(); @@ -787,4 +790,9 @@ namespace rsx // Returns true if the current thread is the active RSX thread bool is_current_thread() const { return std::this_thread::get_id() == m_rsx_thread; } }; + + inline thread* get_current_renderer() + { + return g_fxo->get(); + } } diff --git a/rpcs3/Emu/RSX/rsx_utils.h b/rpcs3/Emu/RSX/rsx_utils.h index ae5fc13727..78170b1edc 100644 --- a/rpcs3/Emu/RSX/rsx_utils.h +++ b/rpcs3/Emu/RSX/rsx_utils.h @@ -30,9 +30,6 @@ namespace rsx using flags16_t = uint16_t; using flags8_t = uint8_t; - // Definitions - class thread; - extern thread* g_current_renderer; extern atomic_t g_rsx_shared_tag; //Base for resources with reference counting @@ -755,11 +752,6 @@ namespace rsx return result; } - static inline thread* get_current_renderer() - { - return g_current_renderer; - } - template void unpack_bitset(std::bitset& block, u64* values) { diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 12b118ccc1..0e39c971e6 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -649,12 +649,9 @@ bool Emulator::BootRsxCapture(const std::string& path) m_state = system_state::ready; GetCallbacks().on_ready(); - auto gsrender = fxm::import(Emu.GetCallbacks().get_gs_render); + Emu.GetCallbacks().init_gs_render(); Emu.GetCallbacks().init_pad_handler(""); - if (gsrender.get() == nullptr) - return false; - GetCallbacks().on_run(); m_state = system_state::running; @@ -1582,7 +1579,7 @@ void Emulator::Load(const std::string& title_id, bool add_only, bool force_globa } g_fxo->init(); - fxm::import(Emu.GetCallbacks().get_gs_render); // TODO: must be created in appropriate sys_rsx syscall + Emu.GetCallbacks().init_gs_render(); Emu.GetCallbacks().init_pad_handler(m_title_id); Emu.GetCallbacks().init_kb_handler(); Emu.GetCallbacks().init_mouse_handler(); diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 521f0d1049..ed4ff65c2d 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -221,7 +221,7 @@ struct EmuCallbacks std::function init_mouse_handler; std::function init_pad_handler; std::function()> get_gs_frame; - std::function()> get_gs_render; + std::function init_gs_render; std::function()> get_audio; std::function()> get_msg_dialog; std::function()> get_osk_dialog; diff --git a/rpcs3/main_application.cpp b/rpcs3/main_application.cpp index 7f48e41634..b6c62c96b9 100644 --- a/rpcs3/main_application.cpp +++ b/rpcs3/main_application.cpp @@ -116,17 +116,33 @@ EmuCallbacks main_application::CreateCallbacks() g_fxo->init(get_thread(), m_game_window, title_id); }; - callbacks.get_gs_render = []() -> std::shared_ptr + callbacks.init_gs_render = []() { switch (video_renderer type = g_cfg.video.renderer) { - case video_renderer::null: return std::make_shared>("rsx::thread"); - case video_renderer::opengl: return std::make_shared>("rsx::thread"); + case video_renderer::null: + { + g_fxo->init>(); + break; + } + case video_renderer::opengl: + { + g_fxo->init>(); + break; + } #if defined(_WIN32) || defined(HAVE_VULKAN) - case video_renderer::vulkan: return std::make_shared>("rsx::thread"); + case video_renderer::vulkan: + { + g_fxo->init>(); + break; + } #endif #ifdef _MSC_VER - case video_renderer::dx12: return std::make_shared>("rsx::thread"); + case video_renderer::dx12: + { + g_fxo->init>(); + break; + } #endif default: fmt::throw_exception("Invalid video renderer: %s" HERE, type); }