Skip to content

Commit

Permalink
[d3d8] Clean up D3D9 shaders on D3D8 device release
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall committed Sep 17, 2024
1 parent 010738c commit 471aaac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
33 changes: 14 additions & 19 deletions src/d3d8/d3d8_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ namespace dxvk {
}

struct D3D8VertexShaderInfo {
d3d9::IDirect3DVertexDeclaration9* pVertexDecl = nullptr;
d3d9::IDirect3DVertexShader9* pVertexShader = nullptr;
std::vector<DWORD> declaration;
std::vector<DWORD> function;
Com<d3d9::IDirect3DVertexDeclaration9> pVertexDecl;
Com<d3d9::IDirect3DVertexShader9> pVertexShader;
std::vector<DWORD> declaration;
std::vector<DWORD> function;
};

D3D8Device::D3D8Device(
Expand Down Expand Up @@ -72,7 +72,7 @@ namespace dxvk {
return D3DERR_INVALIDCALL;

HRESULT res;
d3d9::IDirect3DQuery9* pQuery = nullptr;
Com<d3d9::IDirect3DQuery9> pQuery;

switch (DevInfoID) {
// pre-D3D8 queries
Expand Down Expand Up @@ -133,19 +133,16 @@ namespace dxvk {
res = pQuery->GetData(pDevInfoStruct, DevInfoStructSize, D3DGETDATA_FLUSH);

done:
if (pQuery != nullptr)
pQuery->Release();

if (unlikely(FAILED(res))) {
if (res == D3DERR_NOTAVAILABLE) // unsupported
return E_FAIL;
else // any unknown error
return S_FALSE;
}

return res;
}


HRESULT STDMETHODCALLTYPE D3D8Device::TestCooperativeLevel() {
// Equivalent of D3D11/DXGI present tests.
return GetD3D9()->TestCooperativeLevel();
Expand Down Expand Up @@ -1609,7 +1606,7 @@ namespace dxvk {

D3D8VertexShaderInfo& info = device->m_vertexShaders[Handle];

if (unlikely(!info.pVertexDecl && !info.pVertexShader)) {
if (unlikely(info.pVertexDecl == nullptr && info.pVertexShader == nullptr)) {
Logger::debug(str::format("getVertexShaderInfo: Application provided deleted vertex shader ", std::hex, Handle));
return nullptr;
}
Expand All @@ -1634,8 +1631,8 @@ namespace dxvk {

StateChange();

GetD3D9()->SetVertexDeclaration(info->pVertexDecl);
res = GetD3D9()->SetVertexShader(info->pVertexShader);
GetD3D9()->SetVertexDeclaration(info->pVertexDecl.ptr());
res = GetD3D9()->SetVertexShader(info->pVertexShader.ptr());

if (likely(SUCCEEDED(res))) {
// Cache current shader
Expand Down Expand Up @@ -1701,10 +1698,10 @@ namespace dxvk {
if (!info)
return D3DERR_INVALIDCALL;

if (info->pVertexDecl)
info->pVertexDecl->Release();
if (info->pVertexShader)
info->pVertexShader->Release();
if (info->pVertexDecl != nullptr)
info->pVertexDecl = nullptr;
if (info->pVertexShader != nullptr)
info->pVertexShader = nullptr;

info->declaration.clear();
info->function.clear();
Expand Down Expand Up @@ -1795,7 +1792,7 @@ namespace dxvk {
return nullptr;
}

d3d9::IDirect3DPixelShader9* pPixelShader = device->m_pixelShaders[Handle];
d3d9::IDirect3DPixelShader9* pPixelShader = device->m_pixelShaders[Handle].ptr();

if (unlikely(pPixelShader == nullptr)) {
Logger::debug(str::format("getPixelShaderPtr: Application provided deleted pixel shader ", std::hex, Handle));
Expand Down Expand Up @@ -1850,8 +1847,6 @@ namespace dxvk {
return D3DERR_INVALIDCALL;
}

pPixelShader->Release();

m_pixelShaders[getShaderIndex(Handle)] = nullptr;

return D3D_OK;
Expand Down
8 changes: 4 additions & 4 deletions src/d3d8/d3d8_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ namespace dxvk {
Com<D3D8Surface, false> m_renderTarget;
Com<D3D8Surface, false> m_depthStencil;

std::vector<D3D8VertexShaderInfo> m_vertexShaders;
std::vector<d3d9::IDirect3DPixelShader9*> m_pixelShaders;
DWORD m_currentVertexShader = 0; // can be FVF or vs index (marked by D3DFVF_RESERVED0)
DWORD m_currentPixelShader = 0;
std::vector<D3D8VertexShaderInfo> m_vertexShaders;
std::vector<Com<d3d9::IDirect3DPixelShader9>> m_pixelShaders;
DWORD m_currentVertexShader = 0; // can be FVF or vs index (marked by D3DFVF_RESERVED0)
DWORD m_currentPixelShader = 0;

D3DDEVTYPE m_deviceType;
HWND m_window;
Expand Down

0 comments on commit 471aaac

Please sign in to comment.