diff mbox series

[v12,13/13] virtio-gpu: Support Venus context

Message ID 20240519212712.2605419-14-dmitry.osipenko@collabora.com
State New
Headers show
Series Support blob memory and venus on qemu | expand

Commit Message

Dmitry Osipenko May 19, 2024, 9:27 p.m. UTC
From: Antonio Caggiano <antonio.caggiano@collabora.com>

Request Venus when initializing VirGL and if venus=true flag is set for
virtio-gpu-gl device.

Signed-off-by: Antonio Caggiano <antonio.caggiano@collabora.com>
Signed-off-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
---
 hw/display/virtio-gpu-gl.c     |  2 ++
 hw/display/virtio-gpu-virgl.c  | 22 ++++++++++++++++++----
 hw/display/virtio-gpu.c        | 13 +++++++++++++
 include/hw/virtio/virtio-gpu.h |  3 +++
 meson.build                    |  1 +
 5 files changed, 37 insertions(+), 4 deletions(-)

Comments

Manos Pitsidianakis May 23, 2024, 7:18 a.m. UTC | #1
On Mon, 20 May 2024 00:27, Dmitry Osipenko <dmitry.osipenko@collabora.com> wrote:
>From: Antonio Caggiano <antonio.caggiano@collabora.com>
>
>Request Venus when initializing VirGL and if venus=true flag is set for
>virtio-gpu-gl device.
>
>Signed-off-by: Antonio Caggiano <antonio.caggiano@collabora.com>
>Signed-off-by: Huang Rui <ray.huang@amd.com>
>Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
>---
> hw/display/virtio-gpu-gl.c     |  2 ++
> hw/display/virtio-gpu-virgl.c  | 22 ++++++++++++++++++----
> hw/display/virtio-gpu.c        | 13 +++++++++++++
> include/hw/virtio/virtio-gpu.h |  3 +++
> meson.build                    |  1 +
> 5 files changed, 37 insertions(+), 4 deletions(-)
>
>diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c
>index b8f395be8d2d..2078e74050bb 100644
>--- a/hw/display/virtio-gpu-gl.c
>+++ b/hw/display/virtio-gpu-gl.c
>@@ -148,6 +148,8 @@ static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
> static Property virtio_gpu_gl_properties[] = {
>     DEFINE_PROP_BIT("stats", VirtIOGPU, parent_obj.conf.flags,
>                     VIRTIO_GPU_FLAG_STATS_ENABLED, false),
>+    DEFINE_PROP_BIT("venus", VirtIOGPU, parent_obj.conf.flags,
>+                    VIRTIO_GPU_FLAG_VENUS_ENABLED, false),
>     DEFINE_PROP_END_OF_LIST(),
> };
> 
>diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
>index 70e2d28ba966..2e9862dd186a 100644
>--- a/hw/display/virtio-gpu-virgl.c
>+++ b/hw/display/virtio-gpu-virgl.c
>@@ -1130,6 +1130,11 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
>         flags |= VIRGL_RENDERER_D3D11_SHARE_TEXTURE;
>     }
> #endif
>+#ifdef VIRGL_RENDERER_VENUS
>+    if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
>+        flags |= VIRGL_RENDERER_VENUS | VIRGL_RENDERER_RENDER_SERVER;
>+    }
>+#endif
> 
>     ret = virgl_renderer_init(g, flags, &virtio_gpu_3d_cbs);
>     if (ret != 0) {
>@@ -1161,7 +1166,7 @@ static void virtio_gpu_virgl_add_capset(GArray *capset_ids, uint32_t capset_id)
> 
> GArray *virtio_gpu_virgl_get_capsets(VirtIOGPU *g)
> {
>-    uint32_t capset2_max_ver, capset2_max_size;
>+    uint32_t capset_max_ver, capset_max_size;
>     GArray *capset_ids;
> 
>     capset_ids = g_array_new(false, false, sizeof(uint32_t));
>@@ -1170,12 +1175,21 @@ GArray *virtio_gpu_virgl_get_capsets(VirtIOGPU *g)
>     virtio_gpu_virgl_add_capset(capset_ids, VIRTIO_GPU_CAPSET_VIRGL);
> 
>     virgl_renderer_get_cap_set(VIRTIO_GPU_CAPSET_VIRGL2,
>-                              &capset2_max_ver,
>-                              &capset2_max_size);
>-    if (capset2_max_ver) {
>+                               &capset_max_ver,
>+                               &capset_max_size);
>+    if (capset_max_ver) {
>         virtio_gpu_virgl_add_capset(capset_ids, VIRTIO_GPU_CAPSET_VIRGL2);
>     }
> 
>+    if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
>+        virgl_renderer_get_cap_set(VIRTIO_GPU_CAPSET_VENUS,
>+                                   &capset_max_ver,
>+                                   &capset_max_size);
>+        if (capset_max_size) {
>+            virtio_gpu_virgl_add_capset(capset_ids, VIRTIO_GPU_CAPSET_VENUS);
>+        }
>+    }
>+
>     return capset_ids;
> }
> 
>diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
>index 052ab493a00b..0518bb858e88 100644
>--- a/hw/display/virtio-gpu.c
>+++ b/hw/display/virtio-gpu.c
>@@ -1491,6 +1491,19 @@ void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
> #endif
>     }
> 
>+    if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
>+#ifdef HAVE_VIRGL_VENUS
>+        if (!virtio_gpu_blob_enabled(g->parent_obj.conf) ||
>+            !virtio_gpu_hostmem_enabled(g->parent_obj.conf)) {
>+            error_setg(errp, "venus requires enabled blob and hostmem options");
>+            return;
>+        }
>+#else
>+        error_setg(errp, "old virglrenderer, venus unsupported");
>+        return;
>+#endif
>+    }
>+
>     if (!virtio_gpu_base_device_realize(qdev,
>                                         virtio_gpu_handle_ctrl_cb,
>                                         virtio_gpu_handle_cursor_cb,
>diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
>index 7e1fee836802..ec5d7517f141 100644
>--- a/include/hw/virtio/virtio-gpu.h
>+++ b/include/hw/virtio/virtio-gpu.h
>@@ -99,6 +99,7 @@ enum virtio_gpu_base_conf_flags {
>     VIRTIO_GPU_FLAG_BLOB_ENABLED,
>     VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED,
>     VIRTIO_GPU_FLAG_RUTABAGA_ENABLED,
>+    VIRTIO_GPU_FLAG_VENUS_ENABLED,
> };
> 
> #define virtio_gpu_virgl_enabled(_cfg) \
>@@ -117,6 +118,8 @@ enum virtio_gpu_base_conf_flags {
>     (_cfg.flags & (1 << VIRTIO_GPU_FLAG_RUTABAGA_ENABLED))
> #define virtio_gpu_hostmem_enabled(_cfg) \
>     (_cfg.hostmem > 0)
>+#define virtio_gpu_venus_enabled(_cfg) \
>+    (_cfg.flags & (1 << VIRTIO_GPU_FLAG_VENUS_ENABLED))
> 

Can we have both venus and rutabaga enabled on the same virtio-gpu 
device? How would that work? It seems to me they should be mutually 
exclusive.


> struct virtio_gpu_base_conf {
>     uint32_t max_outputs;
>diff --git a/meson.build b/meson.build
>index 503a7736eda0..5a2b7b660c67 100644
>--- a/meson.build
>+++ b/meson.build
>@@ -2305,6 +2305,7 @@ if virgl.version().version_compare('>=1.0.0')
>   config_host_data.set('HAVE_VIRGL_D3D_INFO_EXT', 1)
>   config_host_data.set('HAVE_VIRGL_CONTEXT_CREATE_WITH_FLAGS', 1)
>   config_host_data.set('HAVE_VIRGL_RESOURCE_BLOB', 1)
>+  config_host_data.set('HAVE_VIRGL_VENUS', 1)
> endif
> config_host_data.set('CONFIG_VIRTFS', have_virtfs)
> config_host_data.set('CONFIG_VTE', vte.found())
>-- 
>2.44.0
>
>
Dmitry Osipenko May 23, 2024, 11:33 p.m. UTC | #2
On 5/23/24 10:18, Manos Pitsidianakis wrote:
>> #define virtio_gpu_hostmem_enabled(_cfg) \
>>     (_cfg.hostmem > 0)
>> +#define virtio_gpu_venus_enabled(_cfg) \
>> +    (_cfg.flags & (1 << VIRTIO_GPU_FLAG_VENUS_ENABLED))
>>
> 
> Can we have both venus and rutabaga enabled on the same virtio-gpu
> device? How would that work? It seems to me they should be mutually
> exclusive.

virtio-gpu-gl and virtio-gpu-rutabaga are separate device types. You
can't enable venus for rutabaga device because it doesn't support venus
and vice versa, Qemu will tell you that flag is invalid.
diff mbox series

Patch

diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c
index b8f395be8d2d..2078e74050bb 100644
--- a/hw/display/virtio-gpu-gl.c
+++ b/hw/display/virtio-gpu-gl.c
@@ -148,6 +148,8 @@  static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
 static Property virtio_gpu_gl_properties[] = {
     DEFINE_PROP_BIT("stats", VirtIOGPU, parent_obj.conf.flags,
                     VIRTIO_GPU_FLAG_STATS_ENABLED, false),
+    DEFINE_PROP_BIT("venus", VirtIOGPU, parent_obj.conf.flags,
+                    VIRTIO_GPU_FLAG_VENUS_ENABLED, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 70e2d28ba966..2e9862dd186a 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -1130,6 +1130,11 @@  int virtio_gpu_virgl_init(VirtIOGPU *g)
         flags |= VIRGL_RENDERER_D3D11_SHARE_TEXTURE;
     }
 #endif
+#ifdef VIRGL_RENDERER_VENUS
+    if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
+        flags |= VIRGL_RENDERER_VENUS | VIRGL_RENDERER_RENDER_SERVER;
+    }
+#endif
 
     ret = virgl_renderer_init(g, flags, &virtio_gpu_3d_cbs);
     if (ret != 0) {
@@ -1161,7 +1166,7 @@  static void virtio_gpu_virgl_add_capset(GArray *capset_ids, uint32_t capset_id)
 
 GArray *virtio_gpu_virgl_get_capsets(VirtIOGPU *g)
 {
-    uint32_t capset2_max_ver, capset2_max_size;
+    uint32_t capset_max_ver, capset_max_size;
     GArray *capset_ids;
 
     capset_ids = g_array_new(false, false, sizeof(uint32_t));
@@ -1170,12 +1175,21 @@  GArray *virtio_gpu_virgl_get_capsets(VirtIOGPU *g)
     virtio_gpu_virgl_add_capset(capset_ids, VIRTIO_GPU_CAPSET_VIRGL);
 
     virgl_renderer_get_cap_set(VIRTIO_GPU_CAPSET_VIRGL2,
-                              &capset2_max_ver,
-                              &capset2_max_size);
-    if (capset2_max_ver) {
+                               &capset_max_ver,
+                               &capset_max_size);
+    if (capset_max_ver) {
         virtio_gpu_virgl_add_capset(capset_ids, VIRTIO_GPU_CAPSET_VIRGL2);
     }
 
+    if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
+        virgl_renderer_get_cap_set(VIRTIO_GPU_CAPSET_VENUS,
+                                   &capset_max_ver,
+                                   &capset_max_size);
+        if (capset_max_size) {
+            virtio_gpu_virgl_add_capset(capset_ids, VIRTIO_GPU_CAPSET_VENUS);
+        }
+    }
+
     return capset_ids;
 }
 
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 052ab493a00b..0518bb858e88 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -1491,6 +1491,19 @@  void virtio_gpu_device_realize(DeviceState *qdev, Error **errp)
 #endif
     }
 
+    if (virtio_gpu_venus_enabled(g->parent_obj.conf)) {
+#ifdef HAVE_VIRGL_VENUS
+        if (!virtio_gpu_blob_enabled(g->parent_obj.conf) ||
+            !virtio_gpu_hostmem_enabled(g->parent_obj.conf)) {
+            error_setg(errp, "venus requires enabled blob and hostmem options");
+            return;
+        }
+#else
+        error_setg(errp, "old virglrenderer, venus unsupported");
+        return;
+#endif
+    }
+
     if (!virtio_gpu_base_device_realize(qdev,
                                         virtio_gpu_handle_ctrl_cb,
                                         virtio_gpu_handle_cursor_cb,
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 7e1fee836802..ec5d7517f141 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -99,6 +99,7 @@  enum virtio_gpu_base_conf_flags {
     VIRTIO_GPU_FLAG_BLOB_ENABLED,
     VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED,
     VIRTIO_GPU_FLAG_RUTABAGA_ENABLED,
+    VIRTIO_GPU_FLAG_VENUS_ENABLED,
 };
 
 #define virtio_gpu_virgl_enabled(_cfg) \
@@ -117,6 +118,8 @@  enum virtio_gpu_base_conf_flags {
     (_cfg.flags & (1 << VIRTIO_GPU_FLAG_RUTABAGA_ENABLED))
 #define virtio_gpu_hostmem_enabled(_cfg) \
     (_cfg.hostmem > 0)
+#define virtio_gpu_venus_enabled(_cfg) \
+    (_cfg.flags & (1 << VIRTIO_GPU_FLAG_VENUS_ENABLED))
 
 struct virtio_gpu_base_conf {
     uint32_t max_outputs;
diff --git a/meson.build b/meson.build
index 503a7736eda0..5a2b7b660c67 100644
--- a/meson.build
+++ b/meson.build
@@ -2305,6 +2305,7 @@  if virgl.version().version_compare('>=1.0.0')
   config_host_data.set('HAVE_VIRGL_D3D_INFO_EXT', 1)
   config_host_data.set('HAVE_VIRGL_CONTEXT_CREATE_WITH_FLAGS', 1)
   config_host_data.set('HAVE_VIRGL_RESOURCE_BLOB', 1)
+  config_host_data.set('HAVE_VIRGL_VENUS', 1)
 endif
 config_host_data.set('CONFIG_VIRTFS', have_virtfs)
 config_host_data.set('CONFIG_VTE', vte.found())