Skip to content

Commit fe3fe12

Browse files
valpackettslp
authored andcommitted
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 158def6 commit fe3fe12

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

crates/muvm/src/bin/muvm.rs

Lines changed: 13 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;
@@ -184,8 +185,14 @@ fn main() -> Result<ExitCode> {
184185
.context("Failed to configure the number of vCPUs and/or the amount of RAM");
185186
}
186187

188+
let virgl_mode = match options.gpu_mode.unwrap_or_default() {
189+
muvm::cli_options::GpuMode::Drm => VIRGLRENDERER_DRM,
190+
muvm::cli_options::GpuMode::Venus => VIRGLRENDERER_VENUS | VIRGLRENDERER_RENDER_SERVER,
191+
muvm::cli_options::GpuMode::Software => 0,
192+
};
187193
let virgl_flags = VIRGLRENDERER_USE_EGL
188-
| VIRGLRENDERER_DRM
194+
| VIRGLRENDERER_NO_VIRGL /* Legacy method that we don't support; interferes with software-only mode */
195+
| virgl_mode
189196
| VIRGLRENDERER_THREAD_SYNC
190197
| VIRGLRENDERER_USE_ASYNC_FENCE_CB;
191198
// SAFETY: Safe as no pointers involved.
@@ -436,6 +443,10 @@ fn main() -> Result<ExitCode> {
436443
env.insert("XAUTHORITY".to_owned(), xauthority);
437444
}
438445

446+
if options.gpu_mode == Some(muvm::cli_options::GpuMode::Venus) {
447+
env.insert("MESA_LOADER_DRIVER_OVERRIDE".to_owned(), "zink".to_owned());
448+
}
449+
439450
let krun_config = KrunBaseConfig {
440451
config: KrunConfig {
441452
args: muvm_guest_args,

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, Copy, Default, PartialEq)]
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>,
@@ -125,6 +149,10 @@ pub fn options() -> OptionParser<Options> {
125149
This notably does not allow root access to the host fs.",
126150
)
127151
.switch();
152+
let gpu_mode = long("gpu-mode")
153+
.help("Use the given GPU virtualization method")
154+
.argument::<GpuMode>("drm|venus|software")
155+
.optional();
128156
let publish_ports = long("publish")
129157
.short('p')
130158
.help(
@@ -169,6 +197,7 @@ pub fn options() -> OptionParser<Options> {
169197
interactive,
170198
tty,
171199
privileged,
200+
gpu_mode,
172201
publish_ports,
173202
emulator,
174203
init_commands,

0 commit comments

Comments
 (0)