@@ -648,6 +648,7 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf
648
648
mtlArgBuffEncSize = mvkDSL->getMetal3ArgumentBufferEncodedLength (variableDescriptorCount);
649
649
}
650
650
}
651
+ uint64_t mtlArgBuffEncAlignedSize = mvkAlignByteCount (mtlArgBuffEncSize, getMetalFeatures ().mtlBufferAlignment );
651
652
652
653
size_t dsCnt = _descriptorSetAvailablility.size ();
653
654
_descriptorSetAvailablility.enumerateEnabledBits (true , [&](size_t dsIdx) {
@@ -665,7 +666,7 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf
665
666
// on a reset pool), set the offset and update the next available offset value.
666
667
if ( !mtlArgBuffOffset && (dsIdx || !_nextMetalArgumentBufferOffset)) {
667
668
mtlArgBuffOffset = _nextMetalArgumentBufferOffset;
668
- _nextMetalArgumentBufferOffset += mtlArgBuffEncSize ;
669
+ _nextMetalArgumentBufferOffset += mtlArgBuffEncAlignedSize ;
669
670
}
670
671
671
672
// Get the offset of the next desc set, if one exists and
@@ -975,9 +976,10 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf
975
976
// contain buffers, we add an additional buffer at the end to track buffer sizes.
976
977
mtlBuffCnt += std::min<NSUInteger >(mtlBuffCnt, pCreateInfo->maxSets );
977
978
978
- // Each descriptor set uses a separate Metal argument buffer, but all of these descriptor set
979
- // Metal argument buffers share a single MTLBuffer. This single MTLBuffer needs to be large
980
- // enough to hold all of the encoded resources for the descriptors.
979
+ // Each descriptor set uses a separate Metal argument buffer, but all of these
980
+ // descriptor set Metal argument buffers share a single MTLBuffer. This single
981
+ // MTLBuffer needs to be large enough to hold all of the encoded resources for the
982
+ // descriptors, plus additional buffer offset alignment space for each descriptor set.
981
983
NSUInteger metalArgBuffSize = 0 ;
982
984
if (needsMetalArgumentBufferEncoders ()) {
983
985
// If argument buffer encoders are required, depending on the platform, a Metal argument
@@ -998,6 +1000,7 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf
998
1000
} else {
999
1001
// For Metal 3, encoders are not required, and each arg buffer entry fits into 64 bits.
1000
1002
metalArgBuffSize = (mtlBuffCnt + mtlTexCnt + mtlSampCnt) * kMVKMetal3ArgBuffSlotSizeInBytes ;
1003
+ metalArgBuffSize += (mtlFeats.mtlBufferAlignment * pCreateInfo->maxSets );
1001
1004
}
1002
1005
1003
1006
if (metalArgBuffSize) {
0 commit comments