ash/extensions/khr/
display_swapchain.rs

1use crate::prelude::*;
2use crate::vk;
3use crate::RawPtr;
4use crate::{Device, Instance};
5use std::ffi::CStr;
6use std::mem;
7
8#[derive(Clone)]
9pub struct DisplaySwapchain {
10    handle: vk::Device,
11    fp: vk::KhrDisplaySwapchainFn,
12}
13
14impl DisplaySwapchain {
15    pub fn new(instance: &Instance, device: &Device) -> Self {
16        let handle = device.handle();
17        let fp = vk::KhrDisplaySwapchainFn::load(|name| unsafe {
18            mem::transmute(instance.get_device_proc_addr(handle, name.as_ptr()))
19        });
20        Self { handle, fp }
21    }
22
23    /// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkCreateSharedSwapchainsKHR.html>
24    #[inline]
25    pub unsafe fn create_shared_swapchains(
26        &self,
27        create_infos: &[vk::SwapchainCreateInfoKHR],
28        allocation_callbacks: Option<&vk::AllocationCallbacks>,
29    ) -> VkResult<Vec<vk::SwapchainKHR>> {
30        let mut swapchains = Vec::with_capacity(create_infos.len());
31        (self.fp.create_shared_swapchains_khr)(
32            self.handle,
33            create_infos.len() as u32,
34            create_infos.as_ptr(),
35            allocation_callbacks.as_raw_ptr(),
36            swapchains.as_mut_ptr(),
37        )
38        .result()?;
39        swapchains.set_len(create_infos.len());
40        Ok(swapchains)
41    }
42
43    #[inline]
44    pub const fn name() -> &'static CStr {
45        vk::KhrDisplaySwapchainFn::name()
46    }
47
48    #[inline]
49    pub fn fp(&self) -> &vk::KhrDisplaySwapchainFn {
50        &self.fp
51    }
52
53    #[inline]
54    pub fn device(&self) -> vk::Device {
55        self.handle
56    }
57}