824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 1 | use crate::device::Shared; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 2 | use ash::vk; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 3 | use smithay::backend::renderer::sync::{Fence, Interrupted}; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 4 | use std::fmt; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 5 | use std::sync::Arc; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 6 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 7 | pub(crate) struct FenceInner { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 8 | pub shared: Arc<Shared>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 9 | pub fence: vk::Fence, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 10 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 11 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 12 | impl FenceInner { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 13 | pub fn new(shared: &Arc<Shared>) -> Result<Arc<Self>, vk::Result> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 14 | let fence = unsafe { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 15 | shared |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 16 | .device |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 17 | .device |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 18 | .create_fence(&vk::FenceCreateInfo::default(), None)? |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 19 | }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 20 | Ok(Arc::new(Self { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 21 | shared: shared.clone(), |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 22 | fence, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 23 | })) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 24 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 25 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 26 | pub fn signaled(&self) -> bool { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 27 | unsafe { self.shared.device.device.get_fence_status(self.fence) }.unwrap_or(true) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 28 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 29 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 30 | pub fn wait(&self) -> Result<(), vk::Result> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 31 | unsafe { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 32 | self.shared |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 33 | .device |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 34 | .device |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 35 | .wait_for_fences(&[self.fence], true, u64::MAX) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 36 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 37 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 38 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 39 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 40 | impl Drop for FenceInner { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 41 | fn drop(&mut self) { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 42 | unsafe { self.shared.device.device.destroy_fence(self.fence, None) }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 43 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 44 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 45 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 46 | impl fmt::Debug for FenceInner { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 47 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 48 | f.debug_tuple("FenceInner").field(&self.fence).finish() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 49 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 50 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 51 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 52 | #[derive(Debug)] |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 53 | pub(crate) struct VkFence(pub Arc<FenceInner>); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 54 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 55 | impl Fence for VkFence { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 56 | fn is_signaled(&self) -> bool { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 57 | self.0.signaled() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 58 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 59 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 60 | fn wait(&self) -> Result<(), Interrupted> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 61 | self.0.wait().map_err(|_| Interrupted) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 62 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 63 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 64 | fn is_exportable(&self) -> bool { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 65 | false |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 66 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 67 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 68 | fn export(&self) -> Option<std::os::fd::OwnedFd> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 69 | None |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 70 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 71 | } |