From f6ca2432f648c11b4147cd8a7aa23b043942f487 Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Tue, 11 Jul 2023 21:16:40 +0300 Subject: [PATCH 1/3] [d3d8] Ensure all references are cleared before d3d9 device reset --- src/d3d8/d3d8_device.cpp | 11 ++++++----- src/d3d8/d3d8_device.h | 8 ++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/d3d8/d3d8_device.cpp b/src/d3d8/d3d8_device.cpp index c3ad1396558..ecf50b38a7d 100644 --- a/src/d3d8/d3d8_device.cpp +++ b/src/d3d8/d3d8_device.cpp @@ -53,10 +53,8 @@ namespace dxvk { m_bridge->SetAPIName("D3D8"); - m_textures.fill(nullptr); - m_streams.fill(D3D8VBO()); - ResetState(); + RecreateBackBuffersAndAutoDepthStencil(); if (m_d3d8Options.batching) m_batcher = new D3D8Batcher(this, GetD3D9()); @@ -214,14 +212,16 @@ namespace dxvk { // Resetting implicitly ends scenes started by BeginScene GetD3D9()->EndScene(); + m_presentParams = *pPresentationParameters; + ResetState(); + d3d9::D3DPRESENT_PARAMETERS params = ConvertPresentParameters9(pPresentationParameters); HRESULT res = GetD3D9()->Reset(¶ms); if (FAILED(res)) return res; - m_presentParams = *pPresentationParameters; - ResetState(); + RecreateBackBuffersAndAutoDepthStencil(); return res; } @@ -970,6 +970,7 @@ namespace dxvk { D3D8StateBlock* block = reinterpret_cast(Token); m_stateBlocks.erase(block); + delete block; return D3D_OK; } diff --git a/src/d3d8/d3d8_device.h b/src/d3d8/d3d8_device.h index 33ea2bbc188..1417236380b 100644 --- a/src/d3d8/d3d8_device.h +++ b/src/d3d8/d3d8_device.h @@ -385,13 +385,17 @@ namespace dxvk { m_backBuffers.clear(); m_backBuffers.resize(m_presentParams.BackBufferCount); + + m_autoDepthStencil = nullptr; + } + + inline void RecreateBackBuffersAndAutoDepthStencil() { for (UINT i = 0; i < m_presentParams.BackBufferCount; i++) { Com pSurface9; GetD3D9()->GetBackBuffer(0, i, d3d9::D3DBACKBUFFER_TYPE_MONO, &pSurface9); m_backBuffers[i] = new D3D8Surface(this, std::move(pSurface9)); } - - m_autoDepthStencil = nullptr; + Com pStencil9 = nullptr; GetD3D9()->GetDepthStencilSurface(&pStencil9); m_autoDepthStencil = new D3D8Surface(this, std::move(pStencil9)); From f7fcd209786ab6bda43b2b9aebd9f569cf0580e9 Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Mon, 15 Jan 2024 23:38:12 +0200 Subject: [PATCH 2/3] [d3d8] Remove extra ref on temporary blit surfaces --- src/d3d8/d3d8_surface.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/d3d8/d3d8_surface.cpp b/src/d3d8/d3d8_surface.cpp index b38239143be..8d7c970bbcd 100644 --- a/src/d3d8/d3d8_surface.cpp +++ b/src/d3d8/d3d8_surface.cpp @@ -8,6 +8,8 @@ namespace dxvk { d3d9::D3DSURFACE_DESC desc; GetD3D9()->GetDesc(&desc); + // NOTE: This adds a D3DPOOL_DEFAULT resource to the + // device, which counts as losable during device reset Com image = nullptr; HRESULT res = GetParent()->GetD3D9()->CreateRenderTarget( desc.Width, desc.Height, desc.Format, @@ -19,7 +21,6 @@ namespace dxvk { if (FAILED(res)) throw new DxvkError("D3D8: Failed to create blit image"); - image.ref(); return image; } } \ No newline at end of file From 4e56157e889ccaac11178c57485596b70b3805e6 Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Sun, 16 Jun 2024 13:37:59 +0300 Subject: [PATCH 3/3] [d3d8] Enable D3D8 compatibility for the D3D9 device --- src/d3d8/d3d8_device.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/d3d8/d3d8_device.cpp b/src/d3d8/d3d8_device.cpp index ecf50b38a7d..5a90c4cad7a 100644 --- a/src/d3d8/d3d8_device.cpp +++ b/src/d3d8/d3d8_device.cpp @@ -52,6 +52,7 @@ namespace dxvk { } m_bridge->SetAPIName("D3D8"); + m_bridge->SetD3D8CompatibilityMode(true); ResetState(); RecreateBackBuffersAndAutoDepthStencil();