Skip to content

Commit 65b847d

Browse files
vivekkreddykraxel
authored andcommitted
ui: Create sync objects and fences only for blobs
Create sync objects and fences only for dmabufs that are blobs. Once a fence is created (after glFlush) and is signalled, graphic_hw_gl_flushed() will be called and virtio-gpu cmd processing will be resumed. Cc: Gerd Hoffmann <[email protected]> Signed-off-by: Vivek Kasireddy <[email protected]> Message-Id: <[email protected]> Signed-off-by: Gerd Hoffmann <[email protected]>
1 parent 121abaf commit 65b847d

File tree

7 files changed

+68
-0
lines changed

7 files changed

+68
-0
lines changed

hw/display/virtio-gpu-udmabuf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ static VGPUDMABuf
185185
dmabuf->buf.stride = fb->stride;
186186
dmabuf->buf.fourcc = qemu_pixman_to_drm_format(fb->format);
187187
dmabuf->buf.fd = res->dmabuf_fd;
188+
dmabuf->buf.allow_fences = true;
188189

189190
dmabuf->scanout_id = scanout_id;
190191
QTAILQ_INSERT_HEAD(&g->dmabuf.bufs, dmabuf, next);

include/ui/console.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ typedef struct QemuDmaBuf {
170170
bool y0_top;
171171
void *sync;
172172
int fence_fd;
173+
bool allow_fences;
173174
} QemuDmaBuf;
174175

175176
typedef struct DisplayState DisplayState;

include/ui/egl-helpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ typedef struct egl_fb {
1919
GLuint texture;
2020
GLuint framebuffer;
2121
bool delete_texture;
22+
QemuDmaBuf *dmabuf;
2223
} egl_fb;
2324

2425
void egl_fb_destroy(egl_fb *fb);

include/ui/gtk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ extern bool gtk_use_gl_area;
155155
/* ui/gtk.c */
156156
void gd_update_windowsize(VirtualConsole *vc);
157157
int gd_monitor_update_interval(GtkWidget *widget);
158+
void gd_hw_gl_flushed(void *vc);
158159

159160
/* ui/gtk-egl.c */
160161
void gd_egl_init(VirtualConsole *vc);

ui/gtk-egl.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313

1414
#include "qemu/osdep.h"
15+
#include "qemu/main-loop.h"
1516

1617
#include "trace.h"
1718

@@ -94,6 +95,18 @@ void gd_egl_draw(VirtualConsole *vc)
9495
}
9596

9697
glFlush();
98+
#ifdef CONFIG_GBM
99+
if (vc->gfx.guest_fb.dmabuf) {
100+
QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf;
101+
102+
egl_dmabuf_create_fence(dmabuf);
103+
if (dmabuf->fence_fd > 0) {
104+
qemu_set_fd_handler(dmabuf->fence_fd, gd_hw_gl_flushed, NULL, vc);
105+
return;
106+
}
107+
graphic_hw_gl_block(vc->gfx.dcl.con, false);
108+
}
109+
#endif
97110
graphic_hw_gl_flushed(vc->gfx.dcl.con);
98111
}
99112

@@ -209,6 +222,8 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
209222
QemuDmaBuf *dmabuf)
210223
{
211224
#ifdef CONFIG_GBM
225+
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
226+
212227
egl_dmabuf_import_texture(dmabuf);
213228
if (!dmabuf->texture) {
214229
return;
@@ -217,6 +232,10 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl,
217232
gd_egl_scanout_texture(dcl, dmabuf->texture,
218233
false, dmabuf->width, dmabuf->height,
219234
0, 0, dmabuf->width, dmabuf->height);
235+
236+
if (dmabuf->allow_fences) {
237+
vc->gfx.guest_fb.dmabuf = dmabuf;
238+
}
220239
#endif
221240
}
222241

@@ -281,6 +300,12 @@ void gd_egl_scanout_flush(DisplayChangeListener *dcl,
281300
egl_fb_blit(&vc->gfx.win_fb, &vc->gfx.guest_fb, !vc->gfx.y0_top);
282301
}
283302

303+
#ifdef CONFIG_GBM
304+
if (vc->gfx.guest_fb.dmabuf) {
305+
egl_dmabuf_create_sync(vc->gfx.guest_fb.dmabuf);
306+
}
307+
#endif
308+
284309
eglSwapBuffers(qemu_egl_display, vc->gfx.esurface);
285310
}
286311

ui/gtk-gl-area.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
#include "qemu/osdep.h"
11+
#include "qemu/main-loop.h"
1112

1213
#include "trace.h"
1314

@@ -71,7 +72,25 @@ void gd_gl_area_draw(VirtualConsole *vc)
7172
surface_gl_render_texture(vc->gfx.gls, vc->gfx.ds);
7273
}
7374

75+
#ifdef CONFIG_GBM
76+
if (vc->gfx.guest_fb.dmabuf) {
77+
egl_dmabuf_create_sync(vc->gfx.guest_fb.dmabuf);
78+
}
79+
#endif
80+
7481
glFlush();
82+
#ifdef CONFIG_GBM
83+
if (vc->gfx.guest_fb.dmabuf) {
84+
QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf;
85+
86+
egl_dmabuf_create_fence(dmabuf);
87+
if (dmabuf->fence_fd > 0) {
88+
qemu_set_fd_handler(dmabuf->fence_fd, gd_hw_gl_flushed, NULL, vc);
89+
return;
90+
}
91+
graphic_hw_gl_block(vc->gfx.dcl.con, false);
92+
}
93+
#endif
7594
graphic_hw_gl_flushed(vc->gfx.dcl.con);
7695
}
7796

@@ -213,6 +232,9 @@ void gd_gl_area_scanout_flush(DisplayChangeListener *dcl,
213232
{
214233
VirtualConsole *vc = container_of(dcl, VirtualConsole, gfx.dcl);
215234

235+
if (vc->gfx.guest_fb.dmabuf) {
236+
graphic_hw_gl_block(vc->gfx.dcl.con, true);
237+
}
216238
gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area));
217239
}
218240

@@ -231,6 +253,10 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *dcl,
231253
gd_gl_area_scanout_texture(dcl, dmabuf->texture,
232254
false, dmabuf->width, dmabuf->height,
233255
0, 0, dmabuf->width, dmabuf->height);
256+
257+
if (dmabuf->allow_fences) {
258+
vc->gfx.guest_fb.dmabuf = dmabuf;
259+
}
234260
#endif
235261
}
236262

ui/gtk.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "qapi/qapi-commands-machine.h"
3737
#include "qapi/qapi-commands-misc.h"
3838
#include "qemu/cutils.h"
39+
#include "qemu/main-loop.h"
3940

4041
#include "ui/console.h"
4142
#include "ui/gtk.h"
@@ -583,6 +584,18 @@ static void gd_gl_release_dmabuf(DisplayChangeListener *dcl,
583584
#endif
584585
}
585586

587+
void gd_hw_gl_flushed(void *vcon)
588+
{
589+
VirtualConsole *vc = vcon;
590+
QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf;
591+
592+
graphic_hw_gl_block(vc->gfx.dcl.con, false);
593+
graphic_hw_gl_flushed(vc->gfx.dcl.con);
594+
qemu_set_fd_handler(dmabuf->fence_fd, NULL, NULL, NULL);
595+
close(dmabuf->fence_fd);
596+
dmabuf->fence_fd = -1;
597+
}
598+
586599
/** DisplayState Callbacks (opengl version) **/
587600

588601
static const DisplayChangeListenerOps dcl_gl_area_ops = {

0 commit comments

Comments
 (0)