1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-03-15 07:29:17 +01:00

[d3d8] Properly initialize state block data

This commit is contained in:
WinterSnowfall 2025-01-09 03:17:07 +02:00 committed by Philip Rebohle
parent 8ead28e481
commit 84ad2ea261
2 changed files with 110 additions and 93 deletions

View File

@ -1,7 +1,55 @@
#include "d3d8_device.h" #include "d3d8_device.h"
#include "d3d8_state_block.h" #include "d3d8_state_block.h"
HRESULT dxvk::D3D8StateBlock::Capture() { namespace dxvk {
D3D8StateBlock::D3D8StateBlock(
D3D8Device* pDevice,
D3DSTATEBLOCKTYPE Type,
Com<d3d9::IDirect3DStateBlock9>&& pStateBlock)
: m_device(pDevice)
, m_stateBlock(std::move(pStateBlock))
, m_type(Type)
, m_isSWVP(pDevice->GetD3D9()->GetSoftwareVertexProcessing()) {
if (Type == D3DSBT_VERTEXSTATE || Type == D3DSBT_ALL) {
// Lights, D3DTSS_TEXCOORDINDEX and D3DTSS_TEXTURETRANSFORMFLAGS,
// vertex shader, VS constants, and various render states.
m_capture.vs = true;
}
if (Type == D3DSBT_PIXELSTATE || Type == D3DSBT_ALL) {
// Pixel shader, PS constants, and various RS/TSS states.
m_capture.ps = true;
}
if (Type == D3DSBT_ALL) {
m_capture.indices = true;
m_capture.swvp = true;
m_capture.textures.setAll();
m_capture.streams.setAll();
}
m_textures.fill(nullptr);
m_streams.fill(D3D8VBOP());
}
// Construct a state block without a D3D9 object
D3D8StateBlock::D3D8StateBlock(D3D8Device* pDevice)
: D3D8StateBlock(pDevice, D3DSTATEBLOCKTYPE(0), nullptr) {
}
D3D8StateBlock::~D3D8StateBlock() {}
// Attach a D3D9 object to a state block that doesn't have one yet
void D3D8StateBlock::SetD3D9(Com<d3d9::IDirect3DStateBlock9>&& pStateBlock) {
if (likely(m_stateBlock == nullptr)) {
m_stateBlock = std::move(pStateBlock);
} else {
Logger::err("D3D8StateBlock::SetD3D9: m_stateBlock has already been initialized");
}
}
HRESULT D3D8StateBlock::Capture() {
if (unlikely(m_stateBlock == nullptr)) if (unlikely(m_stateBlock == nullptr))
return D3DERR_INVALIDCALL; return D3DERR_INVALIDCALL;
@ -31,7 +79,7 @@ HRESULT dxvk::D3D8StateBlock::Capture() {
return m_stateBlock->Capture(); return m_stateBlock->Capture();
} }
HRESULT dxvk::D3D8StateBlock::Apply() { HRESULT D3D8StateBlock::Apply() {
if (unlikely(m_stateBlock == nullptr)) if (unlikely(m_stateBlock == nullptr))
return D3DERR_INVALIDCALL; return D3DERR_INVALIDCALL;
@ -59,3 +107,5 @@ HRESULT dxvk::D3D8StateBlock::Apply() {
return res; return res;
} }
}

View File

@ -39,47 +39,13 @@ namespace dxvk {
D3D8StateBlock( D3D8StateBlock(
D3D8Device* pDevice, D3D8Device* pDevice,
D3DSTATEBLOCKTYPE Type, D3DSTATEBLOCKTYPE Type,
Com<d3d9::IDirect3DStateBlock9>&& pStateBlock) Com<d3d9::IDirect3DStateBlock9>&& pStateBlock);
: m_device(pDevice)
, m_stateBlock(std::move(pStateBlock))
, m_type(Type) {
if (Type == D3DSBT_VERTEXSTATE || Type == D3DSBT_ALL) {
// Lights, D3DTSS_TEXCOORDINDEX and D3DTSS_TEXTURETRANSFORMFLAGS,
// vertex shader, VS constants, and various render states.
m_capture.vs = true;
}
if (Type == D3DSBT_PIXELSTATE || Type == D3DSBT_ALL) { D3D8StateBlock(D3D8Device* pDevice);
// Pixel shader, PS constants, and various RS/TSS states.
m_capture.ps = true;
}
if (Type == D3DSBT_ALL) { ~D3D8StateBlock();
m_capture.indices = true;
m_capture.swvp = true;
m_capture.textures.setAll();
m_capture.streams.setAll();
}
m_textures.fill(nullptr); void SetD3D9(Com<d3d9::IDirect3DStateBlock9>&& pStateBlock);
m_streams.fill(D3D8VBOP());
}
~D3D8StateBlock() {}
// Construct a state block without a D3D9 object
D3D8StateBlock(D3D8Device* pDevice)
: D3D8StateBlock(pDevice, D3DSTATEBLOCKTYPE(0), nullptr) {
}
// Attach a D3D9 object to a state block that doesn't have one yet
void SetD3D9(Com<d3d9::IDirect3DStateBlock9>&& pStateBlock) {
if (likely(m_stateBlock == nullptr)) {
m_stateBlock = std::move(pStateBlock);
} else {
Logger::err("D3D8StateBlock::SetD3D9: m_stateBlock has already been initialized");
}
}
HRESULT Capture(); HRESULT Capture();
@ -126,6 +92,7 @@ namespace dxvk {
} }
private: private:
D3D8Device* m_device; D3D8Device* m_device;
Com<d3d9::IDirect3DStateBlock9> m_stateBlock; Com<d3d9::IDirect3DStateBlock9> m_stateBlock;
D3DSTATEBLOCKTYPE m_type; D3DSTATEBLOCKTYPE m_type;
@ -135,21 +102,21 @@ namespace dxvk {
UINT stride = 0; UINT stride = 0;
}; };
private: // State Data // // State Data //
D3D8StateCapture m_capture; D3D8StateCapture m_capture;
DWORD m_vertexShader; // vs DWORD m_vertexShader = 0;
DWORD m_pixelShader; // ps DWORD m_pixelShader = 0;
std::array<IDirect3DBaseTexture8*, d8caps::MAX_TEXTURE_STAGES> m_textures; // textures std::array<IDirect3DBaseTexture8*, d8caps::MAX_TEXTURE_STAGES> m_textures;
std::array<D3D8VBOP, d8caps::MAX_STREAMS> m_streams; // stream data std::array<D3D8VBOP, d8caps::MAX_STREAMS> m_streams;
IDirect3DIndexBuffer8* m_indices = nullptr; // indices IDirect3DIndexBuffer8* m_indices = nullptr;
UINT m_baseVertexIndex; // indices UINT m_baseVertexIndex = 0;
bool m_isSWVP; // D3DRS_SOFTWAREVERTEXPROCESSING bool m_isSWVP; // D3DRS_SOFTWAREVERTEXPROCESSING
}; };
} }