Skip to main content

ferroui_vulkan/
i_vulkan_context_external_objects_feature.rs

1use crate::VulkanImageInfo;
2use ferroui_base::platform::{IPlatformHandle, PlatformGraphicsExternalImageProperties};
3use ferroui_base::rendering::composition::CompositionGpuImportedImageSynchronizationCapabilities;
4use std::rc::Rc;
5
6/// Lets a Vulkan context import images and semaphores that were created
7/// outside of it (by another device or another process).
8///
9/// A graphics context that is a Vulkan context announces the feature through
10/// its optional features: `try_get_feature(TypeId::of::<dyn
11/// IVulkanContextExternalObjectsFeature>())` returns an `Rc<dyn
12/// IVulkanContextExternalObjectsFeature>`.
13///
14/// This API is unstable.
15pub trait IVulkanContextExternalObjectsFeature {
16    /// The kinds of image handles the device can import.
17    fn supported_image_handle_types(&self) -> Vec<String>;
18
19    /// The kinds of semaphore handles the device can import.
20    fn supported_semaphore_types(&self) -> Vec<String>;
21
22    /// The universally unique identifier of the device, when it has one.
23    fn device_uuid(&self) -> Option<Vec<u8>>;
24
25    /// The locally unique identifier of the device, when it has one.
26    fn device_luid(&self) -> Option<Vec<u8>>;
27
28    /// How access to an imported image of the given handle type can be
29    /// synchronized.
30    ///
31    /// # Panics
32    /// Panics when the handle type is not one of
33    /// [`supported_image_handle_types`](Self::supported_image_handle_types).
34    fn get_synchronization_capabilities(
35        &self,
36        image_handle_type: &str,
37    ) -> CompositionGpuImportedImageSynchronizationCapabilities;
38
39    /// Imports an image.
40    ///
41    /// # Panics
42    /// Panics when the kind of the handle is not supported, and when the
43    /// device refuses the image.
44    fn import_image(
45        &self,
46        handle: Rc<dyn IPlatformHandle>,
47        properties: PlatformGraphicsExternalImageProperties,
48    ) -> Rc<dyn IVulkanExternalImage>;
49
50    /// Imports a semaphore.
51    ///
52    /// # Panics
53    /// Panics when the kind of the handle is not supported, and when the
54    /// device refuses the semaphore.
55    fn import_semaphore(&self, handle: Rc<dyn IPlatformHandle>) -> Rc<dyn IVulkanExternalSemaphore>;
56}
57
58/// A semaphore of a Vulkan device that was imported from a handle.
59///
60/// This API is unstable.
61pub trait IVulkanExternalSemaphore {
62    /// The `VkSemaphore`.
63    ///
64    /// # Panics
65    /// Panics when the semaphore has been disposed.
66    fn handle(&self) -> u64;
67
68    /// Submits an empty batch of commands that waits for the semaphore.
69    fn submit_wait_semaphore(&self);
70
71    /// Submits an empty batch of commands that signals the semaphore.
72    fn submit_signal_semaphore(&self);
73
74    /// Destroys the semaphore.
75    fn dispose(&self);
76}
77
78/// An image of a Vulkan device that was imported from an external image.
79///
80/// This API is unstable.
81pub trait IVulkanExternalImage {
82    /// The image.
83    fn info(&self) -> VulkanImageInfo;
84
85    /// Destroys the image and frees its memory.
86    fn dispose(&self);
87}