Add support for ROCm (Radeon Open Compute) capability in virtio-gpu. This enables GPU compute workloads using AMD's ROCm platform through the virtio-gpu interface.
Changes include: - Add "rocm" property to virtio-gpu-gl device - Define VIRTIO_GPU_FLAG_ROCM_ENABLED flag - Enable VIRGL_RENDERER_USE_ROCM flag when ROCm is enabled - Add virtio_gpu_rocm_enabled() helper macro This allows guests to detect and utilize ROCm capabilities through the virtio-gpu device when the feature is enabled. Signed-off-by: Honglei Huang <[email protected]> --- hw/display/virtio-gpu-gl.c | 2 ++ hw/display/virtio-gpu-virgl.c | 17 +++++++++++++++++ include/hw/virtio/virtio-gpu.h | 3 +++ 3 files changed, 22 insertions(+) diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c index 2b7a41c4664..d1f11a5bb92 100644 --- a/hw/display/virtio-gpu-gl.c +++ b/hw/display/virtio-gpu-gl.c @@ -170,6 +170,8 @@ static const Property virtio_gpu_gl_properties[] = { VIRTIO_GPU_FLAG_VENUS_ENABLED, false), DEFINE_PROP_BIT("drm_native_context", VirtIOGPU, parent_obj.conf.flags, VIRTIO_GPU_FLAG_DRM_ENABLED, false), + DEFINE_PROP_BIT("rocm", VirtIOGPU, parent_obj.conf.flags, + VIRTIO_GPU_FLAG_ROCM_ENABLED, false), }; static void virtio_gpu_gl_device_unrealize(DeviceState *qdev) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index f71f287d948..f3512337d05 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -1514,6 +1514,14 @@ static int virtio_gpu_virgl_init(VirtIOGPU *g) return -EINVAL; } } + if (virtio_gpu_rocm_enabled(g->parent_obj.conf)) { +#ifdef VIRGL_RENDERER_USE_ROCM + flags |= VIRGL_RENDERER_USE_ROCM; +#else + error_report("rocm requires a ROCm-enabled virglrenderer"); + return -EINVAL; +#endif + } #endif ret = virgl_renderer_init(g, flags, &virtio_gpu_3d_cbs); @@ -1615,5 +1623,14 @@ GArray *virtio_gpu_virgl_get_capsets(VirtIOGPU *g) } } + if (virtio_gpu_rocm_enabled(g->parent_obj.conf)) { + virgl_renderer_get_cap_set(VIRTIO_GPU_CAPSET_ROCM, + &capset_max_ver, + &capset_max_size); + if (capset_max_size) { + virtio_gpu_virgl_add_capset(capset_ids, VIRTIO_GPU_CAPSET_ROCM); + } + } + return capset_ids; } diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 631dfc63a4d..3c5119ce0e4 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -112,6 +112,7 @@ enum virtio_gpu_base_conf_flags { VIRTIO_GPU_FLAG_VENUS_ENABLED, VIRTIO_GPU_FLAG_RESOURCE_UUID_ENABLED, VIRTIO_GPU_FLAG_DRM_ENABLED, + VIRTIO_GPU_FLAG_ROCM_ENABLED, }; #define virtio_gpu_virgl_enabled(_cfg) \ @@ -136,6 +137,8 @@ enum virtio_gpu_base_conf_flags { (_cfg.flags & (1 << VIRTIO_GPU_FLAG_VENUS_ENABLED)) #define virtio_gpu_drm_enabled(_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_DRM_ENABLED)) +#define virtio_gpu_rocm_enabled(_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_ROCM_ENABLED)) struct virtio_gpu_base_conf { uint32_t max_outputs; -- 2.34.1
