Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions crates/muvm/src/bin/muvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use krun_sys::{
krun_add_disk, krun_add_virtiofs2, krun_add_vsock_port, krun_add_vsock_port2, krun_create_ctx,
krun_set_env, krun_set_gpu_options2, krun_set_log_level, krun_set_passt_fd, krun_set_root,
krun_set_vm_config, krun_set_workdir, krun_start_enter, VIRGLRENDERER_DRM,
VIRGLRENDERER_THREAD_SYNC, VIRGLRENDERER_USE_ASYNC_FENCE_CB, VIRGLRENDERER_USE_EGL,
VIRGLRENDERER_NO_VIRGL, VIRGLRENDERER_RENDER_SERVER, VIRGLRENDERER_THREAD_SYNC,
VIRGLRENDERER_USE_ASYNC_FENCE_CB, VIRGLRENDERER_USE_EGL, VIRGLRENDERER_VENUS,
};
use log::debug;
use muvm::cli_options::options;
Expand Down Expand Up @@ -184,8 +185,14 @@ fn main() -> Result<ExitCode> {
.context("Failed to configure the number of vCPUs and/or the amount of RAM");
}

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

if options.gpu_mode == Some(muvm::cli_options::GpuMode::Venus) {
env.insert("MESA_LOADER_DRIVER_OVERRIDE".to_owned(), "zink".to_owned());
}

let krun_config = KrunBaseConfig {
config: KrunConfig {
args: muvm_guest_args,
Expand Down
29 changes: 29 additions & 0 deletions crates/muvm/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ use bpaf::{any, construct, long, positional, OptionParser, Parser};
use crate::types::MiB;
use crate::utils::launch::Emulator;

#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub enum GpuMode {
#[default]
Drm,
Venus,
Software,
}

impl std::str::FromStr for GpuMode {
type Err = String;
fn from_str(s: &str) -> Result<Self, String>
where
Self: Sized,
{
match s {
"drm" => Ok(GpuMode::Drm),
"venus" => Ok(GpuMode::Venus),
"software" => Ok(GpuMode::Software),
x => Err(format!("Expected drm|venus|software, got '{x}'")),
}
}
}

#[derive(Clone, Debug)]
pub struct Options {
pub cpu_list: Vec<Range<u16>>,
Expand All @@ -19,6 +42,7 @@ pub struct Options {
pub interactive: bool,
pub tty: bool,
pub privileged: bool,
pub gpu_mode: Option<GpuMode>,
pub publish_ports: Vec<String>,
pub emulator: Option<Emulator>,
pub init_commands: Vec<PathBuf>,
Expand Down Expand Up @@ -125,6 +149,10 @@ pub fn options() -> OptionParser<Options> {
This notably does not allow root access to the host fs.",
)
.switch();
let gpu_mode = long("gpu-mode")
.help("Use the given GPU virtualization method")
.argument::<GpuMode>("drm|venus|software")
.optional();
let publish_ports = long("publish")
.short('p')
.help(
Expand Down Expand Up @@ -169,6 +197,7 @@ pub fn options() -> OptionParser<Options> {
interactive,
tty,
privileged,
gpu_mode,
publish_ports,
emulator,
init_commands,
Expand Down
Loading