main
noah metz 2024-01-13 11:17:26 -07:00
parent f4ed0ad0ac
commit e1cde5c8bb
1 changed files with 25 additions and 34 deletions

@ -691,47 +691,42 @@ VkResult create_logical_device(VkPhysicalDevice physical_device, QueueIndices qu
return VK_SUCCESS;
}
SwapchainDetails get_swapchain_details(VkPhysicalDevice physical_device, VkSurfaceKHR surface) {
SwapchainDetails details = {};
details.formats = 0;
details.present_modes = 0;
VkResult get_swapchain_details(VkPhysicalDevice physical_device, VkSurfaceKHR surface, SwapchainDetails* details) {
details->formats = 0;
details->present_modes = 0;
VkResult result;
result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, surface, &details.capabilities);
result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, surface, &details->capabilities);
if(result != VK_SUCCESS) {
return details;
return result;
}
result = vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &details.formats_count, 0);
result = vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &details->formats_count, 0);
if(result != VK_SUCCESS) {
return details;
return result;
}
details.formats = malloc(sizeof(VkSurfaceFormatKHR)*details.formats_count);
result = vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &details.formats_count, details.formats);
details->formats = malloc(sizeof(VkSurfaceFormatKHR)*details->formats_count);
result = vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &details->formats_count, details->formats);
if(result != VK_SUCCESS) {
free(details.formats);
details.formats = 0;
return details;
free(details->formats);
return result;
}
result = vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &details.present_modes_count, 0);
result = vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &details->present_modes_count, 0);
if(result != VK_SUCCESS) {
free(details.formats);
details.formats = 0;
return details;
free(details->formats);
return result;
}
details.present_modes = malloc(sizeof(VkPresentModeKHR)*details.present_modes_count);
result = vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &details.present_modes_count, details.present_modes);
details->present_modes = malloc(sizeof(VkPresentModeKHR)*details->present_modes_count);
result = vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &details->present_modes_count, details->present_modes);
if(result != VK_SUCCESS) {
free(details.formats);
free(details.present_modes);
details.formats = 0;
details.present_modes = 0;
return details;
free(details->formats);
free(details->present_modes);
return result;
}
return details;
return VK_SUCCESS;
}
VkSurfaceFormatKHR choose_swapchain_format(SwapchainDetails swapchain_details) {
@ -1510,11 +1505,9 @@ VkResult recreate_swapchain(VulkanContext* context) {
vkDestroyImage(context->device, context->depth_image, 0);
vkFreeMemory(context->device, context->depth_image_memory, 0);
SwapchainDetails swapchain_details = get_swapchain_details(context->physical_device, context->surface);
if(swapchain_details.formats == 0) {
return VK_ERROR_INITIALIZATION_FAILED;
} else {
context->swapchain_details = swapchain_details;
VkResult result = get_swapchain_details(context->physical_device, context->surface, &context->swapchain_details);
if(result != VK_SUCCESS) {
return result;
}
context->swapchain_format = choose_swapchain_format(context->swapchain_details);
@ -2224,12 +2217,10 @@ VulkanContext* init_vulkan(GLFWwindow* window, uint32_t max_frames_in_flight) {
vkGetDeviceQueue(context->device, context->queue_indices.present_family, context->queue_indices.present_index, &context->queues.present);
vkGetDeviceQueue(context->device, context->queue_indices.transfer_family, context->queue_indices.transfer_index, &context->queues.transfer);
SwapchainDetails swapchain_details = get_swapchain_details(context->physical_device, context->surface);
if(swapchain_details.formats == 0) {
result = get_swapchain_details(context->physical_device, context->surface, &context->swapchain_details);
if(result != VK_SUCCESS) {
fprintf(stderr, "failed to create vulkan logical device\n");
return 0;
} else {
context->swapchain_details = swapchain_details;
}
context->swapchain_format = choose_swapchain_format(context->swapchain_details);