From 4591e40712621c2e45ea124ee5752b0b40250614 Mon Sep 17 00:00:00 2001 From: patrickvl Date: Sat, 26 Oct 2019 17:36:45 +0200 Subject: [PATCH] Potential fix for Indiana Jones regression? --- src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 11 +++++++---- src/core/hle/D3D8/XbConvert.cpp | 24 +++++++++++------------ src/core/hle/D3D8/XbConvert.h | 12 +++++++----- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index e8138140b..ebff4f30c 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -174,7 +174,7 @@ static XTL::X_D3DSurface *g_pXboxDepthStencil = NULL; static DWORD g_dwVertexShaderUsage = 0; // TODO : Move to XbVertexShader.cpp static DWORD g_VertexShaderSlots[X_VSH_MAX_INSTRUCTION_COUNT]; -DWORD g_XboxBaseVertexIndex = 0; // a value that's effectively added to every VB Index stored in the index buffer +DWORD g_XboxBaseVertexIndex = 0; // Set by D3DDevice_SetIndices : a value that's effectively added to every VB Index stored in the index buffer DWORD g_DefaultPresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; DWORD g_PresentationIntervalOverride = 0; bool g_UnlockFramerateHack = false; // ignore the xbox presentation interval @@ -2668,7 +2668,7 @@ ConvertedIndexBuffer& CxbxUpdateActiveIndexBuffer // Note, that LowIndex and HighIndex won't change due to any quad-to-triangle conversion, // so it's less work to WalkIndexBuffer over the input instead of the converted index buffer. EmuLog(LOG_LEVEL::DEBUG, "CxbxUpdateActiveIndexBuffer: Converting quads to %d triangle indices (D3DFMT_INDEX16)", RequiredIndexCount); - CxbxConvertQuadListToTriangleListIndices((INDEX16*)pXboxIndexData, RequiredIndexCount, pHostIndexBufferData); + CxbxConvertQuadListToTriangleListIndices(pXboxIndexData, RequiredIndexCount, pHostIndexBufferData); } else { EmuLog(LOG_LEVEL::DEBUG, "CxbxUpdateActiveIndexBuffer: Copying %d indices (D3DFMT_INDEX16)", XboxIndexCount); memcpy(pHostIndexBufferData, pXboxIndexData, XboxIndexCount * sizeof(INDEX16)); @@ -6718,7 +6718,10 @@ void CxbxDrawIndexed(CxbxDrawContext &DrawContext) INT BaseVertexIndex = DrawContext.dwBaseVertexIndex; UINT primCount = DrawContext.dwHostPrimitiveCount; if (bConvertQuadListToTriangleList) { - LOG_TEST_CASE("X_D3DPT_QUADLIST"); + if (DrawContext.dwVertexCount == 4) + LOG_TEST_CASE("X_D3DPT_QUADLIST (single quad)"); // breakpoint location + else + LOG_TEST_CASE("X_D3DPT_QUADLIST"); // Convert draw arguments from quads to triangles : BaseVertexIndex = QuadToTriangleVertexCount(BaseVertexIndex); primCount *= TRIANGLES_PER_QUAD; @@ -7154,7 +7157,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawIndexedVertices) DrawContext.XboxPrimitiveType = PrimitiveType; DrawContext.dwVertexCount = VertexCount; - DrawContext.dwBaseVertexIndex = g_XboxBaseVertexIndex; // Used to derive VerticesInBuffer + DrawContext.dwBaseVertexIndex = 0; // DO NOT set to g_XboxBaseVertexIndex (since pIndexData is given, we should ignore D3DDevice_SetIndices) DrawContext.pXboxIndexData = pIndexData; // Used to derive VerticesInBuffer // Test case JSRF draws all geometry through this function (only sparks are drawn via another method) diff --git a/src/core/hle/D3D8/XbConvert.cpp b/src/core/hle/D3D8/XbConvert.cpp index cde765777..6a477b735 100644 --- a/src/core/hle/D3D8/XbConvert.cpp +++ b/src/core/hle/D3D8/XbConvert.cpp @@ -1203,18 +1203,18 @@ UINT EmuD3DVertexToPrimitive[11][2] = // conversion table for xbox->pc primitive types D3DPRIMITIVETYPE EmuPrimitiveTypeLookup[] = { - /* NULL = 0 */ (D3DPRIMITIVETYPE)0, - /* D3DPT_POINTLIST = 1, */ D3DPT_POINTLIST, - /* D3DPT_LINELIST = 2, */ D3DPT_LINELIST, - /* D3DPT_LINELOOP = 3, Xbox */ D3DPT_LINESTRIP, - /* D3DPT_LINESTRIP = 4, */ D3DPT_LINESTRIP, - /* D3DPT_TRIANGLELIST = 5, */ D3DPT_TRIANGLELIST, - /* D3DPT_TRIANGLESTRIP = 6, */ D3DPT_TRIANGLESTRIP, - /* D3DPT_TRIANGLEFAN = 7, */ D3DPT_TRIANGLEFAN, - /* D3DPT_QUADLIST = 8, Xbox */ D3DPT_TRIANGLELIST, - /* D3DPT_QUADSTRIP = 9, Xbox */ D3DPT_TRIANGLESTRIP, - /* D3DPT_POLYGON = 10, Xbox */ D3DPT_TRIANGLEFAN, - /* D3DPT_MAX = 11, */ (D3DPRIMITIVETYPE)11 + /* NULL = 0 */ (D3DPRIMITIVETYPE)0, + /* X_D3DPT_POINTLIST = 1, */ D3DPT_POINTLIST, + /* X_D3DPT_LINELIST = 2, */ D3DPT_LINELIST, + /* X_D3DPT_LINELOOP = 3, Xbox */ D3DPT_LINESTRIP, + /* X_D3DPT_LINESTRIP = 4, */ D3DPT_LINESTRIP, + /* X_D3DPT_TRIANGLELIST = 5, */ D3DPT_TRIANGLELIST, + /* X_D3DPT_TRIANGLESTRIP = 6, */ D3DPT_TRIANGLESTRIP, + /* X_D3DPT_TRIANGLEFAN = 7, */ D3DPT_TRIANGLEFAN, + /* X_D3DPT_QUADLIST = 8, Xbox */ D3DPT_TRIANGLELIST, + /* X_D3DPT_QUADSTRIP = 9, Xbox */ D3DPT_TRIANGLESTRIP, + /* X_D3DPT_POLYGON = 10, Xbox */ D3DPT_TRIANGLEFAN, + /* X_D3DPT_MAX = 11, */ (D3DPRIMITIVETYPE)11 }; void EmuUnswizzleBox diff --git a/src/core/hle/D3D8/XbConvert.h b/src/core/hle/D3D8/XbConvert.h index b02a4a46e..7c7e13249 100644 --- a/src/core/hle/D3D8/XbConvert.h +++ b/src/core/hle/D3D8/XbConvert.h @@ -262,12 +262,14 @@ inline int EmuD3DPrimitive2VertexCount(XTL::X_D3DPRIMITIVETYPE PrimitiveType, in extern D3DPRIMITIVETYPE EmuPrimitiveTypeLookup[]; // convert xbox->pc primitive type -inline D3DPRIMITIVETYPE EmuXB2PC_D3DPrimitiveType(XTL::X_D3DPRIMITIVETYPE PrimitiveType) +inline D3DPRIMITIVETYPE EmuXB2PC_D3DPrimitiveType(XTL::X_D3DPRIMITIVETYPE XboxPrimitiveType) { - if((DWORD)PrimitiveType == 0x7FFFFFFF) - return D3DPT_FORCE_DWORD; - - return EmuPrimitiveTypeLookup[PrimitiveType]; + if (XboxPrimitiveType >= XTL::X_D3DPT_MAX) { + LOG_TEST_CASE("XboxPrimitiveType too large"); + return D3DPT_FORCE_DWORD; + } + + return EmuPrimitiveTypeLookup[XboxPrimitiveType]; } inline int EmuD3DIndexCountToVertexCount(XTL::X_D3DPRIMITIVETYPE XboxPrimitiveType, int IndexCount)