Skip to content

Push constants do not update correctly if you don't call vkCmdBindDescriptorSets after vkCmdBindPipeline #657

@hrydgard

Description

@hrydgard

Broken out from #327.

Push constants in MoltenVK only work correctly for the first pipeline you bind in a command buffer, or after you've called vkCmdBindDescriptorSets after you've bound a later pipeline.

The following call sequence is currently broken in MoltenVK but works on other conforming Vulkan implementations:

vkCmdBindPipeline(pipe1)
vkCmdBindDescriptorSet(pipe1, a uniform buffer in set 0, binding 0)
vkCmdPushConstants(constants1)
vkCmdDraw(draw1)
vkCmdPushConstants(constants2)
vkCmdDraw(draw2)
vkCmdBindPipeline(pipe2)
vkCmdPushConstants(constants3)
vkCmdDraw(draw3)

Note that vkCmdBindDescriptorSets is not called after the second vkCmdBindPipeline.

What happens is that draw3 sees constants2 instead of constants3.

If you do call vkCmdBindDescriptorSets with zero descriptor sets after the second vkCmdBindPipeline (which is UB so validation layers don't like it) it fixes things.

The reason for this behavior appears to be that cmdEncoder->getPushConstants(...)->setMTLBufferIndex is called in vkCmdBindDescriptorSets* instead of vkCmdBindPipeline, where that code should be (push constants are entirely independent of descriptors).

*:

cmdEncoder->getPushConstants(mvkVkShaderStageFlagBitsFromMVKShaderStage(MVKShaderStage(i)))->setMTLBufferIndex(_pushConstantsMTLResourceIndexes.stages[i].bufferIndex);

Metadata

Metadata

Assignees

No one assigned

    Labels

    CompletedIssue has been fixed, or enhancement implemented.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions