Broken: Fixed crash, but a race condition in SDL results in VUID violation

SDL2 does not finish resizing the surface before it emits
WindowEvent::Resized. This means that I cannot actually properly
implement resizing.
pull/1/head
itycodes 2 weeks ago
parent ce697661ae
commit 8c2d55b1c9

@ -533,15 +533,15 @@ fn setup_swapchain(
surface_loader: &surface::Instance, surface_loader: &surface::Instance,
swapchain_loader: &ash::khr::swapchain::Device, swapchain_loader: &ash::khr::swapchain::Device,
instance: &Instance, instance: &Instance,
) -> vk::SwapchainKHR { width: u32,
height: u32,
) -> (vk::SwapchainKHR, vk::Extent2D) {
let caps = unsafe { let caps = unsafe {
surface_loader surface_loader
.get_physical_device_surface_capabilities(*pdev, *surface) .get_physical_device_surface_capabilities(*pdev, *surface)
.expect("Failed to get surface capabilities") .expect("Failed to get surface capabilities")
}; };
println!("Extents: {:?}", caps.current_extent);
let formats = unsafe { let formats = unsafe {
surface_loader surface_loader
.get_physical_device_surface_formats(*pdev, *surface) .get_physical_device_surface_formats(*pdev, *surface)
@ -557,12 +557,20 @@ fn setup_swapchain(
.next() .next()
.expect("No suitable format found"); .expect("No suitable format found");
// When the window is resized fast, then the caps goes out of sync of the target extents
// Thus we are using the passed-in (target) extents instead of the cap extents.
// assert_eq!(caps.current_extent.width, width);
// assert_eq!(caps.current_extent.height, height);
let swap_create = vk::SwapchainCreateInfoKHR::default() let swap_create = vk::SwapchainCreateInfoKHR::default()
.surface(*surface) .surface(*surface)
.min_image_count(caps.min_image_count) .min_image_count(caps.min_image_count)
.image_format(format.format) .image_format(format.format)
.image_color_space(format.color_space) .image_color_space(format.color_space)
.image_extent(caps.current_extent) .image_extent(vk::Extent2D {
width: std::cmp::max(caps.current_extent.width, width),
height: std::cmp::max(caps.current_extent.height, height),
})
.image_array_layers(1) .image_array_layers(1)
.image_usage(vk::ImageUsageFlags::COLOR_ATTACHMENT) .image_usage(vk::ImageUsageFlags::COLOR_ATTACHMENT)
.image_sharing_mode(vk::SharingMode::EXCLUSIVE) .image_sharing_mode(vk::SharingMode::EXCLUSIVE)
@ -577,7 +585,7 @@ fn setup_swapchain(
.expect("Failed to create swapchain") .expect("Failed to create swapchain")
}; };
println!("Created swapchain"); println!("Created swapchain");
swapchain (swapchain, caps.current_extent)
} }
fn setup_desc_pool(dev: &Device) -> vk::DescriptorPool { fn setup_desc_pool(dev: &Device) -> vk::DescriptorPool {
@ -1093,13 +1101,15 @@ fn main() {
let surface_loader = surface::Instance::new(&entry, &instance); let surface_loader = surface::Instance::new(&entry, &instance);
let swapchain_loader = swapchain::Device::new(&instance, &dev); let swapchain_loader = swapchain::Device::new(&instance, &dev);
let mut swapchain = setup_swapchain( let (mut swapchain, mut extents) = setup_swapchain(
&pdev, &pdev,
&dev, &dev,
&surface, &surface,
&surface_loader, &surface_loader,
&swapchain_loader, &swapchain_loader,
&instance, &instance,
width,
height,
); );
let desc_pool = setup_desc_pool(&dev); let desc_pool = setup_desc_pool(&dev);
@ -1145,13 +1155,19 @@ fn main() {
} => { } => {
width = w as u32; width = w as u32;
height = h as u32; height = h as u32;
swapchain = setup_swapchain( unsafe {
dev.device_wait_idle().expect("Failed to wait for device idle");
swapchain_loader.destroy_swapchain(swapchain, None);
}
(swapchain, extents) = setup_swapchain(
&pdev, &pdev,
&dev, &dev,
&surface, &surface,
&surface_loader, &surface_loader,
&swapchain_loader, &swapchain_loader,
&instance, &instance,
width,
height,
); );
swap_images = make_swap_images(&dev, &swapchain, &swapchain_loader); swap_images = make_swap_images(&dev, &swapchain, &swapchain_loader);
swap_views = make_swap_views(&dev, &swap_images, vk::Format::B8G8R8A8_UNORM); swap_views = make_swap_views(&dev, &swap_images, vk::Format::B8G8R8A8_UNORM);

Loading…
Cancel
Save