Skip to content

Commit

Permalink
Merge branch 'dev/adunn/shadow_state_tracking' into 'main'
Browse files Browse the repository at this point in the history
CPU Perf: Implement shadow state elimination on D3D9 client for some common functions

See merge request lightspeedrtx/bridge-remix-nv!96
  • Loading branch information
AlexDunn committed Aug 30, 2024
2 parents ac83cd0 + 3289c55 commit 97ecf73
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/client/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,9 +1196,15 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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;
}
}
Expand Down Expand Up @@ -1367,9 +1373,15 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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;
}
}
Expand Down Expand Up @@ -1409,8 +1421,14 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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;
}
}
Expand Down Expand Up @@ -1502,9 +1520,15 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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;
}
}
Expand Down Expand Up @@ -2040,10 +2064,17 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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());
Expand Down Expand Up @@ -2090,9 +2121,15 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::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;
}
}
Expand Down

0 comments on commit 97ecf73

Please sign in to comment.