|
|
@ -691,47 +691,42 @@ VkResult create_logical_device(VkPhysicalDevice physical_device, QueueIndices qu
|
|
|
|
return VK_SUCCESS;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SwapchainDetails get_swapchain_details(VkPhysicalDevice physical_device, VkSurfaceKHR surface) {
|
|
|
|
VkResult get_swapchain_details(VkPhysicalDevice physical_device, VkSurfaceKHR surface, SwapchainDetails* details) {
|
|
|
|
SwapchainDetails details = {};
|
|
|
|
details->formats = 0;
|
|
|
|
details.formats = 0;
|
|
|
|
details->present_modes = 0;
|
|
|
|
details.present_modes = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VkResult result;
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
|
|
result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, surface, &details.capabilities);
|
|
|
|
result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, surface, &details->capabilities);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
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) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return details;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
details.formats = malloc(sizeof(VkSurfaceFormatKHR)*details.formats_count);
|
|
|
|
details->formats = malloc(sizeof(VkSurfaceFormatKHR)*details->formats_count);
|
|
|
|
result = vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &details.formats_count, details.formats);
|
|
|
|
result = vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &details->formats_count, details->formats);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
free(details.formats);
|
|
|
|
free(details->formats);
|
|
|
|
details.formats = 0;
|
|
|
|
return result;
|
|
|
|
return details;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result = vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &details.present_modes_count, 0);
|
|
|
|
result = vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &details->present_modes_count, 0);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
free(details.formats);
|
|
|
|
free(details->formats);
|
|
|
|
details.formats = 0;
|
|
|
|
return result;
|
|
|
|
return details;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
details.present_modes = malloc(sizeof(VkPresentModeKHR)*details.present_modes_count);
|
|
|
|
details->present_modes = malloc(sizeof(VkPresentModeKHR)*details->present_modes_count);
|
|
|
|
result = vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &details.present_modes_count, details.present_modes);
|
|
|
|
result = vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &details->present_modes_count, details->present_modes);
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
free(details.formats);
|
|
|
|
free(details->formats);
|
|
|
|
free(details.present_modes);
|
|
|
|
free(details->present_modes);
|
|
|
|
details.formats = 0;
|
|
|
|
return result;
|
|
|
|
details.present_modes = 0;
|
|
|
|
|
|
|
|
return details;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return details;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
VkSurfaceFormatKHR choose_swapchain_format(SwapchainDetails swapchain_details) {
|
|
|
|
VkSurfaceFormatKHR choose_swapchain_format(SwapchainDetails swapchain_details) {
|
|
|
@ -1510,11 +1505,9 @@ VkResult recreate_swapchain(VulkanContext* context) {
|
|
|
|
vkDestroyImage(context->device, context->depth_image, 0);
|
|
|
|
vkDestroyImage(context->device, context->depth_image, 0);
|
|
|
|
vkFreeMemory(context->device, context->depth_image_memory, 0);
|
|
|
|
vkFreeMemory(context->device, context->depth_image_memory, 0);
|
|
|
|
|
|
|
|
|
|
|
|
SwapchainDetails swapchain_details = get_swapchain_details(context->physical_device, context->surface);
|
|
|
|
VkResult result = get_swapchain_details(context->physical_device, context->surface, &context->swapchain_details);
|
|
|
|
if(swapchain_details.formats == 0) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
return VK_ERROR_INITIALIZATION_FAILED;
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
context->swapchain_details = swapchain_details;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
context->swapchain_format = choose_swapchain_format(context->swapchain_details);
|
|
|
|
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.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);
|
|
|
|
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);
|
|
|
|
result = get_swapchain_details(context->physical_device, context->surface, &context->swapchain_details);
|
|
|
|
if(swapchain_details.formats == 0) {
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
fprintf(stderr, "failed to create vulkan logical device\n");
|
|
|
|
fprintf(stderr, "failed to create vulkan logical device\n");
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
context->swapchain_details = swapchain_details;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
context->swapchain_format = choose_swapchain_format(context->swapchain_details);
|
|
|
|
context->swapchain_format = choose_swapchain_format(context->swapchain_details);
|
|
|
|