Add MVP projection passed through push constant

This commit is contained in:
Camden Dixie O'Brien committed 2025-09-27 14:18:32 +01:00
1 parent c770895217
commit 3d10fe76ce
4 files changed
+103 -12

No files matched your search

+13 -2
View File
@@ -436,9 +436,15 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config)
};
// Create pipeline layout
const VkPushConstantRange mvp_range = {
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
.offset = 0,
.size = sizeof(mvp_t),
};
const VkPipelineLayoutCreateInfo pipeline_layout_config = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.pushConstantRangeCount = 0,
.pushConstantRangeCount = 1,
.pPushConstantRanges = &mvp_range,
};
result = vkCreatePipelineLayout(
ctx->dev, &pipeline_layout_config, nullptr, &ctx->pipeline_layout);
@@ -641,7 +647,7 @@ void gpu_cleanup(const gpu_ctx_t *ctx)
vkDestroyInstance(ctx->inst, nullptr);
}
void gpu_render(const gpu_ctx_t *ctx)
void gpu_render(const gpu_ctx_t *ctx, const mvp_t *mvp)
{
VkResult result;
@@ -679,6 +685,11 @@ void gpu_render(const gpu_ctx_t *ctx)
vkCmdBindPipeline(
ctx->cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pipeline);
// Push MVP
vkCmdPushConstants(
ctx->cmd_buf, ctx->pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 0,
sizeof(mvp_t), mvp);
// Bind vertex and index buffers then draw
vkCmdBindVertexBuffers(
ctx->cmd_buf, 0, 1, &ctx->vertex_buf, &(VkDeviceSize) { 0 });