I draw 3 triangles and want to use push constants to pass the matrix and color.
Here is the data structure that I want to pass:
struct MatrixesPushConstants
{
glm::mat4 MVPmatrix;
glm::vec3 vertexColors[3];
};
MatrixesPushConstants pushConstants[3];
And I want the third triangle to be completely white
pushConstants[2].MVPmatrix = base_camera.matrices.perspective * base_camera.matrices.view * transform;
pushConstants[2].vertexColors[0] = glm::vec3(1.0f, 1.0f, 1.0f);
pushConstants[2].vertexColors[1] = glm::vec3(1.0f, 1.0f, 1.0f);
pushConstants[2].vertexColors[2] = glm::vec3(1.0f, 1.0f, 1.0f);
I'm specify one push constants range
VkPushConstantRange pushConstantRange{};
pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
pushConstantRange.offset = 0;
pushConstantRange.size = sizeof(MatrixesPushConstants); //100
And I specify it in the Pipeline Layout
VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
pipelineLayoutInfo.pushConstantRangeCount = 1;
pipelineLayoutInfo.pPushConstantRanges = &pushConstantRange;
And I draw three triangles
for (uint32_t i = 0; i < 3; ++i) {
vkCmdPushConstants(commandBuffer, pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(MatrixesPushConstants), &pushConstants[i]);
vkCmdDraw(commandBuffer, 3, 1, 0, 0);
}
For all triangles the matrices are transferred correctly, but there are problems with the colors.
Pay attention to the third triangle (right), but it should be white.
Vertex shader
#version 450
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inColor;
layout(push_constant) uniform MatrixesPushConstants
{
mat4 MVPmatrix;
vec3 vertexColors[3];
} pushConstants;
layout(location = 0) out vec3 fragColor;
void main() {
gl_Position = pushConstants.MVPmatrix * vec4(inPosition, 1.0);
fragColor = pushConstants.vertexColors[gl_VertexIndex];
}
Fragment shader
#version 450
layout(location = 0) in vec3 fragColor;
layout(location = 0) out vec4 outColor;
void main() {
outColor = vec4(fragColor, 1.0);
}
Here is what information I get about renderdoc, in this case it is clear that the third element in the array of colors is incorrectly transmitted.
I've tried using alignas(16), but it doesn't help
struct MatrixesPushConstants
{
alignas(16) glm::mat4 MVPmatrix;
alignas(16) glm::vec3 vertexColors[3];
};

