From e0eeb142cace15c43ebd7489fe47be61eda235f5 Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Fri, 6 Apr 2018 23:37:20 +0100 Subject: [PATCH 1/4] Only Update FPS counter & cap framerate in actual SWAP_PRESENT calls --- src/CxbxKrnl/EmuD3D8.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/CxbxKrnl/EmuD3D8.cpp b/src/CxbxKrnl/EmuD3D8.cpp index f96747e2f..f94f07824 100755 --- a/src/CxbxKrnl/EmuD3D8.cpp +++ b/src/CxbxKrnl/EmuD3D8.cpp @@ -3971,25 +3971,25 @@ DWORD WINAPI XTL::EMUPATCH(D3DDevice_Swap) HRESULT hRet = g_pD3DDevice8->Present(0, 0, 0, 0); DEBUG_D3DRESULT(hRet, "g_pD3DDevice8->Present"); hRet = g_pD3DDevice8->BeginScene(); - - if (!g_UncapFramerate) { - // If the last frame completed faster than the Xbox VBlank period, wait for it - // TODO: Read the frame rate target from the Xbox display mode - // See comments in GetNextVblankTime(); - auto targetDuration = 16.6666666667ms; - while (std::chrono::high_resolution_clock::now() - frameStartTime < targetDuration) { - // We use an empty while loop because actually sleeping is too unstable - // Sleeping causes the frame duration to jitter... - ; - } - - frameStartTime = std::chrono::high_resolution_clock::now(); - } - - UpdateFPSCounter(); if (Flags == CXBX_SWAP_PRESENT_FORWARD) // Only do this when forwarded from Present { + if (!g_UncapFramerate) { + // If the last frame completed faster than the Xbox VBlank period, wait for it + // TODO: Read the frame rate target from the Xbox display mode + // See comments in GetNextVblankTime(); + auto targetDuration = 16.6666666667ms; + while (std::chrono::high_resolution_clock::now() - frameStartTime < targetDuration) { + // We use an empty while loop because actually sleeping is too unstable + // Sleeping causes the frame duration to jitter... + ; + } + + frameStartTime = std::chrono::high_resolution_clock::now(); + } + + UpdateFPSCounter(); + // Put primitives per frame in the title /*{ char szString[64]; From f018ca461e1d38803c47f0f59c08667e6e6e8483 Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Sat, 7 Apr 2018 00:00:52 +0100 Subject: [PATCH 2/4] Unpatch XAPI QueueUserAPC, seems to fix .bik hang --- src/CxbxKrnl/EmuXapi.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CxbxKrnl/EmuXapi.cpp b/src/CxbxKrnl/EmuXapi.cpp index e8133691e..2eb59beee 100644 --- a/src/CxbxKrnl/EmuXapi.cpp +++ b/src/CxbxKrnl/EmuXapi.cpp @@ -954,7 +954,7 @@ DWORD WINAPI XTL::EMUPATCH(QueueUserAPC) DWORD dwData ) { - FUNC_EXPORTS + //FUNC_EXPORTS LOG_FUNC_BEGIN LOG_FUNC_ARG_TYPE(PVOID, pfnAPC) From bfa444d55aa913d0745e8ff51b231df5dfea4076 Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Sat, 7 Apr 2018 00:07:38 +0100 Subject: [PATCH 3/4] Fix FPS counter --- src/CxbxKrnl/EmuD3D8.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CxbxKrnl/EmuD3D8.cpp b/src/CxbxKrnl/EmuD3D8.cpp index f94f07824..5a0e67e4f 100755 --- a/src/CxbxKrnl/EmuD3D8.cpp +++ b/src/CxbxKrnl/EmuD3D8.cpp @@ -3971,6 +3971,8 @@ DWORD WINAPI XTL::EMUPATCH(D3DDevice_Swap) HRESULT hRet = g_pD3DDevice8->Present(0, 0, 0, 0); DEBUG_D3DRESULT(hRet, "g_pD3DDevice8->Present"); hRet = g_pD3DDevice8->BeginScene(); + + UpdateFPSCounter(); if (Flags == CXBX_SWAP_PRESENT_FORWARD) // Only do this when forwarded from Present { @@ -3988,8 +3990,6 @@ DWORD WINAPI XTL::EMUPATCH(D3DDevice_Swap) frameStartTime = std::chrono::high_resolution_clock::now(); } - UpdateFPSCounter(); - // Put primitives per frame in the title /*{ char szString[64]; From 2ee582b56c8070bac85ddef102c61a2d5eaac1ae Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Sat, 7 Apr 2018 00:51:26 +0100 Subject: [PATCH 4/4] Fix an issue where RtlAnsiStringToUnicornSize would truncate strings --- src/CxbxKrnl/EmuKrnlRtl.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/CxbxKrnl/EmuKrnlRtl.cpp b/src/CxbxKrnl/EmuKrnlRtl.cpp index 9eac104b2..3666f71a0 100644 --- a/src/CxbxKrnl/EmuKrnlRtl.cpp +++ b/src/CxbxKrnl/EmuKrnlRtl.cpp @@ -144,8 +144,7 @@ static BOOL TryEnterHostCriticalSection(xboxkrnl::PRTL_CRITICAL_SECTION xbox_cri DWORD WINAPI RtlAnsiStringToUnicodeSize(const xboxkrnl::STRING *str) { - DWORD ret = mbstowcs(nullptr, str->Buffer, str->Length); - return ret + sizeof(WCHAR); // + for the terminating null character + return (str->Length + sizeof(ANSI_NULL)) * sizeof(WCHAR); } // ******************************************************************