|
|
|
@ -1,13 +1,7 @@
|
|
|
|
|
use ash::vk; |
|
|
|
|
use crate::render::{ |
|
|
|
|
Conf, |
|
|
|
|
Device, |
|
|
|
|
Image, |
|
|
|
|
Instance, |
|
|
|
|
PhysicalDevice, |
|
|
|
|
QueueFamilyInfo, |
|
|
|
|
Surface |
|
|
|
|
Conf, Device, Image, Instance, PhysicalDevice, QueueFamilyInfo, Surface, |
|
|
|
|
}; |
|
|
|
|
use ash::vk; |
|
|
|
|
|
|
|
|
|
pub struct Swapchain<'a, 'b> { |
|
|
|
|
device: &'a Device<'b>, |
|
|
|
@ -27,9 +21,10 @@ impl<'a, 'b> Swapchain<'a, 'b> {
|
|
|
|
|
qf_info: &QueueFamilyInfo, |
|
|
|
|
) -> Result<Self, vk::Result> { |
|
|
|
|
let capabilities = unsafe { |
|
|
|
|
instance |
|
|
|
|
.surface_ext |
|
|
|
|
.get_physical_device_surface_capabilities(**phys_device, **surface)? |
|
|
|
|
instance.surface_ext.get_physical_device_surface_capabilities( |
|
|
|
|
**phys_device, |
|
|
|
|
**surface, |
|
|
|
|
)? |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let formats = unsafe { |
|
|
|
@ -39,12 +34,10 @@ impl<'a, 'b> Swapchain<'a, 'b> {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let modes = unsafe { |
|
|
|
|
instance |
|
|
|
|
.surface_ext |
|
|
|
|
.get_physical_device_surface_present_modes( |
|
|
|
|
**phys_device, |
|
|
|
|
**surface, |
|
|
|
|
)? |
|
|
|
|
instance.surface_ext.get_physical_device_surface_present_modes( |
|
|
|
|
**phys_device, |
|
|
|
|
**surface, |
|
|
|
|
)? |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let extent = |
|
|
|
@ -52,33 +45,29 @@ impl<'a, 'b> Swapchain<'a, 'b> {
|
|
|
|
|
capabilities.current_extent |
|
|
|
|
} else { |
|
|
|
|
vk::Extent2D { |
|
|
|
|
width: |
|
|
|
|
capabilities |
|
|
|
|
.min_image_extent |
|
|
|
|
.width |
|
|
|
|
.max(capabilities.max_image_extent.width), |
|
|
|
|
height: |
|
|
|
|
capabilities |
|
|
|
|
.min_image_extent |
|
|
|
|
.height |
|
|
|
|
.max(capabilities.max_image_extent.height), |
|
|
|
|
width: capabilities |
|
|
|
|
.min_image_extent |
|
|
|
|
.width |
|
|
|
|
.max(capabilities.max_image_extent.width), |
|
|
|
|
height: capabilities |
|
|
|
|
.min_image_extent |
|
|
|
|
.height |
|
|
|
|
.max(capabilities.max_image_extent.height), |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let format = |
|
|
|
|
*formats |
|
|
|
|
.iter() |
|
|
|
|
.find(|format| { |
|
|
|
|
format.format == vk::Format::B8G8R8A8_UNORM && |
|
|
|
|
format.color_space == vk::ColorSpaceKHR::SRGB_NONLINEAR |
|
|
|
|
}) |
|
|
|
|
.unwrap_or_else(|| &formats[0]); |
|
|
|
|
|
|
|
|
|
let mode = |
|
|
|
|
*modes |
|
|
|
|
.iter() |
|
|
|
|
.find(|&&mode| mode == conf.swap_mode.into()) |
|
|
|
|
.unwrap_or_else(|| &vk::PresentModeKHR::FIFO); |
|
|
|
|
let format = *formats |
|
|
|
|
.iter() |
|
|
|
|
.find(|format| { |
|
|
|
|
format.format == vk::Format::B8G8R8A8_UNORM && |
|
|
|
|
format.color_space == vk::ColorSpaceKHR::SRGB_NONLINEAR |
|
|
|
|
}) |
|
|
|
|
.unwrap_or_else(|| &formats[0]); |
|
|
|
|
|
|
|
|
|
let mode = *modes |
|
|
|
|
.iter() |
|
|
|
|
.find(|&&mode| mode == conf.swap_mode.into()) |
|
|
|
|
.unwrap_or_else(|| &vk::PresentModeKHR::FIFO); |
|
|
|
|
|
|
|
|
|
let min_image_count = capabilities.min_image_count + 1; |
|
|
|
|
|
|
|
|
@ -115,9 +104,8 @@ impl<'a, 'b> Swapchain<'a, 'b> {
|
|
|
|
|
..Default::default() |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
let handle = unsafe { |
|
|
|
|
device.swapchain_ext.create_swapchain(&create_info, None)? |
|
|
|
|
}; |
|
|
|
|
let handle = |
|
|
|
|
unsafe { device.swapchain_ext.create_swapchain(&create_info, None)? }; |
|
|
|
|
|
|
|
|
|
Ok(Self { device, handle, format: format.format, extent }) |
|
|
|
|
} |
|
|
|
@ -135,13 +123,17 @@ impl<'a, 'b> Swapchain<'a, 'b> {
|
|
|
|
|
|
|
|
|
|
impl Drop for Swapchain<'_, '_> { |
|
|
|
|
fn drop(&mut self) { |
|
|
|
|
unsafe { self.device.swapchain_ext.destroy_swapchain(self.handle, None); } |
|
|
|
|
unsafe { |
|
|
|
|
self.device.swapchain_ext.destroy_swapchain(self.handle, None); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl std::ops::Deref for Swapchain<'_, '_> { |
|
|
|
|
type Target = vk::SwapchainKHR; |
|
|
|
|
fn deref(&self) -> &Self::Target { &self.handle } |
|
|
|
|
fn deref(&self) -> &Self::Target { |
|
|
|
|
&self.handle |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// EOF
|
|
|
|
|