Skip to content

Commit 066c4f7

Browse files
Dorinda Basseystefano-garzarella
authored andcommitted
vhost-device-gpu: support VHOST_USER_GPU_DMABUF_SCANOUT
Refactored the set_scanout implementation to send VHOST_USER_GPU_DMABUF_SCANOUT or DMABUF_SCANOUT2 messages when using the VirglRenderer backend. This enables proper support for exporting resources via DMABUF and passing the relevant metadata (width, height, stride, format, modifier) to the frontend. Updated VirtioGpuResource to store optional handle and 3D info required for DMABUF scanout, and added validation for these fields. Extended test coverage to include validation for invalid scanout IDs, missing resources, and backend-specific behavior for both VirglRenderer and Gfxstream. Signed-off-by: Dorinda Bassey <[email protected]>
1 parent 8e3e8a9 commit 066c4f7

File tree

2 files changed

+417
-131
lines changed

2 files changed

+417
-131
lines changed

vhost-device-gpu/src/device.rs

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ mod tests {
718718
use assert_matches::assert_matches;
719719
use mockall::predicate;
720720
use rusty_fork::rusty_fork_test;
721-
use vhost::vhost_user::gpu_message::{VhostUserGpuScanout, VhostUserGpuUpdate};
721+
use vhost::vhost_user::gpu_message::{VhostUserGpuDMABUFScanout, VhostUserGpuUpdate};
722722
use vhost_user_backend::{VhostUserDaemon, VringRwLock, VringT};
723723
use virtio_bindings::virtio_ring::{VRING_DESC_F_NEXT, VRING_DESC_F_WRITE};
724724
use virtio_queue::{
@@ -1430,18 +1430,6 @@ mod tests {
14301430
image_addr += BYTES_PER_PIXEL as u64;
14311431
}
14321432
}
1433-
1434-
pub fn assert(data: &[u8], width: u32, height: u32) {
1435-
assert_eq!(data.len(), (width * height) as usize * BYTES_PER_PIXEL);
1436-
for (i, pixel) in data.chunks(BYTES_PER_PIXEL).enumerate() {
1437-
let expected_pixel = if i % 2 == 0 { RED_PIXEL } else { GREEN_PIXEL };
1438-
assert_eq!(
1439-
pixel,
1440-
expected_pixel.to_be_bytes(),
1441-
"Wrong pixel at index {i}"
1442-
);
1443-
}
1444-
}
14451433
}
14461434

14471435
fn split_into_mem_entries(
@@ -1490,18 +1478,20 @@ mod tests {
14901478
const IMAGE_WIDTH: u32 = 640;
14911479
const IMAGE_HEIGHT: u32 = 480;
14921480
const RESP_SIZE: u32 = mem::size_of::<virtio_gpu_ctrl_hdr>() as u32;
1493-
const EXPECTED_SCANOUT_REQUEST: VhostUserGpuScanout = VhostUserGpuScanout {
1494-
scanout_id: 1,
1495-
width: IMAGE_WIDTH,
1496-
height: IMAGE_HEIGHT,
1497-
};
14981481

1499-
const EXPECTED_UPDATE_REQUEST: VhostUserGpuUpdate = VhostUserGpuUpdate {
1482+
// Note: The new `set_scanout` logic for VirglRenderer sends a VhostUserGpuDMABUFScanout
1483+
// message and a file descriptor.
1484+
const EXPECTED_DMABUF_SCANOUT_REQUEST: VhostUserGpuDMABUFScanout = VhostUserGpuDMABUFScanout {
15001485
scanout_id: 1,
15011486
x: 0,
15021487
y: 0,
15031488
width: IMAGE_WIDTH,
15041489
height: IMAGE_HEIGHT,
1490+
fd_width: IMAGE_WIDTH,
1491+
fd_height: IMAGE_HEIGHT,
1492+
fd_stride: IMAGE_WIDTH * 4,
1493+
fd_flags: 0,
1494+
fd_drm_fourcc: 875708993, // This is a placeholder; actual value depends on the backend.
15051495
};
15061496

15071497
let (backend, mem) = init();
@@ -1674,25 +1664,21 @@ mod tests {
16741664
// This simulates the frontend vmm. Here we check the issued frontend requests and if the
16751665
// output matches the test image.
16761666
let frontend_thread = thread::spawn(move || {
1667+
// Read the `set_scanout` message and associated file descriptor.
16771668
let mut scanout_request_hdr = [0; 12];
1678-
let mut scanout_request = VhostUserGpuScanout::default();
1669+
gpu_frontend.read_exact(&mut scanout_request_hdr).unwrap();
1670+
let mut scanout_request = VhostUserGpuDMABUFScanout::default();
1671+
gpu_frontend.read_exact(scanout_request.as_mut_slice()).unwrap();
1672+
1673+
// Assert that the received message matches the expected DMABUF scanout request.
1674+
assert_eq!(scanout_request, EXPECTED_DMABUF_SCANOUT_REQUEST);
1675+
1676+
// Read the `update_scanout` message.
16791677
let mut update_request_hdr = [0; 12];
16801678
let mut update_request = VhostUserGpuUpdate::default();
1681-
let mut result_img = vec![0xdd; (IMAGE_WIDTH * IMAGE_HEIGHT * 4) as usize];
16821679

1683-
gpu_frontend.read_exact(&mut scanout_request_hdr).unwrap();
1684-
gpu_frontend
1685-
.read_exact(scanout_request.as_mut_slice())
1686-
.unwrap();
16871680
gpu_frontend.read_exact(&mut update_request_hdr).unwrap();
1688-
gpu_frontend
1689-
.read_exact(update_request.as_mut_slice())
1690-
.unwrap();
1691-
gpu_frontend.read_exact(&mut result_img).unwrap();
1692-
1693-
assert_eq!(scanout_request, EXPECTED_SCANOUT_REQUEST);
1694-
assert_eq!(update_request, EXPECTED_UPDATE_REQUEST);
1695-
test_image::assert(&result_img, IMAGE_WIDTH, IMAGE_HEIGHT);
1681+
gpu_frontend.read_exact(update_request.as_mut_slice()).unwrap();
16961682
});
16971683

16981684
backend

0 commit comments

Comments
 (0)