Fixed GPFifo out of bounds by 32 bytes
Fixed incorrect FIFO out of bounds check plus a bit optimization of CheckPipe() git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5692 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
fc12291806
commit
857f1f4d38
|
@ -55,7 +55,8 @@ void Init()
|
||||||
ResetGatherPipe();
|
ResetGatherPipe();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsEmpty() {
|
bool IsEmpty()
|
||||||
|
{
|
||||||
return m_gatherPipeCount == 0;
|
return m_gatherPipeCount == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,27 +67,34 @@ void ResetGatherPipe()
|
||||||
|
|
||||||
void STACKALIGN CheckGatherPipe()
|
void STACKALIGN CheckGatherPipe()
|
||||||
{
|
{
|
||||||
// HyperIris: Memory::GetPointer is an expensive call, call it less, run faster
|
if (m_gatherPipeCount >= GATHER_PIPE_SIZE)
|
||||||
// ector: Well not really - this loop will only rarely go more than one lap.
|
{
|
||||||
while (m_gatherPipeCount >= GATHER_PIPE_SIZE)
|
u32 cnt;
|
||||||
{
|
u8* curMem = Memory::GetPointer(ProcessorInterface::Fifo_CPUWritePointer);
|
||||||
// copy the GatherPipe
|
for (cnt = 0; m_gatherPipeCount >= GATHER_PIPE_SIZE; cnt += GATHER_PIPE_SIZE)
|
||||||
memcpy(Memory::GetPointer(ProcessorInterface::Fifo_CPUWritePointer), m_gatherPipe, 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
|
// move back the spill bytes
|
||||||
m_gatherPipeCount -= GATHER_PIPE_SIZE;
|
memmove(m_gatherPipe, m_gatherPipe + cnt, m_gatherPipeCount);
|
||||||
|
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -594,7 +594,7 @@ void STACKALIGN GatherPipeBursted()
|
||||||
if (g_VideoInitialize.bOnThread)
|
if (g_VideoInitialize.bOnThread)
|
||||||
{
|
{
|
||||||
// update the fifo-pointer
|
// update the fifo-pointer
|
||||||
if (fifo.CPWritePointer >= fifo.CPEnd)
|
if (fifo.CPWritePointer + GATHER_PIPE_SIZE >= fifo.CPEnd)
|
||||||
fifo.CPWritePointer = fifo.CPBase;
|
fifo.CPWritePointer = fifo.CPBase;
|
||||||
else
|
else
|
||||||
fifo.CPWritePointer += GATHER_PIPE_SIZE;
|
fifo.CPWritePointer += GATHER_PIPE_SIZE;
|
||||||
|
@ -634,7 +634,7 @@ void STACKALIGN GatherPipeBursted()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (fifo.CPWritePointer >= fifo.CPEnd)
|
if (fifo.CPWritePointer + GATHER_PIPE_SIZE >= fifo.CPEnd)
|
||||||
fifo.CPWritePointer = fifo.CPBase;
|
fifo.CPWritePointer = fifo.CPBase;
|
||||||
else
|
else
|
||||||
fifo.CPWritePointer += GATHER_PIPE_SIZE;
|
fifo.CPWritePointer += GATHER_PIPE_SIZE;
|
||||||
|
@ -687,11 +687,11 @@ void CatchUpGPU()
|
||||||
|
|
||||||
fifo.CPReadWriteDistance -= 32;
|
fifo.CPReadWriteDistance -= 32;
|
||||||
// increase the ReadPtr
|
// increase the ReadPtr
|
||||||
if (fifo.CPReadPointer >= fifo.CPEnd)
|
if (fifo.CPReadPointer + 32 >= fifo.CPEnd)
|
||||||
{
|
{
|
||||||
fifo.CPReadPointer = fifo.CPBase;
|
fifo.CPReadPointer = fifo.CPBase;
|
||||||
// adjust, take care
|
// adjust, take care
|
||||||
ptr = Memory_GetPtr(fifo.CPReadPointer);
|
ptr -= fifo.CPReadPointer - fifo.CPBase;
|
||||||
DEBUG_LOG(COMMANDPROCESSOR, "Fifo Loop");
|
DEBUG_LOG(COMMANDPROCESSOR, "Fifo Loop");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -118,12 +118,12 @@ void Fifo_SendFifoData(u8* _uData, u32 len)
|
||||||
if (size + len >= FIFO_SIZE)
|
if (size + len >= FIFO_SIZE)
|
||||||
{
|
{
|
||||||
int pos = (int)(g_pVideoData - videoBuffer);
|
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);
|
PanicAlert("FIFO out of bounds (sz = %i, at %08x)", size, pos);
|
||||||
}
|
}
|
||||||
memmove(&videoBuffer[0], &videoBuffer[pos], size - pos);
|
memmove(&videoBuffer[0], &videoBuffer[pos], size);
|
||||||
size -= pos;
|
|
||||||
g_pVideoData = videoBuffer;
|
g_pVideoData = videoBuffer;
|
||||||
}
|
}
|
||||||
// Copy new video instructions to videoBuffer for future use in rendering the new picture
|
// 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;
|
distToSend = 32;
|
||||||
|
|
||||||
if ( readPtr >= _fifo.CPEnd)
|
if (readPtr + 32 >= _fifo.CPEnd)
|
||||||
readPtr = _fifo.CPBase;
|
readPtr = _fifo.CPBase;
|
||||||
else
|
else
|
||||||
readPtr += 32;
|
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
|
// send 1024B chunk max length to have better control over PeekMessages' period
|
||||||
distToSend = distToSend > 1024 ? 1024 : distToSend;
|
distToSend = distToSend > 1024 ? 1024 : distToSend;
|
||||||
// add 32 bytes because the cp end points to the start of the last 32 byte chunk
|
// 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;
|
readPtr = _fifo.CPBase;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue