Continue working on pipeline

This commit is contained in:
Piotr Krygier committed 2025-06-20 13:44:33 +02:00
1 parent 45be08019e
commit bd05c03a12
28 files changed
+453 -423

No files matched your search

+105 -11
View File
@@ -11,9 +11,11 @@
#include "descriptor_builder.h"
#include <stddef.h>
#include <stdint.h>
#include "src/graphics_context.h"
#include "src/vulkan_commons.h"
#include "utilities/commons.h"
#include "utilities/errors_common.h"
#include "utilities/linked_list.h"
@@ -30,7 +32,7 @@ struct descriptor_t
VkDescriptorType type;
uint32_t descriptor_count;
VkShaderStageFlags shader_stages;
VkSampler immutable_sampler;
VkSampler* immutable_sampler;
};
RSE_LINKED_LIST_DEFINE(descriptor_set_list_t, struct descriptor_t);
@@ -40,6 +42,7 @@ struct descriptor_set_handle_t
VkDescriptorSet descriptor_sets;
VkDescriptorPool descriptor_pool;
VkDescriptorSetLayout descriptor_sets_layout;
struct descriptor_set_list_t* descriptor_set_list;
};
/* FIXME: When new descriptors are introduced to Vulkan, this enum has to be
@@ -66,8 +69,38 @@ enum descriptor_type_id_t
DESCRIPTOR_TYPE_ID_MAX_ENUM,
};
rse_err_t descriptor_add_set(struct descriptor_set_list_t* descriptor_set_list, uint32_t binding, VkDescriptorType type,
uint32_t descriptor_count, VkShaderStageFlags shader_stages, VkSampler sampler)
rse_err_t descriptor_initialize_handle(struct descriptor_set_handle_t **descriptor_set_handle)
{
if (NULL != *descriptor_set_handle) {
LOGE(_("Desciptor already initialized\n"));
return RSE_ERROR_INVALID_PARAM;
}
rse_malloc(*descriptor_set_handle, sizeof(struct descriptor_set_handle_t));
(*descriptor_set_handle)->descriptor_set_list = NULL;
return RSE_ERROR_NO_ERROR;
}
rse_err_t descriptor_free_handle(struct descriptor_set_handle_t **descriptor_set_handle)
{
if (NULL == *descriptor_set_handle) {
LOGE(_("Provided NULL handle\n"));
return RSE_ERROR_INVALID_PARAM;
}
RSE_LINKED_LIST_CLEAR((*descriptor_set_handle)->descriptor_set_list);
rse_free(*descriptor_set_handle);
*descriptor_set_handle = NULL;
return RSE_ERROR_NO_ERROR;
}
rse_err_t descriptor_add_set(struct descriptor_set_handle_t* descriptor_set_handle, uint32_t binding, VkDescriptorType type,
uint32_t descriptor_count, VkShaderStageFlags shader_stages, VkSampler* sampler)
{
struct descriptor_t descriptor_sets = {.binding = binding,
.type = type,
@@ -75,13 +108,12 @@ rse_err_t descriptor_add_set(struct descriptor_set_list_t* descriptor_set_list,
.shader_stages = shader_stages,
.immutable_sampler = sampler};
RSE_LINKED_LIST_PUSH_BACK(descriptor_set_list, descriptor_sets);
RSE_LINKED_LIST_PUSH_BACK(descriptor_set_handle->descriptor_set_list, descriptor_sets);
return RSE_ERROR_NO_ERROR;
}
rse_err_t descriptors_build(struct graphics_context_t* context, struct descriptor_set_list_t* descriptors,
struct descriptor_set_handle_t* descriptor_set_handle)
rse_err_t descriptors_build(struct graphics_context_t* context, struct descriptor_set_handle_t* descriptor_set_handle)
{
size_t iterator = 0U;
size_t pool_size_count = 0U;
@@ -104,8 +136,20 @@ rse_err_t descriptors_build(struct graphics_context_t* context, struct descripto
return RSE_ERROR_NULL_POINTER;
}
if (NULL == descriptor_set_handle) {
LOGF(_("Descriptor set handle is null.\n"));
return RSE_ERROR_NULL_POINTER;
}
if (RSE_LINKED_LIST_IS_EMPTY(descriptor_set_handle->descriptor_set_list)) {
LOGF(_("Provided empty descriptors list\n"));
return RSE_ERROR_NULL_POINTER;
}
iterator = 0U;
RSE_LINKED_LIST_FOREACH(descriptors, descriptor)
RSE_LINKED_LIST_FOREACH(descriptor_set_handle->descriptor_set_list, descriptor)
{
switch (descriptor->data.type) {
case VK_DESCRIPTOR_TYPE_SAMPLER:
@@ -195,6 +239,7 @@ rse_err_t descriptors_build(struct graphics_context_t* context, struct descripto
layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
layout_create_info.bindingCount = iterator;
layout_create_info.pBindings = layout_bindings;
if (VK_SUCCESS != vkCreateDescriptorSetLayout(context->device, &layout_create_info, NULL, &set_layout)) {
LOGF(_("Failed to create descriptor sets layout\n"));
return VULKAN_ERROR_DESCRIPTOR_SET_LAYOUT_CREATION_FAILED;
@@ -204,7 +249,7 @@ rse_err_t descriptors_build(struct graphics_context_t* context, struct descripto
* What I'm doing here is calculating minimum viable number of pool max sets. This is a bit tricky, as
* (unintuitively) we have to select the MINIMUM number of sets, not maximum. This makes sense, but is difficult to
* wrap headr around */
RSE_LINKED_LIST_FOREACH(descriptors, descriptor)
RSE_LINKED_LIST_FOREACH(descriptor_set_handle->descriptor_set_list, descriptor)
{
switch (descriptor->data.type) {
case VK_DESCRIPTOR_TYPE_SAMPLER:
@@ -308,10 +353,10 @@ rse_err_t descriptors_build(struct graphics_context_t* context, struct descripto
}
/* Allocate descriptors from the pool */
alloc_info.descriptorPool = &descriptor_pool;
alloc_info.descriptorPool = descriptor_pool;
alloc_info.descriptorSetCount =
pool_max_sets; /* TODO: Always allocating maximum number of sets? This might get weird */
alloc_info.pSetLayouts = set_layout;
alloc_info.pSetLayouts = &set_layout;
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
if (VK_SUCCESS != vkAllocateDescriptorSets(context->device, &alloc_info, &descriptor_sets)) {
@@ -323,7 +368,56 @@ rse_err_t descriptors_build(struct graphics_context_t* context, struct descripto
descriptor_set_handle->descriptor_sets = descriptor_sets;
descriptor_set_handle->descriptor_sets_layout = set_layout;
context->descriptor_sets = descriptor_set_handle;
return RSE_ERROR_NO_ERROR;
}
rse_err_t descriptor_get_layouts()
rse_err_t descriptor_get_layout(struct descriptor_set_handle_t* descriptor_set_handle,
VkDescriptorSetLayout* descriptor_sets_layout)
{
if (NULL == descriptor_set_handle->descriptor_sets_layout) {
LOGF(_("Requested descriptor set layout is NULL\n"));
return RSE_ERROR_NULL_POINTER;
}
*descriptor_sets_layout = descriptor_set_handle->descriptor_sets_layout;
return RSE_ERROR_NO_ERROR;
}
rse_err_t descriptor_get_vkhandle(struct descriptor_set_handle_t* descriptor_set_handle, VkDescriptorSet* descriptor_set)
{
if (NULL == descriptor_set_handle) {
LOGF(_("Provided handle is NULL\n"));
return RSE_ERROR_NULL_POINTER;
}
*descriptor_set = descriptor_set_handle->descriptor_sets;
return RSE_ERROR_NO_ERROR;
}
rse_err_t descriptor_attach_buffer(struct graphics_context_t* context, struct descriptor_set_handle_t* descriptor_set_handle, struct vulkan_buffer_t* buffer, uint32_t binding, VkDescriptorType type)
{
VkDescriptorBufferInfo buffer_info = {0};
VkWriteDescriptorSet write_set = {0};
buffer_info.buffer = buffer->buffer;
buffer_info.offset = 0U;
buffer_info.range = buffer->allocated_size;
write_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
write_set.pBufferInfo = &buffer_info;
write_set.dstSet = descriptor_set_handle->descriptor_sets;
write_set.dstBinding = binding;
write_set.dstArrayElement = 0U;
write_set.descriptorType = type;
write_set.descriptorCount = 1;
vkUpdateDescriptorSets(context->device, 1U, &write_set, 0, NULL);
return RSE_ERROR_NO_ERROR;
}