Use g_fxo for rsx::thread

This commit is contained in:
Nekotekina 2019-09-26 18:32:31 +03:00
parent b48cdc2260
commit 5f9c5e8765
8 changed files with 42 additions and 35 deletions

View file

@ -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<GSRender>())
if (const auto rsxthr = g_fxo->get<rsx::thread>())
{
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<GSRender>())
if (const auto rsxthr = g_fxo->get<rsx::thread>())
{
rsxthr->on_notify_memory_unmapped(addr, size);
}

View file

@ -244,7 +244,7 @@ namespace rsx
f32 rsx_usage{0};
u32 rsx_load{0};
std::shared_ptr<GSRender> rsx_thread;
const auto rsx_thread = g_fxo->get<rsx::thread>();
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<GSRender>();
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<GSRender>();
rsx_cycles += rsx_thread->get_cycles();
total_cycles = ppu_cycles + spu_cycles + rsx_cycles;

View file

@ -42,7 +42,7 @@ extern thread_local std::string(*g_tls_log_prefix)();
namespace rsx
{
std::function<bool(u32 addr, bool is_writing)> 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 = {};

View file

@ -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<rsx::thread>();
}
}

View file

@ -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<u64> 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 <int N>
void unpack_bitset(std::bitset<N>& block, u64* values)
{

View file

@ -649,12 +649,9 @@ bool Emulator::BootRsxCapture(const std::string& path)
m_state = system_state::ready;
GetCallbacks().on_ready();
auto gsrender = fxm::import<GSRender>(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<GSRender>(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();

View file

@ -221,7 +221,7 @@ struct EmuCallbacks
std::function<void()> init_mouse_handler;
std::function<void(std::string_view title_id)> init_pad_handler;
std::function<std::unique_ptr<class GSFrameBase>()> get_gs_frame;
std::function<std::shared_ptr<class GSRender>()> get_gs_render;
std::function<void()> init_gs_render;
std::function<std::shared_ptr<class AudioBackend>()> get_audio;
std::function<std::shared_ptr<class MsgDialogBase>()> get_msg_dialog;
std::function<std::shared_ptr<class OskDialogBase>()> get_osk_dialog;

View file

@ -116,17 +116,33 @@ EmuCallbacks main_application::CreateCallbacks()
g_fxo->init<pad_thread>(get_thread(), m_game_window, title_id);
};
callbacks.get_gs_render = []() -> std::shared_ptr<GSRender>
callbacks.init_gs_render = []()
{
switch (video_renderer type = g_cfg.video.renderer)
{
case video_renderer::null: return std::make_shared<named_thread<NullGSRender>>("rsx::thread");
case video_renderer::opengl: return std::make_shared<named_thread<GLGSRender>>("rsx::thread");
case video_renderer::null:
{
g_fxo->init<rsx::thread, named_thread<NullGSRender>>();
break;
}
case video_renderer::opengl:
{
g_fxo->init<rsx::thread, named_thread<GLGSRender>>();
break;
}
#if defined(_WIN32) || defined(HAVE_VULKAN)
case video_renderer::vulkan: return std::make_shared<named_thread<VKGSRender>>("rsx::thread");
case video_renderer::vulkan:
{
g_fxo->init<rsx::thread, named_thread<VKGSRender>>();
break;
}
#endif
#ifdef _MSC_VER
case video_renderer::dx12: return std::make_shared<named_thread<D3D12GSRender>>("rsx::thread");
case video_renderer::dx12:
{
g_fxo->init<rsx::thread, named_thread<D3D12GSRender>>();
break;
}
#endif
default: fmt::throw_exception("Invalid video renderer: %s" HERE, type);
}