1
0
Fork 0
forked from wry/wry

vulkan: abstract over the release sync type

This commit is contained in:
Julian Orth 2026-03-01 21:39:06 +01:00
parent 3ecee1b17f
commit 2ac3519f2d
8 changed files with 166 additions and 137 deletions

65
src/vulkan_core/sync.rs Normal file
View file

@ -0,0 +1,65 @@
use {
crate::{
gfx_api::FdSync,
utils::errorfmt::ErrorFmt,
vulkan_core::{
VulkanCoreError,
device::VulkanDeviceInf,
fence::{VulkanDeviceFenceExt, VulkanFence},
},
},
ash::vk::Fence,
std::rc::Rc,
};
pub enum VulkanSync<D>
where
D: VulkanDeviceInf,
{
Fence(Rc<VulkanFence<D>>),
}
impl<D> VulkanSync<D>
where
D: VulkanDeviceInf,
{
pub fn handle_validation(&self) {
// nothing
}
pub fn fence(&self) -> Fence {
match self {
VulkanSync::Fence(f) => f.fence,
}
}
pub fn to_sync(&self, block: impl FnOnce()) -> Option<FdSync> {
match self {
VulkanSync::Fence(release_fence) => {
zone!("export_sync_file");
let release_sync_file = match release_fence.export_sync_file() {
Ok(s) => s,
Err(e) => {
log::error!("Could not export sync file from fence: {}", ErrorFmt(e));
block();
None
}
};
release_sync_file.map(FdSync::SyncFile)
}
}
}
}
pub trait VulkanDeviceSyncExt: VulkanDeviceInf {
fn create_sync(self: &Rc<Self>) -> Result<VulkanSync<Self>, VulkanCoreError>;
}
impl<D> VulkanDeviceSyncExt for D
where
D: VulkanDeviceInf,
{
fn create_sync(self: &Rc<Self>) -> Result<VulkanSync<Self>, VulkanCoreError> {
self.create_fence().map(VulkanSync::Fence)
}
}