Add uniform descriptor for bone matrices
This commit is contained in:
1 parent
e42986adc3
commit
74309be52c
1 file changed
+47
-22
@@ -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 VkDescriptorSetLayoutBinding desc_set_layout_bindings[] = {
|
||||||
|
{
|
||||||
|
.binding = 0,
|
||||||
|
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
|
.descriptorCount = 1,
|
||||||
|
.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 = {
|
const VkDescriptorSetLayoutCreateInfo desc_set_layout_config = {
|
||||||
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
||||||
.bindingCount = 1,
|
.bindingCount = NELEMS(desc_set_layout_bindings),
|
||||||
.pBindings = &(VkDescriptorSetLayoutBinding) {
|
.pBindings = desc_set_layout_bindings,
|
||||||
.binding = 0,
|
|
||||||
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
|
||||||
.descriptorCount = 1,
|
|
||||||
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
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,22 +483,38 @@ 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,
|
{
|
||||||
.dstSet = ctx->desc_sets[i],
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||||
.dstBinding = 0,
|
.dstSet = ctx->desc_sets[i],
|
||||||
.dstArrayElement = 0,
|
.dstBinding = 0,
|
||||||
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
.dstArrayElement = 0,
|
||||||
.descriptorCount = 1,
|
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||||
.pBufferInfo = &(VkDescriptorBufferInfo) {
|
.descriptorCount = 1,
|
||||||
.buffer = ctx->mvp_buffer,
|
.pBufferInfo = &(VkDescriptorBufferInfo) {
|
||||||
.offset = i * sizeof(mvp_t),
|
.buffer = ctx->mvp_buffer,
|
||||||
.range = sizeof(mvp_t),
|
.offset = i * 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
|
||||||
|
|||||||
Reference in new issue
Block a user