Add uniform descriptor for bone matrices

This commit is contained in:
Camden Dixie O'Brien committed 2025-10-02 03:59:16 +01:00
1 parent e42986adc3
commit 74309be52c
1 file changed
+34 -9
+34 -9
View File
@@ -409,15 +409,24 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
}; };
// Create descriptor set layout // Create descriptor set layout
const VkDescriptorSetLayoutCreateInfo desc_set_layout_config = { const VkDescriptorSetLayoutBinding desc_set_layout_bindings[] = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, {
.bindingCount = 1,
.pBindings = &(VkDescriptorSetLayoutBinding) {
.binding = 0, .binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 1, .descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT, .stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
}, },
{
.binding = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
},
};
const VkDescriptorSetLayoutCreateInfo desc_set_layout_config = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
.bindingCount = NELEMS(desc_set_layout_bindings),
.pBindings = desc_set_layout_bindings,
}; };
result = vkCreateDescriptorSetLayout( result = vkCreateDescriptorSetLayout(
ctx->dev, &desc_set_layout_config, nullptr, &ctx->desc_set_layout); ctx->dev, &desc_set_layout_config, nullptr, &ctx->desc_set_layout);
@@ -429,9 +438,9 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
.poolSizeCount = 1, .poolSizeCount = 1,
.pPoolSizes = &(VkDescriptorPoolSize) { .pPoolSizes = &(VkDescriptorPoolSize) {
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = swapchain_img_count, .descriptorCount = 2 * swapchain_img_count,
}, },
.maxSets = swapchain_img_count, .maxSets = 2 * swapchain_img_count,
}; };
result = vkCreateDescriptorPool( result = vkCreateDescriptorPool(
ctx->dev, &desc_pool_config, nullptr, &ctx->desc_pool); ctx->dev, &desc_pool_config, nullptr, &ctx->desc_pool);
@@ -474,9 +483,10 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
ctx->dev, ctx->bone_matrix_buffer_mem, 0, bone_matrix_buffer_size, 0, ctx->dev, ctx->bone_matrix_buffer_mem, 0, bone_matrix_buffer_size, 0,
(void **)&ctx->bone_matrices); (void **)&ctx->bone_matrices);
// Configure descriptor sets to use MVP buffer // Configure descriptor sets to use MVP and bone matrix buffers
for (unsigned i = 0; i < swapchain_img_count; ++i) { for (unsigned i = 0; i < swapchain_img_count; ++i) {
const VkWriteDescriptorSet desc_write = { const VkWriteDescriptorSet desc_writes[] = {
{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, .sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = ctx->desc_sets[i], .dstSet = ctx->desc_sets[i],
.dstBinding = 0, .dstBinding = 0,
@@ -488,8 +498,23 @@ void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config, model_t model)
.offset = i * sizeof(mvp_t), .offset = i * sizeof(mvp_t),
.range = sizeof(mvp_t), .range = sizeof(mvp_t),
}, },
},
{
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = ctx->desc_sets[i],
.dstBinding = 1,
.dstArrayElement = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 1,
.pBufferInfo = &(VkDescriptorBufferInfo) {
.buffer = ctx->bone_matrix_buffer,
.offset = i * model.bone_count * sizeof(mat4_t),
.range = model.bone_count * sizeof(mat4_t),
},
},
}; };
vkUpdateDescriptorSets(ctx->dev, 1, &desc_write, 0, nullptr); vkUpdateDescriptorSets(
ctx->dev, NELEMS(desc_writes), desc_writes, 0, nullptr);
} }
// Set up input configuration // Set up input configuration