1
0
Fork 0
forked from wry/wry

vulkan: use sync objects if possible

This commit is contained in:
Julian Orth 2026-03-01 17:25:40 +01:00
parent 2ac3519f2d
commit 3d3132fe39
23 changed files with 535 additions and 86 deletions

View file

@ -1,21 +1,33 @@
pub mod syncobj;
mod sys;
pub mod wait_for_syncobj;
pub use consts::*;
use {
crate::{
utils::oserror::OsError,
video::drm::sys::{
DRM_DISPLAY_MODE_LEN, DRM_MODE_ATOMIC_TEST_ONLY, DRM_MODE_FB_MODIFIERS,
DRM_MODE_OBJECT_BLOB, DRM_MODE_OBJECT_CONNECTOR, DRM_MODE_OBJECT_CRTC,
DRM_MODE_OBJECT_ENCODER, DRM_MODE_OBJECT_FB, DRM_MODE_OBJECT_PLANE,
DRM_MODE_OBJECT_PROPERTY, create_lease, drm_event, drm_event_vblank, gem_close,
get_cap, get_device_name_from_fd2, get_minor_name_from_fd, get_node_type_from_fd,
get_nodes, mode_addfb2, mode_atomic, mode_create_blob, mode_destroy_blob,
mode_get_resources, mode_getconnector, mode_getencoder, mode_getplane,
mode_getplaneresources, mode_getprobblob, mode_getproperty, mode_obj_getproperties,
mode_rmfb, prime_fd_to_handle, set_client_cap,
backend,
format::Format,
io_uring::{IoUring, IoUringError},
utils::{
buf::Buf, errorfmt::ErrorFmt, oserror::OsError, stack::Stack, syncqueue::SyncQueue,
vec_ext::VecExt,
},
video::{
INVALID_MODIFIER, Modifier,
dmabuf::DmaBuf,
drm::sys::{
DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP, DRM_CAP_CURSOR_HEIGHT, DRM_CAP_CURSOR_WIDTH,
DRM_DISPLAY_MODE_LEN, DRM_MODE_ATOMIC_TEST_ONLY, DRM_MODE_FB_MODIFIERS,
DRM_MODE_OBJECT_BLOB, DRM_MODE_OBJECT_CONNECTOR, DRM_MODE_OBJECT_CRTC,
DRM_MODE_OBJECT_ENCODER, DRM_MODE_OBJECT_FB, DRM_MODE_OBJECT_PLANE,
DRM_MODE_OBJECT_PROPERTY, FORMAT_BLOB_CURRENT, auth_magic, create_lease, drm_event,
drm_event_crtc_sequence, drm_event_vblank, drm_format_modifier,
drm_format_modifier_blob, drop_master, gem_close, get_cap,
get_device_name_from_fd2, get_minor_name_from_fd, get_node_type_from_fd, get_nodes,
get_version, mode_addfb2, mode_atomic, mode_create_blob, mode_destroy_blob,
mode_get_resources, mode_getconnector, mode_getencoder, mode_getplane,
mode_getplaneresources, mode_getprobblob, mode_getproperty, mode_obj_getproperties,
mode_rmfb, prime_fd_to_handle, queue_sequence, revoke_lease, set_client_cap,
},
},
},
ahash::AHashMap,
@ -32,26 +44,14 @@ use {
thiserror::Error,
uapi::{OwnedFd, Pod, Ustring, c},
};
use crate::{
backend,
format::Format,
io_uring::{IoUring, IoUringError},
utils::{buf::Buf, errorfmt::ErrorFmt, stack::Stack, syncqueue::SyncQueue, vec_ext::VecExt},
video::{
INVALID_MODIFIER, Modifier,
dmabuf::DmaBuf,
drm::sys::{
DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP, DRM_CAP_CURSOR_HEIGHT, DRM_CAP_CURSOR_WIDTH,
FORMAT_BLOB_CURRENT, auth_magic, drm_event_crtc_sequence, drm_format_modifier,
drm_format_modifier_blob, drop_master, get_version, queue_sequence, revoke_lease,
},
pub use {
consts::*,
sys::{
DRM_CLIENT_CAP_ATOMIC, DRM_MODE_ATOMIC_ALLOW_MODESET, DRM_MODE_ATOMIC_NONBLOCK,
DRM_MODE_PAGE_FLIP_ASYNC, DRM_MODE_PAGE_FLIP_EVENT, drm_mode_modeinfo,
get_drm_nodes_from_dev,
},
};
pub use sys::{
DRM_CLIENT_CAP_ATOMIC, DRM_MODE_ATOMIC_ALLOW_MODESET, DRM_MODE_ATOMIC_NONBLOCK,
DRM_MODE_PAGE_FLIP_ASYNC, DRM_MODE_PAGE_FLIP_EVENT, drm_mode_modeinfo,
};
#[derive(Debug, Error)]
pub enum DrmError {
@ -123,6 +123,8 @@ pub enum DrmError {
CreateSyncobj(#[source] OsError),
#[error("Could not export a syncobj")]
ExportSyncobj(#[source] OsError),
#[error("Could not query a syncobj")]
QuerySyncobj(#[source] OsError),
#[error("Could not register an eventfd with a syncobj")]
RegisterEventfd(#[source] OsError),
#[error("Could not create an eventfd")]

View file

@ -18,7 +18,7 @@ use {
DRM_SYNCOBJ_HANDLE_TO_FD_FLAGS_TIMELINE, DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE,
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT, sync_ioc_merge, syncobj_create,
syncobj_destroy, syncobj_eventfd, syncobj_fd_to_handle, syncobj_handle_to_fd,
syncobj_signal, syncobj_transfer,
syncobj_query, syncobj_signal, syncobj_transfer,
},
},
},
@ -329,6 +329,11 @@ impl SyncobjCtx {
}
}
}
pub fn query_last_signaled(&self, syncobj: &Syncobj) -> Result<u64, DrmError> {
let handle = self.get_handle(syncobj)?;
syncobj_query(self.inner.drm.raw(), handle.0).map_err(DrmError::QuerySyncobj)
}
}
impl Drop for SyncobjCtx {

View file

@ -171,7 +171,10 @@ pub fn get_device_name_from_fd2(fd: c::c_int) -> Result<Ustring, OsError> {
pub fn get_nodes(fd: c::c_int) -> Result<AHashMap<NodeType, CString>, OsError> {
let (_, maj, min) = drm_stat(fd)?;
get_drm_nodes_from_dev(maj, min)
}
pub fn get_drm_nodes_from_dev(maj: u64, min: u64) -> Result<AHashMap<NodeType, CString>, OsError> {
let dir = device_dir(maj, min);
let mut dir = uapi::opendir(dir)?;
@ -1334,6 +1337,22 @@ pub fn syncobj_signal(drm: c::c_int, handle: u32, point: u64) -> Result<(), OsEr
Ok(())
}
const DRM_IOCTL_SYNCOBJ_QUERY: u64 = drm_iowr::<drm_syncobj_timeline_array>(0xCB);
pub fn syncobj_query(drm: c::c_int, handle: u32) -> Result<u64, OsError> {
let mut point = 0u64;
let mut res = drm_syncobj_timeline_array {
handles: &handle as *const u32 as u64,
points: &mut point as *mut u64 as u64,
count_handles: 1,
flags: 0,
};
unsafe {
ioctl(drm, DRM_IOCTL_SYNCOBJ_QUERY, &mut res)?;
}
Ok(point)
}
#[repr(C)]
struct drm_syncobj_transfer {
src_handle: u32,