From 0632da19357fb3d846ea36ef07166eb93b09173a Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Tue, 19 Sep 2023 17:54:03 +0300 Subject: [d3d9] Add a device compatibility mode for d3d8 --- src/d3d9/d3d9_bridge.cpp | 6 +++++- src/d3d9/d3d9_bridge.h | 8 ++++++++ src/d3d9/d3d9_device.cpp | 6 ++++-- src/d3d9/d3d9_device.h | 18 +++++++++++++++--- src/d3d9/d3d9_stateblock.cpp | 5 +++-- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/d3d9/d3d9_bridge.cpp b/src/d3d9/d3d9_bridge.cpp index 88448ba9..6bb4801a 100644 --- a/src/d3d9/d3d9_bridge.cpp +++ b/src/d3d9/d3d9_bridge.cpp @@ -32,6 +32,10 @@ namespace dxvk { m_device->m_implicitSwapchain->SetApiName(name); } + void DxvkD3D8Bridge::SetD3D8CompatibilityMode(const bool compatMode) { + m_device->SetD3D8CompatibilityMode(compatMode); + } + HRESULT DxvkD3D8Bridge::UpdateTextureFromBuffer( IDirect3DSurface9* pDestSurface, IDirect3DSurface9* pSrcSurface, @@ -104,4 +108,4 @@ namespace dxvk { const Config* DxvkD3D8InterfaceBridge::GetConfig() const { return &m_interface->GetInstance()->config(); } -} \ No newline at end of file +} diff --git a/src/d3d9/d3d9_bridge.h b/src/d3d9/d3d9_bridge.h index f1c12104..163d4130 100644 --- a/src/d3d9/d3d9_bridge.h +++ b/src/d3d9/d3d9_bridge.h @@ -30,6 +30,13 @@ IDxvkD3D8Bridge : public IUnknown { */ virtual void SetAPIName(const char* name) = 0; + /** + * \brief Enables or disables D3D9-specific device features and validations + * + * \param [in] compatibility state + */ + virtual void SetD3D8CompatibilityMode(const bool compatMode) = 0; + /** * \brief Updates a D3D9 surface from a D3D9 buffer * @@ -83,6 +90,7 @@ namespace dxvk { void** ppvObject); void SetAPIName(const char* name); + void SetD3D8CompatibilityMode(const bool compatMode); HRESULT UpdateTextureFromBuffer( IDirect3DSurface9* pDestSurface, diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 7c14efa1..a2f6e9c3 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -2360,7 +2360,8 @@ namespace dxvk { try { const Com sb = new D3D9StateBlock(this, ConvertStateBlockType(Type)); *ppSB = sb.ref(); - m_losableResourceCounter++; + if (!m_isD3D8Compatible) + m_losableResourceCounter++; return D3D_OK; } @@ -2392,7 +2393,8 @@ namespace dxvk { return D3DERR_INVALIDCALL; *ppSB = m_recorder.ref(); - m_losableResourceCounter++; + if (!m_isD3D8Compatible) + m_losableResourceCounter++; m_recorder = nullptr; return D3D_OK; diff --git a/src/d3d9/d3d9_device.h b/src/d3d9/d3d9_device.h index 8b979106..b4a29285 100644 --- a/src/d3d9/d3d9_device.h +++ b/src/d3d9/d3d9_device.h @@ -970,6 +970,17 @@ namespace dxvk { void TouchMappedTexture(D3D9CommonTexture* pTexture); void RemoveMappedTexture(D3D9CommonTexture* pTexture); + bool IsD3D8Compatible() const { + return m_isD3D8Compatible; + } + + void SetD3D8CompatibilityMode(bool compatMode) { + if (compatMode) + Logger::info("The D3D9 device is now operating in D3D8 compatibility mode."); + + m_isD3D8Compatible = compatMode; + } + // Device Lost bool IsDeviceLost() const { return m_deviceLostState != D3D9DeviceLostState::Ok; @@ -1318,9 +1329,10 @@ namespace dxvk { D3D9ShaderMasks m_psShaderMasks = FixedFunctionMask; bool m_isSWVP; - bool m_amdATOC = false; - bool m_nvATOC = false; - bool m_ffZTest = false; + bool m_isD3D8Compatible = false; + bool m_amdATOC = false; + bool m_nvATOC = false; + bool m_ffZTest = false; VkImageLayout m_hazardLayout = VK_IMAGE_LAYOUT_GENERAL; diff --git a/src/d3d9/d3d9_stateblock.cpp b/src/d3d9/d3d9_stateblock.cpp index 9bb7181b..0d5bacd9 100644 --- a/src/d3d9/d3d9_stateblock.cpp +++ b/src/d3d9/d3d9_stateblock.cpp @@ -18,7 +18,8 @@ namespace dxvk { } D3D9StateBlock::~D3D9StateBlock() { - m_parent->DecrementLosableCounter(); + if (!m_parent->IsD3D8Compatible()) + m_parent->DecrementLosableCounter(); } HRESULT STDMETHODCALLTYPE D3D9StateBlock::QueryInterface( @@ -575,4 +576,4 @@ namespace dxvk { this->Capture(); } -} \ No newline at end of file +} -- cgit v1.2.3