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
This commit is contained in:
Anthony 2021-01-19 00:32:56 +13:00
parent 27dbf03743
commit ce369a6259
7 changed files with 32 additions and 34 deletions

View File

@ -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__
//

View File

@ -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<uint32_t, ConvertedIndexBuffer> g_IndexBufferCache;
std::unordered_map<uint32_t, ConvertedIndexBuffer> 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
}

View File

@ -34,6 +34,7 @@
#include "core/hle/Intercept.hpp"
#include "RenderStates.h"
#include "core/hle/D3D8/Direct3D9/Direct3D9.h" // For g_pD3DDevice
#include <optional>
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

View File

@ -28,6 +28,7 @@
#include <cstdint>
#include <array>
#include "core\hle\D3D8\XbD3D8Types.h"
#include <optional>
#define CXBX_D3DRS_UNSUPPORTED (xbox::X_D3DRS_LAST + 1)
@ -47,4 +48,6 @@ private:
uint32_t* D3D__TextureState = nullptr;
std::array<int, xbox::X_D3DTSS_LAST + 1> XboxTextureStateOffsets;
XboxRenderStateConverter* pXboxRenderStates;
// Holds the last state that was set, so we don't set it again
std::optional<DWORD> PreviousStates[xbox::X_D3DTS_STAGECOUNT][xbox::X_D3DTSS_LAST + 1] = {};
};

View File

@ -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;
}

View File

@ -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

View File

@ -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