Skip to content

Commit 84f5aaa

Browse files
Synchronize changes from 1.6 branch [ci skip]
b237964 D3D fix-ups #5 (Performance)
2 parents 28f018e + b237964 commit 84f5aaa

File tree

5 files changed

+30
-45
lines changed

5 files changed

+30
-45
lines changed

Client/core/DXHook/CDirect3DData.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,3 @@ void CDirect3DData::StoreViewport(DWORD dwX, DWORD dwY, DWORD dwWidth, DWORD dwH
103103
m_dwViewportWidth = dwWidth;
104104
m_dwViewportHeight = dwHeight;
105105
}
106-
107-
DWORD CDirect3DData::GetViewportX()
108-
{
109-
return m_dwViewportX;
110-
}
111-
112-
DWORD CDirect3DData::GetViewportY()
113-
{
114-
return m_dwViewportY;
115-
}
116-
117-
DWORD CDirect3DData::GetViewportWidth()
118-
{
119-
return m_dwViewportWidth;
120-
}
121-
122-
DWORD CDirect3DData::GetViewportHeight()
123-
{
124-
return m_dwViewportHeight;
125-
}

Client/core/DXHook/CDirect3DData.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class CDirect3DData : public CSingleton<CDirect3DData>
2929

3030
void StoreViewport(DWORD dwX, DWORD dwY, DWORD dwWidth, DWORD dwHeight);
3131

32-
DWORD GetViewportX();
33-
DWORD GetViewportY();
34-
DWORD GetViewportWidth();
35-
DWORD GetViewportHeight();
32+
DWORD GetViewportX() { return m_dwViewportX; }
33+
DWORD GetViewportY() { return m_dwViewportY; }
34+
DWORD GetViewportWidth() { return m_dwViewportWidth; }
35+
DWORD GetViewportHeight() { return m_dwViewportHeight; }
3636

3737
private:
3838
D3DMATRIX m_mViewMatrix;

Client/core/DXHook/CProxyDirect3D9.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -860,17 +860,15 @@ void AddCapsReport(UINT Adapter, IDirect3D9* pDirect3D, IDirect3DDevice9* pD3DDe
860860
if (pDirect3DOther)
861861
{
862862
// Log graphic card name
863-
D3DADAPTER_IDENTIFIER9 AdapterIdent1;
864-
ZeroMemory(&AdapterIdent1, sizeof(AdapterIdent1));
863+
D3DADAPTER_IDENTIFIER9 AdapterIdent1{};
865864
hr = pDirect3D->GetAdapterIdentifier(Adapter, 0, &AdapterIdent1);
866865
if (FAILED(hr))
867866
WriteDebugEvent(SString("Warning: pDirect3D->GetAdapterIdentifier failed: %08x", hr));
868867
WriteDebugEvent("pDirect3D:");
869868
WriteDebugEvent(ToString(AdapterIdent1));
870869

871870
// Log graphic card name
872-
D3DADAPTER_IDENTIFIER9 AdapterIdent2;
873-
ZeroMemory(&AdapterIdent2, sizeof(AdapterIdent2));
871+
D3DADAPTER_IDENTIFIER9 AdapterIdent2{};
874872
hr = pDirect3DOther->GetAdapterIdentifier(Adapter, 0, &AdapterIdent2);
875873
if (FAILED(hr))
876874
WriteDebugEvent(SString("Warning: pDirect3DOther->GetAdapterIdentifier failed: %08x", hr));
@@ -968,7 +966,7 @@ void AddCapsReport(UINT Adapter, IDirect3D9* pDirect3D, IDirect3DDevice9* pD3DDe
968966
else
969967
{
970968
WriteDebugEvent("Fixing GTA caps");
971-
memcpy(pGTACaps9, &DeviceCaps9, sizeof(D3DCAPS9));
969+
*pGTACaps9 = DeviceCaps9;
972970
}
973971
}
974972
}
@@ -1029,8 +1027,7 @@ HRESULT HandleCreateDeviceResult(HRESULT hResult, IDirect3D9* pDirect3D, UINT Ad
10291027
D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface)
10301028
{
10311029
// Log graphic card name
1032-
D3DADAPTER_IDENTIFIER9 AdapterIdent;
1033-
ZeroMemory(&AdapterIdent, sizeof(AdapterIdent));
1030+
D3DADAPTER_IDENTIFIER9 AdapterIdent{};
10341031
HRESULT hr = pDirect3D->GetAdapterIdentifier(Adapter, 0, &AdapterIdent);
10351032
if (FAILED(hr))
10361033
WriteDebugEvent(SString("Warning: GetAdapterIdentifier failed: %08x", hr));
@@ -1345,8 +1342,7 @@ HRESULT CCore::OnPostCreateDevice(HRESULT hResult, IDirect3D9* pDirect3D, UINT A
13451342
#endif
13461343

13471344
// Log graphic card name
1348-
D3DADAPTER_IDENTIFIER9 AdapterIdent;
1349-
ZeroMemory(&AdapterIdent, sizeof(AdapterIdent));
1345+
D3DADAPTER_IDENTIFIER9 AdapterIdent{};
13501346
HRESULT hr = pDirect3D->GetAdapterIdentifier(Adapter, 0, &AdapterIdent);
13511347
if (FAILED(hr))
13521348
WriteDebugEvent(SString("Warning: GetAdapterIdentifier failed: %08x", hr));

Client/core/DXHook/CProxyDirect3DDevice9.cpp

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ void RefreshCacheIfNeeded()
100100
const CClientVariables* currentSource = cvars;
101101
const int currentRevision = cvars ? cvars->GetRevision() : -1;
102102

103-
const CClientVariables* cachedSource = g_cachedSettings.source.load(std::memory_order_acquire);
104-
const int cachedRevision = g_cachedSettings.revision.load(std::memory_order_acquire);
103+
const CClientVariables* cachedSource = g_cachedSettings.source.load(std::memory_order_relaxed);
104+
const int cachedRevision = g_cachedSettings.revision.load(std::memory_order_relaxed);
105105

106106
if (cachedSource == currentSource && cachedRevision == currentRevision)
107107
return;
@@ -433,7 +433,7 @@ CProxyDirect3DDevice9::~CProxyDirect3DDevice9()
433433

434434
g_GammaState.bOriginalGammaStored = false;
435435
g_GammaState.bLastWasBorderless = false;
436-
ZeroMemory(&g_GammaState.originalGammaRamp, sizeof(g_GammaState.originalGammaRamp));
436+
g_GammaState.originalGammaRamp = {};
437437
}
438438
}
439439

@@ -1341,8 +1341,8 @@ HRESULT CProxyDirect3DDevice9::SetTexture(DWORD Stage, IDirect3DBaseTexture9* pT
13411341
// Fast-path: avoid AddRef/Release if texture hasn't changed
13421342
if (DeviceState.TextureState[Stage].Texture != pTexture)
13431343
{
1344-
const char* context = GetSetTextureContextString(Stage);
1345-
ReplaceInterface(DeviceState.TextureState[Stage].Texture, pTexture, context);
1344+
// Hot path: use non-validating ReplaceInterface since textures come from D3D9 driver
1345+
ReplaceInterface(DeviceState.TextureState[Stage].Texture, pTexture);
13461346
}
13471347
}
13481348
return m_pDevice->SetTexture(Stage, CDirect3DEvents9::GetRealTexture(pTexture));
@@ -1475,7 +1475,9 @@ HRESULT CProxyDirect3DDevice9::CreateVertexDeclaration(CONST D3DVERTEXELEMENT9*
14751475

14761476
HRESULT CProxyDirect3DDevice9::SetVertexDeclaration(IDirect3DVertexDeclaration9* pDecl)
14771477
{
1478-
ReplaceInterface(DeviceState.VertexDeclaration, pDecl);
1478+
// Avoid validation overhead since declarations come from D3D9 driver
1479+
if (DeviceState.VertexDeclaration != pDecl)
1480+
ReplaceInterface(DeviceState.VertexDeclaration, pDecl);
14791481
return CDirect3DEvents9::SetVertexDeclaration(m_pDevice, pDecl);
14801482
}
14811483

@@ -1501,7 +1503,9 @@ HRESULT CProxyDirect3DDevice9::CreateVertexShader(CONST DWORD* pFunction, IDirec
15011503

15021504
HRESULT CProxyDirect3DDevice9::SetVertexShader(IDirect3DVertexShader9* pShader)
15031505
{
1504-
ReplaceInterface(DeviceState.VertexShader, pShader);
1506+
// Avoid validation overhead since shaders come from D3D9 driver
1507+
if (DeviceState.VertexShader != pShader)
1508+
ReplaceInterface(DeviceState.VertexShader, pShader);
15051509
return m_pDevice->SetVertexShader(pShader);
15061510
}
15071511

@@ -1544,7 +1548,9 @@ HRESULT CProxyDirect3DDevice9::SetStreamSource(UINT StreamNumber, IDirect3DVerte
15441548
{
15451549
if (StreamNumber < NUMELMS(DeviceState.VertexStreams))
15461550
{
1547-
ReplaceInterface(DeviceState.VertexStreams[StreamNumber].StreamData, pStreamData);
1551+
// Avoid validation overhead since vertex buffers come from D3D9 driver
1552+
if (DeviceState.VertexStreams[StreamNumber].StreamData != pStreamData)
1553+
ReplaceInterface(DeviceState.VertexStreams[StreamNumber].StreamData, pStreamData);
15481554
DeviceState.VertexStreams[StreamNumber].StreamOffset = OffsetInBytes;
15491555
DeviceState.VertexStreams[StreamNumber].StreamStride = Stride;
15501556
}
@@ -1568,7 +1574,9 @@ HRESULT CProxyDirect3DDevice9::GetStreamSourceFreq(UINT StreamNumber, UINT* pSet
15681574

15691575
HRESULT CProxyDirect3DDevice9::SetIndices(IDirect3DIndexBuffer9* pIndexData)
15701576
{
1571-
ReplaceInterface(DeviceState.IndexBufferData, pIndexData);
1577+
// Avoid validation overhead since index buffers come from D3D9 driver
1578+
if (DeviceState.IndexBufferData != pIndexData)
1579+
ReplaceInterface(DeviceState.IndexBufferData, pIndexData);
15721580
return m_pDevice->SetIndices(CDirect3DEvents9::GetRealIndexBuffer(pIndexData));
15731581
}
15741582

@@ -1584,7 +1592,9 @@ HRESULT CProxyDirect3DDevice9::CreatePixelShader(CONST DWORD* pFunction, IDirect
15841592

15851593
HRESULT CProxyDirect3DDevice9::SetPixelShader(IDirect3DPixelShader9* pShader)
15861594
{
1587-
ReplaceInterface(DeviceState.PixelShader, pShader);
1595+
// Avoid validation overhead since shaders come from D3D9 driver
1596+
if (DeviceState.PixelShader != pShader)
1597+
ReplaceInterface(DeviceState.PixelShader, pShader);
15881598
return m_pDevice->SetPixelShader(pShader);
15891599
}
15901600

Client/core/DXHook/CProxyDirect3DDevice9.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,8 @@ struct SGammaState
604604
D3DGAMMARAMP originalGammaRamp;
605605
UINT lastSwapChain;
606606

607-
SGammaState() : bOriginalGammaStored(false), bLastWasBorderless(false), lastSwapChain(0)
607+
SGammaState() : bOriginalGammaStored(false), bLastWasBorderless(false), originalGammaRamp{}, lastSwapChain(0)
608608
{
609-
ZeroMemory(&originalGammaRamp, sizeof(originalGammaRamp));
610609
}
611610
};
612611

0 commit comments

Comments
 (0)