Skip to content

Commit

Permalink
[d3d9] Add a device compatibility mode for d3d8
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall authored and misyltoad committed Sep 19, 2023
1 parent 83dc467 commit 0632da1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/d3d9/d3d9_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -104,4 +108,4 @@ namespace dxvk {
const Config* DxvkD3D8InterfaceBridge::GetConfig() const {
return &m_interface->GetInstance()->config();
}
}
}
8 changes: 8 additions & 0 deletions src/d3d9/d3d9_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -83,6 +90,7 @@ namespace dxvk {
void** ppvObject);

void SetAPIName(const char* name);
void SetD3D8CompatibilityMode(const bool compatMode);

HRESULT UpdateTextureFromBuffer(
IDirect3DSurface9* pDestSurface,
Expand Down
6 changes: 4 additions & 2 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2360,7 +2360,8 @@ namespace dxvk {
try {
const Com<D3D9StateBlock> sb = new D3D9StateBlock(this, ConvertStateBlockType(Type));
*ppSB = sb.ref();
m_losableResourceCounter++;
if (!m_isD3D8Compatible)
m_losableResourceCounter++;

return D3D_OK;
}
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 15 additions & 3 deletions src/d3d9/d3d9_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
5 changes: 3 additions & 2 deletions src/d3d9/d3d9_stateblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ namespace dxvk {
}

D3D9StateBlock::~D3D9StateBlock() {
m_parent->DecrementLosableCounter();
if (!m_parent->IsD3D8Compatible())
m_parent->DecrementLosableCounter();
}

HRESULT STDMETHODCALLTYPE D3D9StateBlock::QueryInterface(
Expand Down Expand Up @@ -575,4 +576,4 @@ namespace dxvk {
this->Capture();
}

}
}

0 comments on commit 0632da1

Please sign in to comment.