Skip to content
Permalink
Browse files

Use an explicit variable to wait for the GPU thread...

rather than copying the conditions in the big while loop.  I *think*
this doesn't make a difference unless (a) there's a breakpoint and (b)
the CPU thread gets really unlucky and observes the change to
CPReadPointer but not the immediately following change to
CPReadWriteDistance... but the difficulty of working that out
demonstrates why the change is needed.
  • Loading branch information
comex committed Sep 9, 2013
1 parent 9f96ad8 commit fe774d6f496ad92b3ed1f34687b5677ab44dab60
@@ -51,6 +51,7 @@ volatile bool interruptWaiting= false;
volatile bool interruptTokenWaiting = false;
u32 interruptTokenData;
volatile bool interruptFinishWaiting = false;
volatile u32 gpuBusy = 0;

volatile u32 VITicks = CommandProcessor::m_cpClockOrigin;

@@ -141,8 +142,7 @@ void Init()
static void SyncGPU() {
if (IsOnThread())
{
while (!interruptWaiting && cpuFifo.bFF_GPReadEnable &&
gpuFifo->CPReadWriteDistance && !AtBreakpointGpu())
while (Common::AtomicLoad(CommandProcessor::gpuBusy))
Common::YieldCPU();
}
if (Core::g_CoreStartupParameter.bSyncGPUAtIdleOnly)
@@ -760,17 +760,8 @@ void SetCpControlRegister()
ProcessorInterface::Fifo_CPUEnd = cpuFifo.CPEnd;
}

if(cpuFifo.bFF_GPReadEnable && !m_CPCtrlReg.GPReadEnable)
{
cpuFifo.bFF_GPReadEnable = m_CPCtrlReg.GPReadEnable;
SyncGPU();
while(cpuFifo.isGpuReadingData) Common::YieldCPU();
}
else
{
cpuFifo.bFF_GPReadEnable = m_CPCtrlReg.GPReadEnable;
SyncGPU();
}
cpuFifo.bFF_GPReadEnable = m_CPCtrlReg.GPReadEnable;
SyncGPU();

DEBUG_LOG(COMMANDPROCESSOR, "\t GPREAD %s | BP %s | Int %s | OvF %s | UndF %s | LINK %s"
, cpuFifo.bFF_GPReadEnable ? "ON" : "OFF"
@@ -797,10 +788,10 @@ void SetCpClearRegister()
void Update()
{
// called only when bSyncGPU is true
while (VITicks > m_cpClockOrigin && cpuFifo.isGpuReadingData && IsOnThread())
while (VITicks > m_cpClockOrigin && gpuBusy && IsOnThread())
Common::YieldCPU();

if (cpuFifo.isGpuReadingData)
if (gpuBusy)
Common::AtomicAdd(VITicks, SystemTimers::GetTicksPerSecond() / 10000);
}
} // end of namespace CommandProcessor
@@ -26,6 +26,7 @@ extern volatile bool interruptWaiting;
extern volatile bool interruptTokenWaiting;
extern u32 interruptTokenData;
extern volatile bool interruptFinishWaiting;
extern volatile u32 gpuBusy;

// internal hardware addresses
enum
@@ -43,7 +43,7 @@ void Fifo_PauseAndLock(bool doLock, bool unpauseOnUnlock)
EmulatorState(false);
if (!Core::IsGPUThread())
m_csHWVidOccupied.lock();
_dbg_assert_(COMMON, !CommandProcessor::gpuFifo->isGpuReadingData);
_dbg_assert_(COMMON, !CommandProcessor::gpuBusy);
}
else
{
@@ -155,7 +155,8 @@ void RunGpuLoop()
// check if we are able to run this buffer
while (GpuRunningState && !CommandProcessor::interruptWaiting && fifo.bFF_GPReadEnable && fifo.CPReadWriteDistance && !AtBreakpointGpu())
{
fifo.isGpuReadingData = true;

Common::AtomicStore(CommandProcessor::gpuBusy, 1);
CommandProcessor::isPossibleWaitingSetDrawDone = fifo.bFF_GPLinkEnable ? true : false;

if (!Core::g_CoreStartupParameter.bSyncGPU || Common::AtomicLoad(CommandProcessor::VITicks) > CommandProcessor::m_cpClockOrigin)
@@ -193,7 +194,7 @@ void RunGpuLoop()
CommandProcessor::isPossibleWaitingSetDrawDone = false;
}

fifo.isGpuReadingData = false;
Common::AtomicStore(CommandProcessor::gpuBusy, 0);

if (EmuRunningState)
{
@@ -62,7 +62,6 @@ struct SCPFifoStruct

// for GP watchdog hack
volatile u32 Fake_GPWDToken; // cicular incrementer
volatile u32 isGpuReadingData;
};

class VideoBackend

0 comments on commit fe774d6

Please sign in to comment.
You can’t perform that action at this time.