Fix termination errors
Cleanup for objects destruction and process termination. This is still work in progress, I don't like the way it's handled right now.
This commit is contained in:
1 parent
1b5cc7a79c
commit
5ad0ac7fed
10 files changed
+38
-11
No files matched your search
@@ -443,3 +443,9 @@ rse_err_t descriptor_attach_buffer(struct graphics_context_t* context, struct de
|
||||
|
||||
return RSE_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
void destroy_descriptors(struct graphics_context_t* context)
|
||||
{
|
||||
vkDestroyDescriptorSetLayout(context->device, context->descriptor_sets->descriptor_sets_layout, NULL);
|
||||
vkDestroyDescriptorPool(context->device, context->descriptor_sets->descriptor_pool, NULL);
|
||||
}
|
||||
@@ -80,4 +80,5 @@ rse_err_t descriptor_attach_buffer(struct graphics_context_t* context, struct de
|
||||
|
||||
rse_err_t descriptor_attach_image(struct graphics_context_t* context, struct descriptor_set_handle_t* descriptor_set_handle, uint16_t texture_id, VkSampler sampler, uint32_t binding);
|
||||
|
||||
void destroy_descriptors(struct graphics_context_t* context);
|
||||
#endif // !DESCRIPTOR_BUILDER_H
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "vulkan/vulkan_core.h"
|
||||
#include "vulkan_commons.h"
|
||||
|
||||
#define MAX_MESH_NUMBER 256
|
||||
#define MAX_MESH_NUMBER 2
|
||||
#define MAX_INSTANCE_NUMBER 256
|
||||
|
||||
/**
|
||||
@@ -34,6 +34,8 @@
|
||||
#define MAX_PIPELINE_COUNT 16
|
||||
|
||||
RSE_LINKED_LIST_DEFINE(shader_module_list_t, VkShaderModule);
|
||||
RSE_LINKED_LIST_DEFINE(vulkan_buffer_list_t, struct vulkan_buffer_t);
|
||||
RSE_LINKED_LIST_DEFINE(descriptor_sets_list_t, VkDescriptorSet);
|
||||
|
||||
/**
|
||||
* @brief Represents data within vertex or instance buffer.
|
||||
@@ -94,6 +96,7 @@ struct pipeline_internal_t
|
||||
struct graphics_context_t
|
||||
{
|
||||
SDL_Window* window_handle;
|
||||
VkSampler sampler;
|
||||
VkDevice device;
|
||||
VkSurfaceKHR surface;
|
||||
VkInstance instance;
|
||||
@@ -125,6 +128,7 @@ struct graphics_context_t
|
||||
struct vulkan_buffer_t index_buffer;
|
||||
struct vulkan_buffer_t instance_buffers[MAX_MESH_NUMBER];
|
||||
struct vulkan_buffer_t draw_indirect_command_buffer;
|
||||
struct vulkan_buffer_list_t* uniform_buffers;
|
||||
struct vulkan_image_t texture_images[RSE_MAX_IMAGE_COUNT];
|
||||
struct vulkan_image_t depth_image;
|
||||
struct vulkan_image_t color_image;
|
||||
|
||||
@@ -545,6 +545,8 @@ void destroy_pipelines(struct graphics_context_t* context)
|
||||
size_t i = 0;
|
||||
size_t shader_modules_count = RSE_LINKED_LIST_SIZE(context->shader_modules);
|
||||
|
||||
vkDestroyPipelineLayout(context->device, context->pipelines_data.pipeline_layout, NULL);
|
||||
|
||||
for (i = 0; i < context->pipelines_data.pipelines_count; i++) {
|
||||
if (context->pipelines_data.pipelines[i] != VK_NULL_HANDLE) {
|
||||
vkDestroyPipeline(context->device, context->pipelines_data.pipelines[i], NULL);
|
||||
|
||||
@@ -120,15 +120,13 @@ void rse_graphics_test_function(struct rse_graphics_context_t* rse_context)
|
||||
pipeline_add_dynamic_state(pipeline, VK_DYNAMIC_STATE_VIEWPORT);
|
||||
pipeline_add_dynamic_state(pipeline, VK_DYNAMIC_STATE_SCISSOR);
|
||||
|
||||
VkSampler sampler = VK_NULL_HANDLE;
|
||||
|
||||
sampler_create(context, &sampler);
|
||||
sampler_create(context, &context->sampler);
|
||||
|
||||
descriptor_initialize_handle(&descriptor_set_handle);
|
||||
|
||||
descriptor_add_set(descriptor_set_handle, 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_VERTEX_BIT, NULL);
|
||||
descriptor_add_set(descriptor_set_handle, 1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1,
|
||||
VK_SHADER_STAGE_FRAGMENT_BIT, &sampler);
|
||||
VK_SHADER_STAGE_FRAGMENT_BIT, &context->sampler);
|
||||
|
||||
descriptors_build(context, descriptor_set_handle);
|
||||
|
||||
@@ -140,7 +138,7 @@ void rse_graphics_test_function(struct rse_graphics_context_t* rse_context)
|
||||
update_uniform_buffers(context, &ubo);
|
||||
|
||||
descriptor_attach_buffer(context, descriptor_set_handle, &ubo, 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||
descriptor_attach_image(context, descriptor_set_handle, tex_id_2, sampler, 1);
|
||||
descriptor_attach_image(context, descriptor_set_handle, tex_id_2, context->sampler, 1);
|
||||
|
||||
// TODO: Add a shader for text rendering
|
||||
// pipeline_add_shader_stage("../graphics/shaders/on_screen_text.frag.num", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <SDL3/SDL_vulkan.h>
|
||||
#include <vma/vk_mem_alloc.h>
|
||||
|
||||
#include "src/descriptor_builder.h"
|
||||
#include "utilities/commons.h"
|
||||
#include "utilities/errors_common.h"
|
||||
#include "utilities/logger.h"
|
||||
@@ -659,6 +660,7 @@ void deinit_vulkan(struct graphics_context_t* context)
|
||||
destroy_render_pass(context);
|
||||
cleanup_swapchain(context);
|
||||
destroy_pipelines(context);
|
||||
destroy_descriptors(context);
|
||||
|
||||
vmaDestroyAllocator(context->allocator);
|
||||
vkDestroyDevice(context->device, NULL);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "src/vulkan_commons.h"
|
||||
#include "utilities/commons.h"
|
||||
#include "utilities/errors_common.h"
|
||||
#include "utilities/linked_list.h"
|
||||
#include "utilities/localization.h"
|
||||
#include "utilities/logger.h"
|
||||
#include "vulkan_commands.h"
|
||||
@@ -130,10 +131,13 @@ rse_err_t create_uniform_buffer(struct graphics_context_t* context, struct vulka
|
||||
VkDeviceSize buffer_size =
|
||||
sizeof(struct uniform_buffer_object_t); // TODO: Change later. Uniform buffer is not only MVP
|
||||
|
||||
|
||||
STATUS_CHECK(create_buffer(
|
||||
context, buffer_size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_HOST,
|
||||
VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT, buffer));
|
||||
|
||||
RSE_LINKED_LIST_PUSH_BACK(context->uniform_buffers, *buffer);
|
||||
|
||||
return RSE_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -168,6 +172,9 @@ rse_err_t create_buffer(struct graphics_context_t* context, const VkDeviceSize s
|
||||
return VULKAN_ERROR_BUFFER_CREATION_FAILED;
|
||||
}
|
||||
|
||||
static int count = 1;
|
||||
LOGI("Created buffers: %d\n", count++);
|
||||
|
||||
buffer->allocated_size = size;
|
||||
|
||||
return RSE_ERROR_NO_ERROR;
|
||||
@@ -176,6 +183,7 @@ rse_err_t create_buffer(struct graphics_context_t* context, const VkDeviceSize s
|
||||
void destroy_buffer(struct graphics_context_t* context, struct vulkan_buffer_t* buffer)
|
||||
{
|
||||
vmaDestroyBuffer(context->allocator, buffer->buffer, buffer->allocation);
|
||||
|
||||
}
|
||||
|
||||
void update_uniform_buffers(struct graphics_context_t* context, const struct vulkan_buffer_t* buffer)
|
||||
@@ -412,4 +420,8 @@ void destroy_buffers(struct graphics_context_t* context)
|
||||
vmaDestroyBuffer(context->allocator, context->instance_buffers[i].buffer,
|
||||
context->instance_buffers[i].allocation);
|
||||
}
|
||||
|
||||
RSE_LINKED_LIST_FOREACH(context->uniform_buffers, buffer) {
|
||||
vmaDestroyBuffer(context->allocator, buffer->data.buffer, buffer->data.allocation);
|
||||
}
|
||||
}
|
||||
@@ -119,6 +119,9 @@ static rse_err_t create_image(struct graphics_context_t* context, struct vulkan_
|
||||
return VULKAN_ERROR_IMAGE_NOT_CREATED;
|
||||
}
|
||||
|
||||
static int count = 1;
|
||||
LOGI("Created image: %d\n", count++);
|
||||
|
||||
return RSE_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -387,9 +390,6 @@ void destroy_textures(struct graphics_context_t* context)
|
||||
{
|
||||
size_t i = 0U;
|
||||
|
||||
//FIXME: This is not working for now
|
||||
// vkDestroySampler(context->device, context->sampler, NULL);
|
||||
|
||||
for (i = 0U; i < RSE_MAX_IMAGE_COUNT; ++i) {
|
||||
if (context->texture_images[i].id_taken == IMAGE_TAKEN) {
|
||||
vkDestroyImageView(context->device, context->texture_images[i].image_view, NULL);
|
||||
@@ -397,6 +397,8 @@ void destroy_textures(struct graphics_context_t* context)
|
||||
context->texture_images[i].allocation);
|
||||
}
|
||||
}
|
||||
|
||||
vkDestroySampler(context->device, context->sampler, NULL);
|
||||
}
|
||||
|
||||
void destroy_depth_resource(struct graphics_context_t* context)
|
||||
|
||||
@@ -62,6 +62,4 @@ rse_err_t window_loop(struct graphics_context_t* context)
|
||||
void window_terminate(SDL_Window* window_handle)
|
||||
{
|
||||
SDL_DestroyWindow(window_handle);
|
||||
|
||||
SDL_Quit();
|
||||
}
|
||||
Reference in new issue
Block a user