From d731608d5ec3e1db8c46efd66cd6250dfacebd87 Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Wed, 10 Jul 2024 00:51:46 +0300 Subject: [PATCH] [d3d8] Mimic native token allocations --- src/d3d8/d3d8_device.cpp | 12 +++++++++--- src/d3d8/d3d8_device.h | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/d3d8/d3d8_device.cpp b/src/d3d8/d3d8_device.cpp index b1de9a8e9..86ca46bbf 100644 --- a/src/d3d8/d3d8_device.cpp +++ b/src/d3d8/d3d8_device.cpp @@ -976,11 +976,11 @@ namespace dxvk { Com pStateBlock9; HRESULT res = GetD3D9()->CreateStateBlock(d3d9::D3DSTATEBLOCKTYPE(Type), &pStateBlock9); + m_token++; m_stateBlocks.emplace(std::piecewise_construct, std::forward_as_tuple(m_token), std::forward_as_tuple(this, Type, pStateBlock9.ref())); *pToken = m_token; - m_token++; return res; } @@ -1023,6 +1023,12 @@ namespace dxvk { m_stateBlocks.erase(stateBlockIter); + // native apparently does drop the token counter in + // situations where the token being removed is the + // last allocated token, which allows some reuse + if (m_token == Token) + m_token--; + return D3D_OK; } @@ -1030,12 +1036,12 @@ namespace dxvk { if (unlikely(m_recorder != nullptr)) return D3DERR_INVALIDCALL; + m_token++; auto stateBlockIterPair = m_stateBlocks.emplace(std::piecewise_construct, std::forward_as_tuple(m_token), std::forward_as_tuple(this)); m_recorder = &stateBlockIterPair.first->second; m_recorderToken = m_token; - m_token++; return GetD3D9()->BeginStateBlock(); } @@ -1052,7 +1058,7 @@ namespace dxvk { *pToken = m_recorderToken; m_recorder = nullptr; - m_recorderToken = -1; + m_recorderToken = 0; return res; } diff --git a/src/d3d8/d3d8_device.h b/src/d3d8/d3d8_device.h index 2e11f5f7d..eb46b8dfc 100644 --- a/src/d3d8/d3d8_device.h +++ b/src/d3d8/d3d8_device.h @@ -417,7 +417,7 @@ namespace dxvk { D3DPRESENT_PARAMETERS m_presentParams; D3D8StateBlock* m_recorder = nullptr; - DWORD m_recorderToken = -1; + DWORD m_recorderToken = 0; DWORD m_token = 0; std::unordered_map m_stateBlocks; D3D8Batcher* m_batcher = nullptr;