On 2026/09/09 20:03, Marc-André Lureau wrote:
Use the common virtio_gpu_disable_scanout() to reset the scanout state,
including GL state if any.
Fixes: 7c092f17ccee ("virtio-gpu: Handle resource blob commands")
Signed-off-by: Marc-André Lureau <[email protected]>
---
hw/display/virtio-gpu-rutabaga.c | 4 +---
hw/display/virtio-gpu-virgl.c | 6 ++----
hw/display/virtio-gpu.c | 6 ++++--
3 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutabaga.c
index 8a82e96b7461..8697dd6936ba 100644
--- a/hw/display/virtio-gpu-rutabaga.c
+++ b/hw/display/virtio-gpu-rutabaga.c
@@ -312,9 +312,7 @@ rutabaga_cmd_set_scanout(VirtIOGPU *g, struct
virtio_gpu_ctrl_command *cmd)
scanout = &vb->scanout[ss.scanout_id];
if (ss.resource_id == 0) {
- scanout->resource_id = 0;
- qemu_console_set_surface(scanout->con, NULL);
- qemu_console_gl_scanout_disable(scanout->con);
+ virtio_gpu_disable_scanout(g, ss.scanout_id);
return;
}
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 79d4c0b569fb..87d1fc3d5f65 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -618,8 +618,7 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g,
ss.r.x, ss.r.y, ss.r.width, ss.r.height,
d3d_tex2d);
} else {
- qemu_console_set_surface(g->parent_obj.scanout[ss.scanout_id].con,
NULL);
-
qemu_console_gl_scanout_disable(g->parent_obj.scanout[ss.scanout_id].con);
+ virtio_gpu_disable_scanout(g, ss.scanout_id);
}
g->parent_obj.scanout[ss.scanout_id].resource_id = ss.resource_id;
}
@@ -1426,8 +1425,7 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g)
int i;
for (i = 0; i < g->parent_obj.conf.max_outputs; i++) {
- qemu_console_set_surface(g->parent_obj.scanout[i].con, NULL);
- qemu_console_gl_scanout_disable(g->parent_obj.scanout[i].con);
+ virtio_gpu_disable_scanout(g, i);
}
}
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index f9083e9577c3..dc5b2da9a43f 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -435,8 +435,10 @@ void virtio_gpu_disable_scanout(VirtIOGPU *g, int
scanout_id)
{
struct virtio_gpu_scanout *scanout = &g->parent_obj.scanout[scanout_id];
- virtio_gpu_release_scanout_dmabuf(g, scanout_id);
-
+ if (scanout->dmabuf) {
+ virtio_gpu_release_scanout_dmabuf(g, scanout_id);
+ }
+ qemu_console_gl_scanout_disable(scanout->con);
This disables GL scanout before switching surfaces. Previously, the
surface switch made SDL’s window context current. The reordered callback
deletes SDL’s framebuffer in virgl’s context instead. The framebuffer is
created and bound in the SDL context, so this causes a mismatch.
There are two possible consequences. If EXT_framebuffer_object is not
supported, it just won't work. If the extension is supported, the
framebuffer will be deleted, but apparently Mesa keeps it bound to the
SDL context. In either case, matching the creation/binding/deletion
context will fix the issue.
Apparently "[PATCH v3 13/24] ui: make GL context current before
releasing DMA-BUF textures" has an opposite problem, though I gave
Reviewed-by: earlier. The framebuffer is created in the virgl context,
but qemu_console_gl_release_dmabuf() deletes it in qemu_egl_rn_ctx;
egl_release_dmabuf() makes qemu_egl_rn_ctx current and
egl_scanout_disable() uses it.
Regards,
Akihiko Odaki
qemu_console_set_surface(scanout->con, NULL);
scanout->resource_id = 0;
scanout->ds = NULL;