mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-05 18:20:34 +00:00
devices: gpu: add support for mesa gpu shader cache
When requested with the --gpu=cache-path=/path arg, crosvm will pass it to Mesa via env var MESA_GLSL_CACHE_DIR. In addition, the cache-size will also be passed along if provided. BUG=b:168540438 TEST=run with --gpu=cache-path=/tmp,cache-size=50M and confirm that files are created in /tmp/mesa_shader_cache. Change-Id: I2525597749d654a65373a723cefeab6cf2be62d7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2415509 Tested-by: John Bates <jbates@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Riley <davidriley@chromium.org>
This commit is contained in:
parent
ac010c3a8e
commit
b220eac0d3
4 changed files with 39 additions and 0 deletions
|
@ -76,6 +76,8 @@ pub struct GpuParameters {
|
|||
#[cfg(feature = "gfxstream")]
|
||||
pub gfxstream_support_vulkan: bool,
|
||||
pub mode: GpuMode,
|
||||
pub cache_path: Option<String>,
|
||||
pub cache_size: Option<String>,
|
||||
}
|
||||
|
||||
// First queue is for virtio gpu commands. Second queue is for cursor commands, which we expect
|
||||
|
@ -101,6 +103,8 @@ impl Default for GpuParameters {
|
|||
#[cfg(feature = "gfxstream")]
|
||||
gfxstream_support_vulkan: true,
|
||||
mode: GpuMode::Mode3D,
|
||||
cache_path: None,
|
||||
cache_size: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,6 +71,14 @@ stat: 1
|
|||
statx: 1
|
||||
sysinfo: 1
|
||||
|
||||
# Rules for Mesa's shader binary cache.
|
||||
flock: 1
|
||||
mkdir: 1
|
||||
newfstatat: 1
|
||||
rename: 1
|
||||
setpriority: 1
|
||||
unlink: 1
|
||||
|
||||
# Rules specific to AMD gpus.
|
||||
uname: 1
|
||||
sched_setscheduler: 1
|
||||
|
|
25
src/linux.rs
25
src/linux.rs
|
@ -4,6 +4,8 @@
|
|||
|
||||
use std::cmp::{max, Reverse};
|
||||
use std::convert::TryFrom;
|
||||
#[cfg(feature = "gpu")]
|
||||
use std::env;
|
||||
use std::error::Error as StdError;
|
||||
use std::ffi::CStr;
|
||||
use std::fmt::{self, Display};
|
||||
|
@ -736,6 +738,29 @@ fn create_gpu_device(
|
|||
jail.mount_bind(drm_dri_path, drm_dri_path, false)?;
|
||||
}
|
||||
|
||||
// Prepare GPU shader disk cache directory.
|
||||
if let Some(cache_dir) = cfg
|
||||
.gpu_parameters
|
||||
.as_ref()
|
||||
.and_then(|params| params.cache_path.as_ref())
|
||||
{
|
||||
if cfg!(any(target_arch = "arm", target_arch = "aarch64")) && cfg.sandbox {
|
||||
warn!("shader caching not yet supported on ARM with sandbox enabled");
|
||||
env::set_var("MESA_GLSL_CACHE_DISABLE", "true");
|
||||
} else {
|
||||
env::set_var("MESA_GLSL_CACHE_DIR", cache_dir);
|
||||
if let Some(cache_size) = cfg
|
||||
.gpu_parameters
|
||||
.as_ref()
|
||||
.and_then(|params| params.cache_size.as_ref())
|
||||
{
|
||||
env::set_var("MESA_GLSL_CACHE_MAX_SIZE", cache_size);
|
||||
}
|
||||
let shadercache_path = Path::new(cache_dir);
|
||||
jail.mount_bind(shadercache_path, shadercache_path, true)?;
|
||||
}
|
||||
}
|
||||
|
||||
// If the ARM specific devices exist on the host, bind mount them in.
|
||||
let mali0_path = Path::new("/dev/mali0");
|
||||
if mali0_path.exists() {
|
||||
|
|
|
@ -322,6 +322,8 @@ fn parse_gpu_options(s: Option<&str>) -> argument::Result<GpuParameters> {
|
|||
),
|
||||
})?;
|
||||
}
|
||||
"cache-path" => gpu_params.cache_path = Some(v.to_string()),
|
||||
"cache-size" => gpu_params.cache_size = Some(v.to_string()),
|
||||
"" => {}
|
||||
_ => {
|
||||
return Err(argument::Error::UnknownArgument(format!(
|
||||
|
|
Loading…
Reference in a new issue