Create buffer for bone matrices

This commit is contained in:
Camden Dixie O'Brien committed 2025-10-02 03:59:16 +01:00
1 parent 1aaf5a53b8
commit e42986adc3
2 files changed
+19

No files matched your search

+16
View File
@@ -462,6 +462,18 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
ctx->dev, ctx->mvp_buffer_mem, 0, mvp_buffer_size, 0,
(void **)&ctx->mvps);
// Create and map bone matrix buffer
const size_t bone_matrix_buffer_size
= swapchain_img_count * model.bone_count * sizeof(mat4_t);
create_buffer(
ctx, bone_matrix_buffer_size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
| VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
&ctx->bone_matrix_buffer, &ctx->bone_matrix_buffer_mem);
vkMapMemory(
ctx->dev, ctx->bone_matrix_buffer_mem, 0, bone_matrix_buffer_size, 0,
(void **)&ctx->bone_matrices);
// Configure descriptor sets to use MVP buffer
for (unsigned i = 0; i < swapchain_img_count; ++i) {
const VkWriteDescriptorSet desc_write = {
@@ -803,6 +815,10 @@ void gpu_cleanup(const gpu_ctx_t *ctx)
vkDestroyRenderPass(ctx->dev, ctx->render_pass, nullptr);
vkDestroyPipelineLayout(ctx->dev, ctx->pipeline_layout, nullptr);
vkUnmapMemory(ctx->dev, ctx->bone_matrix_buffer_mem);
vkDestroyBuffer(ctx->dev, ctx->bone_matrix_buffer, nullptr);
vkFreeMemory(ctx->dev, ctx->bone_matrix_buffer_mem, nullptr);
vkUnmapMemory(ctx->dev, ctx->mvp_buffer_mem);
vkDestroyBuffer(ctx->dev, ctx->mvp_buffer, nullptr);
vkFreeMemory(ctx->dev, ctx->mvp_buffer_mem, nullptr);
+3
View File
@@ -37,6 +37,9 @@ typedef struct {
VkBuffer mvp_buffer;
VkDeviceMemory mvp_buffer_mem;
mvp_t *mvps;
VkBuffer bone_matrix_buffer;
VkDeviceMemory bone_matrix_buffer_mem;
mat4_t *bone_matrices;
VkPipelineLayout pipeline_layout;
VkRenderPass render_pass;
VkPipeline pipeline;