Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 97ecf73

Browse files
committed
Merge branch 'dev/adunn/shadow_state_tracking' into 'main'
CPU Perf: Implement shadow state elimination on D3D9 client for some common functions See merge request lightspeedrtx/bridge-remix-nv!96
2 parents ac83cd0 + 3289c55 commit 97ecf73

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/client/d3d9_device.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,9 +1196,15 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::SetTransform(D3DTRANSFORMSTATETYPE St
11961196
{
11971197
BRIDGE_DEVICE_LOCKGUARD();
11981198
if (m_stateRecording) {
1199+
if (memcmp(&m_stateRecording->m_captureState.transforms[idx], pMatrix, sizeof(D3DMATRIX)) == 0) {
1200+
return S_OK;
1201+
}
11991202
m_stateRecording->m_captureState.transforms[idx] = *pMatrix;
12001203
m_stateRecording->m_dirtyFlags.transforms[idx] = true;
12011204
} else {
1205+
if (memcmp(&m_state.transforms[idx], pMatrix, sizeof(D3DMATRIX)) == 0) {
1206+
return S_OK;
1207+
}
12021208
m_state.transforms[idx] = *pMatrix;
12031209
}
12041210
}
@@ -1367,9 +1373,15 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::SetLight(DWORD Index, CONST D3DLIGHT9
13671373
{
13681374
BRIDGE_DEVICE_LOCKGUARD();
13691375
if (m_stateRecording) {
1376+
if (memcmp(&m_stateRecording->m_captureState.lights[Index], pLight, sizeof(D3DLIGHT9)) == 0) {
1377+
return S_OK;
1378+
}
13701379
m_stateRecording->m_captureState.lights[Index] = *pLight;
13711380
m_stateRecording->m_dirtyFlags.lights[Index] = true;
13721381
} else {
1382+
if (memcmp(&m_state.lights[Index], pLight, sizeof(D3DLIGHT9)) == 0) {
1383+
return S_OK;
1384+
}
13731385
m_state.lights[Index] = *pLight;
13741386
}
13751387
}
@@ -1409,8 +1421,14 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::LightEnable(DWORD LightIndex, BOOL bE
14091421
{
14101422
BRIDGE_DEVICE_LOCKGUARD();
14111423
if (m_stateRecording) {
1424+
if (m_stateRecording->m_captureState.bLightEnables[LightIndex] == (bool)bEnable) {
1425+
return S_OK;
1426+
}
14121427
m_stateRecording->m_captureState.bLightEnables[LightIndex] = bEnable;
14131428
} else {
1429+
if (m_state.bLightEnables[LightIndex] == (bool)bEnable) {
1430+
return S_OK;
1431+
}
14141432
m_state.bLightEnables[LightIndex] = bEnable;
14151433
}
14161434
}
@@ -1502,9 +1520,15 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::SetRenderState(D3DRENDERSTATETYPE Sta
15021520
{
15031521
BRIDGE_DEVICE_LOCKGUARD();
15041522
if (m_stateRecording) {
1523+
if (m_stateRecording->m_captureState.renderStates[State] == Value) {
1524+
return S_OK;
1525+
}
15051526
m_stateRecording->m_captureState.renderStates[State] = Value;
15061527
m_stateRecording->m_dirtyFlags.renderStates[State] = true;
15071528
} else {
1529+
if (m_state.renderStates[State] == Value) {
1530+
return S_OK;
1531+
}
15081532
m_state.renderStates[State] = Value;
15091533
}
15101534
}
@@ -2040,10 +2064,17 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::SetTextureStageState(DWORD Stage, D3D
20402064
{
20412065
BRIDGE_DEVICE_LOCKGUARD();
20422066
if (m_stateRecording) {
2067+
if (m_stateRecording->m_captureState.textureStageStates[stageIdx][typeIdx] == Value) {
2068+
return S_OK;
2069+
}
20432070
m_stateRecording->m_captureState.textureStageStates[stageIdx][typeIdx] = Value;
20442071
m_stateRecording->m_dirtyFlags.textureStageStates[stageIdx][typeIdx] = true;
2072+
} else {
2073+
if (m_state.textureStageStates[stageIdx][typeIdx] == Value) {
2074+
return S_OK;
2075+
}
2076+
m_state.textureStageStates[stageIdx][typeIdx] = Value;
20452077
}
2046-
m_state.textureStageStates[stageIdx][typeIdx] = Value;
20472078
}
20482079
{
20492080
ClientMessage c(Commands::IDirect3DDevice9Ex_SetTextureStageState, getId());
@@ -2090,9 +2121,15 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::SetSamplerState(DWORD Sampler, D3DSAM
20902121
{
20912122
BRIDGE_DEVICE_LOCKGUARD();
20922123
if (m_stateRecording) {
2124+
if (m_stateRecording->m_captureState.samplerStates[samplerIdx][typeIdx] == Value) {
2125+
return S_OK;
2126+
}
20932127
m_stateRecording->m_captureState.samplerStates[samplerIdx][typeIdx] = Value;
20942128
m_stateRecording->m_dirtyFlags.samplerStates[samplerIdx][typeIdx] = true;
20952129
} else {
2130+
if (m_state.samplerStates[samplerIdx][typeIdx] == Value) {
2131+
return S_OK;
2132+
}
20962133
m_state.samplerStates[samplerIdx][typeIdx] = Value;
20972134
}
20982135
}

0 commit comments

Comments
 (0)