Skip to content

Metal API Validation failure on Mac2 when Argument Buffers enabled #2699

@SRSaunders

Description

@SRSaunders

Metal's minimum constant buffer offset alignment is 32 bytes for Mac2/Metal3 machines and 256 bytes for the iOS Simulator, which are both in contrast to 4 bytes for Apple 1+/Metal 4 machines. MoltenVK does not seem to take this into account and I am getting the following errors in Sascha Willems' Vulkan samples project when Argument Buffers are enabled and XCode's Metal API validation is turned on:

-[MTLDebugRenderCommandEncoder validateCommonDrawErrors:]:5843: failed assertion `Draw Errors Validation
Vertex Function(main0): the offset into the buffer spvDescriptorSet0 that is bound at buffer index 0 must be a multiple of 32 but was set to 40.'

These errors disappear when Argument Buffers are disabled. Note I am using a x86_64 + AMD Mac running Sequoia. I realize these older x86_64 machines may not be a focus going forward, but nonetheess I believe this should work properly and the cause seems to be inside MVKDescriptorPool::Create():

uint32_t gpuAlign = std::max(std::max<uint32_t>(sizes.texture.align, sizes.sampler.align), std::max<uint32_t>(sizes.pointer.align, 1));

should instead be:

uint32_t gpuAlign = std::max(std::max<uint32_t>(sizes.texture.align, sizes.sampler.align), std::max<uint32_t>(sizes.pointer.align, sizes.uniform.align));

Where a new uniform field has been set up properly with the required constant buffer offset alignment in device->getPhysicalDevice()->getArgumentBufferSizes();

I will submit a draft PR for this, but am looking for feedback since others may have a better way of fixing.

While the above change works, I am having second thoughts and am uncertain on how / where to adjust gpuAlign in the descriptor pool creation code. I think I will leave it up to the experts here to assess this issue and correct if possible.

**If the above approach is close to being correct, I do have complete code for it and can submit a PR if desired.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions