From 31253815e120ddcba18dde2fbc8ace61fd5e5a42 Mon Sep 17 00:00:00 2001 From: Luke Usher Date: Mon, 29 Jul 2019 09:19:10 +0100 Subject: [PATCH] Define constants + fix typos --- src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 16 ++++++++-------- src/core/hle/D3D8/XbD3D8Types.h | 4 ++++ src/core/hle/D3D8/XbVertexShader.cpp | 6 +++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index df86afe32..1becddbf7 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -4182,7 +4182,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexData4f) // not present in the vertex declaration. // We use range 193 and up to store these values, as Xbox shaders stop at c192! FLOAT values[] = {a,b,c,d}; - g_pD3DDevice->SetVertexShaderConstantF(193 + Register, values, 1); + g_pD3DDevice->SetVertexShaderConstantF(X_D3DVS_CONSTREG_VERTEXDATA4F_BASE + Register, values, 1); } // Grow g_InlineVertexBuffer_Table to contain at least current, and a potentially next vertex @@ -6500,7 +6500,7 @@ VOID __fastcall XTL::EMUPATCH(D3DDevice_SetRenderState_Simple) return; case X_D3DRS_ALPHATESTENABLE: if (g_LibVersion_D3D8 == 3925) { - // HACK: Many 3925 have missing polygons when this is ture + // HACK: Many 3925 have missing polygons when this is true // Until we find out the true underlying cause, and carry on // Test Cases: Halo, Silent Hill 2. LOG_TEST_CASE("Applying 3925 alpha test disable hack"); @@ -7144,10 +7144,10 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexShader) static const float ColorBlack[4] = { 0,0,0,0 }; static const float ColorWhite[4] = { 1,1,1,1 }; - g_pD3DDevice->SetVertexShaderConstantF(193 + X_D3DVSDE_DIFFUSE, ColorWhite, 1); - g_pD3DDevice->SetVertexShaderConstantF(193 + X_D3DVSDE_BACKDIFFUSE, ColorWhite, 1); - g_pD3DDevice->SetVertexShaderConstantF(193 + X_D3DVSDE_SPECULAR, ColorBlack, 1); - g_pD3DDevice->SetVertexShaderConstantF(193 + X_D3DVSDE_BACKSPECULAR, ColorBlack, 1); + g_pD3DDevice->SetVertexShaderConstantF(X_D3DVS_CONSTREG_VERTEXDATA4F_BASE + X_D3DVSDE_DIFFUSE, ColorWhite, 1); + g_pD3DDevice->SetVertexShaderConstantF(X_D3DVS_CONSTREG_VERTEXDATA4F_BASE + X_D3DVSDE_BACKDIFFUSE, ColorWhite, 1); + g_pD3DDevice->SetVertexShaderConstantF(X_D3DVS_CONSTREG_VERTEXDATA4F_BASE + X_D3DVSDE_SPECULAR, ColorBlack, 1); + g_pD3DDevice->SetVertexShaderConstantF(X_D3DVS_CONSTREG_VERTEXDATA4F_BASE + X_D3DVSDE_BACKSPECULAR, ColorBlack, 1); } else { hRet = g_pD3DDevice->SetVertexShader(nullptr); DEBUG_D3DRESULT(hRet, "g_pD3DDevice->SetVertexShader"); @@ -7528,9 +7528,9 @@ void XTL::CxbxUpdateNativeD3DResources() // Some titles set Vertex Shader constants directly via pushbuffers rather than through D3D // We handle that case by updating any constants that have the dirty flag set on the nv2a. auto nv2a = g_NV2A->GetDeviceState(); - for(int i = 0; i < 192; i++) { + for(int i = 0; i < X_D3DVS_CONSTREG_COUNT; i++) { // Skip vOffset and vScale constants, we don't want our values to be overwritten by accident - if (i == 58 || i == 59) { + if (i == X_D3DSCM_RESERVED_CONSTANT1_CORRECTED || i == X_D3DSCM_RESERVED_CONSTANT2_CORRECTED) { continue; } diff --git a/src/core/hle/D3D8/XbD3D8Types.h b/src/core/hle/D3D8/XbD3D8Types.h index 32e243367..f7d894beb 100644 --- a/src/core/hle/D3D8/XbD3D8Types.h +++ b/src/core/hle/D3D8/XbD3D8Types.h @@ -1081,6 +1081,10 @@ typedef DWORD X_VERTEXSHADERCONSTANTMODE; #define X_D3DSCM_CORRECTION 96 // Add 96 to arrive at the range 0..191 (instead of 96..95) #define X_D3DVS_CONSTREG_COUNT 192 +#define X_D3DSCM_RESERVED_CONSTANT1_CORRECTED (X_D3DSCM_RESERVED_CONSTANT1 + X_D3DSCM_CORRECTION) +#define X_D3DSCM_RESERVED_CONSTANT2_CORRECTED (X_D3DSCM_RESERVED_CONSTANT2 + X_D3DSCM_CORRECTION) +#define X_D3DVS_CONSTREG_VERTEXDATA4F_BASE (X_D3DVS_CONSTREG_COUNT + 1) + // Vertex shader types #define X_VST_NORMAL 1 #define X_VST_READWRITE 2 diff --git a/src/core/hle/D3D8/XbVertexShader.cpp b/src/core/hle/D3D8/XbVertexShader.cpp index 213edcccb..7694fc766 100644 --- a/src/core/hle/D3D8/XbVertexShader.cpp +++ b/src/core/hle/D3D8/XbVertexShader.cpp @@ -913,7 +913,7 @@ static void VshWriteShader(VSH_XBOX_SHADER *pShader, // We need to move these constant values to temporaries so they can be used as input alongside other constants! // We count down from the highest available on the host because Xbox titles don't use values that high, and we read from c192 because Xbox uses 192 constants static int temporaryRegisterBase = g_D3DCaps.VS20Caps.NumTemps - 13; - moveConstantsToTemporaries << "mov r" << (temporaryRegisterBase + i) << ", c" << (193 + i) << "\n"; + moveConstantsToTemporaries << "mov r" << (temporaryRegisterBase + i) << ", c" << (X_D3DVS_CONSTREG_VERTEXDATA4F_BASE + i) << "\n"; LOG_TEST_CASE("Shader uses undeclared Vertex Input Registers"); i++; continue; @@ -1617,7 +1617,7 @@ static boolean VshConvertShader(VSH_XBOX_SHADER *pShader, if (!RegVIsPresentInDeclaration[pIntermediate->Parameters[j].Parameter.Address]) { // This vertex register was not declared and therefore is not present within the Vertex Data object - // We read from tempories instead, that are set based on constants, in-turn, set by SetVertexData4f + // We read from temporary registers instead, that are set based on constants, in-turn, set by SetVertexData4f // We count down from the highest available on the host because Xbox titles don't use values that high, and we read from c192 because Xbox uses 192 constants static int temporaryRegisterBase = g_D3DCaps.VS20Caps.NumTemps - 13; pIntermediate->Parameters[j].Parameter.ParameterType = PARAM_R; @@ -1997,7 +1997,7 @@ static void VshConvertToken_STREAMDATA_REG( } DbgVshPrintf(", "); - // Add this regiseter to the list of declared registers + // Add this register to the list of declared registers RegVIsPresentInDeclaration[VertexRegister] = true; XTL::DWORD XboxVertexElementDataType = (*pToken & X_D3DVSD_DATATYPEMASK) >> X_D3DVSD_DATATYPESHIFT;