drm/control/
syncobj.rs

1//! # SyncObj
2//!
3//! A SyncObj is a binding point for the DRM subsystem to attach single-use fences which are
4//! signalled when a device task completes. They are typically provided as optional arguments to
5//! device-specific command submission IOCTLs. In practice, they are used to implement Vulkan
6//! fence objects.
7//!
8//! After a submission IOCTL sets a fence into a SyncObj, it may be exported as a sync file
9//! descriptor. This sync file may be epoll()'d for EPOLLIN to implement asynchronous waiting on
10//! multiple events. This file descriptor is also compatible with [`tokio::io::unix::AsyncFd`] for
11//! Rust async/await integration.
12//!
13//! [`tokio::io::unix::AsyncFd`]: <https://docs.rs/tokio/latest/tokio/io/unix/struct.AsyncFd.html>
14
15use crate::control;
16
17/// A handle to a specific syncobj
18#[repr(transparent)]
19#[derive(Copy, Clone, Hash, PartialEq, Eq)]
20pub struct Handle(control::RawResourceHandle);
21
22// Safety: Handle is repr(transparent) over NonZeroU32
23unsafe impl bytemuck::ZeroableInOption for Handle {}
24unsafe impl bytemuck::PodInOption for Handle {}
25unsafe impl bytemuck::NoUninit for Handle {}
26
27impl From<Handle> for control::RawResourceHandle {
28    fn from(handle: Handle) -> Self {
29        handle.0
30    }
31}
32
33impl From<Handle> for u32 {
34    fn from(handle: Handle) -> Self {
35        handle.0.into()
36    }
37}
38
39impl From<control::RawResourceHandle> for Handle {
40    fn from(handle: control::RawResourceHandle) -> Self {
41        Handle(handle)
42    }
43}
44
45impl std::fmt::Debug for Handle {
46    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
47        f.debug_tuple("syncobj::Handle").field(&self.0).finish()
48    }
49}