From b3671fe0e48df482bb3d54ecf1cda9f546bc5092 Mon Sep 17 00:00:00 2001 From: PatrickvL Date: Fri, 15 Nov 2019 17:59:16 +0100 Subject: [PATCH] Read Fog color through GetXboxRenderState (not via host GetRenderState), just like all other states. Also updated a few random comments and stuff mentioning the now-obsolete EmuMappedD3DRenderState. Removed unused code and replaced manual conversion of DWORD to 4 ARGB floats by using D3DXCOLOR. --- src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 25 ++++++++--------------- src/core/hle/D3D8/XbD3D8Types.h | 8 ++++---- src/core/hle/D3D8/XbPixelShader.cpp | 21 +++++-------------- 3 files changed, 17 insertions(+), 37 deletions(-) diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index 44fefdacc..74522f27b 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -4368,7 +4368,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexData2s) float fa, fb; // Test case: Halo - // Note : XQEMU recently verified that the int16_t arguments + // Note : XQEMU verified that the int16_t arguments // must be mapped to floats in the range [-32768.0, 32767.0] // (See https://github.com/xqemu/xqemu/pull/176) fa = (float)a; @@ -4377,16 +4377,6 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexData2s) EMUPATCH(D3DDevice_SetVertexData4f)(Register, fa, fb, 0.0f, 1.0f); } -DWORD FloatsToDWORD(FLOAT d, FLOAT a, FLOAT b, FLOAT c) -{ - DWORD ca = (FtoDW(d) << 24); - DWORD cr = (FtoDW(a) << 16) & 0x00FF0000; - DWORD cg = (FtoDW(b) << 8) & 0x0000FF00; - DWORD cb = (FtoDW(c) << 0) & 0x000000FF; - - return ca | cr | cg | cb; -} - extern uint32_t HLE_read_NV2A_pgraph_register(const int reg); // Declared in PushBuffer.cpp extern void HLE_write_NV2A_vertex_attribute_slot(unsigned slot, uint32_t parameter); // Declared in PushBuffer.cpp extern uint32_t HLE_read_NV2A_vertex_attribute_slot(unsigned VertexSlot); // Declared in PushBuffer.cpp @@ -4410,6 +4400,8 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexData4f_16) mov Register, edi } + LOG_FORWARD("D3DDevice_SetVertexData4f"); + EMUPATCH(D3DDevice_SetVertexData4f)(Register, a, b, c, d); } @@ -4727,7 +4719,9 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexData4s) float fa, fb, fc, fd; // Test case: Halo - // See comment note in D3DDevice_SetVertexData2s + // Note : XQEMU verified that the int16_t arguments + // must be mapped to floats in the range [-32768.0, 32767.0] + // (See https://github.com/xqemu/xqemu/pull/176) fa = (float)a; fb = (float)b; fc = (float)c; @@ -4747,12 +4741,9 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexDataColor) { LOG_FORWARD("D3DDevice_SetVertexData4f"); - FLOAT a = ((Color & 0xFF000000) >> 24) / 255.0f; - FLOAT r = ((Color & 0x00FF0000) >> 16) / 255.0f; - FLOAT g = ((Color & 0x0000FF00) >> 8) / 255.0f; - FLOAT b = ((Color & 0x000000FF) >> 0) / 255.0f; + D3DXCOLOR XColor = Color; - EMUPATCH(D3DDevice_SetVertexData4f)(Register, r, g, b, a); + EMUPATCH(D3DDevice_SetVertexData4f)(Register, XColor.r, XColor.g, XColor.b, XColor.a); } // ****************************************************************** diff --git a/src/core/hle/D3D8/XbD3D8Types.h b/src/core/hle/D3D8/XbD3D8Types.h index 345cbe7d0..6131804ab 100644 --- a/src/core/hle/D3D8/XbD3D8Types.h +++ b/src/core/hle/D3D8/XbD3D8Types.h @@ -650,11 +650,11 @@ typedef enum _X_D3DRENDERSTATETYPE { // Dxbx note : These declarations are from XDK version 5933, the most recent and complete version. // Older versions are slightly different (some members are missing), so we use a mapping table to // cater for the differences (see DxbxBuildRenderStateMappingTable). This enables to ignore these - // version-differences in the rest of our code (unless it matters somehow); We write via indirection : - // *EmuMappedD3DRenderState[X_D3DRENDERSTATETYPE] = Value; + // version-differences in the rest of our code (unless it matters somehow); We write like this : + // XboxRenderStates.SetXboxRenderState(X_D3DRENDERSTATETYPE, Value); // - // And we read via the same mapping (do note, that missing elements all point to the same dummy) : - // Result = *EmuMappedD3DRenderState[X_D3DRENDERSTATETYPE]; + // And we read like this (do note, that missing elements all point to the same dummy) : + // Result = XboxRenderStates.GetXboxRenderState(X_D3DRENDERSTATETYPE); // Dxbx note : The PS* render states map 1-on-1 to the X_D3DPIXELSHADERDEF record, // SetPixelShader actually pushes the definition into these render state slots. diff --git a/src/core/hle/D3D8/XbPixelShader.cpp b/src/core/hle/D3D8/XbPixelShader.cpp index 9d1e7ea7a..547973acb 100644 --- a/src/core/hle/D3D8/XbPixelShader.cpp +++ b/src/core/hle/D3D8/XbPixelShader.cpp @@ -1210,7 +1210,7 @@ float PSH_IMD_ARGUMENT::GetConstValue() if (HasModifier(ARGMOD_NEGATE)) Result = -Result; // y = x-0.5 -> 0..1 > -0.5..0.5 - if (HasModifier (ARGMOD_BIAS)) Result = Result-0.5f; + if (HasModifier(ARGMOD_BIAS)) Result = Result-0.5f; // y = x*2 -> 0..1 > 0..2 if (HasModifier(ARGMOD_SCALE_X2)) Result = Result*2.0f; @@ -1650,7 +1650,7 @@ bool PSH_IMD_ARGUMENT::Decode(const DWORD Value, DWORD aMask, TArgumentType Argu Modifiers = (1 << ARGMOD_BIAS); break; // case PS_INPUTMAPPING_HALFBIAS_NEGATE: -// Modifiers = ARGMOD_IDENTITY; ??? +// Modifiers = (1 << ARGMOD_IDENTITY); ??? // break; case PS_INPUTMAPPING_SIGNED_IDENTITY: Modifiers = (1 << ARGMOD_IDENTITY); @@ -5982,11 +5982,9 @@ VOID DxbxUpdateActivePixelShader() // NOPATCH HRESULT Result = D3D_OK; - // TODO: Is this even right? The first RenderState is PSAlpha, + // The first RenderState is PSAlpha, // The pixel shader is stored in pDevice->m_pPixelShader // For now, we still patch SetPixelShader and read from there... - //DWORD *XTL_D3D__RenderState = EmuMappedD3DRenderState[0]; - //pPSDef = (XTL::X_D3DPIXELSHADERDEF*)(XTL_D3D__RenderState); // Use the pixel shader stored in D3D__RenderState rather than the set handle // This allows changes made via SetRenderState to actually take effect! @@ -5994,6 +5992,7 @@ VOID DxbxUpdateActivePixelShader() // NOPATCH // All other fields are the same. // We cast D3D__RenderState to a pPSDef for these fields, but // manually read from D3D__RenderState[X_D3DRS_PSTEXTUREMODES) for that one field. + // See D3DDevice_SetPixelShaderCommon which implements this pPSDef = g_pXbox_PixelShader != nullptr ? (XTL::X_D3DPIXELSHADERDEF*)(XboxRenderStates.GetPixelShaderRenderStatePointer()) : nullptr; @@ -6066,25 +6065,16 @@ VOID DxbxUpdateActivePixelShader() // NOPATCH if (RecompiledPixelShader->ConstInUse[i]) { // Read the color from the corresponding render state slot : - // TODO: These should read from EmuMappedD3DRenderState, but it doesn't exist yet - // The required code needs o be ported from Wip_LessVertexPatching or Dxbx switch (i) { case PSH_XBOX_CONSTANT_FOG: - //dwColor = *EmuMappedD3DRenderState[XTL::X_D3DRS_FOGCOLOR] | 0xFF000000; // Note : FOG.RGB is correct like this, but FOG.a should be coming // from the vertex shader (oFog) - however, D3D8 does not forward this... - g_pD3DDevice->GetRenderState(D3DRS_FOGCOLOR, &dwColor); - fColor.a = ((dwColor >> 24) & 0xFF) / 255.0f; - fColor.r = ((dwColor >> 16) & 0xFF) / 255.0f; - fColor.g = ((dwColor >> 8) & 0xFF) / 255.0f; - fColor.b = (dwColor & 0xFF) / 255.0f; + fColor = dwColor = XboxRenderStates.GetXboxRenderState(XTL::X_D3DRS_FOGCOLOR); break; case PSH_XBOX_CONSTANT_FC0: - //dwColor = *EmuMappedD3DRenderState[XTL::X_D3DRS_PSFINALCOMBINERCONSTANT0]; fColor = dwColor = XboxRenderStates.GetXboxRenderState(XTL::X_D3DRS_PSFINALCOMBINERCONSTANT0); break; case PSH_XBOX_CONSTANT_FC1: - //dwColor = *EmuMappedD3DRenderState[XTL::X_D3DRS_PSFINALCOMBINERCONSTANT1]; fColor = dwColor = XboxRenderStates.GetXboxRenderState(XTL::X_D3DRS_PSFINALCOMBINERCONSTANT1); break; case PSH_XBOX_CONSTANT_MUL0: @@ -6119,7 +6109,6 @@ VOID DxbxUpdateActivePixelShader() // NOPATCH break; } default: - //dwColor = *EmuMappedD3DRenderState[XTL::X_D3DRS_PSCONSTANT0_0 + i]; fColor = dwColor = XboxRenderStates.GetXboxRenderState(XTL::X_D3DRS_PSCONSTANT0_0 + i); break; }