Make repo working again

I rewrote basically all pipeline specific code to make
it more customizable. I made it work, which is insane.
I never thought I would be able to go back to working state again.
This commit is contained in:
Piotr Krygier authored and Piotr Krygier committed 2025-06-20 13:44:33 +02:00
1 parent bd05c03a12
commit 9cb692344f
11 files changed
+62 -80

No files matched your search

+4 -5
View File
@@ -5,10 +5,9 @@ CompileFlags:
"-Wpedantic", "-Wpedantic",
"-Werror", "-Werror",
"-Wno-gnu-statement-expression", "-Wno-gnu-statement-expression",
"-I/home/nonadmin/workspace/RedScarfEngine/", "-I./",
"-I/home/nonadmin/workspace/RedScarfEngine/graphics", "-I./graphics",
"-I/home/nonadmin/workspace/RedScarfEngine/utilites", "-I./utilites",
"-I/home/nonadmin/workspace/RedScarfEngine/third_party/include", "-I./third_party/include",
"-I/home/nonadmin/.conan2/p/stb19b77fb56ffd7/p/include/"
] ]
+6
View File
@@ -44,3 +44,9 @@ third_party/
# Cache folder # Cache folder
.cache/ .cache/
# Cmake cache files
CMakeCache.txt
# Since we are using conan, we can remove CMakeFiles folder
CMakeFiles/
+1 -1
View File
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 4.0.1) cmake_minimum_required(VERSION 3.31)
project("RedScarfEngine" project("RedScarfEngine"
VERSION 0.0.1 VERSION 0.0.1
DESCRIPTION "Vulkan based 3D engine" DESCRIPTION "Vulkan based 3D engine"
+22
View File
@@ -400,6 +400,28 @@ rse_err_t descriptor_get_vkhandle(struct descriptor_set_handle_t* descriptor_set
return RSE_ERROR_NO_ERROR; return RSE_ERROR_NO_ERROR;
} }
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)
{
VkDescriptorImageInfo image_info = {0};
VkWriteDescriptorSet write_set = {0};
image_info.sampler = sampler;
image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
image_info.imageView = context->texture_images[texture_id].image_view;
write_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
write_set.pImageInfo = &image_info;
write_set.dstSet = descriptor_set_handle->descriptor_sets;
write_set.dstBinding = binding;
write_set.dstArrayElement = 0U;
write_set.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; //TODO: Maybe not only samplers?
write_set.descriptorCount = 1;
vkUpdateDescriptorSets(context->device, 1U, &write_set, 0, NULL);
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) 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}; VkDescriptorBufferInfo buffer_info = {0};
+3
View File
@@ -12,6 +12,7 @@
#ifndef DESCRIPTOR_BUILDER_H #ifndef DESCRIPTOR_BUILDER_H
#define DESCRIPTOR_BUILDER_H #define DESCRIPTOR_BUILDER_H
#include <stdint.h>
#include <vulkan/vulkan_core.h> #include <vulkan/vulkan_core.h>
#include "src/graphics_context.h" #include "src/graphics_context.h"
@@ -77,4 +78,6 @@ rse_err_t descriptor_get_vkhandle(struct descriptor_set_handle_t* descriptor_set
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); 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);
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);
#endif // !DESCRIPTOR_BUILDER_H #endif // !DESCRIPTOR_BUILDER_H
+5 -2
View File
@@ -51,9 +51,11 @@ void rse_graphics_test_function(struct rse_graphics_context_t* rse_context)
struct pipeline_t* pipeline = NULL; struct pipeline_t* pipeline = NULL;
struct descriptor_set_handle_t* descriptor_set_handle = NULL; struct descriptor_set_handle_t* descriptor_set_handle = NULL;
struct pipeline_infos_list_t* pipeline_infos = NULL; struct pipeline_infos_list_t* pipeline_infos = NULL;
struct vulkan_buffer_t ubo = {}; struct vulkan_buffer_t ubo = {0};
// status = load_texture_from_file("../../test_image.jpg", &tex_id_2); get_curr_path(curr_path, 4096);
strncat(curr_path, "../../test_image.jpg", 4095);
load_texture_from_file(context, curr_path, &tex_id_2);
// if (status != RSE_ERROR_NO_ERROR) { // if (status != RSE_ERROR_NO_ERROR) {
// LOGE("Failed to do something. Check error messages. Error: %d", status); // LOGE("Failed to do something. Check error messages. Error: %d", status);
// return; // return;
@@ -138,6 +140,7 @@ void rse_graphics_test_function(struct rse_graphics_context_t* rse_context)
update_uniform_buffers(context, &ubo); update_uniform_buffers(context, &ubo);
descriptor_attach_buffer(context, descriptor_set_handle, &ubo, 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER); 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);
// TODO: Add a shader for text rendering // TODO: Add a shader for text rendering
// pipeline_add_shader_stage("../graphics/shaders/on_screen_text.frag.num", VK_SHADER_STAGE_FRAGMENT_BIT); // pipeline_add_shader_stage("../graphics/shaders/on_screen_text.frag.num", VK_SHADER_STAGE_FRAGMENT_BIT);
+4 -3
View File
@@ -110,6 +110,7 @@ static rse_err_t setup_debug_messenger(VkInstance instance, VkDebugUtilsMessenge
create_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT; create_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT;
create_info.pNext = NULL; create_info.pNext = NULL;
create_info.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | create_info.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT |
VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT; VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT;
create_info.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | create_info.messageType = VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT |
@@ -177,13 +178,13 @@ static rse_err_t create_instance(VkInstance* instance)
#endif /* _WIN32 || WIN32 */ #endif /* _WIN32 || WIN32 */
"VK_EXT_debug_utils", "VK_EXT_debug_utils",
}; };
#ifndef NDEBUG
uint32_t enabled_instance_extensions_count = 4; uint32_t enabled_instance_extensions_count = 4;
uint32_t enabled_instance_layers_count = 1; uint32_t enabled_instance_layers_count = 1;
const char* enabled_instance_layers_names[] = { const char* enabled_instance_layers_names[] = {
"VK_LAYER_KHRONOS_validation", "VK_LAYER_KHRONOS_validation",
}; };
#if 0 #else
uint32_t enabled_instance_extensions_count = 3; uint32_t enabled_instance_extensions_count = 3;
uint32_t enabled_instance_layers_count = 0; uint32_t enabled_instance_layers_count = 0;
const char* enabled_instance_layers_names[] = {}; const char* enabled_instance_layers_names[] = {};
@@ -248,7 +249,7 @@ static rse_err_t create_instance(VkInstance* instance)
application_info.applicationVersion = VK_MAKE_VERSION(0, 1, 0); application_info.applicationVersion = VK_MAKE_VERSION(0, 1, 0);
application_info.pEngineName = ENGINE_NAME; application_info.pEngineName = ENGINE_NAME;
application_info.engineVersion = VK_MAKE_VERSION(0, 1, 0); application_info.engineVersion = VK_MAKE_VERSION(0, 1, 0);
application_info.apiVersion = VK_API_VERSION_1_3; application_info.apiVersion = VK_API_VERSION_1_4;
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
create_info.pNext = NULL; create_info.pNext = NULL;
+1 -1
View File
@@ -363,7 +363,7 @@ rse_err_t record_command_buffer(struct graphics_context_t* context, uint32_t ima
vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, context->pipelines_data.pipeline_layout, 0, vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, context->pipelines_data.pipeline_layout, 0,
1, &descriptor_set, 0, NULL); 1, &descriptor_set, 0, NULL);
for (i = 0; i < MAX_MESH_NUMBER; ++i) { for (i = 0; i < 2; ++i) {
VkBuffer instance_buffer = {context->instance_buffers[i].buffer}; VkBuffer instance_buffer = {context->instance_buffers[i].buffer};
vkCmdBindVertexBuffers(command_buffer, 1, 1, &instance_buffer, offsets); vkCmdBindVertexBuffers(command_buffer, 1, 1, &instance_buffer, offsets);
+3 -55
View File
@@ -302,43 +302,13 @@ static rse_err_t create_textured_image(struct graphics_context_t* context, uint3
staging_buffer_size = staging_buffer_size * width * height; staging_buffer_size = staging_buffer_size * width * height;
STATUS_CHECK(create_image(context, free_texture_image, width, height, format, VK_SAMPLE_COUNT_8_BIT, STATUS_CHECK(create_image(context, free_texture_image, width, height, format, VK_SAMPLE_COUNT_1_BIT,
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT)); VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT));
// /* Put image into correct layout to copy pixels from buffer to image
// memory */ range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
// range.baseMipLevel = 0;
// range.levelCount = 1;
// range.baseArrayLayer = 0;
// range.layerCount = 1;
//
// image_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
// image_barrier.pNext = NULL;
// image_barrier.srcAccessMask = 0U;
// image_barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
// image_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
// image_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
// image_barrier.srcQueueFamilyIndex = 0U;
// image_barrier.dstQueueFamilyIndex = 0U;
// image_barrier.image = free_texture_image->image;
// image_barrier.subresourceRange = range;
//
// command_buffer = begin_single_time_command();
// vkCmdPipelineBarrier(command_buffer,
// VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
// VK_PIPELINE_STAGE_TRANSFER_BIT,
// 0,
// 0,
// NULL,
// 0,
// NULL,
// 1,
// &image_barrier);
// end_single_time_comands(command_buffer);
transition_image_layout(context, free_texture_image, VK_IMAGE_LAYOUT_UNDEFINED, transition_image_layout(context, free_texture_image, VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
/* Copy pixel data to GPU memory */ /* Copy pixel data to GPU memory */
STATUS_CHECK(create_buffer( STATUS_CHECK(create_buffer(
context, staging_buffer_size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_HOST, context, staging_buffer_size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VMA_MEMORY_USAGE_AUTO_PREFER_HOST,
@@ -364,28 +334,6 @@ static rse_err_t create_textured_image(struct graphics_context_t* context, uint3
end_single_time_comands(context, command_buffer); end_single_time_comands(context, command_buffer);
destroy_buffer(context, &staging_buffer); destroy_buffer(context, &staging_buffer);
transition_image_layout(context, free_texture_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
// /* Change image layout for shaders to be able to read it */
// image_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
// image_barrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
// image_barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
// image_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
//
// command_buffer = begin_single_time_command();
// vkCmdPipelineBarrier(command_buffer,
// VK_PIPELINE_STAGE_TRANSFER_BIT,
// VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
// 0,
// 0,
// NULL,
// 0,
// NULL,
// 1,
// &image_barrier);
// end_single_time_comands(command_buffer);
STATUS_CHECK(create_image_view(context, free_texture_image, format, VK_IMAGE_ASPECT_COLOR_BIT)); STATUS_CHECK(create_image_view(context, free_texture_image, format, VK_IMAGE_ASPECT_COLOR_BIT));
free_texture_image->id_taken = IMAGE_TAKEN; free_texture_image->id_taken = IMAGE_TAKEN;
+11 -11
View File
@@ -20,16 +20,16 @@
rse_err_t create_render_pass(struct graphics_context_t* context) rse_err_t create_render_pass(struct graphics_context_t* context)
{ {
rse_err_t status = RSE_ERROR_NO_ERROR; rse_err_t status = RSE_ERROR_NO_ERROR;
VkAttachmentDescription attachments[3] = {}; VkAttachmentDescription attachments[3] = {0};
VkAttachmentDescription color_attachment = {}; VkAttachmentDescription color_attachment = {0};
VkAttachmentReference color_attachment_ref = {}; VkAttachmentReference color_attachment_ref = {0};
VkAttachmentDescription color_attachment_resolve = {}; VkAttachmentDescription color_attachment_resolve = {0};
VkAttachmentReference color_attachment_resolve_ref = {}; VkAttachmentReference color_attachment_resolve_ref = {0};
VkSubpassDescription subpass = {}; VkSubpassDescription subpass = {0};
VkRenderPassCreateInfo renderpass_info = {}; VkRenderPassCreateInfo renderpass_info = {0};
VkAttachmentDescription depth_attachment = {}; VkAttachmentDescription depth_attachment = {0};
VkAttachmentReference depth_attachment_ref = {}; VkAttachmentReference depth_attachment_ref = {0};
VkSubpassDependency dependency = {}; VkSubpassDependency dependency = {0};
STATUS_CHECK(find_depth_format(context, &depth_attachment.format)); STATUS_CHECK(find_depth_format(context, &depth_attachment.format));
@@ -112,4 +112,4 @@ rse_err_t create_render_pass(struct graphics_context_t* context)
void destroy_render_pass(struct graphics_context_t* context) void destroy_render_pass(struct graphics_context_t* context)
{ {
vkDestroyRenderPass(context->device, context->render_pass, NULL); vkDestroyRenderPass(context->device, context->render_pass, NULL);
} }
+2 -2
View File
@@ -6,7 +6,7 @@ const char* log_levels[] = {
}; };
#ifndef LOGLEVEL #ifndef LOGLEVEL
#define LOGLEVEL LOGLEVEL_DEBUG #define LOGLEVEL LOGLEVEL_TRACE
#endif #endif
void _log_log(unsigned int level, const char* file, int line, const char* fmt, ...) void _log_log(unsigned int level, const char* file, int line, const char* fmt, ...)
@@ -23,4 +23,4 @@ void _log_log(unsigned int level, const char* file, int line, const char* fmt, .
vfprintf(stdout, fmt, list); vfprintf(stdout, fmt, list);
fprintf(stdout, "\n"); fprintf(stdout, "\n");
fflush(stdout); fflush(stdout);
} }