From ce369a6259363b14668cd0f71d8bf3b2b3a2aea6 Mon Sep 17 00:00:00 2001 From: Anthony Date: Tue, 19 Jan 2021 00:32:56 +1300 Subject: [PATCH] PR cleanup * Create index cache size variable * Use std::optional * Make PreviousStates a class variable * Remove double-cast * Use LOG_TEST_CASE in VertexShaderSource Also move LOG_TEST_CASE to CxbxKrnl.h since it's unuseable from Logging.h --- src/common/Logging.h | 18 ------------------ src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 8 +++++--- src/core/hle/D3D8/Direct3D9/TextureStates.cpp | 13 +++---------- src/core/hle/D3D8/Direct3D9/TextureStates.h | 3 +++ .../hle/D3D8/Direct3D9/VertexShaderSource.cpp | 4 ++-- src/core/hle/D3D8/XbVertexShader.cpp | 2 +- src/core/kernel/init/CxbxKrnl.h | 18 ++++++++++++++++++ 7 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/common/Logging.h b/src/common/Logging.h index 9380529c6..4bec93945 100644 --- a/src/common/Logging.h +++ b/src/common/Logging.h @@ -183,24 +183,6 @@ PopupReturn PopupCustomEx(const void* hwnd, const CXBXR_MODULE cxbxr_module, con // For LOG_TEST_CASE extern inline void EmuLogOutputEx(const CXBXR_MODULE cxbxr_module, const LOG_LEVEL level, const char *szWarningMessage, ...); -// The reason of having EmuLogOutputEx in LOG_TEST_CASE is to allow dump to log directly for any test cases triggered. -// Which will make developers easier to note which applications has triggered quicker, easier, and doesn't require any individual log enabled to capture them. -#define LOG_TEST_CASE(message) do { \ - static bool bTestCaseLogged = false; \ - if (bTestCaseLogged) break; \ - bTestCaseLogged = true; \ - if (g_CurrentLogPopupTestCase) { \ - LOG_CHECK_ENABLED(LOG_LEVEL::INFO) { \ - PopupInfo(nullptr, "Please report that %s shows the following message:\nLOG_TEST_CASE: %s\nIn %s (%s line %d)", \ - CxbxKrnl_Xbe->m_szAsciiTitle, message, __func__, __FILE__, __LINE__); \ - continue; \ - } \ - } \ - EmuLogOutputEx(LOG_PREFIX, LOG_LEVEL::INFO, "Please report that %s shows the following message:\nLOG_TEST_CASE: %s\nIn %s (%s line %d)", \ - CxbxKrnl_Xbe->m_szAsciiTitle, message, __func__, __FILE__, __LINE__); \ -} while (0) -// was g_pCertificate->wszTitleName - // // __FILENAME__ // diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index d8811c22d..a3cb441fb 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -175,6 +175,8 @@ xbox::X_D3DVIEWPORT8 g_Xbox_Viewport = { 0 }; float g_Xbox_BackbufferScaleX = 1; float g_Xbox_BackbufferScaleY = 1; +static constexpr size_t INDEX_BUFFER_CACHE_SIZE = 10000; + /* Unused : static xbox::dword_xt *g_Xbox_D3DDevice; // TODO: This should be a D3DDevice structure */ @@ -2641,8 +2643,8 @@ public: } }; -std::unordered_map g_IndexBufferCache; - + std::unordered_map g_IndexBufferCache; + void CxbxRemoveIndexBuffer(PWORD pData) { // HACK: Never Free @@ -2702,7 +2704,7 @@ ConvertedIndexBuffer& CxbxUpdateActiveIndexBuffer } // Poor-mans eviction policy : when exceeding treshold, clear entire cache : - if (g_IndexBufferCache.size() > 10000) { + if (g_IndexBufferCache.size() > INDEX_BUFFER_CACHE_SIZE) { g_IndexBufferCache.clear(); // Note : ConvertedIndexBuffer destructor will release any assigned pHostIndexBuffer } diff --git a/src/core/hle/D3D8/Direct3D9/TextureStates.cpp b/src/core/hle/D3D8/Direct3D9/TextureStates.cpp index ed7a1fdf4..0a0a07f64 100644 --- a/src/core/hle/D3D8/Direct3D9/TextureStates.cpp +++ b/src/core/hle/D3D8/Direct3D9/TextureStates.cpp @@ -34,6 +34,7 @@ #include "core/hle/Intercept.hpp" #include "RenderStates.h" #include "core/hle/D3D8/Direct3D9/Direct3D9.h" // For g_pD3DDevice +#include typedef struct { char* S; // String representation. @@ -75,13 +76,6 @@ TextureStateInfo CxbxTextureStateInfo[] = { { "D3DTSS_COLORKEYCOLOR", false, 0 }, }; -// Keep track of the last state that was set -typedef struct { - bool HasBeenSet = false; - DWORD LastValue = 0; -} PreviousState; -PreviousState PreviousStates[xbox::X_D3DTS_STAGECOUNT][xbox::X_D3DTSS_LAST + 1] = {}; - bool XboxTextureStateConverter::Init(XboxRenderStateConverter* pState) { // Deferred states start at 0, this means that D3DDeferredTextureState IS D3D__TextureState @@ -188,7 +182,7 @@ void XboxTextureStateConverter::Apply() // If the state hasn't changed, skip setting it auto lastState = &PreviousStates[XboxStage][State]; - if (lastState->HasBeenSet && lastState->LastValue == XboxValue) { + if (*lastState == XboxValue) { continue; } @@ -307,8 +301,7 @@ void XboxTextureStateConverter::Apply() } // Record we set a state - lastState->HasBeenSet = true; - lastState->LastValue = XboxValue; + lastState->emplace(XboxValue); } // Make sure we only do this once diff --git a/src/core/hle/D3D8/Direct3D9/TextureStates.h b/src/core/hle/D3D8/Direct3D9/TextureStates.h index e02f08e9c..d9f6e3742 100644 --- a/src/core/hle/D3D8/Direct3D9/TextureStates.h +++ b/src/core/hle/D3D8/Direct3D9/TextureStates.h @@ -28,6 +28,7 @@ #include #include #include "core\hle\D3D8\XbD3D8Types.h" +#include #define CXBX_D3DRS_UNSUPPORTED (xbox::X_D3DRS_LAST + 1) @@ -47,4 +48,6 @@ private: uint32_t* D3D__TextureState = nullptr; std::array XboxTextureStateOffsets; XboxRenderStateConverter* pXboxRenderStates; + // Holds the last state that was set, so we don't set it again + std::optional PreviousStates[xbox::X_D3DTS_STAGECOUNT][xbox::X_D3DTSS_LAST + 1] = {}; }; diff --git a/src/core/hle/D3D8/Direct3D9/VertexShaderSource.cpp b/src/core/hle/D3D8/Direct3D9/VertexShaderSource.cpp index fa2d7378a..e48e77c31 100644 --- a/src/core/hle/D3D8/Direct3D9/VertexShaderSource.cpp +++ b/src/core/hle/D3D8/Direct3D9/VertexShaderSource.cpp @@ -2,7 +2,7 @@ #include "VertexShaderSource.h" -#include "Logging.h" +#include "core/kernel/init/CxbxKrnl.h" #include "util/hasher.h" #include "core/kernel/support/Emu.h" @@ -78,7 +78,7 @@ ShaderKey VertexShaderSource::CreateShader(const xbox::dword_xt* pXboxFunction, else { // We can't do anything with this shader // Test case: ??? - EmuLog(LOG_LEVEL::WARNING, "Empty vertex shader"); + LOG_TEST_CASE("Empty vertex shader"); newShader.isReady = true; newShader.pHostVertexShader = nullptr; } diff --git a/src/core/hle/D3D8/XbVertexShader.cpp b/src/core/hle/D3D8/XbVertexShader.cpp index d4b7ff084..b884a9ffa 100644 --- a/src/core/hle/D3D8/XbVertexShader.cpp +++ b/src/core/hle/D3D8/XbVertexShader.cpp @@ -1563,7 +1563,7 @@ extern void EmuParseVshFunction ) { // Decode the vertex shader program tokens into an intermediate representation - uint32_t* pCurToken = (uint32_t*)((uintptr_t)pXboxFunction); + auto pCurToken = (uint32_t*)pXboxFunction; // Decode until we hit a token marked final // Note : CxbxSetVertexShaderSlots makes sure this always stops diff --git a/src/core/kernel/init/CxbxKrnl.h b/src/core/kernel/init/CxbxKrnl.h index 3c45d5f60..ded41a1f7 100644 --- a/src/core/kernel/init/CxbxKrnl.h +++ b/src/core/kernel/init/CxbxKrnl.h @@ -235,4 +235,22 @@ extern char szFilePath_Xbe[MAX_PATH*2]; // Returns the last Win32 error, in string format. Returns an empty string if there is no error. extern std::string CxbxGetLastErrorString(char * lpszFunction); +// The reason of having EmuLogOutputEx in LOG_TEST_CASE is to allow dump to log directly for any test cases triggered. +// Which will make developers easier to note which applications has triggered quicker, easier, and doesn't require any individual log enabled to capture them. +#define LOG_TEST_CASE(message) do { \ + static bool bTestCaseLogged = false; \ + if (bTestCaseLogged) break; \ + bTestCaseLogged = true; \ + if (g_CurrentLogPopupTestCase) { \ + LOG_CHECK_ENABLED(LOG_LEVEL::INFO) { \ + PopupInfo(nullptr, "Please report that %s shows the following message:\nLOG_TEST_CASE: %s\nIn %s (%s line %d)", \ + CxbxKrnl_Xbe->m_szAsciiTitle, message, __func__, __FILE__, __LINE__); \ + continue; \ + } \ + } \ + EmuLogOutputEx(LOG_PREFIX, LOG_LEVEL::INFO, "Please report that %s shows the following message:\nLOG_TEST_CASE: %s\nIn %s (%s line %d)", \ + CxbxKrnl_Xbe->m_szAsciiTitle, message, __func__, __FILE__, __LINE__); \ +} while (0) +// was g_pCertificate->wszTitleName + #endif