Reputation: 1588
While I'm aware that my question is probably wrong and that there "shouldn't be anything in the way of having a push constant as a 3x3 matrix", I get a strange issue. These are the relevant parts of the code:
// During command buffer recording
glm::mat3 m(1.0f);
vkCmdPushConstants(cmdBuf, layout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::mat3), static_cast<void*>(&m));
vkCmdDraw(...);
// Vertex shader
layout (location = 0) in vec3 aPosition;
layout (push_constant) uniform PushConstants
{
mat3 modelMatrix;
};
void main()
{
vec3 worldPos = modelMatrix * aPosition;
gl_Position = viewProjection * vec4(worldPos, 1.0f);
}
This results in a blank window where I expect my model to be rendered. YES I am aware that I need a 4x4 matrix to represent translation, right now the question at hand is just why a 3x3 matrix isn't working (assuming correct semantics of the initialization of glm::mat3(1.0f)
).
I now make a choice of trying with a 4x4 matrix instead:
// During command buffer recording
glm::mat4 m(1.0f);
vkCmdPushConstants(cmdBuf, layout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(glm::mat4), static_cast<void*>(&m));
vkCmdDraw(...);
// Vertex shader
layout (location = 0) in vec3 aPosition;
layout (push_constant) uniform PushConstants
{
mat4 modelMatrix;
};
void main()
{
gl_Position = viewProjection * modelMatrix * vec4(aPosition, 1.0f);
}
This results in my model getting drawn as expected. Is there something unexpected that I should be handling, like padding the size of the push constant or aligning it somehow?
Upvotes: 0
Views: 38