Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVKCmdDraw: Fix indirect index for triangle fan topology #2419

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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