virtio-gpu: create drm fd based on specified render node path
PATCH 1/1 virtio-gpu: create drm fd based on specified render node path
Added a special callback function called virtio_get_drm_fd to create a render node based on the path specified by the user via QEMU command line. This function is called during the virglrenderer callback sequence where we specify the get_drm_fd function pointer to call back our new function, allowing us to pass the fd of our created render node.
Based-on: [email protected]
--- hw/display/virtio-gpu-gl.c | 4 ++++ hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++- include/hw/virtio/virtio-gpu.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-)
hw/display/virtio-gpu-gl.c +4 -0
@@ -161,6 +161,10 @@ 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), +#if VIRGL_RENDERER_CALLBACKS_VERSION >= 2s + DEFINE_PROP_STRING("drm_render_node", VirtIOGPU, + parent_obj.drm_render_node), +#endif };static void virtio_gpu_gl_device_unrealize (DeviceState *qdev)
hw/display/virtio-gpu-virgl.c +16 -1
@@ -1016,6 +1016,15 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, } } +#if VIRGL_RENDERER_CALLBACKS_VERSION >=2 +static int virtio_get_drm_fd (void *opaque) +{ +VirtIOGPU *g = opaque; +int fd =open (g->parent_obj.drm_render_node,O_RDWR ); +return fd; +} +#endif +static void virgl_write_fence (void *opaque,uint32_t fence) {VirtIOGPU *g = opaque;
@@ -1300,7 +1309,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g) }if (virtio_gpu_drm_enabled (g->parent_obj.conf)) { flags |=VIRGL_RENDERER_DRM ; - +#if VIRGL_RENDERER_CALLBACKS_VERSION >=2 +if (g->parent_obj.drm_render_node) { +if (virtio_gpu_3d_cbs.version <2 ) + virtio_gpu_3d_cbs.version =2 ; + virtio_gpu_3d_cbs.get_drm_fd = virtio_get_drm_fd; + } +#endif if (!(flags &VIRGL_RENDERER_ASYNC_FENCE_CB )) {/* * Virglrenderer skips enabling DRM context support without
include/hw/virtio/virtio-gpu.h +1 -0
@@ -152,6 +152,7 @@ struct VirtIOGPUBase {struct virtio_gpu_base_conf conf;struct virtio_gpu_config virtio_config;const GraphicHwOps *hw_ops; +char *drm_render_node;int renderer_blocked;int enable;
Signature · 1 line
2.43.0
Hi,
Quoted 6 lines · Luqmaan Irshad
Added a special callback function called
virtio_get_drm_fdto create a render node based on the path specified by the user via QEMU command line. This function is called during the virglrenderer callback sequence where we specify theget_drm_fdfunction pointer to call back our new function, allowing us to pass the fd of our created render node.
Quoted 8 lines
Based-on: [email protected]
Signed-off-by Luqmaan Irshad <[email protected]>--- hw/display/virtio-gpu-gl.c | 4 ++++ hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++- include/hw/virtio/virtio-gpu.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-)
Do you think it could be possible and worthwhile to make QEMU's EGL display to use same GPU as virgl automatically? I.e. we tell QEMU/EGL which GPU to use and then virgl will use same DRM device that backs EGL.
Signature · 2 lines
Best regards, Dmitry
[AMD Official Use Only - AMD Internal Distribution Only]
Hello Dmitry,
Thats an interesting idea! I would be curious to look into that further, however my ability to do so may be limited since my contract ends at the end of this week.
After my contract ends, I won't have access to a multi-GPU system I can test this on. I may be able to work out some way to borrow the system, but at the moment this is uncertain.
If this patch looks good, my suggestion would be to merge this change, and we can look into adding this as a separate patch on top of this if I can get access to a system. Let me know how this sounds 🙂
Sincerely,
Luq
________________________________
From: Dmitry Osipenko <[email protected]>
Sent: Sunday, December 7, 2025 7:49 PM
To: Irshad, Luqmaan <[email protected]>; [email protected] <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; Pelloux-Prayer, Pierre-Eric <[email protected]>; [email protected] <[email protected]>
Subject: Re: [PATCH] virtio-gpu: create drm fd based on specified render node path
Hi,
Quoted 6 lines · Luqmaan Irshad
Added a special callback function called
virtio_get_drm_fdto create a render node based on the path specified by the user via QEMU command line. This function is called during the virglrenderer callback sequence where we specify theget_drm_fdfunction pointer to call back our new function, allowing us to pass the fd of our created render node.
Quoted 8 lines
Based-on: [email protected]
Signed-off-by Luqmaan Irshad <[email protected]>--- hw/display/virtio-gpu-gl.c | 4 ++++ hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++- include/hw/virtio/virtio-gpu.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-)
Do you think it could be possible and worthwhile to make QEMU's EGL display to use same GPU as virgl automatically? I.e. we tell QEMU/EGL which GPU to use and then virgl will use same DRM device that backs EGL.
--
Best regards,
Dmitry
Quoted 11 lines · Luqmaan
[AMD Official Use Only - AMD Internal Distribution Only]
Hello Dmitry,
Thats an interesting idea! I would be curious to look into that further, however my ability to do so may be limited since my contract ends at the end of this week.
After my contract ends, I won't have access to a multi-GPU system I can test this on. I may be able to work out some way to borrow the system, but at the moment this is uncertain.
If this patch looks good, my suggestion would be to merge this change, and we can look into adding this as a separate patch on top of this if I can get access to a system. Let me know how this sounds 🙂
Sincerely,
Thanks for notifying that you won't work on the patch further. It will be merged or amended.
Signature · 2 lines
Best regards, Dmitry
Quoted 8 lines · Dmitry Osipenko
Hi,
Quoted 5 lines · Luqmaan Irshad
Added a special callback function called
virtio_get_drm_fdto create a render node based on the path specified by the user via QEMU command line. This function is called during the virglrenderer callback sequence where we specify theget_drm_fdfunction pointer to call back our new function, allowing us to pass the fd of our created render node.
I guess what you need can be achieved by specifying a render node for the display. Headless displays (egl-headless and dbus) has the rendernode property for this. For the other displays, Mesa should choose an appropriate render node, and it can be overridden with the DRI_PRIME environment variable:
https://docs.mesa3d.org/envvars.html#envvar-DRI_PRIME
Quoted 10 lines
Quoted 9 lines
Based-on: [email protected]
Signed-off-by Luqmaan Irshad <[email protected]>--- hw/display/virtio-gpu-gl.c | 4 ++++ hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++- include/hw/virtio/virtio-gpu.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-)
Quoted 3 lines
Do you think it could be possible and worthwhile to make QEMU's EGL display to use same GPU as virgl automatically? I.e. we tell QEMU/EGL which GPU to use and then virgl will use same DRM device that backs EGL.
As far as I understand, it is already ensured that virgl uses the EGL display QEMU uses, and I think that what you want. Opening a different render node and passing the node to virglrenderer breaks it.
Regards,
Akihiko Odaki
[AMD Official Use Only - AMD Internal Distribution Only]
Hello Akihiko,
I just had a brief conversation with Pierre-Eric, and I believe the use case is slightly different than the one described. For virgl, selecting using DRI_PRIME only would suffice because QEMU and VirGL (both using OpenGL), both rely on the driver to pickup the GPU.
For Native context however (this case) there is no GL driver use from virglrenderer side, which is why we inform virglrenderer using the callback functions instead.
Sincerely,
Luq
________________________________
From: Akihiko Odaki <[email protected]>
Sent: Thursday, December 11, 2025 9:19:22 a.m.
To: Dmitry Osipenko <[email protected]>; Irshad, Luqmaan <[email protected]>; [email protected] <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; Pelloux-Prayer, Pierre-Eric <[email protected]>; [email protected] <[email protected]>
Subject: Re: [PATCH] virtio-gpu: create drm fd based on specified render node path
Quoted 8 lines · Dmitry Osipenko
Hi,
Quoted 5 lines · Luqmaan Irshad
Added a special callback function called
virtio_get_drm_fdto create a render node based on the path specified by the user via QEMU command line. This function is called during the virglrenderer callback sequence where we specify theget_drm_fdfunction pointer to call back our new function, allowing us to pass the fd of our created render node.
I guess what you need can be achieved by specifying a render node for the display. Headless displays (egl-headless and dbus) has the rendernode property for this. For the other displays, Mesa should choose an appropriate render node, and it can be overridden with the DRI_PRIME environment variable:
https://docs.mesa3d.org/envvars.html#envvar-DRI_PRIME
Quoted 10 lines
Quoted 9 lines
Based-on: [email protected]
Signed-off-by Luqmaan Irshad <[email protected]>--- hw/display/virtio-gpu-gl.c | 4 ++++ hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++- include/hw/virtio/virtio-gpu.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-)
Quoted 3 lines
Do you think it could be possible and worthwhile to make QEMU's EGL display to use same GPU as virgl automatically? I.e. we tell QEMU/EGL which GPU to use and then virgl will use same DRM device that backs EGL.
As far as I understand, it is already ensured that virgl uses the EGL display QEMU uses, and I think that what you want. Opening a different render node and passing the node to virglrenderer breaks it.
Regards,
Akihiko Odaki
Quoted 1 line · Luqmaan
[AMD Official Use Only - AMD Internal Distribution Only]
Your keep sending message with this "Internal Distribution Only" mark. Can you remove it? Perhaps you may ask Honglei Huang, who is also from AMD and work on virtio-gpu/QEMU.
Quoted 4 lines
Hello Akihiko,
I just had a brief conversation with Pierre-Eric, and I believe the use case is slightly different than the one described. For virgl, selecting using
DRI_PRIMEonly would suffice because QEMU and VirGL (both using OpenGL), both rely on the driver to pickup the GPU.
DRI_PRIME is used for EGL, not OpenGL. EGL is agnostic to rendering APIs so it works for Vulkan too.
Quoted 2 lines
For Native context however (this case) there is no GL driver use from virglrenderer side, which is why we inform virglrenderer using the callback functions instead.
Now I understand the problem you are facing; virglrenderer does not respect the EGL display for DRM native context, which is the problem that needs to be fixed; adding another callback function only works around it.
Fortunately, there is EXT_device_drm_render_node, an EGL extension that allows virglrenderer to query the underlying render node from the EGL display, which can be used for DRM native context:
https://registry.khronos.org/EGL/extensions/EXT/EGL_EXT_device_drm_render_node.txt
Consuming the EGL display, you can exploit the render-API-agnostic nature of EGL and ensure DRM native context will work consistently with VirGL and Venus. virglrenderer will be able to use the appropriate render node chosen by Mesa, and if you want to choose a render node by your own, you will be able to use the rendernode property of headless displays or DRI_PRIME for the other displays; no need to set another property for virtio-gpu.
Using EXT_device_drm_render_node on the virglrenderer side may also benefit other VMMs that use virglrenderer.
Regards,
Akihiko Odaki
Quoted 51 lines
Sincerely,
Luq
________________________________
From: Akihiko Odaki <[email protected]>
Sent: Thursday, December 11, 2025 9:19:22 a.m.
To: Dmitry Osipenko <[email protected]>; Irshad, Luqmaan <[email protected]>; [email protected] <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; Pelloux-Prayer, Pierre-Eric <[email protected]>; [email protected] <[email protected]>
Subject: Re: [PATCH] virtio-gpu: create drm fd based on specified render node pathQuoted 8 lines · Dmitry Osipenko
Hi,
Quoted 5 lines · Luqmaan Irshad
Added a special callback function called
virtio_get_drm_fdto create a render node based on the path specified by the user via QEMU command line. This function is called during the virglrenderer callback sequence where we specify theget_drm_fdfunction pointer to call back our new function, allowing us to pass the fd of our created render node.I guess what you need can be achieved by specifying a render node for the display. Headless displays (egl-headless and dbus) has the rendernode property for this. For the other displays, Mesa should choose an appropriate render node, and it can be overridden with the
DRI_PRIMEenvironment variable:
https://docs.mesa3d.org/envvars.html#envvar-DRI_PRIMEQuoted 10 lines
Quoted 9 lines
Based-on: [email protected]
Signed-off-by Luqmaan Irshad <[email protected]>--- hw/display/virtio-gpu-gl.c | 4 ++++ hw/display/virtio-gpu-virgl.c | 17 ++++++++++++++++- include/hw/virtio/virtio-gpu.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-)Quoted 3 lines
Do you think it could be possible and worthwhile to make QEMU's EGL display to use same GPU as virgl automatically? I.e. we tell QEMU/EGL which GPU to use and then virgl will use same DRM device that backs EGL.
As far as I understand, it is already ensured that virgl uses the EGL display QEMU uses, and I think that what you want. Opening a different render node and passing the node to virglrenderer breaks it.
Regards,
Akihiko Odaki