diff --git a/include/gx2/state.h b/include/gx2/state.h index 9e7d520..4ea35e2 100644 --- a/include/gx2/state.h +++ b/include/gx2/state.h @@ -21,6 +21,9 @@ GX2Shutdown(); void GX2Flush(); +void +GX2ResetGPU(uint32_t unknown); + #ifdef __cplusplus } #endif diff --git a/src/libwhb/src/gfx.c b/src/libwhb/src/gfx.c index 1cdf9fa..d1159da 100644 --- a/src/libwhb/src/gfx.c +++ b/src/libwhb/src/gfx.c @@ -64,6 +64,9 @@ sTvContextState = NULL; static GX2ContextState * sDrcContextState = NULL; +static BOOL +sGpuTimedOut = FALSE; + static void * GfxGX2RAlloc(GX2RResourceFlags flags, uint32_t size, @@ -426,6 +429,11 @@ error: void WHBGfxShutdown() { + if (sGpuTimedOut) { + GX2ResetGPU(0); + sGpuTimedOut = FALSE; + } + GfxProcCallbackReleased(NULL); GX2Shutdown(); @@ -452,14 +460,24 @@ WHBGfxBeginRender() { uint32_t swapCount, flipCount; OSTime lastFlip, lastVsync; + uint32_t waitCount = 0; while (true) { - GX2WaitForVsync(); GX2GetSwapStatus(&swapCount, &flipCount, &lastFlip, &lastVsync); if (flipCount >= swapCount) { + sGpuTimedOut = FALSE; break; } + + if (waitCount >= 10) { + WHBLogPrint("WHBGfxBeginRender wait for swap timed out"); + sGpuTimedOut = TRUE; + break; + } + + waitCount++; + GX2WaitForVsync(); } } diff --git a/src/rpl/gx2/exports.h b/src/rpl/gx2/exports.h index a0957c1..39bcba1 100644 --- a/src/rpl/gx2/exports.h +++ b/src/rpl/gx2/exports.h @@ -140,6 +140,7 @@ EXPORT(GX2InitSamplerZMFilter); EXPORT(GX2Flush); EXPORT(GX2Init); EXPORT(GX2Shutdown); +EXPORT(GX2ResetGPU); // gx2/shader.h EXPORT(GX2CalcGeometryShaderInputRingBufferSize);