Skip to content
Permalink
Browse files

Fix freeze on close - bFF_GPReadEnable was not enough to stop SyncGPU.

Should look into the potential performance impact of having GPUHasWork
test so many different things - RunGpuLoop already did this, and SyncGPU
doing it once-ish per frame probably doesn't matter, but it might be
possible to make cheaper anyway.
  • Loading branch information...
comex committed Sep 23, 2013
1 parent 2743b31 commit aa3d141e815d26b86528e928c07ac901ecab0e57
@@ -45,6 +45,7 @@ u16 m_tokenReg;
volatile bool interruptSet= false;
volatile bool interruptWaiting= false;
volatile bool interruptTokenWaiting = false;
volatile bool gpuRunning = false;
u32 interruptTokenData;
volatile bool interruptFinishWaiting = false;
bool deterministicGPUSync = false;
@@ -128,7 +129,8 @@ bool GPUHasWork()
// - interruptWaiting *never* becomes true.
// - No work is done between setting the read pointer and comparing it
// against CPWritePointer/CPBreakpoint.
return gpuFifo->bFF_GPReadEnable &&
return gpuRunning &&
gpuFifo->bFF_GPReadEnable &&
!interruptWaiting &&
Common::AtomicLoad(gpuFifo->CPReadPointer) != Common::AtomicLoad(gpuFifo->CPWritePointer) &&
!AtBreakpointGpu();
@@ -20,6 +20,7 @@ extern SCPFifoStruct *gpuFifo;
extern SCPFifoStruct cpuFifo;
extern volatile bool interruptSet;
extern volatile bool interruptWaiting;
extern volatile bool gpuRunning;
extern volatile bool interruptTokenWaiting;
extern u32 interruptTokenData;
extern volatile bool interruptFinishWaiting;
@@ -20,7 +20,6 @@ extern u8* g_pVideoData;

namespace
{
static volatile bool GpuRunningState = false;
static volatile bool EmuRunningState = false;
static std::mutex m_csHWVidOccupied;
// STATE_TO_SAVE
@@ -58,13 +57,13 @@ void Fifo_Init()
{
videoBuffer = (u8*)AllocateMemoryPages(FIFO_SIZE);
size = 0;
GpuRunningState = false;
CommandProcessor::gpuRunning = false;
Common::AtomicStore(CommandProcessor::VITicks, CommandProcessor::m_cpClockOrigin);
}

void Fifo_Shutdown()
{
if (GpuRunningState) PanicAlert("Fifo shutting down while active");
if (CommandProcessor::gpuRunning) PanicAlert("Fifo shutting down while active");
FreeMemoryPages(videoBuffer, FIFO_SIZE);
}

@@ -86,8 +85,7 @@ void Fifo_SetRendering(bool enabled)
void ExitGpuLoop()
{
// Terminate GPU thread loop
GpuRunningState = false;
CommandProcessor::gpuFifo->bFF_GPReadEnable = false;
CommandProcessor::gpuRunning = false;
// No need to wait - g_EmuThread.join() will take care of it.
EmuRunningState = true;
}
@@ -129,10 +127,10 @@ void ResetVideoBuffer()
void RunGpuLoop()
{
std::lock_guard<std::mutex> lk(m_csHWVidOccupied);
GpuRunningState = true;
CommandProcessor::gpuRunning = true;
u32 cyclesExecuted = 0;

while (GpuRunningState)
while (CommandProcessor::gpuRunning)
{
SCPFifoStruct &fifo = *CommandProcessor::gpuFifo;

@@ -143,7 +141,7 @@ void RunGpuLoop()
Common::AtomicStore(CommandProcessor::VITicks, CommandProcessor::m_cpClockOrigin);

// check if we are able to run this buffer
while (GpuRunningState && CommandProcessor::GPUHasWork())
while (CommandProcessor::GPUHasWork())
{
if (!Core::g_CoreStartupParameter.bSyncGPU || Common::AtomicLoad(CommandProcessor::VITicks) > CommandProcessor::m_cpClockOrigin)
{
@@ -217,6 +215,7 @@ bool AtBreakpointCpu()

void RunGpu()
{
CommandProcessor::gpuRunning = true;
SCPFifoStruct &fifo = *CommandProcessor::gpuFifo;
while (CommandProcessor::GPUHasWork())
{

0 comments on commit aa3d141

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