1
0
Fork 0
forked from wry/wry

gfx-api: add support for syncobj synchronization

This commit is contained in:
Julian Orth 2026-03-01 20:29:53 +01:00
parent 80a69ba7ef
commit 7e6facf4e3
20 changed files with 323 additions and 159 deletions

View file

@ -69,8 +69,8 @@ use {
crate::{
cmm::cmm_eotf::Eotf,
gfx_api::{
AcquireSync, CopyTexture, FramebufferRect, GfxApiOpt, GfxContext, GfxError, GfxTexture,
ReleaseSync, SyncFile,
AcquireSync, CopyTexture, FdSync, FramebufferRect, GfxApiOpt, GfxContext, GfxError,
GfxTexture, ReleaseSync, SyncFile,
},
gfx_apis::gl::{
egl::image::EglImage,
@ -221,7 +221,7 @@ struct GlFillRect {
pub color: Color,
}
fn run_ops(fb: &Framebuffer, ops: &[GfxApiOpt]) -> Option<SyncFile> {
fn run_ops(fb: &Framebuffer, ops: &[GfxApiOpt]) -> Option<FdSync> {
let mut state = fb.ctx.gl_state.borrow_mut();
let state = &mut *state;
let mut fill_rect = state.fill_rect.take();
@ -301,13 +301,14 @@ fn run_ops(fb: &Framebuffer, ops: &[GfxApiOpt]) -> Option<SyncFile> {
return None;
}
};
let file = FdSync::SyncFile(file);
let user = fb.ctx.buffer_resv_user;
for op in ops {
if let GfxApiOpt::CopyTexture(ct) = op
&& ct.release_sync == ReleaseSync::Explicit
&& let Some(resv) = &ct.buffer_resv
{
resv.set_sync_file(user, &file);
resv.set_sync(user, &file);
}
}
return Some(file);
@ -417,9 +418,8 @@ fn render_texture(ctx: &GlRenderContext, tex: &CopyTexture) {
}
fn handle_explicit_sync(ctx: &GlRenderContext, img: Option<&Rc<EglImage>>, sync: &AcquireSync) {
let sync_file = match sync {
AcquireSync::None | AcquireSync::Implicit | AcquireSync::Unnecessary => return,
AcquireSync::SyncFile { sync_file } => sync_file,
let Some(sync_file) = sync.get_sync_file() else {
return;
};
let sync_file = match uapi::fcntl_dupfd_cloexec(sync_file.raw(), 0) {
Ok(s) => s,

View file

@ -6,9 +6,9 @@ use {
},
format::Format,
gfx_api::{
AcquireSync, AsyncShmGfxTextureCallback, GfxApiOpt, GfxBlendBuffer, GfxError,
AcquireSync, AsyncShmGfxTextureCallback, FdSync, GfxApiOpt, GfxBlendBuffer, GfxError,
GfxFramebuffer, GfxInternalFramebuffer, GfxStagingBuffer, PendingShmTransfer,
ReleaseSync, ShmMemory, SyncFile,
ReleaseSync, ShmMemory,
},
gfx_apis::gl::{
RenderError,
@ -74,7 +74,7 @@ impl Framebuffer {
acquire_sync: AcquireSync,
ops: &[GfxApiOpt],
clear: Option<&Color>,
) -> Result<Option<SyncFile>, RenderError> {
) -> Result<Option<FdSync>, RenderError> {
let gles = self.ctx.ctx.dpy.gles;
self.ctx.ctx.with_current(|| {
handle_explicit_sync(&self.ctx, self.gl.rb._img.as_ref(), &acquire_sync);
@ -88,13 +88,13 @@ impl Framebuffer {
}
(gles.glBlendFunc)(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
let fd = run_ops(self, ops);
if fd.is_none() {
let sync = run_ops(self, ops);
if sync.is_none() {
unsafe {
(gles.glFinish)();
}
}
Ok(fd)
Ok(sync)
})
}
}
@ -115,7 +115,7 @@ impl GfxFramebuffer for Framebuffer {
_region: &Region,
_blend_buffer: Option<&Rc<dyn GfxBlendBuffer>>,
_blend_cd: &Rc<ColorDescription>,
) -> Result<Option<SyncFile>, GfxError> {
) -> Result<Option<FdSync>, GfxError> {
(*self)
.render(acquire_sync, ops, clear)
.map_err(|e| e.into())

View file

@ -4,9 +4,9 @@ use {
format::Format,
gfx_api::{
AcquireSync, AsyncShmGfxTexture, AsyncShmGfxTextureCallback,
AsyncShmGfxTextureTransferCancellable, GfxApiOpt, GfxBlendBuffer, GfxBuffer, GfxError,
GfxFramebuffer, GfxImage, GfxInternalFramebuffer, GfxStagingBuffer, GfxTexture,
PendingShmTransfer, ReleaseSync, ShmGfxTexture, ShmMemory, SyncFile,
AsyncShmGfxTextureTransferCancellable, FdSync, GfxApiOpt, GfxBlendBuffer, GfxBuffer,
GfxError, GfxFramebuffer, GfxImage, GfxInternalFramebuffer, GfxStagingBuffer,
GfxTexture, PendingShmTransfer, ReleaseSync, ShmGfxTexture, ShmMemory,
},
gfx_apis::vulkan::{
VulkanError, allocator::VulkanAllocation, device::VulkanDevice,
@ -563,7 +563,7 @@ impl GfxFramebuffer for VulkanImage {
region: &Region,
blend_buffer: Option<&Rc<dyn GfxBlendBuffer>>,
blend_cd: &Rc<ColorDescription>,
) -> Result<Option<SyncFile>, GfxError> {
) -> Result<Option<FdSync>, GfxError> {
let mut blend_buffer = blend_buffer
.map(|b| b.clone().into_vk(&self.renderer.device.device))
.transpose()?;

View file

@ -8,7 +8,7 @@ use {
},
cpu_worker::PendingJob,
gfx_api::{
AcquireSync, AlphaMode, BufferResv, BufferResvUser, GfxApiOpt, GfxBlendBuffer,
AcquireSync, AlphaMode, BufferResv, BufferResvUser, FdSync, GfxApiOpt, GfxBlendBuffer,
GfxFormat, GfxTexture, GfxWriteModifier, ReleaseSync, SyncFile,
},
gfx_apis::vulkan::{
@ -1671,10 +1671,12 @@ impl VulkanRenderer {
}
}
}
AcquireSync::SyncFile { sync_file } => {
let fd = uapi::fcntl_dupfd_cloexec(sync_file.raw(), 0)
.map_err(|e| VulkanError::Dupfd(e.into()))?;
import_sync_file(fd)?;
AcquireSync::FdSync(sync) => {
if let Some(sync_file) = sync.get_sync_file() {
let fd = uapi::fcntl_dupfd_cloexec(sync_file.raw(), 0)
.map_err(|e| VulkanError::Dupfd(e.into()))?;
import_sync_file(fd)?;
}
}
AcquireSync::Unnecessary => {}
}
@ -1707,13 +1709,14 @@ impl VulkanRenderer {
Some(sync_file) => sync_file,
_ => return,
};
let fd_sync = FdSync::SyncFile(sync_file.clone());
let import =
|img: &VulkanImage, sync: ReleaseSync, resv: Option<Rc<dyn BufferResv>>, flag: u32| {
if sync == ReleaseSync::None {
return;
}
if let Some(resv) = resv {
resv.set_sync_file(self.buffer_resv_user, sync_file);
resv.set_sync(self.buffer_resv_user, &fd_sync);
} else if sync == ReleaseSync::Implicit {
if let VulkanImageMemory::DmaBuf(buf) = &img.ty
&& let Err(e) = buf.template.dmabuf.import_sync_file(flag, sync_file)
@ -1844,7 +1847,7 @@ impl VulkanRenderer {
region: &Region,
blend_buffer: Option<Rc<VulkanImage>>,
blend_cd: &Rc<ColorDescription>,
) -> Result<Option<SyncFile>, VulkanError> {
) -> Result<Option<FdSync>, VulkanError> {
zone!("execute");
let res = self.try_execute(
fb,
@ -1870,7 +1873,7 @@ impl VulkanRenderer {
memory.ops_tmp.clear();
memory.release_sync_file.take()
};
res.map(|_| sync_file)
res.map(|_| sync_file.map(FdSync::SyncFile))
}
fn allocate_semaphore(&self) -> Result<Rc<VulkanSemaphore>, VulkanError> {