voelin-media: hand a DMA-BUF-taking sink the buffer's real size
The portal offers a sink that accepts DMA-BUFs the buffer as it is, with
its size taken from `mapoffset + maxsize`: the same fields 9b09e7b found
0 for every DMA-BUF this compositor sends, which left the mapping empty.
On the sink path the size goes into the DRM PRIME descriptor of the
import. Mesa happens to ignore it (an import with size 0 encoded the same
picture here), but the size is part of the descriptor and other drivers
use it, so ask the buffer object (lseek to the end, which a DMA-BUF
answers with its size) and fall back to the rows the format describes.
The module documentation now says what a DMA-BUF-taking sink gets, and
why tiled buffers are still not offered: the modifiers the encoder's
driver imports are not known on this side.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3982b8db71
commit
2bd78ca39d
3 files changed
+29
-6
No files matched your search
@@ -21,6 +21,18 @@ const DMA_BUF_SYNC_END: u64 = 1 << 2;
|
||||
/// `DMA_BUF_IOCTL_SYNC`: `_IOW('b', 0, struct dma_buf_sync)`.
|
||||
const SYNC: rustix::ioctl::Opcode = rustix::ioctl::opcode::write::<DmaBufSync>(b'b', 0);
|
||||
|
||||
/// The size of DMA-BUF `fd` in bytes (`lseek(fd, 0, SEEK_END)`, which a
|
||||
/// DMA-BUF answers with its buffer object's size without moving anything).
|
||||
pub(crate) fn size_of(fd: RawFd) -> Option<usize> {
|
||||
if fd < 0 {
|
||||
return None;
|
||||
}
|
||||
// SAFETY: borrowed for the call from a caller that holds it open.
|
||||
let fd = unsafe { BorrowedFd::borrow_raw(fd) };
|
||||
let end = rustix::fs::seek(fd, rustix::fs::SeekFrom::End(0)).ok()?;
|
||||
usize::try_from(end).ok().filter(|&size| size > 0)
|
||||
}
|
||||
|
||||
/// A read-only mapping of a DMA-BUF.
|
||||
pub(crate) struct DmaBufMap {
|
||||
fd: RawFd,
|
||||
@@ -97,5 +109,7 @@ mod tests {
|
||||
assert_eq!(map.fd(), file.as_raw_fd());
|
||||
assert_eq!(map.read(|b| b.iter().map(|&x| u64::from(x)).sum::<u64>()), 7 * 8192);
|
||||
assert!(DmaBufMap::new(-1, 10).is_err());
|
||||
assert_eq!(size_of(file.as_raw_fd()), Some(8192));
|
||||
assert_eq!(size_of(-1), None);
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,13 @@
|
||||
//! (`BGRx` / `BGRA` / `RGBx` / `RGBA`) second, so compositors without
|
||||
//! DMA-BUF support use shared memory. When reading DMA-BUFs turns out slow
|
||||
//! (buffers in memory the CPU reads uncached, e.g. a discrete GPU's VRAM),
|
||||
//! the stream switches to shared memory. Tiled DMA-BUFs would need a GPU
|
||||
//! import and are not offered. Frames go to the [`FrameSink`] while the
|
||||
//! buffer is dequeued; nothing is copied before conversion. The frame rate
|
||||
//! the stream switches to shared memory. A sink that
|
||||
//! [accepts DMA-BUFs](FrameSink::accepts_dmabuf) (a VA-API encoder, which
|
||||
//! converts and encodes them on the GPU) gets them before anything is
|
||||
//! mapped, and then the CPU never reads them. Tiled DMA-BUFs are not
|
||||
//! offered: the modifiers the encoder's driver imports are not known here.
|
||||
//! Frames go to the [`FrameSink`] while the buffer is dequeued; nothing is
|
||||
//! copied before conversion. The frame rate
|
||||
//! follows the sink's cap: the compositor is asked for up to that rate and
|
||||
//! sends frames when the screen changes.
|
||||
|
||||
@@ -31,7 +35,7 @@ use pw::spa::pod::{
|
||||
use pw::spa::utils::{Choice, ChoiceEnum, ChoiceFlags, Fraction, Id, Rectangle, SpaTypes};
|
||||
use tracing::{debug, warn};
|
||||
|
||||
use crate::capture::dmabuf::DmaBufMap;
|
||||
use crate::capture::dmabuf::{self, DmaBufMap};
|
||||
use crate::capture::pw::{PwThread, pod, serialize};
|
||||
use crate::capture::{
|
||||
BoxFuture, CaptureOptions, CaptureSource, DRM_MOD_LINEAR, DmaBufRef, FrameSink, QueueSink,
|
||||
@@ -600,7 +604,12 @@ fn process(stream: &pw::stream::Stream, state: &mut VideoState) {
|
||||
fourcc,
|
||||
modifier: format.modifier.map_or(DRM_MOD_LINEAR, |m| m as u64),
|
||||
fd: data.fd(),
|
||||
size: (raw.mapoffset + raw.maxsize) as usize,
|
||||
// As for the mapping below: compositors leave `maxsize` 0 for
|
||||
// a DMA-BUF, whose size is its buffer object's.
|
||||
size: match (raw.mapoffset + raw.maxsize) as usize {
|
||||
0 => dmabuf::size_of(data.fd()).unwrap_or(raw.mapoffset as usize + needed),
|
||||
size => size,
|
||||
},
|
||||
planes: [(raw.mapoffset as usize + offset, stride), (0, 0), (0, 0), (0, 0)],
|
||||
plane_count: 1,
|
||||
};
|
||||
|
||||
@@ -1098,7 +1098,7 @@ impl FfmpegEncoder {
|
||||
/// this frame's packet came out (the encoder reads them one frame deep).
|
||||
/// RGB buffers (`XR24`, `AR24`, `XB24`, `AB24`: what screen capture
|
||||
/// delivers) are converted into the session's NV12 surfaces on the GPU
|
||||
/// (VA-API video processing, [`vpp`]), cropped to the coded size, and
|
||||
/// (VA-API video processing), cropped to the coded size, and
|
||||
/// are no longer read when this returns.
|
||||
///
|
||||
/// Anything else fails with `Error::CodecUnavailable`; callers then map
|
||||
|
||||
Reference in new issue
Block a user