Skip to content

Commit

Permalink
Reset FPU only if status is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Apr 18, 2024
1 parent 79abff3 commit 1166024
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 7001
#define BUILD_NUMBER 7002
9 changes: 9 additions & 0 deletions Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,15 @@ void Utils::BusyWaitYield()
#endif
}

// Reset FPU if the _SW_INVALID flag is set
void Utils::ResetInvalidFPUState()
{
if (_statusfp() & _SW_INVALID)
{
__asm { fninit }
}
}

void Utils::CheckMessageQueue(HWND hwnd)
{
// Peek messages to help prevent a "Not Responding" window
Expand Down
1 change: 1 addition & 0 deletions Utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace Utils
DWORD ReverseBits(DWORD v);
void DDrawResolutionHack(HMODULE hD3DIm);
void BusyWaitYield();
void ResetInvalidFPUState();
void CheckMessageQueue(HWND hwnd);
void GetScreenSettings();
void ResetScreenSettings();
Expand Down
4 changes: 2 additions & 2 deletions d3d9/IDirect3DDevice9Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ HRESULT m_IDirect3DDevice9Ex::SetPixelShader(THIS_ IDirect3DPixelShader9* pShade

HRESULT m_IDirect3DDevice9Ex::Present(CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion)
{
__asm { fninit } // Reset FPU before presenting
Utils::ResetInvalidFPUState(); // Check FPU state before presenting

Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

Expand Down Expand Up @@ -2080,7 +2080,7 @@ HRESULT m_IDirect3DDevice9Ex::ComposeRects(THIS_ IDirect3DSurface9* pSrc, IDirec

HRESULT m_IDirect3DDevice9Ex::PresentEx(THIS_ CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags)
{
__asm { fninit } // Reset FPU before presenting
Utils::ResetInvalidFPUState(); // Check FPU state before presenting

Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";

Expand Down

0 comments on commit 1166024

Please sign in to comment.