diff --git a/graphics/src/vulkan_base.c b/graphics/src/vulkan_base.c index b03dd719..7cbc461f 100644 --- a/graphics/src/vulkan_base.c +++ b/graphics/src/vulkan_base.c @@ -608,7 +608,7 @@ rse_err_t vulkan_draw_frame(struct graphics_context_t* context) submit_info.commandBufferCount = 1; submit_info.pCommandBuffers = &context->vulkan_handles.command_buffers[context->current_frame]; - signal_semaphores[0] = context->vulkan_handles.render_finished_semaphores[context->current_frame]; + signal_semaphores[0] = context->vulkan_handles.render_finished_semaphores[image_index]; submit_info.signalSemaphoreCount = 1; submit_info.pSignalSemaphores = signal_semaphores; @@ -620,7 +620,7 @@ rse_err_t vulkan_draw_frame(struct graphics_context_t* context) present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; present_info.waitSemaphoreCount = 1; - present_info.pWaitSemaphores = &context->vulkan_handles.render_finished_semaphores[context->current_frame]; + present_info.pWaitSemaphores = &context->vulkan_handles.render_finished_semaphores[image_index]; swap_chains[0] = context->swapchain_data.swapchain; present_info.swapchainCount = 1; diff --git a/graphics/src/vulkan_image.c b/graphics/src/vulkan_image.c index da8b983c..acbf49dd 100644 --- a/graphics/src/vulkan_image.c +++ b/graphics/src/vulkan_image.c @@ -3,6 +3,7 @@ #include #include +#include "SDL3/SDL_video.h" #include "src/graphics_context.h" #include "utilities/commons.h" #include "utilities/errors_common.h" @@ -168,16 +169,14 @@ rse_err_t create_color_resource(struct graphics_context_t* context) { rse_err_t status = RSE_ERROR_NO_ERROR; VkFormat color_format = IMAGE_FORMAT; - VkSurfaceCapabilitiesKHR physical_device_surface_capabilities; + VkExtent2D extent = {0}; - vkGetPhysicalDeviceSurfaceCapabilitiesKHR(context->vulkan_handles.physical_device, - context->vulkan_handles.surface, - &physical_device_surface_capabilities); + STATUS_CHECK(image_get_extent(context, &extent)); STATUS_CHECK(create_image(context, &context->color_image, - physical_device_surface_capabilities.currentExtent.width, - physical_device_surface_capabilities.currentExtent.height, + extent.width, + extent.height, color_format, VK_SAMPLE_COUNT_8_BIT, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, @@ -191,17 +190,16 @@ rse_err_t create_depth_resources(struct graphics_context_t* context) { rse_err_t status = RSE_ERROR_NO_ERROR; VkFormat depth_format = {0}; - VkSurfaceCapabilitiesKHR physical_device_surface_capabilities; + VkExtent2D extent = {0}; + + STATUS_CHECK(image_get_extent(context, &extent)); STATUS_CHECK(find_depth_format(context, &depth_format)); - vkGetPhysicalDeviceSurfaceCapabilitiesKHR(context->vulkan_handles.physical_device, - context->vulkan_handles.surface, - &physical_device_surface_capabilities); STATUS_CHECK(create_image(context, &context->depth_image, - physical_device_surface_capabilities.currentExtent.width, - physical_device_surface_capabilities.currentExtent.height, + extent.width, + extent.height, depth_format, VK_SAMPLE_COUNT_8_BIT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, @@ -407,6 +405,33 @@ rse_err_t init_vulkan_images(struct graphics_context_t* context) return status; } +rse_err_t image_get_extent(struct graphics_context_t* context, VkExtent2D* extent) +{ + VkSurfaceCapabilitiesKHR physical_device_surface_capabilities; + int w = 0; + int h = 0; + + if (extent == NULL) { + SDL_LogCritical(SDL_LOG_CATEGORY_GPU, "Provided extent pointer is NULL"); + + return RSE_ERROR_NULL_POINTER; + } + + vkGetPhysicalDeviceSurfaceCapabilitiesKHR(context->vulkan_handles.physical_device, + context->vulkan_handles.surface, + &physical_device_surface_capabilities); + + if (physical_device_surface_capabilities.currentExtent.width != UINT32_MAX) { + *extent = physical_device_surface_capabilities.currentExtent; + } else { + SDL_GetWindowSize(context->window_handle, &w, &h); + extent->width = w; + extent->height = h; + } + + return RSE_ERROR_NO_ERROR; +} + rse_err_t texture_update_image(struct graphics_context_t* context, const unsigned char* pixels, int width, diff --git a/graphics/src/vulkan_image.h b/graphics/src/vulkan_image.h index 2d7b0ac3..68e2265c 100644 --- a/graphics/src/vulkan_image.h +++ b/graphics/src/vulkan_image.h @@ -29,6 +29,8 @@ */ rse_err_t init_vulkan_images(struct graphics_context_t* context); +rse_err_t image_get_extent(struct graphics_context_t* context, VkExtent2D* extent); + /** * @brief Loads image from file, for later to be used as a texture * diff --git a/graphics/src/vulkan_swapchain.c b/graphics/src/vulkan_swapchain.c index d586491b..f67b8b99 100644 --- a/graphics/src/vulkan_swapchain.c +++ b/graphics/src/vulkan_swapchain.c @@ -21,14 +21,18 @@ static rse_err_t create_swapchain(struct graphics_context_t* context) { VkSwapchainCreateInfoKHR create_info; VkSurfaceCapabilitiesKHR physical_device_surface_capabilities; + rse_err_t status = RSE_ERROR_NO_ERROR; VkBool32 surfaceSupported; + VkExtent2D extent = {0}; vkGetPhysicalDeviceSurfaceCapabilitiesKHR(context->vulkan_handles.physical_device, context->vulkan_handles.surface, &physical_device_surface_capabilities); + STATUS_CHECK(image_get_extent(context, &extent)); + /* Store extent in global variable, for later use */ - context->swapchain_data.swapchain_extent = physical_device_surface_capabilities.currentExtent; + context->swapchain_data.swapchain_extent = extent; /* Check if device supports surface for presentation */ vkGetPhysicalDeviceSurfaceSupportKHR(context->vulkan_handles.physical_device,