Skip to content

Introduce a display subsystem for GPU output #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mtjhrc
Copy link
Collaborator

@mtjhrc mtjhrc commented Apr 23, 2025

This PR adds initial support for the more traditional display output from the VM by basically having virtual displays (until now we only had cross-domain/wayland).

This implementes 2 display backends:

  • DisplayBackendNoop - used by default, pretty much returns an error for every operation
  • DisplayBackendGtk - implementation using GTK (works on Linux, to be tested on macOS)

This introduces 2 new public API function:

  • int32_t krun_set_display_backend_gtk(uint32_t ctx_id)
  • int32_t krun_set_display(uint32_t ctx_id, uint32_t display_id, uint32_t width, uint32_t height)

Current limitations to be addressed by future PRs:

  • add a virtio-input device and forward the events from the window to the guest
  • improve the performance by using dmabufs instead copying it to the CPU
  • send display resize events to the guest

You can test this using the newly added --display option in chroot_vm and running something graphical in the guest - the simplest option is probably kmscube:
$ ./chroot_vm --display=0:1920:1080 rootfs_fedora kmscube

@mtjhrc mtjhrc force-pushed the gtk-display branch 4 times, most recently from d7deac6 to 056b470 Compare April 23, 2025 13:48
mtjhrc added 2 commits April 24, 2025 12:59
This is similar concept to the mpsc::channel but uses an EventFd to notify the
reader when data is availible. This seems like it could be generally useful,
when we need to use Epoll to also wait for other file descriptor events.

This is just a simple implementation using EventFd and could maybe be optimized.
(maybe even using a unix pipe directly)

Signed-off-by: Matej Hrica <[email protected]>
We wrongly expected an extra virtio_gpu_ctrl_hdr for VIRTIO_GPU_CMD_GET_DISPLAY_INFO
The command doesn't have any body and we have already read the ctrl_header.

Signed-off-by: Matej Hrica <[email protected]>
@mtjhrc mtjhrc force-pushed the gtk-display branch 4 times, most recently from dbb85d3 to ee15200 Compare April 25, 2025 14:35
mtjhrc added 3 commits April 25, 2025 16:36
Introduce a DisplayBackend trait and a DisplayBackendNoop implementation. Hook
up the gpu device to use the display backend. For now this only hooks up the
simplest and slowest option of display output - the output is copied to the
CPU using the transfer_read operation and passed to the display backend. The
DisplayBackendNoop doesn't provide any displays, so this doesn't display
anything yet.

Introduce a new public API function krun_set_display() for configuring VM
displays.

The virtio-gpu code is based on rust-vmm/vhost-device-gpu.

Signed-off-by: Matej Hrica <[email protected]>
Add a DisplayBackend implementation using GTK. This also introduces a new public
API function krun_set_display_backend_gtk() for enabling the gtk display backend.

Signed-off-by: Matej Hrica <[email protected]>
The --display option can be provided multiple times. Specyfing at least one
display automatically enables the GTK display backend.

Signed-off-by: Matej Hrica <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant