mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2024-12-12 03:34:34 +08:00
91ab35efab
This enables crosvm to map opaque-fd-backed external memory into the guest. Signed-off-by: Omar Akkila <omar.akkila@collabora.com> Acked-by: David Heidelberg <david.heidelberg@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15692>
70 lines
2.9 KiB
Diff
70 lines
2.9 KiB
Diff
From 1cac06ceb16f73448b61e96c02956ec222bf681b Mon Sep 17 00:00:00 2001
|
|
From: Omar Akkila <omar.akkila@collabora.com>
|
|
Date: Tue, 12 Apr 2022 12:30:08 -0400
|
|
Subject: [PATCH 1/1] Map opaque fd resources
|
|
|
|
Signed-off-by: Omar Akkila <omar.akkila@collabora.com>
|
|
---
|
|
devices/src/virtio/gpu/virtio_gpu.rs | 24 +++++++++++++++++++-----
|
|
rutabaga_gfx/src/virgl_renderer.rs | 1 +
|
|
2 files changed, 20 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/devices/src/virtio/gpu/virtio_gpu.rs b/devices/src/virtio/gpu/virtio_gpu.rs
|
|
index 1c4f4f68..d26d7eb0 100644
|
|
--- a/devices/src/virtio/gpu/virtio_gpu.rs
|
|
+++ b/devices/src/virtio/gpu/virtio_gpu.rs
|
|
@@ -698,19 +698,33 @@ impl VirtioGpu {
|
|
let vulkan_info_opt = self.rutabaga.vulkan_info(resource_id).ok();
|
|
|
|
let source = if let Ok(export) = self.rutabaga.export_blob(resource_id) {
|
|
- match vulkan_info_opt {
|
|
- Some(vulkan_info) => VmMemorySource::Vulkan {
|
|
+ if let Some(vulkan_info) = vulkan_info_opt {
|
|
+ VmMemorySource::Vulkan {
|
|
descriptor: export.os_handle,
|
|
handle_type: export.handle_type,
|
|
memory_idx: vulkan_info.memory_idx,
|
|
physical_device_idx: vulkan_info.physical_device_idx,
|
|
size: resource.size,
|
|
- },
|
|
- None => VmMemorySource::Descriptor {
|
|
+ }
|
|
+ } else if export.handle_type == rutabaga_gfx::RUTABAGA_MEM_HANDLE_TYPE_OPAQUE_FD {
|
|
+ let mapping = self.rutabaga.map(resource_id)?;
|
|
+ // Scope for lock
|
|
+ {
|
|
+ let mut map_req = self.map_request.lock();
|
|
+ if map_req.is_some() {
|
|
+ return Err(ErrUnspec);
|
|
+ }
|
|
+ *map_req = Some(mapping);
|
|
+ }
|
|
+ VmMemorySource::ExternalMapping {
|
|
+ size: resource.size,
|
|
+ }
|
|
+ } else {
|
|
+ VmMemorySource::Descriptor {
|
|
descriptor: export.os_handle,
|
|
offset: 0,
|
|
size: resource.size,
|
|
- },
|
|
+ }
|
|
}
|
|
} else {
|
|
if self.external_blob {
|
|
diff --git a/rutabaga_gfx/src/virgl_renderer.rs b/rutabaga_gfx/src/virgl_renderer.rs
|
|
index b29854f5..7110a69d 100644
|
|
--- a/rutabaga_gfx/src/virgl_renderer.rs
|
|
+++ b/rutabaga_gfx/src/virgl_renderer.rs
|
|
@@ -284,6 +284,7 @@ impl VirglRenderer {
|
|
let handle_type = match fd_type {
|
|
VIRGL_RENDERER_BLOB_FD_TYPE_DMABUF => RUTABAGA_MEM_HANDLE_TYPE_DMABUF,
|
|
VIRGL_RENDERER_BLOB_FD_TYPE_SHM => RUTABAGA_MEM_HANDLE_TYPE_SHM,
|
|
+ VIRGL_RENDERER_BLOB_FD_TYPE_OPAQUE => RUTABAGA_MEM_HANDLE_TYPE_OPAQUE_FD,
|
|
_ => {
|
|
return Err(RutabagaError::Unsupported);
|
|
}
|
|
--
|
|
2.25.1
|
|
|