D3D : Apply WalkIndexBuffer everywhere possible

This commit is contained in:
patrickvl 2018-05-08 00:14:59 +02:00
parent b35ec48a27
commit b3a10ba949
1 changed files with 29 additions and 47 deletions

View File

@ -2285,7 +2285,6 @@ void CxbxRemoveIndexBuffer(PWORD pData)
void CxbxUpdateActiveIndexBuffer void CxbxUpdateActiveIndexBuffer
( (
PWORD pIndexData, PWORD pIndexData,
PDWORD pIndexBase,
UINT IndexCount UINT IndexCount
) )
{ {
@ -2348,15 +2347,12 @@ void CxbxUpdateActiveIndexBuffer
indexBuffer.pHostIndexBuffer->Unlock(); indexBuffer.pHostIndexBuffer->Unlock();
} }
*pIndexBase = g_XboxBaseVertexIndex;
// Activate the new native index buffer : // Activate the new native index buffer :
#ifdef CXBX_USE_D3D9 #ifdef CXBX_USE_D3D9
HRESULT hRet = g_pD3DDevice->SetIndices(indexBuffer.pHostIndexBuffer); HRESULT hRet = g_pD3DDevice->SetIndices(indexBuffer.pHostIndexBuffer);
// Note : *pIndexBase is moved to DrawIndexedPrimitive // Note : Under Direct3D 9, the BaseVertexIndex argument is moved towards DrawIndexedPrimitive
#else #else
HRESULT hRet = g_pD3DDevice->SetIndices(indexBuffer.pHostIndexBuffer, *pIndexBase); HRESULT hRet = g_pD3DDevice->SetIndices(indexBuffer.pHostIndexBuffer, g_XboxBaseVertexIndex);
#endif #endif
DEBUG_D3DRESULT(hRet, "g_pD3DDevice->SetIndices"); DEBUG_D3DRESULT(hRet, "g_pD3DDevice->SetIndices");
@ -7045,7 +7041,7 @@ void CxbxDrawIndexedClosingLine(XTL::INDEX16 LowIndex, XTL::INDEX16 HighIndex)
#ifdef CXBX_USE_D3D9 #ifdef CXBX_USE_D3D9
hRet = g_pD3DDevice->SetIndices(pClosingLineLoopIndexBuffer); hRet = g_pD3DDevice->SetIndices(pClosingLineLoopIndexBuffer);
#else #else
hRet = g_pD3DDevice->SetIndices(pClosingLineLoopIndexBuffer, 0); hRet = g_pD3DDevice->SetIndices(pClosingLineLoopIndexBuffer, g_XboxBaseVertexIndex);
#endif #endif
DEBUG_D3DRESULT(hRet, "g_pD3DDevice->SetIndices"); DEBUG_D3DRESULT(hRet, "g_pD3DDevice->SetIndices");
@ -7088,21 +7084,18 @@ void CxbxDrawIndexedClosingLineUP(XTL::INDEX16 LowIndex, XTL::INDEX16 HighIndex,
// TODO : Move to own file // TODO : Move to own file
//Walk through index buffer //Walk through index buffer
void WalkIndexBuffer(UINT16 & LowIndex, UINT16 & HighIndex, void * pIndexDataInput,DWORD dwVertexCount) void WalkIndexBuffer(XTL::INDEX16 &LowIndex, XTL::INDEX16 &HighIndex, XTL::INDEX16 *pIndexData, DWORD dwIndexCount)
{ {
int iIndexCounts = (int)dwVertexCount;
// Determine highest and lowest index in use // Determine highest and lowest index in use
UINT16 * pIndexData = (UINT16*)pIndexDataInput;
LowIndex = pIndexData[0]; LowIndex = pIndexData[0];
HighIndex = LowIndex; HighIndex = LowIndex;
for (int i = 1; i < iIndexCounts; i++) { for (uint i = 1; i < dwIndexCount; i++) {
UINT16 Index = pIndexData[i]; XTL::INDEX16 Index = pIndexData[i];
if (LowIndex > Index) if (LowIndex > Index)
LowIndex = Index; LowIndex = Index;
if (HighIndex < Index) if (HighIndex < Index)
HighIndex = Index; HighIndex = Index;
} }
return;
} }
// Requires assigned pIndexData // Requires assigned pIndexData
@ -7115,8 +7108,7 @@ void XTL::CxbxDrawIndexed(CxbxDrawContext &DrawContext, INDEX16 *pIndexData)
assert(pIndexData != nullptr); assert(pIndexData != nullptr);
assert(IsValidCurrentShader()); assert(IsValidCurrentShader());
DWORD indexBase = 0; CxbxUpdateActiveIndexBuffer(pIndexData, DrawContext.dwVertexCount);
CxbxUpdateActiveIndexBuffer(pIndexData, &indexBase, DrawContext.dwVertexCount);
CxbxVertexBufferConverter VertexBufferConverter = {}; CxbxVertexBufferConverter VertexBufferConverter = {};
VertexBufferConverter.Apply(&DrawContext); VertexBufferConverter.Apply(&DrawContext);
if (DrawContext.XboxPrimitiveType == X_D3DPT_QUADLIST) { if (DrawContext.XboxPrimitiveType == X_D3DPT_QUADLIST) {
@ -7131,19 +7123,16 @@ void XTL::CxbxDrawIndexed(CxbxDrawContext &DrawContext, INDEX16 *pIndexData)
// Test-case : XDK Samples (Billboard, BumpLens, DebugKeyboard, Gamepad, Lensflare, PerfTest?VolumeLight, PointSprites, Tiling, VolumeFog, VolumeSprites, etc) // Test-case : XDK Samples (Billboard, BumpLens, DebugKeyboard, Gamepad, Lensflare, PerfTest?VolumeLight, PointSprites, Tiling, VolumeFog, VolumeSprites, etc)
while (iNumVertices >= VERTICES_PER_QUAD) { while (iNumVertices >= VERTICES_PER_QUAD) {
// Determine highest and lowest index in use : // Determine highest and lowest index in use :
INDEX16 LowIndex = pIndexData[uiStartIndex]; INDEX16 LowIndex;
INDEX16 HighIndex = LowIndex; INDEX16 HighIndex;
for (int i = 1; i < VERTICES_PER_QUAD; i++) { WalkIndexBuffer(LowIndex, HighIndex, &pIndexData[uiStartIndex], VERTICES_PER_QUAD);
INDEX16 Index = pIndexData[i];
if (LowIndex > Index)
LowIndex = Index;
if (HighIndex < Index)
HighIndex = Index;
}
// Emulate a quad by drawing each as a fan of 2 triangles // Emulate a quad by drawing each as a fan of 2 triangles
HRESULT hRet = g_pD3DDevice->DrawIndexedPrimitive( HRESULT hRet = g_pD3DDevice->DrawIndexedPrimitive(
D3DPT_TRIANGLEFAN, D3DPT_TRIANGLEFAN,
//{ $IFDEF DXBX_USE_D3D9 } {BaseVertexIndex = }0, { $ENDIF } #ifdef CXBX_USE_D3D9
g_XboxBaseVertexIndex,
#endif
LowIndex, // minIndex LowIndex, // minIndex
HighIndex - LowIndex + 1, // NumVertices HighIndex - LowIndex + 1, // NumVertices
uiStartIndex, uiStartIndex,
@ -7160,7 +7149,8 @@ void XTL::CxbxDrawIndexed(CxbxDrawContext &DrawContext, INDEX16 *pIndexData)
//Walk through index buffer //Walk through index buffer
// Determine highest and lowest index in use : // Determine highest and lowest index in use :
INDEX16 LowIndex, HighIndex; INDEX16 LowIndex, HighIndex;
WalkIndexBuffer( LowIndex, HighIndex, pIndexData, DrawContext.dwVertexCount); WalkIndexBuffer(LowIndex, HighIndex, pIndexData, DrawContext.dwVertexCount);
// Primitives other than X_D3DPT_QUADLIST can be drawn using one DrawIndexedPrimitive call : // Primitives other than X_D3DPT_QUADLIST can be drawn using one DrawIndexedPrimitive call :
HRESULT hRet = g_pD3DDevice->DrawIndexedPrimitive( HRESULT hRet = g_pD3DDevice->DrawIndexedPrimitive(
EmuXB2PC_D3DPrimitiveType(DrawContext.XboxPrimitiveType), EmuXB2PC_D3DPrimitiveType(DrawContext.XboxPrimitiveType),
@ -7218,16 +7208,15 @@ void XTL::CxbxDrawPrimitiveUP(CxbxDrawContext &DrawContext)
//walk through index buffer //walk through index buffer
INDEX16 LowIndex, HighIndex; INDEX16 LowIndex, HighIndex;
WalkIndexBuffer(LowIndex, HighIndex,pIndexData, DrawContext.dwVertexCount); WalkIndexBuffer(LowIndex, HighIndex, pIndexData, DrawContext.dwVertexCount);
HRESULT hRet = g_pD3DDevice->DrawIndexedPrimitiveUP( HRESULT hRet = g_pD3DDevice->DrawIndexedPrimitiveUP(
D3DPT_TRIANGLELIST, // Draw indexed triangles instead of quads D3DPT_TRIANGLELIST, // Draw indexed triangles instead of quads
LowIndex, // MinVertexIndex LowIndex, // MinVertexIndex
HighIndex-LowIndex+1, // NumVertexIndices HighIndex - LowIndex + 1, // NumVertexIndices
PrimitiveCount, PrimitiveCount,
pIndexData, pIndexData,
D3DFMT_INDEX16, D3DFMT_INDEX16, // IndexDataFormat
DrawContext.pHostVertexStreamZeroData, DrawContext.pHostVertexStreamZeroData,
DrawContext.uiHostVertexStreamZeroStride DrawContext.uiHostVertexStreamZeroStride
); );
@ -7537,15 +7526,14 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawIndexedVertices)
if(!g_bVBSkipStream) if(!g_bVBSkipStream)
#endif #endif
if (IsValidCurrentShader()) { if (IsValidCurrentShader()) {
DWORD indexBase = 0; CxbxUpdateActiveIndexBuffer(pIndexData, VertexCount);
CxbxUpdateActiveIndexBuffer(pIndexData, &indexBase, VertexCount);
CxbxDrawContext DrawContext = {}; CxbxDrawContext DrawContext = {};
DrawContext.XboxPrimitiveType = PrimitiveType; DrawContext.XboxPrimitiveType = PrimitiveType;
DrawContext.dwVertexCount = VertexCount; DrawContext.dwVertexCount = VertexCount;
DrawContext.hVertexShader = g_CurrentXboxVertexShaderHandle; DrawContext.hVertexShader = g_CurrentXboxVertexShaderHandle;
DrawContext.dwIndexBase = indexBase; // Used by GetVertexBufferSize DrawContext.dwIndexBase = g_XboxBaseVertexIndex; // Used by GetVertexBufferSize
DrawContext.pIndexData = pIndexData; // Used by GetVertexBufferSize DrawContext.pIndexData = pIndexData; // Used by GetVertexBufferSize
// Test case JSRF draws all geometry through this function (only sparks are drawn via another method) // Test case JSRF draws all geometry through this function (only sparks are drawn via another method)
@ -7621,15 +7609,9 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawIndexedVerticesUP)
int iNumVertices = (int)VertexCount; int iNumVertices = (int)VertexCount;
while (iNumVertices >= VERTICES_PER_QUAD) { while (iNumVertices >= VERTICES_PER_QUAD) {
// Determine highest and lowest index in use : // Determine highest and lowest index in use :
INDEX16 LowIndex = pWalkIndexData[0]; INDEX16 LowIndex;
INDEX16 HighIndex = LowIndex; INDEX16 HighIndex;
for (int i = 1; i < VERTICES_PER_QUAD; i++) { WalkIndexBuffer(LowIndex, HighIndex, pWalkIndexData, VERTICES_PER_QUAD);
INDEX16 Index = pWalkIndexData[i];
if (LowIndex > Index)
LowIndex = Index;
if (HighIndex < Index)
HighIndex = Index;
}
// Emulate a quad by drawing each as a fan of 2 triangles // Emulate a quad by drawing each as a fan of 2 triangles
HRESULT hRet = g_pD3DDevice->DrawIndexedPrimitiveUP( HRESULT hRet = g_pD3DDevice->DrawIndexedPrimitiveUP(
D3DPT_TRIANGLEFAN, // Draw a triangle-fan instead of a quad D3DPT_TRIANGLEFAN, // Draw a triangle-fan instead of a quad
@ -7637,7 +7619,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawIndexedVerticesUP)
HighIndex - LowIndex + 1, // NumVertexIndices HighIndex - LowIndex + 1, // NumVertexIndices
TRIANGLES_PER_QUAD, // primCount = Draw 2 triangles TRIANGLES_PER_QUAD, // primCount = Draw 2 triangles
pWalkIndexData, pWalkIndexData,
D3DFMT_INDEX16, D3DFMT_INDEX16, // IndexDataFormat
DrawContext.pHostVertexStreamZeroData, DrawContext.pHostVertexStreamZeroData,
DrawContext.uiHostVertexStreamZeroStride DrawContext.uiHostVertexStreamZeroStride
); );
@ -7650,18 +7632,18 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_DrawIndexedVerticesUP)
g_dwPrimPerFrame += VertexCount / VERTICES_PER_QUAD * TRIANGLES_PER_QUAD; g_dwPrimPerFrame += VertexCount / VERTICES_PER_QUAD * TRIANGLES_PER_QUAD;
} }
else { else {
//walk through the index buffer // Walk through the index buffer
INDEX16 LowIndex, HighIndex; INDEX16 LowIndex, HighIndex;
WalkIndexBuffer( LowIndex, HighIndex, pIndexData, DrawContext.dwVertexCount); WalkIndexBuffer(LowIndex, HighIndex, (INDEX16*)pIndexData, DrawContext.dwVertexCount);
// LOG_TEST_CASE("DrawIndexedPrimitiveUP"); // Test-case : Burnout, Namco Museum 50th Anniversary // LOG_TEST_CASE("DrawIndexedPrimitiveUP"); // Test-case : Burnout, Namco Museum 50th Anniversary
HRESULT hRet = g_pD3DDevice->DrawIndexedPrimitiveUP( HRESULT hRet = g_pD3DDevice->DrawIndexedPrimitiveUP(
EmuXB2PC_D3DPrimitiveType(DrawContext.XboxPrimitiveType), EmuXB2PC_D3DPrimitiveType(DrawContext.XboxPrimitiveType),
LowIndex, // MinVertexIndex LowIndex, // MinVertexIndex
HighIndex-LowIndex+1, //this shall be Vertex Spans DrawContext.dwVertexCount, // NumVertexIndices HighIndex - LowIndex + 1, //this shall be Vertex Spans DrawContext.dwVertexCount, // NumVertexIndices
DrawContext.dwHostPrimitiveCount, DrawContext.dwHostPrimitiveCount,
pIndexData, pIndexData,
D3DFMT_INDEX16, D3DFMT_INDEX16, // IndexDataFormat
DrawContext.pHostVertexStreamZeroData, DrawContext.pHostVertexStreamZeroData,
DrawContext.uiHostVertexStreamZeroStride DrawContext.uiHostVertexStreamZeroStride
); );