Push constant variable not accesible from vertex shader

I am trying to use a push constant to pass a transformation matrix to a vertex shader. The validation layer is giving me the error that:

"validation layer: Push constant range covering variable starting at offset 0 not accessible from stage VK_SHADER_STAGE_VERTEX_BIT"

Oddly enough it seems to be working, the transformation matrix is doing what is expected in the shader and I tested with a fragment shader using colors and got the same error (for VK_SHADER_STAGE_FRAGMENT_BIT). The error is thrown on a call to vkCreateGraphicsPipelines().

Here is the relevant c++ code:

VkPushConstantRange pushConstantRange = VkPushConstantRange();
pushConstantRange.size = sizeof(glm::mat4);
pushConstantRange.offset = 0;
pushConstantRange.stageFlags = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT;

VkPipelineLayoutCreateInfo pipelineLayoutInfo = {};
pipelineLayoutInfo.setLayoutCount = 2;
pipelineLayoutInfo.pSetLayouts = descriptorSetLayouts;
pipelineLayoutInfo.pushConstantRangeCount = 1;
pipelineLayoutInfo.pPushConstantRanges = &pushConstantRange;

The push constant layout in the shader is:

layout(push_constant) uniform modelBlock {
    mat4 model;
} modelPushConstant;

It seems to me that the vertex shader definitely does have access to this variable as it is used successfully. What is going on and how would I fix it?

Oddly enough it seems to be working

First rule of Vulkan: just because something “seems to be working” doesn’t mean your code is right.

You haven’t posted enough code to know what exactly is going on, but my first thought is that your push_constant uniform block probably ought to have an explicitly defined offset value on it.

pushConstantRange.stageFlags = VK_PIPELINE_STAGE_VERTEX_SHADER_BIT;

That’s the wrong flag. You’re passing a pipeline stage flag where a shader stage flag is required.

Correct would be:

pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;

Ah yes thank you so much!