Skip to content

Commit 2bfe82d

Browse files
committed
Add CLI flag --gpu=drm|venus|software to support various GPU virtualization modes
vDRM is great, but not supported everywhere yet, so on some machines the only way to get GPU acceleration is via Venus. Also, make it possible to use software rendering only while still having working cross-domain Wayland. Signed-off-by: Val Packett <[email protected]>
1 parent 67fdf91 commit 2bfe82d

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

crates/muvm/src/bin/muvm.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use krun_sys::{
1111
krun_add_disk, krun_add_virtiofs2, krun_add_vsock_port, krun_add_vsock_port2, krun_create_ctx,
1212
krun_set_env, krun_set_gpu_options2, krun_set_log_level, krun_set_passt_fd, krun_set_root,
1313
krun_set_vm_config, krun_set_workdir, krun_start_enter, VIRGLRENDERER_DRM,
14-
VIRGLRENDERER_THREAD_SYNC, VIRGLRENDERER_USE_ASYNC_FENCE_CB, VIRGLRENDERER_USE_EGL,
14+
VIRGLRENDERER_NO_VIRGL, VIRGLRENDERER_RENDER_SERVER, VIRGLRENDERER_THREAD_SYNC,
15+
VIRGLRENDERER_USE_ASYNC_FENCE_CB, VIRGLRENDERER_USE_EGL, VIRGLRENDERER_VENUS,
1516
};
1617
use log::debug;
1718
use muvm::cli_options::options;
@@ -185,7 +186,14 @@ fn main() -> Result<ExitCode> {
185186
}
186187

187188
let virgl_flags = VIRGLRENDERER_USE_EGL
188-
| VIRGLRENDERER_DRM
189+
| VIRGLRENDERER_NO_VIRGL
190+
| match options.gpu_mode.unwrap_or_default() {
191+
muvm::cli_options::GpuMode::Drm => VIRGLRENDERER_DRM,
192+
muvm::cli_options::GpuMode::Venus => {
193+
VIRGLRENDERER_VENUS | VIRGLRENDERER_RENDER_SERVER
194+
},
195+
muvm::cli_options::GpuMode::Software => 0,
196+
}
189197
| VIRGLRENDERER_THREAD_SYNC
190198
| VIRGLRENDERER_USE_ASYNC_FENCE_CB;
191199
// SAFETY: Safe as no pointers involved.

crates/muvm/src/cli_options.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@ use bpaf::{any, construct, long, positional, OptionParser, Parser};
77
use crate::types::MiB;
88
use crate::utils::launch::Emulator;
99

10+
#[derive(Debug, Clone, Default)]
11+
pub enum GpuMode {
12+
#[default]
13+
Drm,
14+
Venus,
15+
Software,
16+
}
17+
18+
impl std::str::FromStr for GpuMode {
19+
type Err = String;
20+
fn from_str(s: &str) -> Result<Self, String>
21+
where
22+
Self: Sized,
23+
{
24+
match s {
25+
"drm" => Ok(GpuMode::Drm),
26+
"venus" => Ok(GpuMode::Venus),
27+
"software" => Ok(GpuMode::Software),
28+
x => Err(format!("Expected drm|venus|software, got '{}'", x)),
29+
}
30+
}
31+
}
32+
1033
#[derive(Clone, Debug)]
1134
pub struct Options {
1235
pub cpu_list: Vec<Range<u16>>,
@@ -19,6 +42,7 @@ pub struct Options {
1942
pub interactive: bool,
2043
pub tty: bool,
2144
pub privileged: bool,
45+
pub gpu_mode: Option<GpuMode>,
2246
pub publish_ports: Vec<String>,
2347
pub emulator: Option<Emulator>,
2448
pub init_commands: Vec<PathBuf>,
@@ -124,6 +148,10 @@ pub fn options() -> OptionParser<Options> {
124148
This notably does not allow root access to the host fs.",
125149
)
126150
.switch();
151+
let gpu_mode = long("gpu-mode")
152+
.help("Use the given GPU virtualization method")
153+
.argument::<GpuMode>("drm|venus|software")
154+
.optional();
127155
let publish_ports = long("publish")
128156
.short('p')
129157
.help(
@@ -160,6 +188,7 @@ pub fn options() -> OptionParser<Options> {
160188
interactive,
161189
tty,
162190
privileged,
191+
gpu_mode,
163192
publish_ports,
164193
emulator,
165194
init_commands,

0 commit comments

Comments
 (0)