From 74333af9c0e858807acafeb0a5e7cc4f93ff9f6e Mon Sep 17 00:00:00 2001 From: Silent Date: Tue, 17 Nov 2020 20:33:34 +0100 Subject: [PATCH 1/2] Remove hacks skipping guest resource removal if they are bound Fixes games running out of guest memory: - Outrun 2 - Monster Garage - probably many more Removes "Skipping Release of..." test cases --- src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 60 +++++------------------ 1 file changed, 12 insertions(+), 48 deletions(-) diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index d05a9f3d0..a34f0af79 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -8732,44 +8732,6 @@ __declspec(naked) void WINAPI xbox::EMUPATCH(D3D_BlockOnTime_4)( dword_xt Unknow } } - -bool DestroyResource_Common(xbox::X_D3DResource* pResource) -{ - if (pResource == g_pXbox_RenderTarget) { - LOG_TEST_CASE("Skipping Release of active Xbox Render Target"); - return false; - } - - if (pResource == g_pXbox_DepthStencil) { - LOG_TEST_CASE("Skipping Release of active Xbox Depth Stencil"); - return false; - } - - if (pResource == g_pXbox_BackBufferSurface) { - LOG_TEST_CASE("Skipping Release of active Xbox BackBuffer"); - return false; - } - - if (pResource == g_pXbox_DefaultDepthStencilSurface) { - LOG_TEST_CASE("Skipping Release of default Xbox Depth Stencil"); - return false; - } - - for (int i = 0; i < xbox::X_D3DTS_STAGECOUNT; i++) { - if (pResource == g_pXbox_SetTexture[i]) { - // This shouldn't happen, since texture resources that get destroyed, - // shouldn't be set to any stage anymore. - LOG_TEST_CASE("Skipping Release of active Xbox Texture"); - return false; - } - } - - // Release the host copy (if it exists!) - FreeHostResource(GetHostResourceKey(pResource)); - - return true; -} - // ****************************************************************** // * patch: D3D_DestroyResource // ****************************************************************** @@ -8777,10 +8739,11 @@ void WINAPI xbox::EMUPATCH(D3D_DestroyResource)(X_D3DResource* pResource) { LOG_FUNC_ONE_ARG(pResource); - if (DestroyResource_Common(pResource)) { - // Call the Xbox version of DestroyResource - XB_TRMP(D3D_DestroyResource)(pResource); - } + // Release the host copy (if it exists!) + FreeHostResource(GetHostResourceKey(pResource)); + + // Call the Xbox version of DestroyResource + XB_TRMP(D3D_DestroyResource)(pResource); } // ****************************************************************** @@ -8793,12 +8756,13 @@ void WINAPI xbox::EMUPATCH(D3D_DestroyResource__LTCG)() mov pResource, edi } - if (DestroyResource_Common(pResource)) { - // Call the Xbox version of DestroyResource - __asm { - mov edi, pResource - call XB_TRMP(D3D_DestroyResource__LTCG) - } + // Release the host copy (if it exists!) + FreeHostResource(GetHostResourceKey(pResource)); + + // Call the Xbox version of DestroyResource + __asm { + mov edi, pResource + call XB_TRMP(D3D_DestroyResource__LTCG) } } From 43eefa8041ee3b88e329142418fe21d8d79176c8 Mon Sep 17 00:00:00 2001 From: Silent Date: Tue, 17 Nov 2020 20:44:26 +0100 Subject: [PATCH 2/2] Improve the D3D_DestroyResource__LTCG patch EDI register is unlikely to be trashed, but use a naked function anyway Added logging, same as the non-LTCG DestroyResource --- src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index a34f0af79..2510ec13d 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -8749,20 +8749,34 @@ void WINAPI xbox::EMUPATCH(D3D_DestroyResource)(X_D3DResource* pResource) // ****************************************************************** // * patch: D3D_DestroyResource_LTCG // ****************************************************************** -void WINAPI xbox::EMUPATCH(D3D_DestroyResource__LTCG)() +static void D3D_DestroyResource__LTCG(xbox::X_D3DResource* pResource) +{ + LOG_FUNC_ONE_ARG(pResource); +} + +__declspec(naked) void WINAPI xbox::EMUPATCH(D3D_DestroyResource__LTCG)() { X_D3DResource* pResource; __asm { - mov pResource, edi + push ebp + mov ebp, esp + sub esp, __LOCAL_SIZE + mov pResource, edi } + // Log + D3D_DestroyResource__LTCG(pResource); + // Release the host copy (if it exists!) FreeHostResource(GetHostResourceKey(pResource)); // Call the Xbox version of DestroyResource __asm { - mov edi, pResource + mov edi, pResource call XB_TRMP(D3D_DestroyResource__LTCG) + mov esp, ebp + pop ebp + ret } }