summary refs log tree commit diff
diff options
context:
space:
mode:
authorJason Macnak <natsu@google.com>2019-11-20 16:25:49 -0800
committerCommit Bot <commit-bot@chromium.org>2019-12-11 16:58:39 +0000
commitbf19558be57556bb92696827c31c1f0cba035801 (patch)
treee0bffda439e8db7e7763e897e22828a10d97752b
parent8d3f9ba350137a3f423a4241067cf96762e518bf (diff)
downloadcrosvm-bf19558be57556bb92696827c31c1f0cba035801.tar
crosvm-bf19558be57556bb92696827c31c1f0cba035801.tar.gz
crosvm-bf19558be57556bb92696827c31c1f0cba035801.tar.bz2
crosvm-bf19558be57556bb92696827c31c1f0cba035801.tar.lz
crosvm-bf19558be57556bb92696827c31c1f0cba035801.tar.xz
crosvm-bf19558be57556bb92696827c31c1f0cba035801.tar.zst
crosvm-bf19558be57556bb92696827c31c1f0cba035801.zip
Makes gpu renderer flags configurable via command line
BUG=b:134086390
TEST=built crosvm and booted cuttlefish locally with gpu

Change-Id: I4d816ddb52a2eadd06088d204d95118289a3f587
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1927873
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Jason Macnak <natsu@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Jason Macnak <natsu@google.com>
-rw-r--r--devices/src/virtio/gpu/mod.rs21
-rw-r--r--src/main.rs59
2 files changed, 79 insertions, 1 deletions
diff --git a/devices/src/virtio/gpu/mod.rs b/devices/src/virtio/gpu/mod.rs
index 637f22b..83031c8 100644
--- a/devices/src/virtio/gpu/mod.rs
+++ b/devices/src/virtio/gpu/mod.rs
@@ -47,11 +47,19 @@ pub const DEFAULT_DISPLAY_HEIGHT: u32 = 1024;
 pub struct GpuParameters {
     pub display_width: u32,
     pub display_height: u32,
+    pub renderer_use_egl: bool,
+    pub renderer_use_gles: bool,
+    pub renderer_use_glx: bool,
+    pub renderer_use_surfaceless: bool,
 }
 
 pub const DEFAULT_GPU_PARAMS: GpuParameters = GpuParameters {
     display_width: DEFAULT_DISPLAY_WIDTH,
     display_height: DEFAULT_DISPLAY_HEIGHT,
+    renderer_use_egl: true,
+    renderer_use_gles: true,
+    renderer_use_glx: false,
+    renderer_use_surfaceless: true,
 };
 
 // First queue is for virtio gpu commands. Second queue is for cursor commands, which we expect
@@ -675,11 +683,12 @@ fn build_backend(
     possible_displays: &[DisplayBackend],
     display_width: u32,
     display_height: u32,
+    renderer_flags: RendererFlags,
     event_devices: Vec<EventDevice>,
     gpu_device_socket: VmMemoryControlRequestSocket,
     pci_bar: Alloc,
 ) -> Option<Backend> {
-    let mut renderer_flags = RendererFlags::default();
+    let mut renderer_flags = renderer_flags;
     let mut display_opt = None;
     for display in possible_displays {
         match display.build() {
@@ -749,6 +758,7 @@ pub struct Gpu {
     display_backends: Vec<DisplayBackend>,
     display_width: u32,
     display_height: u32,
+    renderer_flags: RendererFlags,
     pci_bar: Option<Alloc>,
 }
 
@@ -762,6 +772,12 @@ impl Gpu {
         gpu_parameters: &GpuParameters,
         event_devices: Vec<EventDevice>,
     ) -> Gpu {
+        let renderer_flags = RendererFlags::new()
+            .use_egl(gpu_parameters.renderer_use_egl)
+            .use_gles(gpu_parameters.renderer_use_gles)
+            .use_glx(gpu_parameters.renderer_use_glx)
+            .use_surfaceless(gpu_parameters.renderer_use_surfaceless);
+
         Gpu {
             exit_evt,
             gpu_device_socket,
@@ -774,6 +790,7 @@ impl Gpu {
             display_backends,
             display_width: gpu_parameters.display_width,
             display_height: gpu_parameters.display_height,
+            renderer_flags,
             pci_bar: None,
         }
     }
@@ -894,6 +911,7 @@ impl VirtioDevice for Gpu {
         let display_backends = self.display_backends.clone();
         let display_width = self.display_width;
         let display_height = self.display_height;
+        let renderer_flags = self.renderer_flags;
         let event_devices = self.event_devices.split_off(0);
         if let (Some(gpu_device_socket), Some(pci_bar)) =
             (self.gpu_device_socket.take(), self.pci_bar.take())
@@ -906,6 +924,7 @@ impl VirtioDevice for Gpu {
                             &display_backends,
                             display_width,
                             display_height,
+                            renderer_flags,
                             event_devices,
                             gpu_device_socket,
                             pci_bar,
diff --git a/src/main.rs b/src/main.rs
index 7f12841..d630d6c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -122,6 +122,62 @@ fn parse_gpu_options(s: Option<&str>) -> argument::Result<GpuParameters> {
 
         for (k, v) in opts {
             match k {
+                "egl" => match v {
+                    "true" | "" => {
+                        gpu_params.renderer_use_egl = true;
+                    }
+                    "false" => {
+                        gpu_params.renderer_use_egl = false;
+                    }
+                    _ => {
+                        return Err(argument::Error::InvalidValue {
+                            value: v.to_string(),
+                            expected: "gpu parameter 'egl' should be a boolean",
+                        });
+                    }
+                },
+                "gles" => match v {
+                    "true" | "" => {
+                        gpu_params.renderer_use_gles = true;
+                    }
+                    "false" => {
+                        gpu_params.renderer_use_gles = false;
+                    }
+                    _ => {
+                        return Err(argument::Error::InvalidValue {
+                            value: v.to_string(),
+                            expected: "gpu parameter 'gles' should be a boolean",
+                        });
+                    }
+                },
+                "glx" => match v {
+                    "true" | "" => {
+                        gpu_params.renderer_use_glx = true;
+                    }
+                    "false" => {
+                        gpu_params.renderer_use_glx = false;
+                    }
+                    _ => {
+                        return Err(argument::Error::InvalidValue {
+                            value: v.to_string(),
+                            expected: "gpu parameter 'glx' should be a boolean",
+                        });
+                    }
+                },
+                "surfaceless" => match v {
+                    "true" | "" => {
+                        gpu_params.renderer_use_surfaceless = true;
+                    }
+                    "false" => {
+                        gpu_params.renderer_use_surfaceless = false;
+                    }
+                    _ => {
+                        return Err(argument::Error::InvalidValue {
+                            value: v.to_string(),
+                            expected: "gpu parameter 'surfaceless' should be a boolean",
+                        });
+                    }
+                },
                 "width" => {
                     gpu_params.display_width =
                         v.parse::<u32>()
@@ -980,6 +1036,9 @@ writeback=BOOL - Indicates whether the VM can use writeback caching (default: fa
                                   Possible key values:
                                   width=INT - The width of the virtual display connected to the virtio-gpu.
                                   height=INT - The height of the virtual display connected to the virtio-gpu.
+                                  egl[=true|=false] - If the virtio-gpu backend should use a EGL context for rendering.
+                                  glx[=true|=false] - If the virtio-gpu backend should use a GLX context for rendering.
+                                  surfaceless[=true|=false] - If the virtio-gpu backend should use a surfaceless context for rendering.
                                   "),
           #[cfg(feature = "tpm")]
           Argument::flag("software-tpm", "enable a software emulated trusted platform module device"),