From 0cb849a3f8a167bd16441b6b0d62bceed470abe7 Mon Sep 17 00:00:00 2001 From: Anthony Date: Sun, 6 Jun 2021 21:38:16 +1200 Subject: [PATCH] Avoid setting vertex shader constants more than once per draw --- src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 40 +++++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index c704d7342..16a81354a 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -7561,20 +7561,29 @@ extern float* HLE_get_NV2A_vertex_constant_float4_ptr(unsigned const_index); // // remove our patches on D3DDevice_SetVertexShaderConstant (and CxbxImpl_SetVertexShaderConstant) void CxbxUpdateHostVertexShaderConstants() { - // Copy all constants (as they may have been overwritten with fixed-function mode) - // Though we should only have to copy overwritten or dirty constants - float* constant_floats = HLE_get_NV2A_vertex_constant_float4_ptr(0); - g_pD3DDevice->SetVertexShaderConstantF(0, constant_floats, X_D3DVS_CONSTREG_COUNT); + // For Xbox vertex shader programs, the Xbox vertex shader constants + // are mirrored on the host. + // Otherwise, the same set of constants is used for the fixed function vertex shader + // implementation instead + if (g_Xbox_VertexShaderMode == VertexShaderMode::FixedFunction && g_UseFixedFunctionVertexShader) { + UpdateFixedFunctionVertexShaderState(); + } + else { + // Copy all constants (as they may have been overwritten with fixed-function mode) + // Though we should only have to copy overwritten or dirty constants + float* constant_floats = HLE_get_NV2A_vertex_constant_float4_ptr(0); + g_pD3DDevice->SetVertexShaderConstantF(0, constant_floats, X_D3DVS_CONSTREG_COUNT); - // FIXME our viewport constants don't match Xbox values - // If we write them to pgraph constants, like we do with constants set by the title, - // the Xbox could overwrite them (at any time?) and we get flickering geometry. - // For now, set our viewport constants directly in the call below, - // overwriting whatever was in pgraph - // Test case: - // Xbox dashboard (during initial fade from black) - // Need for Speed: Hot Pursuit 2 (car select) - CxbxUpdateHostViewPortOffsetAndScaleConstants(); + // FIXME our viewport constants don't match Xbox values + // If we write them to pgraph constants, like we do with constants set by the title, + // the Xbox could overwrite them (at any time?) and we get flickering geometry. + // For now, set our viewport constants directly in the call below, + // overwriting whatever was in pgraph + // Test case: + // Xbox dashboard (during initial fade from black) + // Need for Speed: Hot Pursuit 2 (car select) + CxbxUpdateHostViewPortOffsetAndScaleConstants(); + } } void CxbxUpdateHostViewport() { @@ -7655,11 +7664,6 @@ void CxbxUpdateNativeD3DResources() CxbxUpdateHostVertexShaderConstants(); CxbxUpdateHostViewport(); - - // Update fixed function vertex shader state - if (g_Xbox_VertexShaderMode == VertexShaderMode::FixedFunction && g_UseFixedFunctionVertexShader) { - UpdateFixedFunctionVertexShaderState(); - } // NOTE: Order is important here // Some Texture States depend on RenderState values (Point Sprites)