From d28b4836fd7e4d3971bdcef146bbc37848384910 Mon Sep 17 00:00:00 2001 From: patrickvl Date: Wed, 18 Dec 2019 21:45:44 +0100 Subject: [PATCH] Halve the selection of input attrbibute or constant, using lerp. For this, made sure that the crossover value (as set in SetOverrideFlags) is either 0 or 1. Also replaced the v0..v15 defines by actual variables. Instead, manually unrolled the initialization code via a concatenating define. --- .../Direct3D9/CxbxVertexShaderTemplate.hlsl | 33 ++++++------------- src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 2 +- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/core/hle/D3D8/Direct3D9/CxbxVertexShaderTemplate.hlsl b/src/core/hle/D3D8/Direct3D9/CxbxVertexShaderTemplate.hlsl index 569ea6127..ab510d6ca 100644 --- a/src/core/hle/D3D8/Direct3D9/CxbxVertexShaderTemplate.hlsl +++ b/src/core/hle/D3D8/Direct3D9/CxbxVertexShaderTemplate.hlsl @@ -283,33 +283,20 @@ VS_OUTPUT main(const VS_INPUT xIn) r0 = r1 = r2 = r3 = r4 = r5 = r6 = r7 = r8 = r9 = r10 = r11 = float4(0, 0, 0, 0); #define r12 oPos // oPos and r12 are two ways of accessing the same register on Xbox - // Input registerss - float4 v[16]; - # define v0 v[0] - # define v1 v[1] - # define v2 v[2] - # define v3 v[3] - # define v4 v[4] - # define v5 v[5] - # define v6 v[6] - # define v7 v[7] - # define v8 v[8] - # define v9 v[9] - # define v10 v[10] - # define v11 v[11] - # define v12 v[12] - # define v13 v[13] - # define v14 v[14] - # define v15 v[15] - + // Input registers + float4 v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15; + // View 4 packed overrides as an array of 16 floats float vOverride[16] = (float[16])vOverridePacked; // Initialize input registers from the vertex buffer - // Or use an override value set with SetVertexData4f - for(int i = 0; i < 16; i++){ - v[i] = vOverride[i] ? vOverrideValue[i] : xIn.v[i]; - } + // Or use an override value set with SetVertexData4f + #define init_v(i) v##i = lerp(xIn.v[i], vOverride[i], vOverrideValue[i]); + // Note : unroll manually instead of for-loop, because of the ## concatenation + init_v( 0); init_v( 1); init_v( 2); init_v( 3); + init_v( 4); init_v( 5); init_v( 6); init_v( 7); + init_v( 8); init_v( 9); init_v(10); init_v(11); + init_v(12); init_v(13); init_v(14); init_v(15); // Xbox shader program)DELIMITER", /* This terminates the header raw string" // */ diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index ca9d5e0ee..40ec07720 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -494,7 +494,7 @@ void SetOverrideFlags(CxbxVertexShader* pCxbxVertexShader) { if (pCxbxVertexShader != nullptr && pCxbxVertexShader->pHostVertexShader != nullptr) { float overrideFlags[16]; for (int i = 0; i < 16; i++) { - overrideFlags[i] = !pCxbxVertexShader->VertexShaderInfo.vRegisterInDeclaration[i]; + overrideFlags[i] = pCxbxVertexShader->VertexShaderInfo.vRegisterInDeclaration[i] ? 1.0f : 0.0f; } g_pD3DDevice->SetVertexShaderConstantF(X_D3DVS_CONSTREG_VERTEXDATA4F_FLAG_BASE, overrideFlags, 4); }