From 52952bce929fdaec16c872a0f1d94d93c6770aef Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Tue, 13 Jan 2009 15:57:20 +0000 Subject: [PATCH] Squashed an MTGS bug that I strongly suspect was responsible for MTGS problems reported in Issue 108. git-svn-id: http://pcsx2-playground.googlecode.com/svn/trunk@585 a6443dda-0b58-4228-96e9-037be469359c --- pcsx2/GS.h | 4 ++-- pcsx2/MTGS.cpp | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pcsx2/GS.h b/pcsx2/GS.h index cae8927bcf..f446cd1dd1 100644 --- a/pcsx2/GS.h +++ b/pcsx2/GS.h @@ -225,8 +225,8 @@ protected: u32 _gifTransferDummy( GIF_PATH pathidx, const u8 *pMem, u32 size ); // Used internally by SendSimplePacket type functions - void _PrepForSimplePacket(); - void _FinishSimplePacket(); + const u8* _PrepForSimplePacket(); + void _FinishSimplePacket( const u8* future_writepos ); int Callback(); }; diff --git a/pcsx2/MTGS.cpp b/pcsx2/MTGS.cpp index 5a814c0667..70c8f91342 100644 --- a/pcsx2/MTGS.cpp +++ b/pcsx2/MTGS.cpp @@ -896,7 +896,7 @@ int mtgsThreadObject::PrepDataPacket( GIF_PATH pathidx, const u8* srcdata, u32 s return m_packet_size; } -__forceinline void mtgsThreadObject::_PrepForSimplePacket() +__forceinline const u8* mtgsThreadObject::_PrepForSimplePacket() { #ifdef RINGBUF_DEBUG_STACK m_lock_Stack.Lock(); @@ -907,41 +907,42 @@ __forceinline void mtgsThreadObject::_PrepForSimplePacket() const u8* future_writepos = m_WritePos+16; jASSUME( future_writepos <= m_RingBufferEnd ); - if( future_writepos == m_RingBufferEnd ) + if( future_writepos >= m_RingBufferEnd ) future_writepos = m_RingBuffer; while( future_writepos == volatize(m_RingPos) ) SetEventWait(); + + return future_writepos; } -__forceinline void mtgsThreadObject::_FinishSimplePacket() +__forceinline void mtgsThreadObject::_FinishSimplePacket( const u8* future_writepos ) { - const u8* future_writepos = m_WritePos+16; assert( future_writepos != volatize(m_RingPos) ); AtomicExchangePointer( m_WritePos, future_writepos ); } void mtgsThreadObject::SendSimplePacket( GS_RINGTYPE type, int data0, int data1, int data2 ) { - _PrepForSimplePacket(); + const u8* const thefuture = _PrepForSimplePacket(); *(u32*)m_WritePos = type; *(u32*)(m_WritePos+4) = data0; *(u32*)(m_WritePos+8) = data1; *(u32*)(m_WritePos+12) = data2; - _FinishSimplePacket(); + _FinishSimplePacket( thefuture ); } void mtgsThreadObject::SendPointerPacket( GS_RINGTYPE type, u32 data0, void* data1 ) { - _PrepForSimplePacket(); + const u8* const thefuture = _PrepForSimplePacket(); *(u32*)m_WritePos = type; *(u32*)(m_WritePos+4) = data0; *(uptr*)(m_WritePos+8) = (uptr)data1; - _FinishSimplePacket(); + _FinishSimplePacket( thefuture ); } // Waits for the GS to empty out the entire ring buffer contents.