From 3289c551d4ea51d27d7cf2d0d9f95fa9db7db09c Mon Sep 17 00:00:00 2001 From: Alex Dunn Date: Fri, 30 Aug 2024 13:06:45 -0700 Subject: [PATCH] CPU Perf: Implement shadow state elimination on D3D9 client for some common functions --- src/client/d3d9_device.cpp | 39 +++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/client/d3d9_device.cpp b/src/client/d3d9_device.cpp index 1cfa694..8fdab7e 100644 --- a/src/client/d3d9_device.cpp +++ b/src/client/d3d9_device.cpp @@ -1196,9 +1196,15 @@ HRESULT Direct3DDevice9Ex_LSS::SetTransform(D3DTRANSFORMSTATETYPE St { BRIDGE_DEVICE_LOCKGUARD(); if (m_stateRecording) { + if (memcmp(&m_stateRecording->m_captureState.transforms[idx], pMatrix, sizeof(D3DMATRIX)) == 0) { + return S_OK; + } m_stateRecording->m_captureState.transforms[idx] = *pMatrix; m_stateRecording->m_dirtyFlags.transforms[idx] = true; } else { + if (memcmp(&m_state.transforms[idx], pMatrix, sizeof(D3DMATRIX)) == 0) { + return S_OK; + } m_state.transforms[idx] = *pMatrix; } } @@ -1367,9 +1373,15 @@ HRESULT Direct3DDevice9Ex_LSS::SetLight(DWORD Index, CONST D3DLIGHT9 { BRIDGE_DEVICE_LOCKGUARD(); if (m_stateRecording) { + if (memcmp(&m_stateRecording->m_captureState.lights[Index], pLight, sizeof(D3DLIGHT9)) == 0) { + return S_OK; + } m_stateRecording->m_captureState.lights[Index] = *pLight; m_stateRecording->m_dirtyFlags.lights[Index] = true; } else { + if (memcmp(&m_state.lights[Index], pLight, sizeof(D3DLIGHT9)) == 0) { + return S_OK; + } m_state.lights[Index] = *pLight; } } @@ -1409,8 +1421,14 @@ HRESULT Direct3DDevice9Ex_LSS::LightEnable(DWORD LightIndex, BOOL bE { BRIDGE_DEVICE_LOCKGUARD(); if (m_stateRecording) { + if (m_stateRecording->m_captureState.bLightEnables[LightIndex] == (bool)bEnable) { + return S_OK; + } m_stateRecording->m_captureState.bLightEnables[LightIndex] = bEnable; } else { + if (m_state.bLightEnables[LightIndex] == (bool)bEnable) { + return S_OK; + } m_state.bLightEnables[LightIndex] = bEnable; } } @@ -1502,9 +1520,15 @@ HRESULT Direct3DDevice9Ex_LSS::SetRenderState(D3DRENDERSTATETYPE Sta { BRIDGE_DEVICE_LOCKGUARD(); if (m_stateRecording) { + if (m_stateRecording->m_captureState.renderStates[State] == Value) { + return S_OK; + } m_stateRecording->m_captureState.renderStates[State] = Value; m_stateRecording->m_dirtyFlags.renderStates[State] = true; } else { + if (m_state.renderStates[State] == Value) { + return S_OK; + } m_state.renderStates[State] = Value; } } @@ -2040,10 +2064,17 @@ HRESULT Direct3DDevice9Ex_LSS::SetTextureStageState(DWORD Stage, D3D { BRIDGE_DEVICE_LOCKGUARD(); if (m_stateRecording) { + if (m_stateRecording->m_captureState.textureStageStates[stageIdx][typeIdx] == Value) { + return S_OK; + } m_stateRecording->m_captureState.textureStageStates[stageIdx][typeIdx] = Value; m_stateRecording->m_dirtyFlags.textureStageStates[stageIdx][typeIdx] = true; + } else { + if (m_state.textureStageStates[stageIdx][typeIdx] == Value) { + return S_OK; + } + m_state.textureStageStates[stageIdx][typeIdx] = Value; } - m_state.textureStageStates[stageIdx][typeIdx] = Value; } { ClientMessage c(Commands::IDirect3DDevice9Ex_SetTextureStageState, getId()); @@ -2090,9 +2121,15 @@ HRESULT Direct3DDevice9Ex_LSS::SetSamplerState(DWORD Sampler, D3DSAM { BRIDGE_DEVICE_LOCKGUARD(); if (m_stateRecording) { + if (m_stateRecording->m_captureState.samplerStates[samplerIdx][typeIdx] == Value) { + return S_OK; + } m_stateRecording->m_captureState.samplerStates[samplerIdx][typeIdx] = Value; m_stateRecording->m_dirtyFlags.samplerStates[samplerIdx][typeIdx] = true; } else { + if (m_state.samplerStates[samplerIdx][typeIdx] == Value) { + return S_OK; + } m_state.samplerStates[samplerIdx][typeIdx] = Value; } }