mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-09-20 03:11:51 +02:00
Added ability to run functions on CPU
This commit is contained in:
parent
aadbaafaf9
commit
240e7da2bb
5 changed files with 50 additions and 15 deletions
|
@ -44,6 +44,8 @@
|
|||
#include "Core/GeckoCode.h"
|
||||
#include "Core/HW/EXI/EXI.h"
|
||||
#include "Core/HW/EXI/EXI_DeviceIPL.h"
|
||||
#include "Core/PowerPC/CPUCoreBase.h"
|
||||
#include "Core/PowerPC/JitInterface.h"
|
||||
#include "Core/State.h"
|
||||
#ifdef HAS_LIBMGBA
|
||||
#include "Core/HW/GBACore.h"
|
||||
|
@ -1511,18 +1513,18 @@ bool NetPlayClient::LoadFromFrame(u64 frame)
|
|||
|
||||
void NetPlayClient::RollbackToFrame(u64 frame)
|
||||
{
|
||||
is_rollingback = true;
|
||||
if (LoadFromFrame(frame))
|
||||
is_rollingback = true;
|
||||
if (LoadFromFrame(frame))
|
||||
{
|
||||
frame_to_stop_at = current_frame;
|
||||
current_frame = frame;
|
||||
Config::SetCurrent(Config::MAIN_EMULATION_SPEED, 0.0);
|
||||
}
|
||||
else
|
||||
frame_to_stop_at = current_frame;
|
||||
current_frame = frame;
|
||||
Config::SetCurrent(Config::MAIN_EMULATION_SPEED, 0.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
is_rollingback = false;
|
||||
DEBUG_LOG_FMT(NETPLAY, "Failed to roll back to frame {}!", frame);
|
||||
}
|
||||
is_rollingback = false;
|
||||
DEBUG_LOG_FMT(NETPLAY, "Failed to roll back to frame {}!", frame);
|
||||
}
|
||||
}
|
||||
|
||||
void NetPlayClient::OnFrameEnd(std::unique_lock<std::mutex>& lock)
|
||||
|
@ -1546,9 +1548,9 @@ void NetPlayClient::OnFrameEnd(std::unique_lock<std::mutex>& lock)
|
|||
std::shared_ptr<SaveState> new_save_state =
|
||||
std::make_shared<SaveState>(std::vector<u8>{}, current_frame);
|
||||
|
||||
lock.unlock();
|
||||
State::SaveToBuffer(new_save_state->first);
|
||||
lock.lock();
|
||||
auto save_state_lambda = [new_save_state]() { State::SaveToBuffer(new_save_state->first); };
|
||||
|
||||
JitInterface::GetCore()->RegisterCPUFunction(save_state_lambda);
|
||||
|
||||
save_states.New() = new_save_state;
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ public:
|
|||
virtual void Init() = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
virtual void ClearCache() = 0;
|
||||
virtual void RegisterCPUFunction(std::function<void()> function){};
|
||||
virtual void Run() = 0;
|
||||
virtual void SingleStep() = 0;
|
||||
virtual const char* GetName() const = 0;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "Core/PowerPC/Jit64/Jit.h"
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
|
@ -32,6 +33,7 @@
|
|||
#include "Core/HW/Memmap.h"
|
||||
#include "Core/HW/ProcessorInterface.h"
|
||||
#include "Core/MachineContext.h"
|
||||
#include "Core/NetPlayClient.h"
|
||||
#include "Core/PatchEngine.h"
|
||||
#include "Core/PowerPC/Jit64/JitAsm.h"
|
||||
#include "Core/PowerPC/Jit64/RegCache/JitRegCache.h"
|
||||
|
@ -917,6 +919,18 @@ bool Jit64::DoJit(u32 em_address, JitBlock* b, u32 nextPC)
|
|||
b->checkedEntry = start;
|
||||
b->normalEntry = start;
|
||||
|
||||
{
|
||||
std::unique_lock lock(m_external_functions_mutex);
|
||||
while (!m_external_functions.empty())
|
||||
{
|
||||
auto external_function = m_external_functions.front();
|
||||
m_external_functions.pop();
|
||||
lock.unlock();
|
||||
external_function();
|
||||
lock.lock();
|
||||
}
|
||||
}
|
||||
|
||||
// Used to get a trace of the last few blocks before a crash, sometimes VERY useful
|
||||
if (ImHereDebug)
|
||||
{
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
// ----------
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <rangeset/rangesizeset.h>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
@ -93,6 +95,13 @@ public:
|
|||
void WriteIdleExit(u32 destination);
|
||||
bool Cleanup();
|
||||
|
||||
// Runs a function on the CPU during the next JIT compilation
|
||||
void RegisterCPUFunction(std::function<void()> function) override
|
||||
{
|
||||
std::lock_guard lock(m_external_functions_mutex);
|
||||
m_external_functions.push(function);
|
||||
}
|
||||
|
||||
void GenerateConstantOverflow(bool overflow);
|
||||
void GenerateConstantOverflow(s64 val);
|
||||
void GenerateOverflow(Gen::CCFlags cond = Gen::CCFlags::CC_NO);
|
||||
|
@ -271,6 +280,9 @@ private:
|
|||
|
||||
HyoutaUtilities::RangeSizeSet<u8*> m_free_ranges_near;
|
||||
HyoutaUtilities::RangeSizeSet<u8*> m_free_ranges_far;
|
||||
|
||||
std::mutex m_external_functions_mutex;
|
||||
std::queue<std::function<void()>> m_external_functions{};
|
||||
};
|
||||
|
||||
void LogGeneratedX86(size_t size, const PPCAnalyst::CodeBuffer& code_buffer, const u8* normalEntry,
|
||||
|
|
|
@ -147,7 +147,10 @@ public:
|
|||
JitBase();
|
||||
~JitBase() override;
|
||||
|
||||
bool IsDebuggingEnabled() const { return m_enable_debugging; }
|
||||
bool IsDebuggingEnabled() const
|
||||
{
|
||||
return m_enable_debugging;
|
||||
}
|
||||
|
||||
static const u8* Dispatch(JitBase& jit);
|
||||
virtual JitBaseBlockCache* GetBlockCache() = 0;
|
||||
|
@ -157,7 +160,10 @@ public:
|
|||
virtual const CommonAsmRoutinesBase* GetAsmRoutines() = 0;
|
||||
|
||||
virtual bool HandleFault(uintptr_t access_address, SContext* ctx) = 0;
|
||||
virtual bool HandleStackFault() { return false; }
|
||||
virtual bool HandleStackFault()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
static constexpr std::size_t code_buffer_size = 32000;
|
||||
|
||||
|
|
Loading…
Reference in a new issue