From e2d2a2e9b91e911f4666110d4d8edb77a8cf90cf Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Wed, 11 Mar 2026 11:49:42 +0100 Subject: [PATCH] vulkan-core: make SyncobjCtx optional --- src/copy_device.rs | 4 ++-- src/gfx_apis/vulkan/device.rs | 4 ++-- src/vulkan_core.rs | 2 ++ src/vulkan_core/device.rs | 2 +- src/vulkan_core/sync.rs | 5 ++--- src/vulkan_core/timeline_semaphore.rs | 10 +++++++--- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/copy_device.rs b/src/copy_device.rs index fe935e20..6ab005cc 100644 --- a/src/copy_device.rs +++ b/src/copy_device.rs @@ -2037,8 +2037,8 @@ impl VulkanDeviceInf for CopyDeviceInner { self.phy.supports_timeline_opaque_export } - fn sync_ctx(&self) -> &Rc { - &self.phy.sync_ctx + fn sync_ctx(&self) -> Option<&Rc> { + Some(&self.phy.sync_ctx) } fn eventfd_cache(&self) -> &Rc { diff --git a/src/gfx_apis/vulkan/device.rs b/src/gfx_apis/vulkan/device.rs index f65e8e06..afd159cc 100644 --- a/src/gfx_apis/vulkan/device.rs +++ b/src/gfx_apis/vulkan/device.rs @@ -671,8 +671,8 @@ impl VulkanDeviceInf for VulkanDevice { self.supports_timeline_opaque_export } - fn sync_ctx(&self) -> &Rc { - &self.sync_ctx + fn sync_ctx(&self) -> Option<&Rc> { + Some(&self.sync_ctx) } fn eventfd_cache(&self) -> &Rc { diff --git a/src/vulkan_core.rs b/src/vulkan_core.rs index 00dac433..546e820d 100644 --- a/src/vulkan_core.rs +++ b/src/vulkan_core.rs @@ -76,6 +76,8 @@ pub enum VulkanCoreError { AcquireEventfd(#[source] EventfdError), #[error("Could not create a sync obj eventfd wait")] CreateSyncobjWait(#[source] DrmError), + #[error("Device does not have a syncobj ctx")] + NoSyncobjCtx, } pub struct VulkanCoreInstance { diff --git a/src/vulkan_core/device.rs b/src/vulkan_core/device.rs index ab4ceb1a..83a4c73f 100644 --- a/src/vulkan_core/device.rs +++ b/src/vulkan_core/device.rs @@ -16,6 +16,6 @@ pub trait VulkanDeviceInf: Sized { fn external_fence_fd(&self) -> &external_fence_fd::Device; fn external_semaphore_fd(&self) -> &external_semaphore_fd::Device; fn supports_timeline_opaque_export(&self) -> bool; - fn sync_ctx(&self) -> &Rc; + fn sync_ctx(&self) -> Option<&Rc>; fn eventfd_cache(&self) -> &Rc; } diff --git a/src/vulkan_core/sync.rs b/src/vulkan_core/sync.rs index aaa7e317..e78d88c2 100644 --- a/src/vulkan_core/sync.rs +++ b/src/vulkan_core/sync.rs @@ -113,12 +113,11 @@ where .eventfd_cache() .acquire() .map_err(VulkanCoreError::AcquireEventfd)?; - device - .sync_ctx() + tls.sync_ctx .wait_for_point(&eventfd.fd, &tls.syncobj, point, true) .map_err(VulkanCoreError::CreateSyncobjWait)?; let pending = Rc::new(ReservedSyncobjPoint { - ctx: device.sync_ctx().clone(), + ctx: tls.sync_ctx.clone(), syncobj: tls.syncobj.clone(), point, sync_file: Default::default(), diff --git a/src/vulkan_core/timeline_semaphore.rs b/src/vulkan_core/timeline_semaphore.rs index 7f46c689..63340578 100644 --- a/src/vulkan_core/timeline_semaphore.rs +++ b/src/vulkan_core/timeline_semaphore.rs @@ -1,7 +1,7 @@ use { crate::{ utils::{errorfmt::ErrorFmt, numcell::NumCell}, - video::drm::syncobj::Syncobj, + video::drm::syncobj::{Syncobj, SyncobjCtx}, vulkan_core::{VulkanCoreError, device::VulkanDeviceInf}, }, ash::vk::{ @@ -20,6 +20,7 @@ where { pub(super) device: Rc, pub(super) semaphore: Semaphore, + pub(super) sync_ctx: Rc, pub(super) syncobj: Rc, pub(super) next_point: NumCell, } @@ -55,6 +56,9 @@ where if !self.supports_timeline_opaque_export() { return Err(VulkanCoreError::TimelineExportNotSupported); } + let Some(sync_ctx) = self.sync_ctx() else { + return Err(VulkanCoreError::NoSyncobjCtx); + }; let sem = { let mut export_info = ExportSemaphoreCreateInfo::default() .handle_types(ExternalSemaphoreHandleTypeFlags::OPAQUE_FD); @@ -87,8 +91,7 @@ where for _ in 0..2 { let n = next_point.fetch_add(1); signal(n)?; - let signaled = self - .sync_ctx() + let signaled = sync_ctx .query_last_signaled(&syncobj) .map_err(VulkanCoreError::QueryLastSignaled)?; if signaled != n { @@ -99,6 +102,7 @@ where Ok(Rc::new(VulkanTimelineSemaphore { device: self.clone(), semaphore: sem, + sync_ctx: sync_ctx.clone(), syncobj: Rc::new(syncobj), next_point, }))