Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/virtgpu api: blob resources

This makes blob resources available to guest userspace. They are needed
for GL4.5, Vulkan and zero-copy virtio-gpu.

For Mesa, blob resources have been tested with Piglit's ARB_buffer_storage
tests and apitraces. Apitraces of GL4.5 games show we're between 70%
to 80% of host performance on Iris, based on a apitrace of a 2013 GL4.5
game:

11.204 FPS (guest)
15.947 FPS (host)

This is still better than the status quo, when said game was unplayable
with Virgl due to an inefficient GL4.3 fallback. But there's still room
for improvement if we want to match HW-assisted virtualization.

For Vulkan, blob resources have been tested with dEQP.vk.memory* and
running Vulkan applications in production with the "Cuttlefish" virtual
Android device. This has been done with Lingfeng Yang's "gfxstream"
Vulkan implementation, which virtualizes Vulkan across many Google
products.

Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>
Acked-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Acked-by: Chia-I Wu <olvaffe@gmail.com>
Acked-by: Lingfeng Yang <lfy@google.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20200924003214.662-5-gurchetansingh@chromium.org
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

authored by

Gurchetan Singh and committed by
Gerd Hoffmann
eda3e101 e5cd6cbe

+36 -1
+36 -1
include/uapi/drm/virtgpu_drm.h
··· 46 46 #define DRM_VIRTGPU_TRANSFER_TO_HOST 0x07 47 47 #define DRM_VIRTGPU_WAIT 0x08 48 48 #define DRM_VIRTGPU_GET_CAPS 0x09 49 + #define DRM_VIRTGPU_RESOURCE_CREATE_BLOB 0x0a 49 50 50 51 #define VIRTGPU_EXECBUF_FENCE_FD_IN 0x01 51 52 #define VIRTGPU_EXECBUF_FENCE_FD_OUT 0x02 ··· 72 71 73 72 #define VIRTGPU_PARAM_3D_FEATURES 1 /* do we have 3D features in the hw */ 74 73 #define VIRTGPU_PARAM_CAPSET_QUERY_FIX 2 /* do we have the capset fix */ 74 + #define VIRTGPU_PARAM_RESOURCE_BLOB 3 /* DRM_VIRTGPU_RESOURCE_CREATE_BLOB */ 75 75 76 76 struct drm_virtgpu_getparam { 77 77 __u64 param; ··· 102 100 __u32 bo_handle; 103 101 __u32 res_handle; 104 102 __u32 size; 105 - __u32 stride; 103 + __u32 blob_mem; 106 104 }; 107 105 108 106 struct drm_virtgpu_3d_box { ··· 119 117 struct drm_virtgpu_3d_box box; 120 118 __u32 level; 121 119 __u32 offset; 120 + __u32 stride; 121 + __u32 layer_stride; 122 122 }; 123 123 124 124 struct drm_virtgpu_3d_transfer_from_host { ··· 128 124 struct drm_virtgpu_3d_box box; 129 125 __u32 level; 130 126 __u32 offset; 127 + __u32 stride; 128 + __u32 layer_stride; 131 129 }; 132 130 133 131 #define VIRTGPU_WAIT_NOWAIT 1 /* like it */ ··· 144 138 __u64 addr; 145 139 __u32 size; 146 140 __u32 pad; 141 + }; 142 + 143 + struct drm_virtgpu_resource_create_blob { 144 + #define VIRTGPU_BLOB_MEM_GUEST 0x0001 145 + #define VIRTGPU_BLOB_MEM_HOST3D 0x0002 146 + #define VIRTGPU_BLOB_MEM_HOST3D_GUEST 0x0003 147 + 148 + #define VIRTGPU_BLOB_FLAG_USE_MAPPABLE 0x0001 149 + #define VIRTGPU_BLOB_FLAG_USE_SHAREABLE 0x0002 150 + #define VIRTGPU_BLOB_FLAG_USE_CROSS_DEVICE 0x0004 151 + /* zero is invalid blob_mem */ 152 + __u32 blob_mem; 153 + __u32 blob_flags; 154 + __u32 bo_handle; 155 + __u32 res_handle; 156 + __u64 size; 157 + 158 + /* 159 + * for 3D contexts with VIRTGPU_BLOB_MEM_HOST3D_GUEST and 160 + * VIRTGPU_BLOB_MEM_HOST3D otherwise, must be zero. 161 + */ 162 + __u32 pad; 163 + __u32 cmd_size; 164 + __u64 cmd; 165 + __u64 blob_id; 147 166 }; 148 167 149 168 #define DRM_IOCTL_VIRTGPU_MAP \ ··· 205 174 #define DRM_IOCTL_VIRTGPU_GET_CAPS \ 206 175 DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_GET_CAPS, \ 207 176 struct drm_virtgpu_get_caps) 177 + 178 + #define DRM_IOCTL_VIRTGPU_RESOURCE_CREATE_BLOB \ 179 + DRM_IOWR(DRM_COMMAND_BASE + DRM_VIRTGPU_RESOURCE_CREATE_BLOB, \ 180 + struct drm_virtgpu_resource_create_blob) 208 181 209 182 #if defined(__cplusplus) 210 183 }