1
0
Fork 0
forked from wry/wry

Merge pull request #624 from mahkoh/jorth/cache-disjoint

dmabuf: cache is_disjoint property
This commit is contained in:
mahkoh 2025-10-01 23:51:05 +02:00 committed by GitHub
commit 636b242347
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 37 additions and 14 deletions

View file

@ -69,6 +69,7 @@ async fn run(screenshot: Rc<Screenshot>) {
format: XRGB8888,
modifier: ev.modifier,
planes,
is_disjoint: Default::default(),
};
res.push(Ok((buf, Some(ev.drm_dev))));
});
@ -96,6 +97,7 @@ async fn run(screenshot: Rc<Screenshot>) {
format: XRGB8888,
modifier: ev.modifier,
planes: planes.take(),
is_disjoint: Default::default(),
};
res.push(Ok((buf, dev.take())))
},

View file

@ -230,6 +230,7 @@ impl VulkanBoAllocator {
format: format.format,
modifier: modifier.modifier,
planes,
is_disjoint: Default::default(),
};
unsafe {
let cmd = data.command_buffer.buffer;

View file

@ -1649,6 +1649,9 @@ impl VulkanRenderer {
let fd = dma_buf_export_sync_file(&plane.fd, flag)
.map_err(VulkanError::IoctlExportSyncFile)?;
import_sync_file(fd)?;
if buf.template.dmabuf.is_one_file() {
break;
}
}
}
AcquireSync::SyncFile { sync_file } => {

View file

@ -142,6 +142,7 @@ impl WlDrmRequestHandler for WlDrm {
format,
modifier: INVALID_MODIFIER,
planes: PlaneVec::new(),
is_disjoint: Default::default(),
};
if req.stride0 > 0 {
dmabuf.planes.push(DmaBufPlane {

View file

@ -93,6 +93,7 @@ impl ZwpLinuxBufferParamsV1 {
format: format.format,
modifier,
planes: PlaneVec::new(),
is_disjoint: Default::default(),
};
let mut planes: Vec<_> = self.planes.borrow_mut().drain_values().collect();
planes.sort_by_key(|a| a.plane_idx);

View file

@ -38,6 +38,7 @@ impl TestJayScreenshot {
format: XRGB8888,
modifier: ev.modifier,
planes,
is_disjoint: Default::default(),
})));
Ok(())
}
@ -73,6 +74,7 @@ impl TestJayScreenshot {
format: XRGB8888,
modifier: ev.modifier,
planes: self.planes.take(),
is_disjoint: Default::default(),
})));
Ok(())
}

View file

@ -162,6 +162,7 @@ impl Allocator for Udmabuf {
format,
modifier: LINEAR_MODIFIER,
planes,
is_disjoint: Default::default(),
};
Ok(Rc::new(UdmabufBo {
buf: dmabuf,

View file

@ -5,7 +5,7 @@ use {
video::{LINEAR_MODIFIER, Modifier},
},
arrayvec::ArrayVec,
std::{rc::Rc, sync::OnceLock},
std::{cell::OnceCell, rc::Rc, sync::OnceLock},
uapi::{
_IOW, _IOWR, OwnedFd,
c::{self, dev_t, ioctl},
@ -30,6 +30,7 @@ pub struct DmaBuf {
pub format: &'static Format,
pub modifier: Modifier,
pub planes: PlaneVec<DmaBufPlane>,
pub is_disjoint: OnceCell<bool>,
}
pub const MAX_PLANES: usize = 4;
@ -38,23 +39,29 @@ pub type PlaneVec<T> = ArrayVec<T, MAX_PLANES>;
impl DmaBuf {
pub fn is_disjoint(&self) -> bool {
if self.planes.len() <= 1 {
return false;
}
let stat = match uapi::fstat(self.planes[0].fd.raw()) {
Ok(s) => s,
_ => return true,
};
for plane in &self.planes[1..] {
let stat2 = match uapi::fstat(plane.fd.raw()) {
*self.is_disjoint.get_or_init(|| {
if self.planes.len() <= 1 {
return false;
}
let stat = match uapi::fstat(self.planes[0].fd.raw()) {
Ok(s) => s,
_ => return true,
};
if stat2.st_ino != stat.st_ino {
return true;
for plane in &self.planes[1..] {
let stat2 = match uapi::fstat(plane.fd.raw()) {
Ok(s) => s,
_ => return true,
};
if stat2.st_ino != stat.st_ino {
return true;
}
}
}
false
false
})
}
pub fn is_one_file(&self) -> bool {
!self.is_disjoint()
}
pub fn udmabuf_size(&self) -> Option<usize> {
@ -100,6 +107,9 @@ impl DmaBuf {
pub fn import_sync_file(&self, flags: u32, sync_file: &OwnedFd) -> Result<(), OsError> {
for plane in &self.planes {
dma_buf_import_sync_file(&plane.fd, flags, sync_file)?;
if self.is_one_file() {
break;
}
}
Ok(())
}

View file

@ -202,6 +202,7 @@ unsafe fn export_bo(dmabuf_ids: &DmaBufIds, bo: *mut Bo) -> Result<DmaBuf, GbmEr
}
planes
},
is_disjoint: Default::default(),
})
}
}

View file

@ -155,6 +155,7 @@ impl JayScreencastEventHandler for UsrJayScreencast {
format,
modifier: ev.modifier,
planes: mem::take(self.pending_planes.borrow_mut().deref_mut()),
is_disjoint: Default::default(),
});
Ok(())
}