From a407b40f46b5074410ea7c08ea963a26cb5050bc Mon Sep 17 00:00:00 2001 From: PatrickvL Date: Fri, 13 Sep 2019 14:35:02 +0200 Subject: [PATCH] Moved XbState.h outside the XTL namespace. Fixed up all XTL-hell that resulted from this. --- src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 5 +++-- src/core/hle/D3D8/XbPixelShader.cpp | 16 ++++++++-------- src/core/hle/D3D8/XbPushBuffer.cpp | 1 + src/core/hle/D3D8/XbState.cpp | 22 +++++++++++----------- src/core/hle/D3D8/XbState.h | 8 ++++---- src/core/hle/D3D8/XbVertexBuffer.cpp | 3 ++- src/core/hle/Intercept.cpp | 9 ++++++--- src/core/kernel/support/EmuXTL.h | 1 - 8 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index ea54b61fa..133de9768 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -47,6 +47,7 @@ namespace xboxkrnl #include "core\hle\D3D8\XbVertexShader.h" #include "core\hle\D3D8\XbPixelShader.h" // For DxbxUpdateActivePixelShader #include "core\hle\D3D8\XbPushBuffer.h" +#include "core\hle\D3D8\XbState.h" // For EmuUpdateDeferredStates #include "core\kernel\memory-manager\VMManager.h" // for g_VMManager #include "core\kernel\support\EmuXTL.h" #include "core\hle\D3D8\XbConvert.h" @@ -7709,7 +7710,7 @@ void EmuUpdateActiveTextureStages() } } -void XTL::CxbxUpdateNativeD3DResources() +void CxbxUpdateNativeD3DResources() { EmuUpdateActiveTextureStages(); @@ -7733,7 +7734,7 @@ void XTL::CxbxUpdateNativeD3DResources() } } - XTL::EmuUpdateDeferredStates(); + EmuUpdateDeferredStates(); /* TODO : Port these : DxbxUpdateActiveVertexShader(); DxbxUpdateActiveTextures(); diff --git a/src/core/hle/D3D8/XbPixelShader.cpp b/src/core/hle/D3D8/XbPixelShader.cpp index 4a9faffb4..f28decd10 100644 --- a/src/core/hle/D3D8/XbPixelShader.cpp +++ b/src/core/hle/D3D8/XbPixelShader.cpp @@ -66,9 +66,9 @@ #include "core\kernel\support\Emu.h" #include "core\kernel\support\EmuFS.h" #include "core\kernel\support\EmuXTL.h" // X_PSH_COMBINECOUNT -//#include -#include "core\hle\D3D8\XbPixelShader.h" +#include "core\hle\D3D8\XbPixelShader.h" +#include "core\hle\D3D8\XbState.h" // For CXBX_D3DRS_UNSUPPORTED #include "core\kernel\init\CxbxKrnl.h" // For CxbxKrnlCleanup() @@ -5980,7 +5980,7 @@ static const } // DxbxRecompilePixelShader // TODO : Initialize this : -DWORD *XTL::EmuMappedD3DRenderState[X_D3DRS_UNSUPPORTED]; // 1 extra for the unsupported value +DWORD *EmuMappedD3DRenderState[CXBX_D3DRS_UNSUPPORTED]; // 1 extra for the unsupported value std::vector g_RecompiledPixelShaders; @@ -6005,7 +6005,7 @@ VOID DxbxUpdateActivePixelShader() // NOPATCH // TODO: Is this even right? 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 = XTL::EmuMappedD3DRenderState[0]; + //DWORD *XTL_D3D__RenderState = EmuMappedD3DRenderState[0]; //pPSDef = (XTL::X_D3DPIXELSHADERDEF*)(XTL_D3D__RenderState); // Use the pixel shader stored in TemporaryPixelShaderRenderStates rather than the set handle @@ -6088,18 +6088,18 @@ VOID DxbxUpdateActivePixelShader() // NOPATCH // The required code needs o be ported from Wip_LessVertexPatching or Dxbx switch (i) { case PSH_XBOX_CONSTANT_FOG: - //dwColor = *XTL::EmuMappedD3DRenderState[XTL::X_D3DRS_FOGCOLOR] | 0xFF000000; + //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 = dwColor; break; case PSH_XBOX_CONSTANT_FC0: - //dwColor = *XTL::EmuMappedD3DRenderState[XTL::X_D3DRS_PSFINALCOMBINERCONSTANT0]; + //dwColor = *EmuMappedD3DRenderState[XTL::X_D3DRS_PSFINALCOMBINERCONSTANT0]; fColor = dwColor = TemporaryPixelShaderRenderStates[XTL::X_D3DRS_PSFINALCOMBINERCONSTANT0]; break; case PSH_XBOX_CONSTANT_FC1: - //dwColor = *XTL::EmuMappedD3DRenderState[XTL::X_D3DRS_PSFINALCOMBINERCONSTANT1]; + //dwColor = *EmuMappedD3DRenderState[XTL::X_D3DRS_PSFINALCOMBINERCONSTANT1]; fColor = dwColor = TemporaryPixelShaderRenderStates[XTL::X_D3DRS_PSFINALCOMBINERCONSTANT1]; break; case PSH_XBOX_CONSTANT_MUL0: @@ -6134,7 +6134,7 @@ VOID DxbxUpdateActivePixelShader() // NOPATCH break; } default: - //dwColor = *XTL::EmuMappedD3DRenderState[XTL::X_D3DRS_PSCONSTANT0_0 + i]; + //dwColor = *EmuMappedD3DRenderState[XTL::X_D3DRS_PSCONSTANT0_0 + i]; fColor = dwColor = TemporaryPixelShaderRenderStates[XTL::X_D3DRS_PSCONSTANT0_0 + i]; break; } diff --git a/src/core/hle/D3D8/XbPushBuffer.cpp b/src/core/hle/D3D8/XbPushBuffer.cpp index 5fa551621..5e0c9a548 100644 --- a/src/core/hle/D3D8/XbPushBuffer.cpp +++ b/src/core/hle/D3D8/XbPushBuffer.cpp @@ -36,6 +36,7 @@ namespace XTL { } #include "core\hle\D3D8\ResourceTracker.h" #include "core\hle\D3D8\XbPushBuffer.h" +#include "core\hle\D3D8\XbState.h" // For CxbxUpdateNativeD3DResources, etc #include "core\hle\D3D8\XbConvert.h" #include "devices/video/nv2a.h" // For g_NV2A, PGRAPHState #include "devices/video/nv2a_int.h" // For NV** defines diff --git a/src/core/hle/D3D8/XbState.cpp b/src/core/hle/D3D8/XbState.cpp index 5bde60022..fc1509e6d 100644 --- a/src/core/hle/D3D8/XbState.cpp +++ b/src/core/hle/D3D8/XbState.cpp @@ -32,8 +32,8 @@ #include "core\hle\D3D8\XbConvert.h" // For DxbxRenderStateInfo // deferred state lookup tables -DWORD *XTL::EmuD3DDeferredRenderState = nullptr; -DWORD *XTL::EmuD3DDeferredTextureState = nullptr; +DWORD *EmuD3DDeferredRenderState = nullptr; +DWORD *EmuD3DDeferredTextureState = nullptr; #include "core\hle\Intercept.hpp" // For g_SymbolAddresses #include "common/Settings.hpp" // For g_LibVersion_D3D8 @@ -67,17 +67,17 @@ void VerifyAndFixEmuDeferredRenderStateOffset() } // If the offset was incorrect, calculate the correct offset, log it, and fix it - if ((DWORD)(&XTL::EmuD3DDeferredRenderState[CullModeIndex]) != CullModeOffset) { + if ((DWORD)(&EmuD3DDeferredRenderState[CullModeIndex]) != CullModeOffset) { DWORD CorrectOffset = CullModeOffset - (CullModeIndex * sizeof(DWORD)); - EmuLog(LOG_LEVEL::WARNING, "EmuD3DDeferredRenderState returned by XboxSymbolDatabase (0x%08X) was incorrect. Correcting to be 0x%08X.\nPlease file an issue with the XbSymbolDatabase project", XTL::EmuD3DDeferredRenderState, CorrectOffset); - XTL::EmuD3DDeferredRenderState = (DWORD*)CorrectOffset; + EmuLog(LOG_LEVEL::WARNING, "EmuD3DDeferredRenderState returned by XboxSymbolDatabase (0x%08X) was incorrect. Correcting to be 0x%08X.\nPlease file an issue with the XbSymbolDatabase project", EmuD3DDeferredRenderState, CorrectOffset); + EmuD3DDeferredRenderState = (DWORD*)CorrectOffset; } } void UpdateDeferredRenderStates() { // Certain D3DRS values need to be checked on each Draw[Indexed]Vertices - if (XTL::EmuD3DDeferredRenderState != 0) { + if (EmuD3DDeferredRenderState != 0) { // Loop through all deferred render states for (unsigned int RenderState = XTL::X_D3DRS_FOGENABLE; RenderState <= XTL::X_D3DRS_PRESENTATIONINTERVAL; RenderState++) { // If the current state is not present within our desired XDK, skip it @@ -86,7 +86,7 @@ void UpdateDeferredRenderStates() } uint8_t index = RenderState - XTL::X_D3DRS_FOGENABLE; - DWORD Value = XTL::EmuD3DDeferredRenderState[index]; + DWORD Value = EmuD3DDeferredRenderState[index]; // Convert from Xbox Data Formats to PC switch (RenderState) { @@ -253,7 +253,7 @@ void UpdateDeferredTextureStates() // The Xbox NV2A uses only Stage 3 for point-sprites, so we emulate this // by mapping Stage 3 to Stage 0, and disabling all stages > 0 bool pointSpriteOverride = false; - if (XTL::EmuD3DDeferredRenderState[XTL::X_D3DRS_POINTSPRITEENABLE - XTL::X_D3DRS_FOGENABLE] == TRUE) { + if (EmuD3DDeferredRenderState[XTL::X_D3DRS_POINTSPRITEENABLE - XTL::X_D3DRS_FOGENABLE] == TRUE) { pointSpriteOverride = true; } @@ -263,7 +263,7 @@ void UpdateDeferredTextureStates() for (int StateIndex = XTL::X_D3DTSS_DEFERRED_FIRST; StateIndex <= XTL::X_D3DTSS_DEFERRED_LAST; StateIndex++) { // Read the value of the current stage/state from the Xbox data structure - DWORD Value = XTL::EmuD3DDeferredTextureState[(XboxStage * XTL::X_D3DTS_STAGESIZE) + StateIndex]; + DWORD Value = EmuD3DDeferredTextureState[(XboxStage * XTL::X_D3DTS_STAGESIZE) + StateIndex]; // Convert the index of the current state to an index that we can use // This handles the case when XDKs have different state values @@ -519,7 +519,7 @@ void UpdateDeferredTextureStates() } } - if (XTL::EmuD3DDeferredRenderState[XTL::X_D3DRS_POINTSPRITEENABLE - XTL::X_D3DRS_FOGENABLE] == TRUE) { + if (EmuD3DDeferredRenderState[XTL::X_D3DRS_POINTSPRITEENABLE - XTL::X_D3DRS_FOGENABLE] == TRUE) { XTL::IDirect3DBaseTexture *pTexture; // set the point sprites texture @@ -537,7 +537,7 @@ void UpdateDeferredTextureStates() // ****************************************************************** // * patch: UpdateDeferredStates // ****************************************************************** -void XTL::EmuUpdateDeferredStates() +void EmuUpdateDeferredStates() { VerifyAndFixEmuDeferredRenderStateOffset(); UpdateDeferredRenderStates(); diff --git a/src/core/hle/D3D8/XbState.h b/src/core/hle/D3D8/XbState.h index 8f0503ef8..b7ba5c405 100644 --- a/src/core/hle/D3D8/XbState.h +++ b/src/core/hle/D3D8/XbState.h @@ -25,10 +25,10 @@ #ifndef XBSTATE_H #define XBSTATE_H -#define X_D3DRS_UNSUPPORTED (X_D3DRS_LAST + 1) +#define CXBX_D3DRS_UNSUPPORTED (XTL::X_D3DRS_LAST + 1) // XDK version independent renderstate table, containing pointers to the original locations. -extern DWORD *EmuMappedD3DRenderState[X_D3DRS_UNSUPPORTED]; // 1 extra for the unsupported value +extern DWORD *EmuMappedD3DRenderState[CXBX_D3DRS_UNSUPPORTED]; // 1 extra for the unsupported value struct X_Stream { DWORD Stride; @@ -43,7 +43,7 @@ extern DWORD *EmuD3DDeferredRenderState; extern DWORD *EmuD3DDeferredTextureState; extern void EmuUpdateDeferredStates(); - + extern void CxbxUpdateNativeD3DResources(); - + #endif diff --git a/src/core/hle/D3D8/XbVertexBuffer.cpp b/src/core/hle/D3D8/XbVertexBuffer.cpp index befb8863c..0e2f2c26a 100644 --- a/src/core/hle/D3D8/XbVertexBuffer.cpp +++ b/src/core/hle/D3D8/XbVertexBuffer.cpp @@ -34,6 +34,7 @@ #include "core\kernel\support\EmuXTL.h" #include "core\hle\D3D8\ResourceTracker.h" #include "core\hle\D3D8\XbPushBuffer.h" // for DxbxFVF_GetNumberOfTextureCoordinates +#include "core\hle\D3D8\XbState.h" // For CxbxUpdateNativeD3DResources, etc #include "core\hle\D3D8\XbVertexBuffer.h" #include "core\hle\D3D8\XbConvert.h" @@ -841,7 +842,7 @@ void CxbxVertexBufferConverter::Apply(CxbxDrawContext *pDrawContext) VOID EmuFlushIVB() { - XTL::CxbxUpdateNativeD3DResources(); + CxbxUpdateNativeD3DResources(); // Parse IVB table with current FVF shader if possible. bool bFVF = VshHandleIsFVF(g_CurrentXboxVertexShaderHandle); diff --git a/src/core/hle/Intercept.cpp b/src/core/hle/Intercept.cpp index de3b3da2e..48f9e1bcb 100644 --- a/src/core/hle/Intercept.cpp +++ b/src/core/hle/Intercept.cpp @@ -34,10 +34,12 @@ #include #include // For std::setfill and std::setw + #include "core\kernel\init\CxbxKrnl.h" #include "core\kernel\support\Emu.h" #include "core\kernel\support\EmuFS.h" -#include "core\kernel\support\EmuXTL.h" +#include "core\kernel\support\EmuXTL.h" +#include "core\hle\D3D8\XbState.h" // For EmuD3DDeferredTextureState #include "EmuShared.h" #include "common\CxbxDebugger.h" #include "Logging.h" @@ -46,6 +48,7 @@ #include "Intercept.hpp" #include "Patches.hpp" #include "common\util\hasher.h" + #include #include #include @@ -292,11 +295,11 @@ void CDECL EmuRegisterSymbol(const char* library_str, void EmuD3D_Init_DeferredStates() { if (g_SymbolAddresses.find("D3DDeferredRenderState") != g_SymbolAddresses.end()) { - XTL::EmuD3DDeferredRenderState = (DWORD*)g_SymbolAddresses["D3DDeferredRenderState"]; + EmuD3DDeferredRenderState = (DWORD*)g_SymbolAddresses["D3DDeferredRenderState"]; } if (g_SymbolAddresses.find("D3DDeferredTextureState") != g_SymbolAddresses.end()) { - XTL::EmuD3DDeferredTextureState = (DWORD*)g_SymbolAddresses["D3DDeferredTextureState"]; + EmuD3DDeferredTextureState = (DWORD*)g_SymbolAddresses["D3DDeferredTextureState"]; } } diff --git a/src/core/kernel/support/EmuXTL.h b/src/core/kernel/support/EmuXTL.h index de5b3991e..c11dcb6b8 100644 --- a/src/core/kernel/support/EmuXTL.h +++ b/src/core/kernel/support/EmuXTL.h @@ -32,7 +32,6 @@ namespace XTL { #include "core\hle\XAPI\Xapi.h" #include "core\hle\D3D8\Direct3D9/Direct3D9.h" - #include "core\hle\D3D8\XbState.h" #include "core\hle\DSOUND\DirectSound\DirectSound.hpp" #include "core\hle\XONLINE\XOnline.h" #include "core\hle\XGRAPHIC\XGraphic.h"