single vkCmdPushConstants for multiple vkCmdDrawIndexed
I ran into an issue where I sometimes had some undefined values in push constants in a fragment shader. It seems to be related to reusing the push constants for 2 consecutive draw commands. Because the values needed for the push constants are identical for both draw calls, I didn't push them twice. The issue was seen on ios and mac os, via MoltenVK, but the same code running on android and windows didn't show it.
I used to do something like this:
vkCmdPushConstants(..);
vkCmdDrawIndexed(..);
vkCmdDrawIndexed(..);
This fixed the issue:
vkCmdPushConstants(..);
vkCmdDrawIndexed(..);
vkCmdPushConstants(..);
vkCmdDrawIndexed(..);
The vulkan spec (vkCmdPushConstants) states this:
When a command buffer begins recording, all push constant values are undefined. Reads of undefined push constant values by the executing shader return undefined values.
But it doesn't say anything about reusing them between draw calls.
Some additional information for ^^^ This could be reliably reproduced situationally on iOS and iOS simulator. It could be intermittently reproduced on macOS. It was initially observed on Vulkan SDK 1.3.283 and can be reproduced on 1.3.296 (the last Vulkan SDK version with a new MoltenVk) The issue does not occur on native Vulkan implementations for Android, desktop Linux, or Windows.