diff --git a/Source/Core/Core/Src/HW/GPFifo.cpp b/Source/Core/Core/Src/HW/GPFifo.cpp index 333f52b789..28ba18da1f 100644 --- a/Source/Core/Core/Src/HW/GPFifo.cpp +++ b/Source/Core/Core/Src/HW/GPFifo.cpp @@ -55,7 +55,8 @@ void Init() ResetGatherPipe(); } -bool IsEmpty() { +bool IsEmpty() +{ return m_gatherPipeCount == 0; } @@ -66,27 +67,34 @@ void ResetGatherPipe() void STACKALIGN CheckGatherPipe() { - // HyperIris: Memory::GetPointer is an expensive call, call it less, run faster - // ector: Well not really - this loop will only rarely go more than one lap. - while (m_gatherPipeCount >= GATHER_PIPE_SIZE) - { - // copy the GatherPipe - memcpy(Memory::GetPointer(ProcessorInterface::Fifo_CPUWritePointer), m_gatherPipe, GATHER_PIPE_SIZE); + if (m_gatherPipeCount >= GATHER_PIPE_SIZE) + { + u32 cnt; + u8* curMem = Memory::GetPointer(ProcessorInterface::Fifo_CPUWritePointer); + for (cnt = 0; m_gatherPipeCount >= GATHER_PIPE_SIZE; cnt += GATHER_PIPE_SIZE) + { + // copy the GatherPipe + memcpy(curMem, m_gatherPipe + cnt, GATHER_PIPE_SIZE); + m_gatherPipeCount -= GATHER_PIPE_SIZE; + // increase the CPUWritePointer + if (ProcessorInterface::Fifo_CPUWritePointer + GATHER_PIPE_SIZE >= ProcessorInterface::Fifo_CPUEnd) + { + curMem -= ProcessorInterface::Fifo_CPUWritePointer - ProcessorInterface::Fifo_CPUBase; + ProcessorInterface::Fifo_CPUWritePointer = ProcessorInterface::Fifo_CPUBase; + } + else + { + curMem += GATHER_PIPE_SIZE; + ProcessorInterface::Fifo_CPUWritePointer += GATHER_PIPE_SIZE; + } + + // TODO store video plugin pointer + CPluginManager::GetInstance().GetVideo()->Video_GatherPipeBursted(); + } + // move back the spill bytes - m_gatherPipeCount -= GATHER_PIPE_SIZE; - - // HyperIris: dunno why, but I use memcpy. TODO: See if a custom copy can be faster, like 4x MOVAPD - memmove(m_gatherPipe, m_gatherPipe + GATHER_PIPE_SIZE, m_gatherPipeCount); - - // increase the CPUWritePointer - 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(); + memmove(m_gatherPipe, m_gatherPipe + cnt, m_gatherPipeCount); } } diff --git a/Source/Core/VideoCommon/Src/CommandProcessor.cpp b/Source/Core/VideoCommon/Src/CommandProcessor.cpp index 4e8bcfb849..f8f0f4bb1c 100644 --- a/Source/Core/VideoCommon/Src/CommandProcessor.cpp +++ b/Source/Core/VideoCommon/Src/CommandProcessor.cpp @@ -594,7 +594,7 @@ void STACKALIGN GatherPipeBursted() if (g_VideoInitialize.bOnThread) { // update the fifo-pointer - if (fifo.CPWritePointer >= fifo.CPEnd) + if (fifo.CPWritePointer + GATHER_PIPE_SIZE >= fifo.CPEnd) fifo.CPWritePointer = fifo.CPBase; else fifo.CPWritePointer += GATHER_PIPE_SIZE; @@ -634,7 +634,7 @@ void STACKALIGN GatherPipeBursted() } else { - if (fifo.CPWritePointer >= fifo.CPEnd) + if (fifo.CPWritePointer + GATHER_PIPE_SIZE >= fifo.CPEnd) fifo.CPWritePointer = fifo.CPBase; else fifo.CPWritePointer += GATHER_PIPE_SIZE; @@ -687,11 +687,11 @@ void CatchUpGPU() fifo.CPReadWriteDistance -= 32; // increase the ReadPtr - if (fifo.CPReadPointer >= fifo.CPEnd) + if (fifo.CPReadPointer + 32 >= fifo.CPEnd) { fifo.CPReadPointer = fifo.CPBase; // adjust, take care - ptr = Memory_GetPtr(fifo.CPReadPointer); + ptr -= fifo.CPReadPointer - fifo.CPBase; DEBUG_LOG(COMMANDPROCESSOR, "Fifo Loop"); } else diff --git a/Source/Core/VideoCommon/Src/Fifo.cpp b/Source/Core/VideoCommon/Src/Fifo.cpp index 099084fae5..a24a96b3ad 100644 --- a/Source/Core/VideoCommon/Src/Fifo.cpp +++ b/Source/Core/VideoCommon/Src/Fifo.cpp @@ -118,12 +118,12 @@ void Fifo_SendFifoData(u8* _uData, u32 len) if (size + len >= FIFO_SIZE) { int pos = (int)(g_pVideoData - videoBuffer); - if (size - pos > pos) + size -= pos; + if (size + len > FIFO_SIZE) { PanicAlert("FIFO out of bounds (sz = %i, at %08x)", size, pos); } - memmove(&videoBuffer[0], &videoBuffer[pos], size - pos); - size -= pos; + memmove(&videoBuffer[0], &videoBuffer[pos], size); g_pVideoData = videoBuffer; } // Copy new video instructions to videoBuffer for future use in rendering the new picture @@ -180,7 +180,7 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize) } distToSend = 32; - if ( readPtr >= _fifo.CPEnd) + if (readPtr + 32 >= _fifo.CPEnd) readPtr = _fifo.CPBase; else readPtr += 32; @@ -192,9 +192,9 @@ void Fifo_EnterLoop(const SVideoInitialize &video_initialize) // send 1024B chunk max length to have better control over PeekMessages' period distToSend = distToSend > 1024 ? 1024 : distToSend; // 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? + if (readPtr + distToSend >= _fifo.CPEnd) { - distToSend =(_fifo.CPEnd + 32) - readPtr; + distToSend = _fifo.CPEnd - readPtr; readPtr = _fifo.CPBase; } else