whb: Handle GPU hangs by resetting the GPU on shutdown.

So your application will exit cleanly even when you break the GPU.
This commit is contained in:
James Benton 2017-06-02 11:50:12 +01:00
parent 2c18b246ae
commit ee9bd49c34
3 changed files with 23 additions and 1 deletions

View File

@ -21,6 +21,9 @@ GX2Shutdown();
void void
GX2Flush(); GX2Flush();
void
GX2ResetGPU(uint32_t unknown);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -64,6 +64,9 @@ sTvContextState = NULL;
static GX2ContextState * static GX2ContextState *
sDrcContextState = NULL; sDrcContextState = NULL;
static BOOL
sGpuTimedOut = FALSE;
static void * static void *
GfxGX2RAlloc(GX2RResourceFlags flags, GfxGX2RAlloc(GX2RResourceFlags flags,
uint32_t size, uint32_t size,
@ -426,6 +429,11 @@ error:
void void
WHBGfxShutdown() WHBGfxShutdown()
{ {
if (sGpuTimedOut) {
GX2ResetGPU(0);
sGpuTimedOut = FALSE;
}
GfxProcCallbackReleased(NULL); GfxProcCallbackReleased(NULL);
GX2Shutdown(); GX2Shutdown();
@ -452,14 +460,24 @@ WHBGfxBeginRender()
{ {
uint32_t swapCount, flipCount; uint32_t swapCount, flipCount;
OSTime lastFlip, lastVsync; OSTime lastFlip, lastVsync;
uint32_t waitCount = 0;
while (true) { while (true) {
GX2WaitForVsync();
GX2GetSwapStatus(&swapCount, &flipCount, &lastFlip, &lastVsync); GX2GetSwapStatus(&swapCount, &flipCount, &lastFlip, &lastVsync);
if (flipCount >= swapCount) { if (flipCount >= swapCount) {
sGpuTimedOut = FALSE;
break; break;
} }
if (waitCount >= 10) {
WHBLogPrint("WHBGfxBeginRender wait for swap timed out");
sGpuTimedOut = TRUE;
break;
}
waitCount++;
GX2WaitForVsync();
} }
} }

View File

@ -140,6 +140,7 @@ EXPORT(GX2InitSamplerZMFilter);
EXPORT(GX2Flush); EXPORT(GX2Flush);
EXPORT(GX2Init); EXPORT(GX2Init);
EXPORT(GX2Shutdown); EXPORT(GX2Shutdown);
EXPORT(GX2ResetGPU);
// gx2/shader.h // gx2/shader.h
EXPORT(GX2CalcGeometryShaderInputRingBufferSize); EXPORT(GX2CalcGeometryShaderInputRingBufferSize);