Skip to content

Commit

Permalink
Merge pull request #2419 from dboyan/fix-trifan
Browse files Browse the repository at this point in the history
MVKCmdDraw: Fix indirect index for triangle fan topology
  • Loading branch information
cdavis5e authored Jan 13, 2025
2 parents 9f0b616 + e89b0b8 commit 30ec0de
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions MoltenVK/MoltenVK/Commands/MVKCmdDraw.mm
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,20 @@
auto* indirectIdxBuff = cmdEncoder->getTempMTLBuffer(indirectIdxBuffStride);
auto* pIndArg = (MTLDrawIndexedPrimitivesIndirectArguments*)indirectIdxBuff->getContents();
pIndArg->indexCount = _vertexCount;
pIndArg->indexStart = _firstVertex;
// let the indirect index point to the beginning of vertex index buffer below
pIndArg->indexStart = 0;
pIndArg->baseVertex = 0;
pIndArg->instanceCount = _instanceCount;
pIndArg->baseInstance = _firstInstance;

// Create an index buffer populated with synthetic indexes.
// Start populating indexes below _firstVertex so that indexes align with their corresponding vertexes
// Start populating indexes directly from the beginning and align with corresponding vertexes by adding _firstVertex
MTLIndexType mtlIdxType = MTLIndexTypeUInt32;
auto* vtxIdxBuff = cmdEncoder->getTempMTLBuffer(mvkMTLIndexTypeSizeInBytes(mtlIdxType) * _vertexCount);
auto* pIdxBuff = (uint32_t*)vtxIdxBuff->getContents();
uint32_t idxCnt = _firstVertex + _vertexCount;
for (uint32_t idx = 0; idx < idxCnt; idx++) {
pIdxBuff[idx] = idx;

for (uint32_t idx = 0; idx < _vertexCount; idx++) {
pIdxBuff[idx] = _firstVertex + idx;
}

MVKIndexMTLBufferBinding ibb;
Expand Down

0 comments on commit 30ec0de

Please sign in to comment.