Forwarded Present to Swap and improved return values

This commit is contained in:
PatrickvL 2017-04-18 09:37:33 +02:00
parent 34e4497ede
commit c4523bdfe5
2 changed files with 41 additions and 61 deletions

View File

@ -4255,6 +4255,8 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_Clear)
return ret;
}
#define CXBX_SWAP_PRESENT_FORWARD (256 + 4 + 1) // = CxbxPresentForwardMarker + D3DSWAP_FINISH + D3DSWAP_COPY
// ******************************************************************
// * patch: D3DDevice_Present
// ******************************************************************
@ -4266,8 +4268,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_Present)
PVOID pDummy2
)
{
// LOG_FORWARD("D3DDevice_Swap");
DbgPrintf("EmuD3D8: EmuD3DDevice_Present\n"
"(\n"
" pSourceRect : 0x%.08X\n"
@ -4277,7 +4278,27 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_Present)
");\n",
pSourceRect, pDestRect, pDummy1, pDummy2);
HRESULT hRet = S_OK;
return EMUPATCH(D3DDevice_Swap)(CXBX_SWAP_PRESENT_FORWARD); // Xbox present ignores
}
// ******************************************************************
// * patch: D3DDevice_Swap
// ******************************************************************
DWORD WINAPI XTL::EMUPATCH(D3DDevice_Swap)
(
DWORD Flags
)
{
DbgPrintf("EmuD3D8: EmuD3DDevice_Swap\n"
"(\n"
" Flags : 0x%.08X\n"
");\n",
Flags);
// TODO: Ensure this flag is always the same across library versions
if(Flags != 0)
if (Flags != CXBX_SWAP_PRESENT_FORWARD) // Avoid a warning when forwarded
EmuWarning("XTL::EmuD3DDevice_Swap: Flags != 0");
CxbxReleaseBackBufferLock();
@ -4287,8 +4308,10 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_Present)
// g_pDD7->WaitForVerticalBlank( DDWAITVB_BLOCKEND, NULL );
// g_pDD7->WaitForVerticalBlank( DDWAITVB_BLOCKEND, NULL );
hRet = g_pD3DDevice8->Present(pSourceRect, pDestRect, (HWND)pDummy1, (CONST RGNDATA*)pDummy2);
g_pD3DDevice8->Present(0, 0, 0, 0);
if (Flags == CXBX_SWAP_PRESENT_FORWARD) // Only do this when forwarded from Present
{
// Put primitives per frame in the title
/*{
char szString[64];
@ -4300,6 +4323,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_Present)
g_dwPrimPerFrame = 0;
}*/
// TODO : Check if this should be done at Swap-not-Present-time too :
// not really accurate because you definately dont always present on every vblank
g_VBData.Swap = g_VBData.VBlank;
@ -4310,6 +4334,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_Present)
g_VBData.Flags = 2; // D3DVBLANK_SWAPMISSED
g_SwapData.MissedVBlanks++;
}
}
// Handle Swap Callback function
{
@ -4325,58 +4350,13 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_Present)
g_bHackUpdateSoftwareOverlay = FALSE;
DWORD result;
if (Flags == CXBX_SWAP_PRESENT_FORWARD) // Only do this when forwarded from Present
result = S_OK; // Present always returns success
else
result = g_SwapData.Swap; // Swap returns number of swaps
return hRet;
}
// ******************************************************************
// * patch: D3DDevice_Swap
// ******************************************************************
HRESULT WINAPI XTL::EMUPATCH(D3DDevice_Swap)
(
DWORD Flags
)
{
DbgPrintf("EmuD3D8: EmuD3DDevice_Swap\n"
"(\n"
" Flags : 0x%.08X\n"
");\n",
Flags);
// TODO: Ensure this flag is always the same across library versions
if(Flags != 0)
EmuWarning("XTL::EmuD3DDevice_Swap: Flags != 0");
CxbxReleaseBackBufferLock();
// TODO: Make a video option to wait for VBlank before calling Present.
// Makes syncing to 30fps easier (which is the native frame rate for Azurik
// and Halo).
// g_pDD7->WaitForVerticalBlank( DDWAITVB_BLOCKEND, NULL );
// g_pDD7->WaitForVerticalBlank( DDWAITVB_BLOCKEND, NULL );
HRESULT hRet = g_pD3DDevice8->Present(0, 0, 0, 0);
// Handle Swap Callback function
{
g_SwapData.Swap++;
if(g_pSwapCallback != NULL)
{
g_pSwapCallback(&g_SwapData);
}
}
g_bHackUpdateSoftwareOverlay = FALSE;
return hRet;
return result;
}
// ******************************************************************

View File

@ -669,7 +669,7 @@ HRESULT WINAPI EMUPATCH(D3DDevice_Present)
// ******************************************************************
// * patch: D3DDevice_Swap
// ******************************************************************
HRESULT WINAPI EMUPATCH(D3DDevice_Swap)
DWORD WINAPI EMUPATCH(D3DDevice_Swap)
(
DWORD Flags
);