From 4295751662abc0f3018d6cdef66cc30257010426 Mon Sep 17 00:00:00 2001 From: degasus Date: Wed, 20 Jan 2016 19:42:37 +0100 Subject: [PATCH] Fifo: More comments for SyncGPU functions. --- Source/Core/Core/State.cpp | 2 +- Source/Core/VideoCommon/Fifo.cpp | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index 33a7454083..df97809e16 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -71,7 +71,7 @@ static Common::Event g_compressAndDumpStateSyncEvent; static std::thread g_save_thread; // Don't forget to increase this after doing changes on the savestate system -static const u32 STATE_VERSION = 50; // Last changed in PR 3457 +static const u32 STATE_VERSION = 51; // Last changed in PR 3530 // Maps savestate versions to Dolphin versions. // Versions after 42 don't need to be added to this list, diff --git a/Source/Core/VideoCommon/Fifo.cpp b/Source/Core/VideoCommon/Fifo.cpp index 0ca6096de8..f916504357 100644 --- a/Source/Core/VideoCommon/Fifo.cpp +++ b/Source/Core/VideoCommon/Fifo.cpp @@ -47,7 +47,7 @@ static u8* s_fifo_aux_read_ptr; bool g_use_deterministic_gpu_thread; static u64 s_last_sync_gpu_tick; -static int s_et_syncGPU; +static int s_event_sync_gpu; // STATE_TO_SAVE static u8* s_video_buffer; @@ -497,6 +497,11 @@ void UpdateWantDeterminism(bool want) } } +/* This function checks the emulated CPU - GPU distance and may wake up the GPU, + * or block the CPU if required. It should be called by the CPU thread regulary. + * @ticks The gone emulated CPU time. + * @return A good time to call Update() next. + */ static int Update(int ticks) { const SConfig& param = SConfig::GetInstance(); @@ -513,10 +518,12 @@ static int Update(int ticks) return param.iSyncGpuMaxDistance; } + // Wakeup GPU int old = s_sync_ticks.fetch_add(ticks); if (old < param.iSyncGpuMinDistance && old + ticks >= param.iSyncGpuMinDistance) RunGpu(); + // Wait for GPU if (s_sync_ticks.load() >= param.iSyncGpuMaxDistance) { while (s_sync_ticks.load() > 0) @@ -535,15 +542,16 @@ static void SyncGPUCallback(u64 userdata, int cyclesLate) s_last_sync_gpu_tick = now; if (next > 0) - CoreTiming::ScheduleEvent(next, s_et_syncGPU); + CoreTiming::ScheduleEvent(next, s_event_sync_gpu); } +// Initialize GPU - CPU thread syncing, this gives us a deterministic way to start the GPU thread. void Prepare() { if (SConfig::GetInstance().bCPUThread && SConfig::GetInstance().bSyncGPU) { - s_et_syncGPU = CoreTiming::RegisterEvent("SyncGPUCallback", SyncGPUCallback); - CoreTiming::ScheduleEvent(0, s_et_syncGPU); + s_event_sync_gpu = CoreTiming::RegisterEvent("SyncGPUCallback", SyncGPUCallback); + CoreTiming::ScheduleEvent(0, s_event_sync_gpu); s_last_sync_gpu_tick = CoreTiming::GetTicks(); } }