diff --git a/GPU/Software/DrawPixelX86.cpp b/GPU/Software/DrawPixelX86.cpp index 4470b11225..5814d81ac5 100644 --- a/GPU/Software/DrawPixelX86.cpp +++ b/GPU/Software/DrawPixelX86.cpp @@ -676,6 +676,9 @@ bool PixelJitCache::Jit_StencilTest(const PixelFuncID &id, RegCache::Reg stencil return true; } + bool hadGStateReg = regCache_.Has(RegCache::GEN_GSTATE); + bool hadColorOffReg = regCache_.Has(RegCache::GEN_COLOR_OFF); + bool success = true; if (stencilReg != INVALID_REG && (!hasFixedResult || !fixedResult)) { // This is the fail path. @@ -685,6 +688,12 @@ bool PixelJitCache::Jit_StencilTest(const PixelFuncID &id, RegCache::Reg stencil Discard(); } + // If we allocated either gstate or colorOff in the conditional, forget. + if (!hadGStateReg && regCache_.Has(RegCache::GEN_GSTATE)) + regCache_.Change(RegCache::GEN_GSTATE, RegCache::GEN_INVALID); + if (!hadColorOffReg && regCache_.Has(RegCache::GEN_COLOR_OFF)) + regCache_.Change(RegCache::GEN_COLOR_OFF, RegCache::GEN_INVALID); + if (!hasFixedResult) SetJumpTarget(toPass); return success; @@ -741,11 +750,20 @@ bool PixelJitCache::Jit_DepthTestForStencil(const PixelFuncID &id, RegCache::Reg break; } + bool hadGStateReg = regCache_.Has(RegCache::GEN_GSTATE); + bool hadColorOffReg = regCache_.Has(RegCache::GEN_COLOR_OFF); + bool success = true; success = success && Jit_ApplyStencilOp(id, id.ZFail(), stencilReg); success = success && Jit_WriteStencilOnly(id, stencilReg); Discard(); + // If we allocated either gstate or colorOff in the conditional, forget. + if (!hadGStateReg && regCache_.Has(RegCache::GEN_GSTATE)) + regCache_.Change(RegCache::GEN_GSTATE, RegCache::GEN_INVALID); + if (!hadColorOffReg && regCache_.Has(RegCache::GEN_COLOR_OFF)) + regCache_.Change(RegCache::GEN_COLOR_OFF, RegCache::GEN_INVALID); + SetJumpTarget(skip); // Like in Jit_DepthTest(), at this point we may not need this reg anymore.