Vulkan: Remove exception handler/old swapchain use.

Exceptions are now turned off anyway.
This commit is contained in:
BearOso 2024-06-11 16:06:30 -05:00
parent c7b77d4a76
commit 4f1a2d9c29
1 changed files with 24 additions and 17 deletions

View File

@ -164,11 +164,21 @@ bool Swapchain::create(unsigned int desired_num_swapchain_images, int new_width,
extents.height = surface_capabilities.minImageExtent.height; extents.height = surface_capabilities.minImageExtent.height;
auto present_modes = physical_device.getSurfacePresentModesKHR(surface).value; auto present_modes = physical_device.getSurfacePresentModesKHR(surface).value;
auto tearing_present_mode = vk::PresentModeKHR::eFifo; bool mailbox_supported =
if (std::find(present_modes.begin(), present_modes.end(), vk::PresentModeKHR::eImmediate) != present_modes.end()) std::find(present_modes.begin(), present_modes.end(),
tearing_present_mode = vk::PresentModeKHR::eImmediate; vk::PresentModeKHR::eMailbox) != present_modes.end();
if (std::find(present_modes.begin(), present_modes.end(), vk::PresentModeKHR::eMailbox) != present_modes.end()) bool immediate_supported =
tearing_present_mode = vk::PresentModeKHR::eMailbox; std::find(present_modes.begin(), present_modes.end(),
vk::PresentModeKHR::eImmediate) != present_modes.end();
vk::PresentModeKHR present_mode = vk::PresentModeKHR::eFifo;
if (mailbox_supported)
present_mode = vk::PresentModeKHR::eMailbox;
if (!vsync && immediate_supported)
present_mode = vk::PresentModeKHR::eImmediate;
if (present_mode == vk::PresentModeKHR::eMailbox)
num_swapchain_images++;
auto swapchain_create_info = vk::SwapchainCreateInfoKHR{} auto swapchain_create_info = vk::SwapchainCreateInfoKHR{}
.setMinImageCount(num_swapchain_images) .setMinImageCount(num_swapchain_images)
@ -179,23 +189,20 @@ bool Swapchain::create(unsigned int desired_num_swapchain_images, int new_width,
.setImageUsage(vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc) .setImageUsage(vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eTransferSrc)
.setCompositeAlpha(vk::CompositeAlphaFlagBitsKHR::eOpaque) .setCompositeAlpha(vk::CompositeAlphaFlagBitsKHR::eOpaque)
.setClipped(true) .setClipped(true)
.setPresentMode(vsync ? vk::PresentModeKHR::eFifo : tearing_present_mode) .setPresentMode(present_mode)
.setSurface(surface) .setSurface(surface)
.setPreTransform(vk::SurfaceTransformFlagBitsKHR::eIdentity) .setPreTransform(vk::SurfaceTransformFlagBitsKHR::eIdentity)
.setImageArrayLayers(1) .setImageArrayLayers(1)
.setQueueFamilyIndices(graphics_queue_index); .setQueueFamilyIndices(graphics_queue_index);
if (swapchain_object)
swapchain_create_info.setOldSwapchain(swapchain_object.get());
try {
swapchain_object = device.createSwapchainKHRUnique(swapchain_create_info).value;
} catch (std::exception &e) {
swapchain_object.reset(); swapchain_object.reset();
} auto resval = device.createSwapchainKHRUnique(swapchain_create_info);
if (resval.result != vk::Result::eSuccess && resval.result != vk::Result::eSuboptimalKHR)
if (!swapchain_object) {
swapchain_object.reset();
return false; return false;
}
swapchain_object = std::move(resval.value);
auto swapchain_images = device.getSwapchainImagesKHR(swapchain_object.get()).value; auto swapchain_images = device.getSwapchainImagesKHR(swapchain_object.get()).value;
vk::CommandBufferAllocateInfo command_buffer_allocate_info(command_pool, vk::CommandBufferLevel::ePrimary, swapchain_images.size()); vk::CommandBufferAllocateInfo command_buffer_allocate_info(command_pool, vk::CommandBufferLevel::ePrimary, swapchain_images.size());