From 248837900a5c505715c0e5630debdb70e57bdfcd Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Tue, 4 Feb 2025 14:35:58 +0100 Subject: [PATCH] Go Vulkan 1.3 for now and implement render passes --- .../Vulkan/Sources/kope/vulkan/commandlist.c | 62 ++++++++++++++++++- .../Vulkan/Sources/kope/vulkan/device.c | 6 +- .../Sources/kope/vulkan/texture_structs.h | 4 +- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/Backends/Graphics5/Vulkan/Sources/kope/vulkan/commandlist.c b/Backends/Graphics5/Vulkan/Sources/kope/vulkan/commandlist.c index f17dae760..59581b8cb 100644 --- a/Backends/Graphics5/Vulkan/Sources/kope/vulkan/commandlist.c +++ b/Backends/Graphics5/Vulkan/Sources/kope/vulkan/commandlist.c @@ -17,9 +17,66 @@ void kope_vulkan_command_list_destroy(kope_g5_command_list *list) { vkFreeCommandBuffers(list->vulkan.device, list->vulkan.command_pool, 1, &list->vulkan.command_buffer); } -void kope_vulkan_command_list_begin_render_pass(kope_g5_command_list *list, const kope_g5_render_pass_parameters *parameters) {} +void kope_vulkan_command_list_begin_render_pass(kope_g5_command_list *list, const kope_g5_render_pass_parameters *parameters) { + const kope_g5_texture *texture = parameters->color_attachments[0].texture.texture; + + const VkClearValue clear_value = { + .color = + { + .float32 = {0.0f, 0.0f, 0.0f, 1.0f}, + }, + .depthStencil = + { + .depth = 1.0f, + .stencil = 0, + }, + }; -void kope_vulkan_command_list_end_render_pass(kope_g5_command_list *list) {} + const VkRenderingAttachmentInfo color_attachment_info = { + .sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO, + .pNext = NULL, + .imageView = texture->vulkan.image_view, + .imageLayout = VK_IMAGE_LAYOUT_GENERAL, + .resolveMode = VK_RESOLVE_MODE_NONE, + .resolveImageView = VK_NULL_HANDLE, + .resolveImageLayout = VK_IMAGE_LAYOUT_GENERAL, + .loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE, + .storeOp = VK_ATTACHMENT_STORE_OP_STORE, + .clearValue = clear_value, + }; + + const VkRect2D render_area = { + .offset = + { + .x = 0, + .y = 0, + }, + .extent = + { + .width = texture->vulkan.width, + .height = texture->vulkan.height, + }, + }; + + const VkRenderingInfo rendering_info = { + .sType = VK_STRUCTURE_TYPE_RENDERING_INFO, + .pNext = NULL, + .flags = 0, + .renderArea = render_area, + .layerCount = 1, + .viewMask = 0, + .colorAttachmentCount = 1, + .pColorAttachments = &color_attachment_info, + .pDepthAttachment = VK_NULL_HANDLE, + .pStencilAttachment = VK_NULL_HANDLE, + }; + + vkCmdBeginRendering(list->vulkan.command_buffer, &rendering_info); +} + +void kope_vulkan_command_list_end_render_pass(kope_g5_command_list *list) { + vkCmdEndRendering(list->vulkan.command_buffer); +} void kope_vulkan_command_list_present(kope_g5_command_list *list) {} @@ -32,7 +89,6 @@ void kope_vulkan_command_list_set_vertex_buffer(kope_g5_command_list *list, uint void kope_vulkan_command_list_set_render_pipeline(kope_g5_command_list *list, kope_vulkan_render_pipeline *pipeline) {} void kope_vulkan_command_list_draw(kope_g5_command_list *list, uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance) { - } void kope_vulkan_command_list_draw_indexed(kope_g5_command_list *list, uint32_t index_count, uint32_t instance_count, uint32_t first_index, int32_t base_vertex, diff --git a/Backends/Graphics5/Vulkan/Sources/kope/vulkan/device.c b/Backends/Graphics5/Vulkan/Sources/kope/vulkan/device.c index 1e884ef48..ab7e62d3c 100644 --- a/Backends/Graphics5/Vulkan/Sources/kope/vulkan/device.c +++ b/Backends/Graphics5/Vulkan/Sources/kope/vulkan/device.c @@ -318,11 +318,7 @@ void kope_vulkan_device_create(kope_g5_device *device, const kope_g5_device_wish .applicationVersion = 0, .pEngineName = "Kope", .engineVersion = 0, -#ifdef KINC_VKRT - .apiVersion = VK_API_VERSION_1_2, -#else - .apiVersion = VK_API_VERSION_1_0, -#endif + .apiVersion = VK_API_VERSION_1_3, }; const VkInstanceCreateInfo instance_create_info = { diff --git a/Backends/Graphics5/Vulkan/Sources/kope/vulkan/texture_structs.h b/Backends/Graphics5/Vulkan/Sources/kope/vulkan/texture_structs.h index ad81a1e20..d685e69ec 100644 --- a/Backends/Graphics5/Vulkan/Sources/kope/vulkan/texture_structs.h +++ b/Backends/Graphics5/Vulkan/Sources/kope/vulkan/texture_structs.h @@ -6,7 +6,9 @@ extern "C" { #endif typedef struct kope_vulkan_texture { - int nothing; + uint32_t width; + uint32_t height; + VkImageView image_view; } kope_vulkan_texture; #ifdef __cplusplus