Skip to content

Commit edbdcf0

Browse files
authored
Merge pull request #2276 from billhollings/sdk-testing-fixes
Fixes from Vulkan SDK 1.3.290 testing.
2 parents d459406 + 66a2545 commit edbdcf0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm

+7-4
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf
648648
mtlArgBuffEncSize = mvkDSL->getMetal3ArgumentBufferEncodedLength(variableDescriptorCount);
649649
}
650650
}
651+
uint64_t mtlArgBuffEncAlignedSize = mvkAlignByteCount(mtlArgBuffEncSize, getMetalFeatures().mtlBufferAlignment);
651652

652653
size_t dsCnt = _descriptorSetAvailablility.size();
653654
_descriptorSetAvailablility.enumerateEnabledBits(true, [&](size_t dsIdx) {
@@ -665,7 +666,7 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf
665666
// on a reset pool), set the offset and update the next available offset value.
666667
if ( !mtlArgBuffOffset && (dsIdx || !_nextMetalArgumentBufferOffset)) {
667668
mtlArgBuffOffset = _nextMetalArgumentBufferOffset;
668-
_nextMetalArgumentBufferOffset += mtlArgBuffEncSize;
669+
_nextMetalArgumentBufferOffset += mtlArgBuffEncAlignedSize;
669670
}
670671

671672
// Get the offset of the next desc set, if one exists and
@@ -975,9 +976,10 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf
975976
// contain buffers, we add an additional buffer at the end to track buffer sizes.
976977
mtlBuffCnt += std::min<NSUInteger>(mtlBuffCnt, pCreateInfo->maxSets);
977978

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.
981983
NSUInteger metalArgBuffSize = 0;
982984
if (needsMetalArgumentBufferEncoders()) {
983985
// If argument buffer encoders are required, depending on the platform, a Metal argument
@@ -998,6 +1000,7 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf
9981000
} else {
9991001
// For Metal 3, encoders are not required, and each arg buffer entry fits into 64 bits.
10001002
metalArgBuffSize = (mtlBuffCnt + mtlTexCnt + mtlSampCnt) * kMVKMetal3ArgBuffSlotSizeInBytes;
1003+
metalArgBuffSize += (mtlFeats.mtlBufferAlignment * pCreateInfo->maxSets);
10011004
}
10021005

10031006
if (metalArgBuffSize) {

0 commit comments

Comments
 (0)