mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-08 21:53:31 +01:00
CoreTiming: Avoid ppcState global.
This commit is contained in:
parent
94455ee9e1
commit
41ad0490f0
@ -44,6 +44,10 @@ static void EmptyTimedCallback(Core::System& system, u64 userdata, s64 cyclesLat
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CoreTimingManager::CoreTimingManager(Core::System& system) : m_system(system)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// Changing the CPU speed in Dolphin isn't actually done by changing the physical clock rate,
|
// Changing the CPU speed in Dolphin isn't actually done by changing the physical clock rate,
|
||||||
// but by changing the amount of work done in a particular amount of time. This tends to be more
|
// but by changing the amount of work done in a particular amount of time. This tends to be more
|
||||||
// compatible because it stops the games from actually knowing directly that the clock rate has
|
// compatible because it stops the games from actually knowing directly that the clock rate has
|
||||||
@ -90,7 +94,7 @@ void CoreTimingManager::Init()
|
|||||||
|
|
||||||
m_last_oc_factor = m_config_oc_factor;
|
m_last_oc_factor = m_config_oc_factor;
|
||||||
m_globals.last_OC_factor_inverted = m_config_oc_inv_factor;
|
m_globals.last_OC_factor_inverted = m_config_oc_inv_factor;
|
||||||
PowerPC::ppcState.downcount = CyclesToDowncount(MAX_SLICE_LENGTH);
|
m_system.GetPPCState().downcount = CyclesToDowncount(MAX_SLICE_LENGTH);
|
||||||
m_globals.slice_length = MAX_SLICE_LENGTH;
|
m_globals.slice_length = MAX_SLICE_LENGTH;
|
||||||
m_globals.global_timer = 0;
|
m_globals.global_timer = 0;
|
||||||
m_idled_cycles = 0;
|
m_idled_cycles = 0;
|
||||||
@ -195,7 +199,7 @@ u64 CoreTimingManager::GetTicks() const
|
|||||||
u64 ticks = static_cast<u64>(m_globals.global_timer);
|
u64 ticks = static_cast<u64>(m_globals.global_timer);
|
||||||
if (!m_is_global_timer_sane)
|
if (!m_is_global_timer_sane)
|
||||||
{
|
{
|
||||||
int downcount = DowncountToCycles(PowerPC::ppcState.downcount);
|
int downcount = DowncountToCycles(m_system.GetPPCState().downcount);
|
||||||
ticks += m_globals.slice_length - downcount;
|
ticks += m_globals.slice_length - downcount;
|
||||||
}
|
}
|
||||||
return ticks;
|
return ticks;
|
||||||
@ -277,13 +281,13 @@ void CoreTimingManager::RemoveAllEvents(EventType* event_type)
|
|||||||
void CoreTimingManager::ForceExceptionCheck(s64 cycles)
|
void CoreTimingManager::ForceExceptionCheck(s64 cycles)
|
||||||
{
|
{
|
||||||
cycles = std::max<s64>(0, cycles);
|
cycles = std::max<s64>(0, cycles);
|
||||||
if (DowncountToCycles(PowerPC::ppcState.downcount) > cycles)
|
auto& ppc_state = m_system.GetPPCState();
|
||||||
|
if (DowncountToCycles(ppc_state.downcount) > cycles)
|
||||||
{
|
{
|
||||||
// downcount is always (much) smaller than MAX_INT so we can safely cast cycles to an int here.
|
// downcount is always (much) smaller than MAX_INT so we can safely cast cycles to an int here.
|
||||||
// Account for cycles already executed by adjusting the m_globals.slice_length
|
// Account for cycles already executed by adjusting the m_globals.slice_length
|
||||||
m_globals.slice_length -=
|
m_globals.slice_length -= DowncountToCycles(ppc_state.downcount) - static_cast<int>(cycles);
|
||||||
DowncountToCycles(PowerPC::ppcState.downcount) - static_cast<int>(cycles);
|
ppc_state.downcount = CyclesToDowncount(static_cast<int>(cycles));
|
||||||
PowerPC::ppcState.downcount = CyclesToDowncount(static_cast<int>(cycles));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,11 +303,12 @@ void CoreTimingManager::MoveEvents()
|
|||||||
|
|
||||||
void CoreTimingManager::Advance()
|
void CoreTimingManager::Advance()
|
||||||
{
|
{
|
||||||
auto& system = Core::System::GetInstance();
|
auto& system = m_system;
|
||||||
|
auto& ppc_state = m_system.GetPPCState();
|
||||||
|
|
||||||
MoveEvents();
|
MoveEvents();
|
||||||
|
|
||||||
int cyclesExecuted = m_globals.slice_length - DowncountToCycles(PowerPC::ppcState.downcount);
|
int cyclesExecuted = m_globals.slice_length - DowncountToCycles(ppc_state.downcount);
|
||||||
m_globals.global_timer += cyclesExecuted;
|
m_globals.global_timer += cyclesExecuted;
|
||||||
m_last_oc_factor = m_config_oc_factor;
|
m_last_oc_factor = m_config_oc_factor;
|
||||||
m_globals.last_OC_factor_inverted = m_config_oc_inv_factor;
|
m_globals.last_OC_factor_inverted = m_config_oc_inv_factor;
|
||||||
@ -330,7 +335,7 @@ void CoreTimingManager::Advance()
|
|||||||
std::min<s64>(m_event_queue.front().time - m_globals.global_timer, MAX_SLICE_LENGTH));
|
std::min<s64>(m_event_queue.front().time - m_globals.global_timer, MAX_SLICE_LENGTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
PowerPC::ppcState.downcount = CyclesToDowncount(m_globals.slice_length);
|
ppc_state.downcount = CyclesToDowncount(m_globals.slice_length);
|
||||||
|
|
||||||
// Check for any external exceptions.
|
// Check for any external exceptions.
|
||||||
// It's important to do this after processing events otherwise any exceptions will be delayed
|
// It's important to do this after processing events otherwise any exceptions will be delayed
|
||||||
@ -438,18 +443,20 @@ void CoreTimingManager::AdjustEventQueueTimes(u32 new_ppc_clock, u32 old_ppc_clo
|
|||||||
|
|
||||||
void CoreTimingManager::Idle()
|
void CoreTimingManager::Idle()
|
||||||
{
|
{
|
||||||
|
auto& system = m_system;
|
||||||
|
auto& ppc_state = m_system.GetPPCState();
|
||||||
|
|
||||||
if (m_config_sync_on_skip_idle)
|
if (m_config_sync_on_skip_idle)
|
||||||
{
|
{
|
||||||
// When the FIFO is processing data we must not advance because in this way
|
// When the FIFO is processing data we must not advance because in this way
|
||||||
// the VI will be desynchronized. So, We are waiting until the FIFO finish and
|
// the VI will be desynchronized. So, We are waiting until the FIFO finish and
|
||||||
// while we process only the events required by the FIFO.
|
// while we process only the events required by the FIFO.
|
||||||
auto& system = Core::System::GetInstance();
|
|
||||||
system.GetFifo().FlushGpu(system);
|
system.GetFifo().FlushGpu(system);
|
||||||
}
|
}
|
||||||
|
|
||||||
PowerPC::UpdatePerformanceMonitor(PowerPC::ppcState.downcount, 0, 0, PowerPC::ppcState);
|
PowerPC::UpdatePerformanceMonitor(ppc_state.downcount, 0, 0, ppc_state);
|
||||||
m_idled_cycles += DowncountToCycles(PowerPC::ppcState.downcount);
|
m_idled_cycles += DowncountToCycles(ppc_state.downcount);
|
||||||
PowerPC::ppcState.downcount = 0;
|
ppc_state.downcount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CoreTimingManager::GetScheduledEventsSummary() const
|
std::string CoreTimingManager::GetScheduledEventsSummary() const
|
||||||
|
@ -75,6 +75,8 @@ void GlobalIdle();
|
|||||||
class CoreTimingManager
|
class CoreTimingManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
explicit CoreTimingManager(Core::System& system);
|
||||||
|
|
||||||
// CoreTiming begins at the boundary of timing slice -1. An initial call to Advance() is
|
// CoreTiming begins at the boundary of timing slice -1. An initial call to Advance() is
|
||||||
// required to end slice -1 and start slice 0 before the first cycle of code is executed.
|
// required to end slice -1 and start slice 0 before the first cycle of code is executed.
|
||||||
void Init();
|
void Init();
|
||||||
@ -151,6 +153,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
Globals m_globals;
|
Globals m_globals;
|
||||||
|
|
||||||
|
Core::System& m_system;
|
||||||
|
|
||||||
// unordered_map stores each element separately as a linked list node so pointers to elements
|
// unordered_map stores each element separately as a linked list node so pointers to elements
|
||||||
// remain stable regardless of rehashes/resizing.
|
// remain stable regardless of rehashes/resizing.
|
||||||
std::unordered_map<std::string, EventType> m_event_types;
|
std::unordered_map<std::string, EventType> m_event_types;
|
||||||
|
@ -33,7 +33,10 @@ namespace Core
|
|||||||
{
|
{
|
||||||
struct System::Impl
|
struct System::Impl
|
||||||
{
|
{
|
||||||
explicit Impl(System& system) : m_gp_fifo(system), m_ppc_state(PowerPC::ppcState) {}
|
explicit Impl(System& system)
|
||||||
|
: m_core_timing(system), m_gp_fifo(system), m_ppc_state(PowerPC::ppcState)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<SoundStream> m_sound_stream;
|
std::unique_ptr<SoundStream> m_sound_stream;
|
||||||
bool m_sound_stream_running = false;
|
bool m_sound_stream_running = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user