From 4a8ba5cd409fb45352d6e96a2b5f23d00982fea2 Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Sat, 21 Feb 2009 17:23:39 +0000 Subject: [PATCH] Added some diagnostic and recovery checks to the MTGS queued frame counter, as per problems expressed in Issue 49. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@562 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/GS.h | 2 +- pcsx2/MTGS.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pcsx2/GS.h b/pcsx2/GS.h index d5eb2a542d..a30654e3fe 100644 --- a/pcsx2/GS.h +++ b/pcsx2/GS.h @@ -174,7 +174,7 @@ protected: // Counts the number of vsync frames queued in the MTGS ringbuffer. This is used to // throttle the number of frames allowed to be rendered ahead of time for games that // run very fast and have little or no ringbuffer overhead (typically opening menus) - volatile u32 m_QueuedFrames; + volatile s32 m_QueuedFrames; // Protection lock for the frame queue counter -- needed because we can't safely // AtomicExchange from two threads. diff --git a/pcsx2/MTGS.cpp b/pcsx2/MTGS.cpp index b8f8b061dd..c77eb10817 100644 --- a/pcsx2/MTGS.cpp +++ b/pcsx2/MTGS.cpp @@ -442,6 +442,13 @@ void mtgsThreadObject::PostVsyncEnd( bool updategs ) { while( m_QueuedFrames > 8 ) { + if( m_WritePos == volatize( m_RingPos ) ) + { + // MTGS ringbuffer is empty, but we still have queued frames in the counter? Ouch! + Console::Error( "MTGS > Queued framecount mismatch = %d", params m_QueuedFrames ); + m_QueuedFrames = 0; + break; + } Sleep( 2 ); // Sleep off quite a bit of time, since we're obviously *waaay* ahead. SpinWait(); } @@ -560,7 +567,7 @@ int mtgsThreadObject::Callback() gsFrameSkip( !tag.data[1] ); m_lock_FrameQueueCounter.Lock(); - m_QueuedFrames--; + AtomicDecrement( m_QueuedFrames ); jASSUME( m_QueuedFrames >= 0 ); m_lock_FrameQueueCounter.Unlock();