From dee90fa7aa2d6252f1fe4b51ba11b82e71add9df Mon Sep 17 00:00:00 2001 From: donkopunchstania Date: Thu, 12 Nov 2009 01:51:40 +0000 Subject: [PATCH] The WGP does not loop if the write pointer is set beyond the end of the fifo. Updated the video plugins this time. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4531 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Core/Src/HW/GPFifo.cpp | 10 +++------- .../Core/VideoCommon/Src/CommandProcessor.cpp | 19 ++++++++++++------- Source/Core/VideoCommon/Src/Fifo.cpp | 9 ++++++--- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Source/Core/Core/Src/HW/GPFifo.cpp b/Source/Core/Core/Src/HW/GPFifo.cpp index 01d38ed0f5..fa3e751941 100644 --- a/Source/Core/Core/Src/HW/GPFifo.cpp +++ b/Source/Core/Core/Src/HW/GPFifo.cpp @@ -80,14 +80,10 @@ void STACKALIGN CheckGatherPipe() memcpy(m_gatherPipe, m_gatherPipe + GATHER_PIPE_SIZE, m_gatherPipeCount); // increase the CPUWritePointer - ProcessorInterface::Fifo_CPUWritePointer += GATHER_PIPE_SIZE; - - if (ProcessorInterface::Fifo_CPUWritePointer > ProcessorInterface::Fifo_CPUEnd) - _assert_msg_(DYNA_REC, 0, "Fifo_CPUWritePointer out of bounds: %08x (end = %08x)", - ProcessorInterface::Fifo_CPUWritePointer, ProcessorInterface::Fifo_CPUEnd); - - if (ProcessorInterface::Fifo_CPUWritePointer >= ProcessorInterface::Fifo_CPUEnd) + if (ProcessorInterface::Fifo_CPUWritePointer == ProcessorInterface::Fifo_CPUEnd) ProcessorInterface::Fifo_CPUWritePointer = ProcessorInterface::Fifo_CPUBase; + else + ProcessorInterface::Fifo_CPUWritePointer += GATHER_PIPE_SIZE; // TODO store video plugin pointer CPluginManager::GetInstance().GetVideo()->Video_GatherPipeBursted(); diff --git a/Source/Core/VideoCommon/Src/CommandProcessor.cpp b/Source/Core/VideoCommon/Src/CommandProcessor.cpp index fccf3e44e6..b7ab90d64a 100644 --- a/Source/Core/VideoCommon/Src/CommandProcessor.cpp +++ b/Source/Core/VideoCommon/Src/CommandProcessor.cpp @@ -590,9 +590,11 @@ void STACKALIGN GatherPipeBursted() if (g_VideoInitialize.bOnThread) { // update the fifo-pointer - fifo.CPWritePointer += GATHER_PIPE_SIZE; - if (fifo.CPWritePointer >= fifo.CPEnd) + if (fifo.CPWritePointer >= fifo.CPEnd) fifo.CPWritePointer = fifo.CPBase; + else + fifo.CPWritePointer += GATHER_PIPE_SIZE; + Common::AtomicAdd(fifo.CPReadWriteDistance, GATHER_PIPE_SIZE); // High watermark overflow handling (hacked way) @@ -626,9 +628,10 @@ void STACKALIGN GatherPipeBursted() } else { - fifo.CPWritePointer += GATHER_PIPE_SIZE; if (fifo.CPWritePointer >= fifo.CPEnd) fifo.CPWritePointer = fifo.CPBase; + else + fifo.CPWritePointer += GATHER_PIPE_SIZE; // check if we are in sync _assert_msg_(COMMANDPROCESSOR, fifo.CPWritePointer == *(g_VideoInitialize.Fifo_CPUWritePointer), "FIFOs linked but out of sync"); _assert_msg_(COMMANDPROCESSOR, fifo.CPBase == *(g_VideoInitialize.Fifo_CPUBase), "FIFOs linked but out of sync"); @@ -666,14 +669,11 @@ void CatchUpGPU() } // read the data and send it to the VideoPlugin - fifo.CPReadPointer += 32; // We are going to do FP math on the main thread so have to save the current state SaveSSEState(); LoadDefaultSSEState(); Fifo_SendFifoData(ptr,32); LoadSSEState(); - // adjust - ptr += 32; fifo.CPReadWriteDistance -= 32; @@ -685,6 +685,11 @@ void CatchUpGPU() ptr = Memory_GetPtr(fifo.CPReadPointer); INFO_LOG(COMMANDPROCESSOR, "BUFFER LOOP"); } + else + { + fifo.CPReadPointer += 32; + ptr += 32; + } } } } @@ -712,7 +717,7 @@ void UpdateFifoRegister() if (wp >= rp) dist = wp - rp; else - dist = (wp - fifo.CPBase) + (fifo.CPEnd - rp); + dist = (wp - fifo.CPBase) + ((fifo.CPEnd + GATHER_PIPE_SIZE) - rp); Common::AtomicStore(fifo.CPReadWriteDistance, dist); diff --git a/Source/Core/VideoCommon/Src/Fifo.cpp b/Source/Core/VideoCommon/Src/Fifo.cpp index 6285e37afe..0375fdfd0a 100644 --- a/Source/Core/VideoCommon/Src/Fifo.cpp +++ b/Source/Core/VideoCommon/Src/Fifo.cpp @@ -165,18 +165,21 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize) break; } distToSend = 32; - readPtr += 32; + if ( readPtr >= _fifo.CPEnd) readPtr = _fifo.CPBase; + else + readPtr += 32; } else { distToSend = _fifo.CPReadWriteDistance; // send 1024B chunk max length to have better control over PeekMessages' period distToSend = distToSend > 1024 ? 1024 : distToSend; - if ((distToSend + readPtr) >= _fifo.CPEnd) // TODO: better? + // add 32 bytes because the cp end points to the start of the last 32 byte chunk + if ((distToSend + readPtr) >= (_fifo.CPEnd + 32)) // TODO: better? { - distToSend =_fifo.CPEnd - readPtr; + distToSend =(_fifo.CPEnd + 32) - readPtr; readPtr = _fifo.CPBase; } else