1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-26 04:32:35 +01:00

Savestates: Implement 'autostart off' mode for debugging

This commit is contained in:
Eladash 2023-11-25 09:31:10 +02:00 committed by Elad Ashkenazi
parent f60bdbaece
commit c7c2baae03
4 changed files with 80 additions and 14 deletions

View File

@ -1023,6 +1023,44 @@ cpu_thread& cpu_thread::operator=(thread_state)
return *this; return *this;
} }
void cpu_thread::add_remove_flags(bs_t<cpu_flag> to_add, bs_t<cpu_flag> to_remove)
{
bs_t<cpu_flag> result{};
if (!to_remove)
{
state.add_fetch(to_add);
return;
}
else if (!to_add)
{
result = state.sub_fetch(to_remove);
}
else
{
result = state.atomic_op([&](bs_t<cpu_flag>& v)
{
v += to_add;
v -= to_remove;
return v;
});
}
if (!::is_paused(to_remove) && !::is_stopped(to_remove))
{
// No notable change requiring notification
return;
}
if (::is_paused(result) || ::is_stopped(result))
{
// Flags that stop thread execution
return;
}
state.notify_one();
}
std::string cpu_thread::get_name() const std::string cpu_thread::get_name() const
{ {
// Downcast to correct type // Downcast to correct type

View File

@ -149,7 +149,9 @@ public:
void notify(); void notify();
cpu_thread& operator=(thread_state); cpu_thread& operator=(thread_state);
public: // Add/remove CPU state flags in an atomic operations, notifying if required
void add_remove_flags(bs_t<cpu_flag> to_add, bs_t<cpu_flag> to_remove);
// Thread stats for external observation // Thread stats for external observation
static atomic_t<u64> g_threads_created, g_threads_deleted, g_suspend_counter; static atomic_t<u64> g_threads_created, g_threads_deleted, g_suspend_counter;

View File

@ -652,13 +652,14 @@ namespace rsx
m_overlay_manager = g_fxo->init<rsx::overlays::display_manager>(0); m_overlay_manager = g_fxo->init<rsx::overlays::display_manager>(0);
} }
state -= cpu_flag::stop + cpu_flag::wait; // TODO: Remove workaround
if (!_ar) if (!_ar)
{ {
add_remove_flags({}, cpu_flag::stop); // TODO: Remove workaround
return; return;
} }
add_remove_flags(cpu_flag::suspend, cpu_flag::stop);
serialized = true; serialized = true;
save(*_ar); save(*_ar);

View File

@ -2230,7 +2230,7 @@ game_boot_result Emulator::Load(const std::string& title_id, bool is_disc_patch,
} }
} }
const bool autostart = (std::exchange(m_force_boot, false) || g_cfg.misc.autostart); const bool autostart = m_ar || (std::exchange(m_force_boot, false) || g_cfg.misc.autostart);
if (IsReady()) if (IsReady())
{ {
@ -2333,8 +2333,6 @@ void Emulator::FixGuestTime()
} }
} }
m_ar.reset();
g_tls_log_prefix = []() g_tls_log_prefix = []()
{ {
return std::string(); return std::string();
@ -2349,33 +2347,60 @@ void Emulator::FixGuestTime()
void Emulator::FinalizeRunRequest() void Emulator::FinalizeRunRequest()
{ {
auto on_select = [](u32, spu_thread& spu) const bool autostart = !m_ar || !!g_cfg.misc.autostart;
bs_t<cpu_flag> add_flags = cpu_flag::dbg_global_pause;
if (autostart)
{ {
add_flags -= cpu_flag::dbg_global_pause;
}
auto spu_select = [&](u32, spu_thread& spu)
{
bs_t<cpu_flag> sub_flags = cpu_flag::stop;
if (spu.group && spu.index == spu.group->waiter_spu_index) if (spu.group && spu.index == spu.group->waiter_spu_index)
{ {
return; sub_flags -= cpu_flag::stop;
} }
else if (std::exchange(spu.stop_flag_removal_protection, false))
if (std::exchange(spu.stop_flag_removal_protection, false))
{ {
return; sub_flags -= cpu_flag::stop;
} }
ensure(spu.state.test_and_reset(cpu_flag::stop)); spu.add_remove_flags(add_flags, sub_flags);
spu.state.notify_one();
}; };
auto ppu_select = [&](u32, ppu_thread& ppu)
{
ppu.state += add_flags;
};
if (auto rsx = g_fxo->try_get<rsx::thread>())
{
static_cast<cpu_thread*>(rsx)->add_remove_flags(add_flags, cpu_flag::suspend);
}
if (m_savestate_extension_flags1 & SaveStateExtentionFlags1::ShouldCloseMenu) if (m_savestate_extension_flags1 & SaveStateExtentionFlags1::ShouldCloseMenu)
{ {
g_fxo->get<SysutilMenuOpenStatus>().active = true; g_fxo->get<SysutilMenuOpenStatus>().active = true;
} }
idm::select<named_thread<spu_thread>>(on_select); idm::select<named_thread<spu_thread>>(spu_select);
idm::select<named_thread<ppu_thread>>(ppu_select);
lv2_obj::make_scheduler_ready(); lv2_obj::make_scheduler_ready();
m_state.compare_and_swap_test(system_state::starting, system_state::running); m_state.compare_and_swap_test(system_state::starting, system_state::running);
m_ar.reset();
if (!autostart)
{
Pause();
}
if (m_savestate_extension_flags1 & SaveStateExtentionFlags1::ShouldCloseMenu) if (m_savestate_extension_flags1 & SaveStateExtentionFlags1::ShouldCloseMenu)
{ {
std::thread([this, info = GetEmulationIdentifier()]() std::thread([this, info = GetEmulationIdentifier()]()