Skip to main content

maplibre_native_ffi/generated/
vulkan_device.rs

1// Generated from C headers by tools/bindgen. Do not edit.
2use super::*;
3
4native_owner! {
5    /// Owns one native handle.
6    ///
7    /// A Vulkan instance, device, and queue that the library creates and owns.
8    ///
9    /// See `mln_vulkan_device` in the
10    /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/base_8h.html).
11    pub struct VulkanDeviceHandle(mln_vulkan_device) dispose |raw| { unsafe { sys::mln_vulkan_device_release(raw) }; Ok(()) };
12    /// Returns the native handle value.
13    fn id;
14}
15
16impl VulkanDeviceHandle {
17    /// Creates a Vulkan instance, device, and graphics queue for render
18    /// sessions.
19    ///
20    /// Attach sessions with the context from
21    /// `VulkanDeviceHandle::get_context()`, in place of a device of your own.
22    /// Without `device_uuid` or `device_luid`, it prefers a discrete GPU. The
23    /// device enables the external memory and semaphore extensions that the GPU
24    /// offers.
25    ///
26    /// See `mln_vulkan_device_create` in the
27    /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/vulkan_8h.html).
28    ///
29    /// # Errors
30    ///
31    /// - `Status::Unsupported` when `supported_render_backend_mask()` lacks
32    ///   `RenderBackendFlag::VULKAN`, or when `presentation` is true and the
33    ///   Vulkan loader or the GPU can't present.
34    /// - `Status::NotFound` when no GPU matches `device_uuid` and
35    ///   `device_luid`.
36    /// - `Status::NativeError` when there is no Vulkan loader, no GPU has a
37    ///   graphics queue, or Vulkan can't create the instance or the device.
38    #[cfg(any(
39        target_os = "android",
40        target_os = "freebsd",
41        target_os = "linux",
42        target_os = "macos",
43        target_os = "windows"
44    ))]
45    pub fn create(options: Option<&VulkanDeviceOptions<'_>>) -> Result<VulkanDeviceHandle> {
46        let mut call = Call::global();
47        crate::abi::validate_abi_version()?;
48        let mut out_device = sys::mln_vulkan_device(0);
49        let options = call.optional_reference(options.as_ref())?;
50        call.status(|_, out_diagnostic| unsafe {
51            sys::mln_vulkan_device_create(options, &mut out_device, out_diagnostic)
52        })?;
53        Ok(VulkanDeviceHandle::adopt(out_device)?)
54    }
55
56    /// Gets the context to attach render sessions to the device with.
57    ///
58    /// Pass it as the context of `MapHandle::attach_vulkan_surface()` or
59    /// `MapHandle::attach_vulkan_borrowed_texture()`. The sessions on the
60    /// device share its graphics queue. To submit to the queue yourself, set
61    /// `RenderSessionAttachOptions::queue_lock` on each session.
62    ///
63    /// See `mln_vulkan_device_get_context` in the
64    /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/vulkan_8h.html).
65    #[cfg(any(
66        target_os = "android",
67        target_os = "freebsd",
68        target_os = "linux",
69        target_os = "macos",
70        target_os = "windows"
71    ))]
72    pub fn get_context(&self) -> Result<VulkanDeviceContextResult> {
73        let mut call = self.inner.call();
74        let mut out_result: sys::mln_vulkan_device_context_result = unsafe { std::mem::zeroed() };
75        out_result.size = std::mem::size_of::<sys::mln_vulkan_device_context_result>() as _;
76        call.status(|device, out_diagnostic| unsafe {
77            sys::mln_vulkan_device_get_context(device, &mut out_result, out_diagnostic)
78        })?;
79        Ok(unsafe { from_native(out_result) }?)
80    }
81
82    /// Releases a Vulkan device.
83    ///
84    /// Render sessions that attached with the device's context keep using it
85    /// until they detach or their release finishes.
86    ///
87    /// See `mln_vulkan_device_release` in the
88    /// [C API reference](https://maplibre.org/maplibre-native-ffi/reference/c/vulkan_8h.html).
89    pub fn release(self) -> std::result::Result<(), ReleaseError<Self>> {
90        self.consume(|device| {
91            let mut call = Call::new(device);
92            call.run(|device| unsafe { sys::mln_vulkan_device_release(device) });
93            Ok(())
94        })
95    }
96}