Skip to main content

ferroui_base/platform/
platform_graphics_external_memory.rs

1/// The description of a GPU image to import.
2#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
3pub struct PlatformGraphicsExternalImageProperties {
4    pub width: i32,
5    pub height: i32,
6    pub format: PlatformGraphicsExternalImageFormat,
7    pub memory_size: u64,
8    pub memory_offset: u64,
9    pub top_left_origin: bool,
10    /// Vulkan-specific properties of the imported image, ignored by other backends.
11    pub vulkan_properties: Option<PlatformGraphicsExternalImageVulkanProperties>,
12    /// dma-buf-specific properties of the imported image.
13    pub dma_buf_properties: Option<PlatformGraphicsExternalImageDmaBufProperties>,
14}
15
16#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
17pub struct PlatformGraphicsExternalImageVulkanProperties {
18    /// The VkImageLayout the underlying memory is currently in.
19    pub layout: i32,
20}
21
22/// Describes the DRM layout of a dma-buf image.
23#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
24pub struct PlatformGraphicsExternalImageDmaBufProperties {
25    /// The DRM_FORMAT_* fourcc of the buffer.
26    pub drm_format: u32,
27    /// The DRM_FORMAT_MOD_* layout modifier of the buffer, or [`DRM_MODIFIER_INVALID`](Self::DRM_MODIFIER_INVALID) for the implicit layout.
28    pub drm_modifier: u64,
29    /// The number of memory planes. When zero, a single plane described by the handle itself and
30    /// [`PlatformGraphicsExternalImageProperties::memory_offset`] is assumed.
31    pub plane_count: i32,
32    /// Per-plane dma-buf file descriptors. When `None`, the handle's file descriptor is used for every plane.
33    pub plane_fds: Option<Vec<i32>>,
34    /// Per-plane row pitches in bytes.
35    pub plane_strides: Option<Vec<u32>>,
36    /// Per-plane byte offsets into the corresponding file descriptor.
37    pub plane_offsets: Option<Vec<u32>>,
38}
39
40impl PlatformGraphicsExternalImageDmaBufProperties {
41    /// The DRM_FORMAT_MOD_INVALID modifier.
42    pub const DRM_MODIFIER_INVALID: u64 = 0x00ff_ffff_ffff_ffff;
43}
44
45#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
46pub enum PlatformGraphicsExternalImageFormat {
47    #[default]
48    R8G8B8A8UNorm,
49    B8G8R8A8UNorm,
50}
51
52/// A DRM fourcc format + modifier pair the GPU backend can import as a
53/// [`KnownPlatformGraphicsExternalImageHandleTypes::DMA_BUF_FILE_DESCRIPTOR`] image.
54/// `format` is a DRM_FORMAT_* fourcc; `modifier` is a
55/// DRM_FORMAT_MOD_* layout ([`PlatformGraphicsExternalImageDmaBufProperties::DRM_MODIFIER_INVALID`]
56/// meaning the implicit, driver-chosen layout).
57#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
58pub struct PlatformGraphicsDrmFormat {
59    pub format: u32,
60    pub modifier: u64,
61}
62
63impl PlatformGraphicsDrmFormat {
64    pub fn new(format: u32, modifier: u64) -> Self {
65        Self { format, modifier }
66    }
67}
68
69/// Describes various GPU memory handle types that are currently supported by the graphics backends
70pub struct KnownPlatformGraphicsExternalImageHandleTypes;
71
72impl KnownPlatformGraphicsExternalImageHandleTypes {
73    /// An DXGI global shared handle returned by IDXGIResource::GetSharedHandle D3D11_RESOURCE_MISC_SHARED or D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX flag.
74    /// The handle does not own the reference to the underlying video memory, so the provider should make sure that the resource is valid until
75    /// the handle has been successfully imported
76    pub const D3D11_TEXTURE_GLOBAL_SHARED_HANDLE: &'static str = "D3D11TextureGlobalSharedHandle";
77    /// A DXGI NT handle returned by IDXGIResource1::CreateSharedHandle for a texture created with D3D11_RESOURCE_MISC_SHARED_NTHANDLE or flag
78    pub const D3D11_TEXTURE_NT_HANDLE: &'static str = "D3D11TextureNtHandle";
79    /// A POSIX file descriptor that's exported by Vulkan using VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT or in a compatible way
80    pub const VULKAN_OPAQUE_POSIX_FILE_DESCRIPTOR: &'static str = "VulkanOpaquePosixFileDescriptor";
81    /// A NT handle that's been exported by Vulkan using VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT or in a compatible way
82    pub const VULKAN_OPAQUE_NT_HANDLE: &'static str = "VulkanOpaqueNtHandle";
83    // A global shared handle that's been exported by Vulkan using VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT or in a compatible way
84    pub const VULKAN_OPAQUE_KMT_HANDLE: &'static str = "VulkanOpaqueKmtHandle";
85    /// A reference to IOSurface
86    pub const IO_SURFACE_REF: &'static str = "IOSurfaceRef";
87    /// A Linux dma-buf file descriptor, imported via EGL_LINUX_DMA_BUF_EXT or VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT.
88    pub const DMA_BUF_FILE_DESCRIPTOR: &'static str = "DmaBufFileDescriptor";
89}
90
91/// Describes various GPU semaphore handle types that are currently supported by the graphics backends
92pub struct KnownPlatformGraphicsExternalSemaphoreHandleTypes;
93
94impl KnownPlatformGraphicsExternalSemaphoreHandleTypes {
95    /// A POSIX file descriptor that's been exported by Vulkan using VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT or in a compatible way
96    pub const VULKAN_OPAQUE_POSIX_FILE_DESCRIPTOR: &'static str = "VulkanOpaquePosixFileDescriptor";
97    /// A NT handle that's been exported by Vulkan using VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT or in a compatible way
98    pub const VULKAN_OPAQUE_NT_HANDLE: &'static str = "VulkanOpaqueNtHandle";
99    // A global shared handle that's been exported by Vulkan using VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT or in a compatible way
100    pub const VULKAN_OPAQUE_KMT_HANDLE: &'static str = "VulkanOpaqueKmtHandle";
101    /// A DXGI NT handle returned by ID3D12Device::CreateSharedHandle or ID3D11Fence::CreateSharedHandle
102    pub const DIRECT3D12_FENCE_NT_HANDLE: &'static str = "Direct3D12FenceNtHandle";
103    /// A pointer to MTLSharedEvent object
104    pub const METAL_SHARED_EVENT: &'static str = "MetalSharedEvent";
105}