16
16
#include < atomic>
17
17
#include < cmath>
18
18
#include < mutex>
19
+ #include < thread>
19
20
#include < game/CSettings.h>
20
21
21
22
class CProxyDirect3DDevice9 ;
@@ -26,24 +27,6 @@ void ApplyBorderlessColorCorrection(CProxyDirect3DDevice9* proxyDevice, const D3
26
27
namespace
27
28
{
28
29
29
- constexpr const char * kSetTextureContexts [] = {
30
- " SetTexture stage 0" ,
31
- " SetTexture stage 1" ,
32
- " SetTexture stage 2" ,
33
- " SetTexture stage 3" ,
34
- " SetTexture stage 4" ,
35
- " SetTexture stage 5" ,
36
- " SetTexture stage 6" ,
37
- " SetTexture stage 7" ,
38
- };
39
-
40
- const char * GetSetTextureContextString (size_t stage)
41
- {
42
- constexpr auto count = std::size (kSetTextureContexts );
43
- if (stage < count)
44
- return kSetTextureContexts [stage];
45
- return " SetTexture" ;
46
- }
47
30
48
31
} // unnamed namespace
49
32
@@ -702,7 +685,7 @@ static bool WaitForGpuIdle(IDirect3DDevice9* pDevice)
702
685
break ;
703
686
}
704
687
705
- Sleep ( 0 );
688
+ std::this_thread::yield ( );
706
689
}
707
690
}
708
691
@@ -841,8 +824,8 @@ HRESULT CProxyDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS* pPresentationParamet
841
824
842
825
HRESULT CProxyDirect3DDevice9::Present (CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion)
843
826
{
844
- // Reset frame stat counters
845
- DeviceState.FrameStats = {} ;
827
+ // Reset frame stat counters - using memset for efficiency
828
+ memset (& DeviceState.FrameStats , 0 , sizeof (DeviceState. FrameStats )) ;
846
829
847
830
bool bDeviceTemporarilyLost = false ;
848
831
HRESULT hrCoopLevel = D3DERR_INVALIDCALL;
@@ -1152,7 +1135,6 @@ HRESULT CProxyDirect3DDevice9::BeginScene()
1152
1135
m_pDevice->SetTextureStageState (0 , D3DTSS_ALPHAOP, D3DTOP_MODULATE);
1153
1136
m_pDevice->SetTextureStageState (0 , D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
1154
1137
m_pDevice->SetTextureStageState (0 , D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
1155
-
1156
1138
m_pDevice->SetTextureStageState (1 , D3DTSS_COLOROP, D3DTOP_DISABLE);
1157
1139
m_pDevice->SetTextureStageState (1 , D3DTSS_ALPHAOP, D3DTOP_DISABLE);
1158
1140
@@ -1243,7 +1225,9 @@ HRESULT CProxyDirect3DDevice9::SetMaterial(CONST D3DMATERIAL9* pMaterial)
1243
1225
return D3DERR_INVALIDCALL;
1244
1226
}
1245
1227
1246
- DeviceState.Material = *pMaterial;
1228
+ // Update cache if material has changed (avoid 68-byte copy)
1229
+ if (memcmp (&DeviceState.Material , pMaterial, sizeof (D3DMATERIAL9)) != 0 )
1230
+ DeviceState.Material = *pMaterial;
1247
1231
return m_pDevice->SetMaterial (pMaterial);
1248
1232
}
1249
1233
@@ -1259,7 +1243,8 @@ HRESULT CProxyDirect3DDevice9::SetLight(DWORD Index, CONST D3DLIGHT9* pLight)
1259
1243
return D3DERR_INVALIDCALL;
1260
1244
}
1261
1245
1262
- if (Index < NUMELMS (DeviceState.Lights ))
1246
+ // Update cache if light has changed (avoid 104-byte copy)
1247
+ if (Index < NUMELMS (DeviceState.Lights ) && memcmp (&DeviceState.Lights [Index], pLight, sizeof (D3DLIGHT9)) != 0 )
1263
1248
DeviceState.Lights [Index] = *pLight;
1264
1249
return m_pDevice->SetLight (Index, pLight);
1265
1250
}
@@ -1293,8 +1278,10 @@ HRESULT CProxyDirect3DDevice9::GetClipPlane(DWORD Index, float* pPlane)
1293
1278
1294
1279
HRESULT CProxyDirect3DDevice9::SetRenderState (D3DRENDERSTATETYPE State, DWORD Value)
1295
1280
{
1281
+ // Update cache for state tracking
1296
1282
if (State < NUMELMS (DeviceState.RenderState .Raw ))
1297
1283
DeviceState.RenderState .Raw [State] = Value;
1284
+
1298
1285
return m_pDevice->SetRenderState (State, Value);
1299
1286
}
1300
1287
@@ -1355,9 +1342,11 @@ HRESULT CProxyDirect3DDevice9::GetTextureStageState(DWORD Stage, D3DTEXTURESTAGE
1355
1342
1356
1343
HRESULT CProxyDirect3DDevice9::SetTextureStageState (DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value)
1357
1344
{
1345
+ // Update cache for state tracking
1358
1346
if (Stage < NUMELMS (DeviceState.StageState ))
1359
1347
if (Type < NUMELMS (DeviceState.StageState [Stage].Raw ))
1360
1348
DeviceState.StageState [Stage].Raw [Type] = Value;
1349
+
1361
1350
return m_pDevice->SetTextureStageState (Stage, Type, Value);
1362
1351
}
1363
1352
@@ -1368,9 +1357,11 @@ HRESULT CProxyDirect3DDevice9::GetSamplerState(DWORD Sampler, D3DSAMPLERSTATETYP
1368
1357
1369
1358
HRESULT CProxyDirect3DDevice9::SetSamplerState (DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD Value)
1370
1359
{
1360
+ // Update cache for state tracking
1371
1361
if (Sampler < NUMELMS (DeviceState.SamplerState ))
1372
1362
if (Type < NUMELMS (DeviceState.SamplerState [Sampler].Raw ))
1373
1363
DeviceState.SamplerState [Sampler].Raw [Type] = Value;
1364
+
1374
1365
return m_pDevice->SetSamplerState (Sampler, Type, Value);
1375
1366
}
1376
1367
0 commit comments