From 0ae9e398c8e0f808eb4da6cc6f5e3cd553e975a1 Mon Sep 17 00:00:00 2001 From: comex Date: Tue, 26 Aug 2014 13:37:32 -0400 Subject: Rejigger some FIFO buffer variables to be more rational. videoBuffer -> s_video_buffer size -> s_video_buffer_write_ptr g_pVideoData -> g_video_buffer_read_ptr (impl moved to Fifo.cpp) This eradicates the wonderful use of 'size' as a global name, and makes it clear that s_video_buffer_write_ptr and g_video_buffer_read_ptr are the two ends of the FIFO buffer s_video_buffer. Oh, and remove a useless namespace {}. --- Source/Core/VideoCommon/Fifo.cpp | 56 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 27 deletions(-) (limited to 'Source/Core/VideoCommon/Fifo.cpp') diff --git a/Source/Core/VideoCommon/Fifo.cpp b/Source/Core/VideoCommon/Fifo.cpp index 4e1b52dfa1..e8ba7a2b22 100644 --- a/Source/Core/VideoCommon/Fifo.cpp +++ b/Source/Core/VideoCommon/Fifo.cpp @@ -22,21 +22,22 @@ bool g_bSkipCurrentFrame = false; -namespace -{ static volatile bool GpuRunningState = false; static volatile bool EmuRunningState = false; static std::mutex m_csHWVidOccupied; // STATE_TO_SAVE -static u8 *videoBuffer; -static int size = 0; -} // namespace +static u8* s_video_buffer; +static u8* s_video_buffer_write_ptr; + +// Note: during display list execution, temporarily points to the list instead +// of inside s_video_buffer. +u8* g_video_buffer_read_ptr; void Fifo_DoState(PointerWrap &p) { - p.DoArray(videoBuffer, FIFO_SIZE); - p.Do(size); - p.DoPointer(g_pVideoData, videoBuffer); + p.DoArray(s_video_buffer, FIFO_SIZE); + p.DoPointer(s_video_buffer_write_ptr, s_video_buffer); + p.DoPointer(g_video_buffer_read_ptr, s_video_buffer); p.Do(g_bSkipCurrentFrame); } @@ -61,8 +62,8 @@ void Fifo_PauseAndLock(bool doLock, bool unpauseOnUnlock) void Fifo_Init() { - videoBuffer = (u8*)AllocateMemoryPages(FIFO_SIZE); - size = 0; + s_video_buffer = (u8*)AllocateMemoryPages(FIFO_SIZE); + s_video_buffer_write_ptr = s_video_buffer; GpuRunningState = false; Common::AtomicStore(CommandProcessor::VITicks, CommandProcessor::m_cpClockOrigin); } @@ -70,18 +71,18 @@ void Fifo_Init() void Fifo_Shutdown() { if (GpuRunningState) PanicAlert("Fifo shutting down while active"); - FreeMemoryPages(videoBuffer, FIFO_SIZE); - videoBuffer = nullptr; + FreeMemoryPages(s_video_buffer, FIFO_SIZE); + s_video_buffer = nullptr; } u8* GetVideoBufferStartPtr() { - return videoBuffer; + return s_video_buffer; } u8* GetVideoBufferEndPtr() { - return &videoBuffer[size]; + return s_video_buffer_write_ptr; } void Fifo_SetRendering(bool enabled) @@ -111,26 +112,27 @@ void EmulatorState(bool running) // Description: RunGpuLoop() sends data through this function. void ReadDataFromFifo(u8* _uData, u32 len) { - if (size + len >= FIFO_SIZE) + if (len > (s_video_buffer + FIFO_SIZE - s_video_buffer_write_ptr)) { - int pos = (int)(g_pVideoData - videoBuffer); - size -= pos; - if (size + len > FIFO_SIZE) + size_t size = s_video_buffer_write_ptr - g_video_buffer_read_ptr; + if (len > FIFO_SIZE - size) { - PanicAlert("FIFO out of bounds (size = %i, len = %i at %08x)", size, len, pos); + PanicAlert("FIFO out of bounds (existing %lu + new %lu > %lu)", (unsigned long) size, (unsigned long) len, (unsigned long) FIFO_SIZE); + return; } - memmove(&videoBuffer[0], &videoBuffer[pos], size); - g_pVideoData = videoBuffer; + memmove(s_video_buffer, g_video_buffer_read_ptr, size); + s_video_buffer_write_ptr = s_video_buffer + size; + g_video_buffer_read_ptr = s_video_buffer; } - // Copy new video instructions to videoBuffer for future use in rendering the new picture - memcpy(videoBuffer + size, _uData, len); - size += len; + // Copy new video instructions to s_video_buffer for future use in rendering the new picture + memcpy(s_video_buffer_write_ptr, _uData, len); + s_video_buffer_write_ptr += len; } void ResetVideoBuffer() { - g_pVideoData = videoBuffer; - size = 0; + g_video_buffer_read_ptr = s_video_buffer; + s_video_buffer_write_ptr = s_video_buffer; } @@ -181,7 +183,7 @@ void RunGpuLoop() Common::AtomicStore(fifo.CPReadPointer, readPtr); Common::AtomicAdd(fifo.CPReadWriteDistance, -32); - if ((GetVideoBufferEndPtr() - g_pVideoData) == 0) + if ((GetVideoBufferEndPtr() - g_video_buffer_read_ptr) == 0) Common::AtomicStore(fifo.SafeCPReadPointer, fifo.CPReadPointer); } -- cgit v1.2.3 From 2d4b7c59005d516fc6d21ec48689c062b6ff6c16 Mon Sep 17 00:00:00 2001 From: comex Date: Tue, 26 Aug 2014 21:18:47 -0400 Subject: Make ReadDataFromFifo static. --- Source/Core/VideoCommon/Fifo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/Fifo.cpp') diff --git a/Source/Core/VideoCommon/Fifo.cpp b/Source/Core/VideoCommon/Fifo.cpp index e8ba7a2b22..b6412c796c 100644 --- a/Source/Core/VideoCommon/Fifo.cpp +++ b/Source/Core/VideoCommon/Fifo.cpp @@ -110,7 +110,7 @@ void EmulatorState(bool running) // Description: RunGpuLoop() sends data through this function. -void ReadDataFromFifo(u8* _uData, u32 len) +static void ReadDataFromFifo(u8* _uData, u32 len) { if (len > (s_video_buffer + FIFO_SIZE - s_video_buffer_write_ptr)) { -- cgit v1.2.3 From 65af90669bd5f9e02bbaa994d51d5c83d147b868 Mon Sep 17 00:00:00 2001 From: comex Date: Wed, 27 Aug 2014 22:56:19 -0400 Subject: Add the 'desynced GPU thread' mode. It's a relatively big commit (less big with -w), but it's hard to test any of this separately... The basic problem is that in netplay or movies, the state of the CPU must be deterministic, including when the game receives notification that the GPU has processed FIFO data. Dual core mode notifies the game whenever the GPU thread actually gets around to doing the work, so it isn't deterministic. Single core mode is because it notifies the game 'instantly' (after processing the data synchronously), but it's too slow for many systems and games. My old dc-netplay branch worked as follows: everything worked as normal except the state of the CP registers was a lie, and the CPU thread only delivered results when idle detection triggered (waiting for the GPU if they weren't ready at that point). Usually, a game is idle iff all the work for the frame has been done, except for a small amount of work depending on the GPU result, so neither the CPU or the GPU waiting on the other affected performance much. However, it's possible that the game could be waiting for some earlier interrupt, and any of several games which, for whatever reason, never went into a detectable idle (even when I tried to improve the detection) would never receive results at all. (The current method should have better compatibility, but it also has slightly higher overhead and breaks some other things, so I want to reimplement this, hopefully with less impact on the code, in the future.) With this commit, the basic idea is that the CPU thread acts as if the work has been done instantly, like single core mode, but actually hands it off asynchronously to the GPU thread (after backing up some data that the game might change in memory before it's actually done). Since the work isn't done, any feedback from the GPU to the CPU, such as real XFB/EFB copies (virtual are OK), EFB pokes, performance queries, etc. is broken; but most games work with these options disabled, and there is no need to try to detect what the CPU thread is doing. Technically: when the flag g_use_deterministic_gpu_thread (currently stuck on) is on, the CPU thread calls RunGpu like in single core mode. This function synchronously copies the data from the FIFO to the internal video buffer and updates the CP registers, interrupts, etc. However, instead of the regular ReadDataFromFifo followed by running the opcode decoder, it runs ReadDataFromFifoOnCPU -> OpcodeDecoder_Preprocess, which relatively quickly scans through the FIFO data, detects SetFinish calls etc., which are immediately fired, and saves certain associated data from memory (e.g. display lists) in AuxBuffers (a parallel stream to the main FIFO, which is a bit slow at the moment), before handing the data off to the GPU thread to actually render. That makes up the bulk of this commit. In various circumstances, including the aforementioned EFB pokes and performance queries as well as swap requests (i.e. the end of a frame - we don't want the CPU potentially pumping out frames too quickly and the GPU falling behind*), SyncGPU is called to wait for actual completion. The overhead mainly comes from OpcodeDecoder_Preprocess (which is, again, synchronous), as well as the actual copying. Currently, display lists and such are escrowed from main memory even though they usually won't change over the course of a frame, and textures are not even though they might, resulting in a small chance of graphical glitches. When the texture locking (i.e. fault on write) code lands, I can make this all correct and maybe a little faster. * This suggests an alternate determinism method of just delaying results until a short time before the end of each frame. For all I know this might mostly work - I haven't tried it - but if any significant work hinges on the competion of render to texture etc., the frame will be missed. --- Source/Core/VideoCommon/Fifo.cpp | 251 ++++++++++++++++++++++++++++++++------- 1 file changed, 206 insertions(+), 45 deletions(-) (limited to 'Source/Core/VideoCommon/Fifo.cpp') diff --git a/Source/Core/VideoCommon/Fifo.cpp b/Source/Core/VideoCommon/Fifo.cpp index b6412c796c..87764ec85c 100644 --- a/Source/Core/VideoCommon/Fifo.cpp +++ b/Source/Core/VideoCommon/Fifo.cpp @@ -25,19 +25,46 @@ bool g_bSkipCurrentFrame = false; static volatile bool GpuRunningState = false; static volatile bool EmuRunningState = false; static std::mutex m_csHWVidOccupied; + +// Most of this array is unlikely to be faulted in... +static u8 s_fifo_aux_data[FIFO_SIZE]; +static u8* s_fifo_aux_write_ptr; +static u8* s_fifo_aux_read_ptr; + +bool g_use_deterministic_gpu_thread = true; // XXX + // STATE_TO_SAVE +static std::mutex s_video_buffer_lock; +static std::condition_variable s_video_buffer_cond; static u8* s_video_buffer; -static u8* s_video_buffer_write_ptr; - -// Note: during display list execution, temporarily points to the list instead -// of inside s_video_buffer. u8* g_video_buffer_read_ptr; +static std::atomic s_video_buffer_write_ptr; +static std::atomic s_video_buffer_seen_ptr; +u8* g_video_buffer_pp_read_ptr; +// The read_ptr is always owned by the GPU thread. In normal mode, so is the +// write_ptr, despite it being atomic. In g_use_deterministic_gpu_thread mode, +// things get a bit more complicated: +// - The seen_ptr is written by the GPU thread, and points to what it's already +// processed as much of as possible - in the case of a partial command which +// caused it to stop, not the same as the read ptr. It's written by the GPU, +// under the lock, and updating the cond. +// - The write_ptr is written by the CPU thread after it copies data from the +// FIFO. Maybe someday it will be under the lock. For now, because RunGpuLoop +// polls, it's just atomic. +// - The pp_read_ptr is the CPU preprocessing version of the read_ptr. void Fifo_DoState(PointerWrap &p) { p.DoArray(s_video_buffer, FIFO_SIZE); - p.DoPointer(s_video_buffer_write_ptr, s_video_buffer); + u8* write_ptr = s_video_buffer_write_ptr; + p.DoPointer(write_ptr, s_video_buffer); + s_video_buffer_write_ptr = write_ptr; p.DoPointer(g_video_buffer_read_ptr, s_video_buffer); + if (p.mode == PointerWrap::MODE_READ && g_use_deterministic_gpu_thread) + { + // We're good and paused, right? + s_video_buffer_seen_ptr = g_video_buffer_pp_read_ptr = g_video_buffer_read_ptr; + } p.Do(g_bSkipCurrentFrame); } @@ -45,6 +72,7 @@ void Fifo_PauseAndLock(bool doLock, bool unpauseOnUnlock) { if (doLock) { + SyncGPU(SYNC_GPU_OTHER); EmulatorState(false); if (!Core::IsGPUThread()) m_csHWVidOccupied.lock(); @@ -63,7 +91,7 @@ void Fifo_PauseAndLock(bool doLock, bool unpauseOnUnlock) void Fifo_Init() { s_video_buffer = (u8*)AllocateMemoryPages(FIFO_SIZE); - s_video_buffer_write_ptr = s_video_buffer; + ResetVideoBuffer(); GpuRunningState = false; Common::AtomicStore(CommandProcessor::VITicks, CommandProcessor::m_cpClockOrigin); } @@ -73,6 +101,12 @@ void Fifo_Shutdown() if (GpuRunningState) PanicAlert("Fifo shutting down while active"); FreeMemoryPages(s_video_buffer, FIFO_SIZE); s_video_buffer = nullptr; + s_video_buffer_write_ptr = nullptr; + g_video_buffer_pp_read_ptr = nullptr; + g_video_buffer_read_ptr = nullptr; + s_video_buffer_seen_ptr = nullptr; + s_fifo_aux_write_ptr = nullptr; + s_fifo_aux_read_ptr = nullptr; } u8* GetVideoBufferStartPtr() @@ -108,6 +142,66 @@ void EmulatorState(bool running) EmuRunningState = running; } +void SyncGPU(SyncGPUReason reason, bool may_move_read_ptr) +{ + if (g_use_deterministic_gpu_thread && GpuRunningState) + { + std::unique_lock lk(s_video_buffer_lock); + u8* write_ptr = s_video_buffer_write_ptr; + s_video_buffer_cond.wait(lk, [&]() { + return !GpuRunningState || s_video_buffer_seen_ptr == write_ptr; + }); + if (!GpuRunningState) + return; + + // Opportunistically reset FIFOs so we don't wrap around. + if (may_move_read_ptr && s_fifo_aux_write_ptr != s_fifo_aux_read_ptr) + PanicAlert("aux fifo not synced (%p, %p)", s_fifo_aux_write_ptr, s_fifo_aux_read_ptr); + + memmove(s_fifo_aux_data, s_fifo_aux_read_ptr, s_fifo_aux_write_ptr - s_fifo_aux_read_ptr); + s_fifo_aux_write_ptr -= (s_fifo_aux_read_ptr - s_fifo_aux_data); + s_fifo_aux_read_ptr = s_fifo_aux_data; + + if (may_move_read_ptr) + { + // what's left over in the buffer + size_t size = write_ptr - g_video_buffer_pp_read_ptr; + + memmove(s_video_buffer, g_video_buffer_pp_read_ptr, size); + // This change always decreases the pointers. We write seen_ptr + // after write_ptr here, and read it before in RunGpuLoop, so + // 'write_ptr > seen_ptr' there cannot become spuriously true. + s_video_buffer_write_ptr = write_ptr = s_video_buffer + size; + g_video_buffer_pp_read_ptr = s_video_buffer; + g_video_buffer_read_ptr = s_video_buffer; + s_video_buffer_seen_ptr = write_ptr; + } + } +} + +void PushFifoAuxBuffer(void* ptr, size_t size) +{ + if (size > (size_t) (s_fifo_aux_data + FIFO_SIZE - s_fifo_aux_write_ptr)) + { + SyncGPU(SYNC_GPU_AUX_SPACE, /* may_move_read_ptr */ false); + if (size > (size_t) (s_fifo_aux_data + FIFO_SIZE - s_fifo_aux_write_ptr)) + { + // That will sync us up to the last 32 bytes, so this short region + // of FIFO would have to point to a 2MB display list or something. + PanicAlert("absurdly large aux buffer"); + return; + } + } + memcpy(s_fifo_aux_write_ptr, ptr, size); + s_fifo_aux_write_ptr += size; +} + +void* PopFifoAuxBuffer(size_t size) +{ + void* ret = s_fifo_aux_read_ptr; + s_fifo_aux_read_ptr += size; + return ret; +} // Description: RunGpuLoop() sends data through this function. static void ReadDataFromFifo(u8* _uData, u32 len) @@ -129,10 +223,42 @@ static void ReadDataFromFifo(u8* _uData, u32 len) s_video_buffer_write_ptr += len; } +// The deterministic_gpu_thread version. +static void ReadDataFromFifoOnCPU(u8* _uData, u32 len) +{ + u8 *write_ptr = s_video_buffer_write_ptr; + if (len > (s_video_buffer + FIFO_SIZE - write_ptr)) + { + // We can't wrap around while the GPU is working on the data. + // This should be very rare due to the reset in SyncGPU. + SyncGPU(SYNC_GPU_WRAPAROUND); + if (g_video_buffer_pp_read_ptr != g_video_buffer_read_ptr) + { + PanicAlert("desynced read pointers"); + return; + } + write_ptr = s_video_buffer_write_ptr; + size_t size = write_ptr - g_video_buffer_pp_read_ptr; + if (len > FIFO_SIZE - size) + { + PanicAlert("FIFO out of bounds (existing %lu + new %lu > %lu)", (unsigned long) size, (unsigned long) len, (unsigned long) FIFO_SIZE); + return; + } + } + memcpy(write_ptr, _uData, len); + OpcodeDecoder_Preprocess(write_ptr + len); + // This would have to be locked if the GPU thread didn't spin. + s_video_buffer_write_ptr = write_ptr + len; +} + void ResetVideoBuffer() { g_video_buffer_read_ptr = s_video_buffer; s_video_buffer_write_ptr = s_video_buffer; + s_video_buffer_seen_ptr = s_video_buffer; + g_video_buffer_pp_read_ptr = s_video_buffer; + s_fifo_aux_write_ptr = s_fifo_aux_data; + s_fifo_aux_read_ptr = s_fifo_aux_data; } @@ -150,53 +276,75 @@ void RunGpuLoop() g_video_backend->PeekMessages(); VideoFifo_CheckAsyncRequest(); + if (g_use_deterministic_gpu_thread) + { + // All the fifo/CP stuff is on the CPU. We just need to run the opcode decoder. + u8* seen_ptr = s_video_buffer_seen_ptr; + u8* write_ptr = s_video_buffer_write_ptr; + // See comment in SyncGPU + if (write_ptr > seen_ptr) + { + OpcodeDecoder_Run(write_ptr); - CommandProcessor::SetCPStatusFromGPU(); - - Common::AtomicStore(CommandProcessor::VITicks, CommandProcessor::m_cpClockOrigin); - - // check if we are able to run this buffer - while (GpuRunningState && EmuRunningState && !CommandProcessor::interruptWaiting && fifo.bFF_GPReadEnable && fifo.CPReadWriteDistance && !AtBreakpoint()) + { + std::lock_guard vblk(s_video_buffer_lock); + s_video_buffer_seen_ptr = write_ptr; + s_video_buffer_cond.notify_all(); + } + } + } + else { - fifo.isGpuReadingData = true; - CommandProcessor::isPossibleWaitingSetDrawDone = fifo.bFF_GPLinkEnable ? true : false; + CommandProcessor::SetCPStatusFromGPU(); + + Common::AtomicStore(CommandProcessor::VITicks, CommandProcessor::m_cpClockOrigin); - if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bSyncGPU || Common::AtomicLoad(CommandProcessor::VITicks) > CommandProcessor::m_cpClockOrigin) + // check if we are able to run this buffer + while (GpuRunningState && EmuRunningState && !CommandProcessor::interruptWaiting && fifo.bFF_GPReadEnable && fifo.CPReadWriteDistance && !AtBreakpoint()) { - u32 readPtr = fifo.CPReadPointer; - u8 *uData = Memory::GetPointer(readPtr); + fifo.isGpuReadingData = true; + CommandProcessor::isPossibleWaitingSetDrawDone = fifo.bFF_GPLinkEnable ? true : false; - if (readPtr == fifo.CPEnd) - readPtr = fifo.CPBase; - else - readPtr += 32; + if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bSyncGPU || Common::AtomicLoad(CommandProcessor::VITicks) > CommandProcessor::m_cpClockOrigin) + { + u32 readPtr = fifo.CPReadPointer; + u8 *uData = Memory::GetPointer(readPtr); - _assert_msg_(COMMANDPROCESSOR, (s32)fifo.CPReadWriteDistance - 32 >= 0 , - "Negative fifo.CPReadWriteDistance = %i in FIFO Loop !\nThat can produce instability in the game. Please report it.", fifo.CPReadWriteDistance - 32); + if (readPtr == fifo.CPEnd) + readPtr = fifo.CPBase; + else + readPtr += 32; - ReadDataFromFifo(uData, 32); + _assert_msg_(COMMANDPROCESSOR, (s32)fifo.CPReadWriteDistance - 32 >= 0 , + "Negative fifo.CPReadWriteDistance = %i in FIFO Loop !\nThat can produce instability in the game. Please report it.", fifo.CPReadWriteDistance - 32); - cyclesExecuted = OpcodeDecoder_Run(GetVideoBufferEndPtr()); + ReadDataFromFifo(uData, 32); - if (SConfig::GetInstance().m_LocalCoreStartupParameter.bSyncGPU && Common::AtomicLoad(CommandProcessor::VITicks) >= cyclesExecuted) - Common::AtomicAdd(CommandProcessor::VITicks, -(s32)cyclesExecuted); + u8* write_ptr = s_video_buffer_write_ptr; - Common::AtomicStore(fifo.CPReadPointer, readPtr); - Common::AtomicAdd(fifo.CPReadWriteDistance, -32); - if ((GetVideoBufferEndPtr() - g_video_buffer_read_ptr) == 0) - Common::AtomicStore(fifo.SafeCPReadPointer, fifo.CPReadPointer); - } + cyclesExecuted = OpcodeDecoder_Run(write_ptr); - CommandProcessor::SetCPStatusFromGPU(); - // This call is pretty important in DualCore mode and must be called in the FIFO Loop. - // If we don't, s_swapRequested or s_efbAccessRequested won't be set to false - // leading the CPU thread to wait in Video_BeginField or Video_AccessEFB thus slowing things down. - VideoFifo_CheckAsyncRequest(); - CommandProcessor::isPossibleWaitingSetDrawDone = false; - } + if (SConfig::GetInstance().m_LocalCoreStartupParameter.bSyncGPU && Common::AtomicLoad(CommandProcessor::VITicks) >= cyclesExecuted) + Common::AtomicAdd(CommandProcessor::VITicks, -(s32)cyclesExecuted); + + Common::AtomicStore(fifo.CPReadPointer, readPtr); + Common::AtomicAdd(fifo.CPReadWriteDistance, -32); + if ((write_ptr - g_video_buffer_read_ptr) == 0) + Common::AtomicStore(fifo.SafeCPReadPointer, fifo.CPReadPointer); + } + + CommandProcessor::SetCPStatusFromGPU(); + + // This call is pretty important in DualCore mode and must be called in the FIFO Loop. + // If we don't, s_swapRequested or s_efbAccessRequested won't be set to false + // leading the CPU thread to wait in Video_BeginField or Video_AccessEFB thus slowing things down. + VideoFifo_CheckAsyncRequest(); + CommandProcessor::isPossibleWaitingSetDrawDone = false; + } - fifo.isGpuReadingData = false; + fifo.isGpuReadingData = false; + } if (EmuRunningState) { @@ -219,6 +367,8 @@ void RunGpuLoop() } } } + // wake up SyncGPU if we were interrupted + s_video_buffer_cond.notify_all(); } @@ -230,16 +380,27 @@ bool AtBreakpoint() void RunGpu() { + if (SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread && + !g_use_deterministic_gpu_thread) + return; + SCPFifoStruct &fifo = CommandProcessor::fifo; while (fifo.bFF_GPReadEnable && fifo.CPReadWriteDistance && !AtBreakpoint() ) { u8 *uData = Memory::GetPointer(fifo.CPReadPointer); - FPURoundMode::SaveSIMDState(); - FPURoundMode::LoadDefaultSIMDState(); - ReadDataFromFifo(uData, 32); - OpcodeDecoder_Run(GetVideoBufferEndPtr()); - FPURoundMode::LoadSIMDState(); + if (g_use_deterministic_gpu_thread) + { + ReadDataFromFifoOnCPU(uData, 32); + } + else + { + FPURoundMode::SaveSIMDState(); + FPURoundMode::LoadDefaultSIMDState(); + ReadDataFromFifo(uData, 32); + OpcodeDecoder_Run(s_video_buffer_write_ptr); + FPURoundMode::LoadSIMDState(); + } //DEBUG_LOG(COMMANDPROCESSOR, "Fifo wraps to base"); -- cgit v1.2.3 From 3a2048ea570b428ea34adbfea6b71280e1ae5cc0 Mon Sep 17 00:00:00 2001 From: comex Date: Sat, 6 Sep 2014 17:26:40 -0400 Subject: Add a central variable g_want_determinism which controls whether to try to make things deterministic. It now affects the GPU determinism mode as well as some miscellaneous things that were calling IsNetPlayRunning. Probably incomplete. Notably, this can change while paused, if the user starts recording a movie. The movie code appears to have been missing locking between setting g_playMode and doing other things, which probably had a small chance of causing crashes or even desynced movies; fix that with PauseAndLock. The next commit will add a hidden config variable to override GPU determinism mode. --- Source/Core/VideoCommon/Fifo.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/Fifo.cpp') diff --git a/Source/Core/VideoCommon/Fifo.cpp b/Source/Core/VideoCommon/Fifo.cpp index 87764ec85c..a47438c41e 100644 --- a/Source/Core/VideoCommon/Fifo.cpp +++ b/Source/Core/VideoCommon/Fifo.cpp @@ -11,13 +11,16 @@ #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/CoreTiming.h" +#include "Core/NetPlayProto.h" #include "Core/HW/Memmap.h" #include "VideoCommon/CommandProcessor.h" +#include "VideoCommon/CPMemory.h" #include "VideoCommon/DataReader.h" #include "VideoCommon/Fifo.h" #include "VideoCommon/OpcodeDecoding.h" #include "VideoCommon/PixelEngine.h" +#include "VideoCommon/VertexLoaderManager.h" #include "VideoCommon/VideoConfig.h" bool g_bSkipCurrentFrame = false; @@ -31,7 +34,7 @@ static u8 s_fifo_aux_data[FIFO_SIZE]; static u8* s_fifo_aux_write_ptr; static u8* s_fifo_aux_read_ptr; -bool g_use_deterministic_gpu_thread = true; // XXX +bool g_use_deterministic_gpu_thread; // STATE_TO_SAVE static std::mutex s_video_buffer_lock; @@ -413,3 +416,26 @@ void RunGpu() } CommandProcessor::SetCPStatusFromGPU(); } + +void Fifo_UpdateWantDeterminism(bool want) +{ + // We are paused (or not running at all yet) and have m_csHWVidOccupied, so + // it should be safe to change this. + g_use_deterministic_gpu_thread = want && SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread; + + // Hack: For now movies are an exception to this being on (but not + // to wanting determinism in general). Once vertex arrays are + // fixed, there should be no reason to want this off for movies by + // default, so this can be removed. + if (NetPlay::IsNetPlayRunning()) + g_use_deterministic_gpu_thread = false; + + if (g_use_deterministic_gpu_thread) + { + // These haven't been updated in non-deterministic mode. + s_video_buffer_seen_ptr = g_video_buffer_pp_read_ptr = g_video_buffer_read_ptr; + CopyPreprocessCPStateFromMain(); + VertexLoaderManager::MarkAllDirty(); + } + +} -- cgit v1.2.3 From 6c0a68d50765c24a205f7133205b54c26ae1bbfb Mon Sep 17 00:00:00 2001 From: comex Date: Sat, 6 Sep 2014 17:43:43 -0400 Subject: Add the override config option. I hate the config code, but now is not the time to fix it... --- Source/Core/VideoCommon/Fifo.cpp | 45 ++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'Source/Core/VideoCommon/Fifo.cpp') diff --git a/Source/Core/VideoCommon/Fifo.cpp b/Source/Core/VideoCommon/Fifo.cpp index a47438c41e..44322d4d3b 100644 --- a/Source/Core/VideoCommon/Fifo.cpp +++ b/Source/Core/VideoCommon/Fifo.cpp @@ -421,21 +421,40 @@ void Fifo_UpdateWantDeterminism(bool want) { // We are paused (or not running at all yet) and have m_csHWVidOccupied, so // it should be safe to change this. - g_use_deterministic_gpu_thread = want && SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread; + const SCoreStartupParameter& param = SConfig::GetInstance().m_LocalCoreStartupParameter; + bool gpu_thread; + switch (param.m_GPUDeterminismMode) + { + case GPU_DETERMINISM_AUTO: + gpu_thread = want; + + // Hack: For now movies are an exception to this being on (but not + // to wanting determinism in general). Once vertex arrays are + // fixed, there should be no reason to want this off for movies by + // default, so this can be removed. + if (!NetPlay::IsNetPlayRunning()) + gpu_thread = false; + + break; + case GPU_DETERMINISM_NONE: + gpu_thread = false; + break; + case GPU_DETERMINISM_FAKE_COMPLETION: + gpu_thread = true; + break; + } - // Hack: For now movies are an exception to this being on (but not - // to wanting determinism in general). Once vertex arrays are - // fixed, there should be no reason to want this off for movies by - // default, so this can be removed. - if (NetPlay::IsNetPlayRunning()) - g_use_deterministic_gpu_thread = false; + gpu_thread = gpu_thread && SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread; - if (g_use_deterministic_gpu_thread) + if (g_use_deterministic_gpu_thread != gpu_thread) { - // These haven't been updated in non-deterministic mode. - s_video_buffer_seen_ptr = g_video_buffer_pp_read_ptr = g_video_buffer_read_ptr; - CopyPreprocessCPStateFromMain(); - VertexLoaderManager::MarkAllDirty(); + g_use_deterministic_gpu_thread = gpu_thread; + if (gpu_thread) + { + // These haven't been updated in non-deterministic mode. + s_video_buffer_seen_ptr = g_video_buffer_pp_read_ptr = g_video_buffer_read_ptr; + CopyPreprocessCPStateFromMain(); + VertexLoaderManager::MarkAllDirty(); + } } - } -- cgit v1.2.3