From 9309575e7f150b66f941a0ae76deda703fbbbcb5 Mon Sep 17 00:00:00 2001 From: PatrickvL Date: Sun, 7 May 2017 16:16:20 +0100 Subject: [PATCH] Disabled D3D_MakeSpace patch, let D3D_MakeRequestedSpace return a buffer This buffer will receive push-buffer commands, pushed by unpatched functions. For now we'll ignore them, but at least this prevents fatal errors. Later we can execute these pushbuffer commands too. Also prevented memory leaks in BeginPush / EndPush --- src/CxbxKrnl/EmuD3D8.cpp | 54 +++++++++++++++------- src/CxbxKrnl/EmuD3D8.h | 6 ++- src/CxbxKrnl/HLEDataBase/D3D8.1.0.5558.inl | 2 +- 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/CxbxKrnl/EmuD3D8.cpp b/src/CxbxKrnl/EmuD3D8.cpp index fe8e56c2f..0623a81c0 100644 --- a/src/CxbxKrnl/EmuD3D8.cpp +++ b/src/CxbxKrnl/EmuD3D8.cpp @@ -1817,13 +1817,17 @@ PDWORD WINAPI XTL::EMUPATCH(D3DDevice_BeginPush)(DWORD Count) LOG_FUNC_ONE_ARG(Count); + if (g_pPrimaryPB != nullptr) + { + EmuWarning("D3DDevice_BeginPush called without D3DDevice_EndPush in between?!"); + delete[] g_pPrimaryPB; // prevent a memory leak + } + DWORD *pRet = new DWORD[Count]; g_dwPrimaryPBCount = Count; g_pPrimaryPB = pRet; - - return pRet; } @@ -1840,14 +1844,17 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_EndPush)(DWORD *pPush) // DbgDumpPushBuffer(g_pPrimaryPB, g_dwPrimaryPBCount*sizeof(DWORD)); #endif + if (g_pPrimaryPB == nullptr) + EmuWarning("D3DDevice_EndPush called without preceding D3DDevice_BeginPush?!"); + else + { + EmuUnswizzleTextureStages(); - EmuUnswizzleTextureStages(); + EmuExecutePushBufferRaw(g_pPrimaryPB); - EmuExecutePushBufferRaw(g_pPrimaryPB); - - delete[] g_pPrimaryPB; - - g_pPrimaryPB = 0; + delete[] g_pPrimaryPB; + g_pPrimaryPB = nullptr; + } } // ****************************************************************** @@ -9571,26 +9578,40 @@ HRESULT WINAPI XTL::EMUPATCH(D3D_GetAdapterIdentifier) } #endif +DWORD PushBuffer[64 * 1024 / sizeof(DWORD)]; + // ****************************************************************** // * patch: D3D_MakeRequestedSpace // ****************************************************************** -HRESULT WINAPI XTL::EMUPATCH(D3D_MakeRequestedSpace)( DWORD Unknown1, DWORD Unknown2 ) +PDWORD WINAPI XTL::EMUPATCH(D3D_MakeRequestedSpace) +( + DWORD MinimumSpace, + DWORD RequestedSpace +) { FUNC_EXPORTS LOG_FUNC_BEGIN - LOG_FUNC_ARG(Unknown1) - LOG_FUNC_ARG(Unknown2) + LOG_FUNC_ARG(MinimumSpace) + LOG_FUNC_ARG(RequestedSpace) LOG_FUNC_END; - // NOTE: This function is not meant to me emulated. Just use it to find out - // the function that is calling it, and emulate that instead!!! If necessary, - // create an XRef... - LOG_UNIMPLEMENTED(); + // NOTE: This function is ignored, as we currently don't emulate the push buffer + LOG_IGNORED(); - return S_OK; + return PushBuffer; // Return a buffer that will be filled with GPU commands + + // Note: This should work together with functions like XMETAL_StartPush/ + // D3DDevice_BeginPush(Buffer)/D3DDevice_EndPush(Buffer) and g_pPrimaryPB + + // TODO : Once we start emulating the PushBuffer, this will have to be the + // actual pushbuffer, for which we should let CreateDevice run unpatched. + // Also, we will require a mechanism (thread) which handles the commands + // send to the pushbuffer, emulating them much like EmuExecutePushBufferRaw + // (maybe even use that). } +#if 0 // patch disabled // ****************************************************************** // * patch: D3DDevice_MakeSpace // ****************************************************************** @@ -9605,6 +9626,7 @@ void WINAPI XTL::EMUPATCH(D3DDevice_MakeSpace)() LOG_UNIMPLEMENTED(); } +#endif // ****************************************************************** // * patch: D3D_SetCommonDebugRegisters diff --git a/src/CxbxKrnl/EmuD3D8.h b/src/CxbxKrnl/EmuD3D8.h index 77a45b2bb..d66e4036e 100644 --- a/src/CxbxKrnl/EmuD3D8.h +++ b/src/CxbxKrnl/EmuD3D8.h @@ -1850,7 +1850,11 @@ HRESULT WINAPI EMUPATCH(D3D_GetAdapterIdentifier) // ****************************************************************** // * patch: D3D::MakeRequestedSpace // ****************************************************************** -HRESULT WINAPI EMUPATCH(D3D_MakeRequestedSpace)( DWORD Unknown1, DWORD Unknown2 ); +PDWOR WINAPI EMUPATCH(D3D_MakeRequestedSpace) +( + DWORD MinimumSpace, + DWORD RequestedSpace +); // ****************************************************************** // * patch: D3DDevice_MakeSpace diff --git a/src/CxbxKrnl/HLEDataBase/D3D8.1.0.5558.inl b/src/CxbxKrnl/HLEDataBase/D3D8.1.0.5558.inl index 38545b747..a456cc6ce 100644 --- a/src/CxbxKrnl/HLEDataBase/D3D8.1.0.5558.inl +++ b/src/CxbxKrnl/HLEDataBase/D3D8.1.0.5558.inl @@ -1451,7 +1451,7 @@ OOVPATable D3D8_5558[] = { REGISTER_OOVPA(D3DDevice_SetRenderState_FrontFace, 4134, PATCH), REGISTER_OOVPA(Get2DSurfaceDesc, 5558, PATCH), REGISTER_OOVPA(D3D_MakeRequestedSpace, 5558, PATCH), - REGISTER_OOVPA(D3DDevice_MakeSpace, 5558, PATCH), + REGISTER_OOVPA(D3DDevice_MakeSpace, 5558, DISABLED), REGISTER_OOVPA(D3DDevice_SetRenderTarget, 5558, PATCH), REGISTER_OOVPA(D3DDevice_SetPixelShaderConstant, 5558, PATCH), REGISTER_OOVPA(Lock2DSurface, 3925, PATCH),