From 046df60760f3b0691f23c27a7f24a96c9afe8c05 Mon Sep 17 00:00:00 2001 From: Gurchetan Singh Date: Tue, 2 Oct 2018 16:07:26 -0700 Subject: [PATCH] virtio-gpu: use the newest caps capset2 has many new features. We currently hardcode num_capsets to 1, however our Mesa/guest kernel/virglrenderer are new enough to support caps v2. We could attempt to do negotiation (see virtio_gpu_virgl_get_num_capset in QEMU), but virtio::gpu::Gpu::get_config actually comes before virtio::gpu::Gpu::activate. To support older Mesa/guest kernel/virglrenderer configurations, this must be refactored. BUG=none TEST=get a gles31 context on tatl Change-Id: I8d9ed54774a63da2ec5a4ba86187330521785566 Reviewed-on: https://chromium-review.googlesource.com/1258323 Commit-Ready: ChromeOS CL Exonerator Bot Tested-by: Gurchetan Singh Reviewed-by: Zach Reizner Reviewed-by: Gurchetan Singh --- devices/src/virtio/gpu/backend.rs | 16 ++++++++-------- devices/src/virtio/gpu/mod.rs | 2 +- devices/src/virtio/gpu/protocol.rs | 3 ++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/devices/src/virtio/gpu/backend.rs b/devices/src/virtio/gpu/backend.rs index 0a48549e6d..62cceb2e64 100644 --- a/devices/src/virtio/gpu/backend.rs +++ b/devices/src/virtio/gpu/backend.rs @@ -23,6 +23,7 @@ use super::gpu_renderer::{Box3, Renderer, Context as RendererContext, format_fourcc as renderer_fourcc}; use super::protocol::GpuResponse; +use super::protocol::{VIRTIO_GPU_CAPSET_VIRGL, VIRTIO_GPU_CAPSET_VIRGL2}; const DEFAULT_WIDTH: u32 = 1280; const DEFAULT_HEIGHT: u32 = 1024; @@ -595,14 +596,13 @@ impl Backend { /// Gets the renderer's capset information associated with `index`. pub fn get_capset_info(&self, index: u32) -> GpuResponse { - match index { - 0 => { - let id = 1; // VIRTIO_GPU_CAPSET_VIRGL - let (version, size) = self.renderer.get_cap_set_info(id); - GpuResponse::OkCapsetInfo { id, version, size } - } - _ => GpuResponse::ErrInvalidParameter, - } + let id = match index { + 0 => VIRTIO_GPU_CAPSET_VIRGL, + 1 => VIRTIO_GPU_CAPSET_VIRGL2, + _ => return GpuResponse::ErrInvalidParameter, + }; + let (version, size) = self.renderer.get_cap_set_info(id); + GpuResponse::OkCapsetInfo { id, version, size } } /// Gets the capset of `version` associated with `id`. diff --git a/devices/src/virtio/gpu/mod.rs b/devices/src/virtio/gpu/mod.rs index 38efa41064..0b6f05e161 100644 --- a/devices/src/virtio/gpu/mod.rs +++ b/devices/src/virtio/gpu/mod.rs @@ -610,7 +610,7 @@ impl Gpu { events_read: Le32::from(events_read), events_clear: Le32::from(0), num_scanouts: Le32::from(1), - num_capsets: Le32::from(1), + num_capsets: Le32::from(2), } } } diff --git a/devices/src/virtio/gpu/protocol.rs b/devices/src/virtio/gpu/protocol.rs index c0fbfc3c0f..1c9b1c31db 100644 --- a/devices/src/virtio/gpu/protocol.rs +++ b/devices/src/virtio/gpu/protocol.rs @@ -369,7 +369,8 @@ pub struct virtio_gpu_cmd_submit { unsafe impl DataInit for virtio_gpu_cmd_submit {} -const VIRTIO_GPU_CAPSET_VIRGL: u32 = 1; +pub const VIRTIO_GPU_CAPSET_VIRGL: u32 = 1; +pub const VIRTIO_GPU_CAPSET_VIRGL2: u32 = 2; /* VIRTIO_GPU_CMD_GET_CAPSET_INFO */ #[derive(Copy, Clone, Debug)]