Skip to content

Commit

Permalink
[d3d8] Ensure all references are cleared before d3d9 device reset
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall committed Jul 11, 2023
1 parent 1fba0a2 commit 6d54828
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/d3d8/d3d8_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ namespace dxvk {

m_bridge->SetAPIName("D3D8");

m_textures.fill(nullptr);
m_streams.fill(D3D8VBO());

ResetState();
RegenBackBuffersAndAutoDepthStencil();

if (m_d3d8Options.batching)
m_batcher = new D3D8Batcher(this, GetD3D9());
Expand Down Expand Up @@ -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(&params);

if (FAILED(res))
return res;

m_presentParams = *pPresentationParameters;
ResetState();
RegenBackBuffersAndAutoDepthStencil();

return res;
}
Expand Down Expand Up @@ -970,6 +970,7 @@ namespace dxvk {

D3D8StateBlock* block = reinterpret_cast<D3D8StateBlock*>(Token);
m_stateBlocks.erase(block);
delete block;

return D3D_OK;
}
Expand Down
8 changes: 6 additions & 2 deletions src/d3d8/d3d8_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,17 @@ namespace dxvk {

m_backBuffers.clear();
m_backBuffers.resize(m_presentParams.BackBufferCount);

m_autoDepthStencil = nullptr;
}

inline void RegenBackBuffersAndAutoDepthStencil() {
for (UINT i = 0; i < m_presentParams.BackBufferCount; i++) {
Com<d3d9::IDirect3DSurface9> pSurface9;
GetD3D9()->GetBackBuffer(0, i, d3d9::D3DBACKBUFFER_TYPE_MONO, &pSurface9);
m_backBuffers[i] = new D3D8Surface(this, std::move(pSurface9));
}

m_autoDepthStencil = nullptr;

Com<d3d9::IDirect3DSurface9> pStencil9 = nullptr;
GetD3D9()->GetDepthStencilSurface(&pStencil9);
m_autoDepthStencil = new D3D8Surface(this, std::move(pStencil9));
Expand Down

0 comments on commit 6d54828

Please sign in to comment.