mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-03 13:24:20 +01:00
[d3d8] Implement monotonic state block tokens
This commit is contained in:
parent
d456d0b437
commit
ff137dac9f
@ -63,11 +63,6 @@ namespace dxvk {
|
|||||||
D3D8Device::~D3D8Device() {
|
D3D8Device::~D3D8Device() {
|
||||||
if (m_batcher)
|
if (m_batcher)
|
||||||
delete m_batcher;
|
delete m_batcher;
|
||||||
|
|
||||||
// Delete any remaining state blocks.
|
|
||||||
for (D3D8StateBlock* block : m_stateBlocks) {
|
|
||||||
delete block;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT STDMETHODCALLTYPE D3D8Device::GetInfo(DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize) {
|
HRESULT STDMETHODCALLTYPE D3D8Device::GetInfo(DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize) {
|
||||||
@ -981,21 +976,37 @@ namespace dxvk {
|
|||||||
Com<d3d9::IDirect3DStateBlock9> pStateBlock9;
|
Com<d3d9::IDirect3DStateBlock9> pStateBlock9;
|
||||||
HRESULT res = GetD3D9()->CreateStateBlock(d3d9::D3DSTATEBLOCKTYPE(Type), &pStateBlock9);
|
HRESULT res = GetD3D9()->CreateStateBlock(d3d9::D3DSTATEBLOCKTYPE(Type), &pStateBlock9);
|
||||||
|
|
||||||
D3D8StateBlock* pStateBlock = new D3D8StateBlock(this, Type, pStateBlock9.ref());
|
m_stateBlocks.emplace(std::piecewise_construct,
|
||||||
m_stateBlocks.insert(pStateBlock);
|
std::forward_as_tuple(m_token),
|
||||||
|
std::forward_as_tuple(this, Type, pStateBlock9.ref()));
|
||||||
*pToken = DWORD(reinterpret_cast<uintptr_t>(pStateBlock));
|
*pToken = m_token;
|
||||||
|
m_token++;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT STDMETHODCALLTYPE D3D8Device::CaptureStateBlock(DWORD Token) {
|
HRESULT STDMETHODCALLTYPE D3D8Device::CaptureStateBlock(DWORD Token) {
|
||||||
return reinterpret_cast<D3D8StateBlock*>(Token)->Capture();
|
auto stateBlockIter = m_stateBlocks.find(Token);
|
||||||
|
|
||||||
|
if (unlikely(stateBlockIter == m_stateBlocks.end())) {
|
||||||
|
Logger::err("Invalid token passed to CaptureStateBlock");
|
||||||
|
return D3DERR_INVALIDCALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return stateBlockIter->second.Capture();
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT STDMETHODCALLTYPE D3D8Device::ApplyStateBlock(DWORD Token) {
|
HRESULT STDMETHODCALLTYPE D3D8Device::ApplyStateBlock(DWORD Token) {
|
||||||
StateChange();
|
StateChange();
|
||||||
return reinterpret_cast<D3D8StateBlock*>(Token)->Apply();
|
|
||||||
|
auto stateBlockIter = m_stateBlocks.find(Token);
|
||||||
|
|
||||||
|
if (unlikely(stateBlockIter == m_stateBlocks.end())) {
|
||||||
|
Logger::err("Invalid token passed to ApplyStateBlock");
|
||||||
|
return D3DERR_INVALIDCALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return stateBlockIter->second.Apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT STDMETHODCALLTYPE D3D8Device::DeleteStateBlock(DWORD Token) {
|
HRESULT STDMETHODCALLTYPE D3D8Device::DeleteStateBlock(DWORD Token) {
|
||||||
@ -1003,9 +1014,14 @@ namespace dxvk {
|
|||||||
if (unlikely(ShouldRecord()))
|
if (unlikely(ShouldRecord()))
|
||||||
return D3DERR_INVALIDCALL;
|
return D3DERR_INVALIDCALL;
|
||||||
|
|
||||||
D3D8StateBlock* block = reinterpret_cast<D3D8StateBlock*>(Token);
|
auto stateBlockIter = m_stateBlocks.find(Token);
|
||||||
m_stateBlocks.erase(block);
|
|
||||||
delete block;
|
if (unlikely(stateBlockIter == m_stateBlocks.end())) {
|
||||||
|
Logger::err("Invalid token passed to DeleteStateBlock");
|
||||||
|
return D3DERR_INVALIDCALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_stateBlocks.erase(stateBlockIter);
|
||||||
|
|
||||||
return D3D_OK;
|
return D3D_OK;
|
||||||
}
|
}
|
||||||
@ -1014,8 +1030,12 @@ namespace dxvk {
|
|||||||
if (unlikely(m_recorder != nullptr))
|
if (unlikely(m_recorder != nullptr))
|
||||||
return D3DERR_INVALIDCALL;
|
return D3DERR_INVALIDCALL;
|
||||||
|
|
||||||
m_recorder = new D3D8StateBlock(this);
|
auto stateBlockIterPair = m_stateBlocks.emplace(std::piecewise_construct,
|
||||||
m_stateBlocks.insert(m_recorder);
|
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();
|
return GetD3D9()->BeginStateBlock();
|
||||||
}
|
}
|
||||||
@ -1029,9 +1049,10 @@ namespace dxvk {
|
|||||||
|
|
||||||
m_recorder->SetD3D9(std::move(pStateBlock));
|
m_recorder->SetD3D9(std::move(pStateBlock));
|
||||||
|
|
||||||
*pToken = DWORD(reinterpret_cast<uintptr_t>(m_recorder));
|
*pToken = m_recorderToken;
|
||||||
|
|
||||||
m_recorder = nullptr;
|
m_recorder = nullptr;
|
||||||
|
m_recorderToken = -1;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <unordered_set>
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace dxvk {
|
namespace dxvk {
|
||||||
|
|
||||||
@ -416,9 +416,11 @@ namespace dxvk {
|
|||||||
|
|
||||||
D3DPRESENT_PARAMETERS m_presentParams;
|
D3DPRESENT_PARAMETERS m_presentParams;
|
||||||
|
|
||||||
D3D8StateBlock* m_recorder = nullptr;
|
D3D8StateBlock* m_recorder = nullptr;
|
||||||
std::unordered_set<D3D8StateBlock*> m_stateBlocks;
|
DWORD m_recorderToken = -1;
|
||||||
D3D8Batcher* m_batcher = nullptr;
|
DWORD m_token = 0;
|
||||||
|
std::unordered_map<DWORD, D3D8StateBlock> m_stateBlocks;
|
||||||
|
D3D8Batcher* m_batcher = nullptr;
|
||||||
|
|
||||||
struct D3D8VBO {
|
struct D3D8VBO {
|
||||||
Com<D3D8VertexBuffer, false> buffer = nullptr;
|
Com<D3D8VertexBuffer, false> buffer = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user