@@ -178,6 +178,47 @@ static void virtio_gpu_free_dmabuf(VirtIOGPU *g, VGPUDMABuf *dmabuf)
g_free(dmabuf);
}
+static VGPUDMABuf
+*virtio_gpu_find_dmabuf(VirtIOGPU *g,
+ struct virtio_gpu_simple_resource *res)
+{
+ VGPUDMABuf *dmabuf, *tmp;
+
+ QTAILQ_FOREACH_SAFE(dmabuf, &g->dmabuf.bufs, next, tmp) {
+ if (dmabuf->buf.fd == res->dmabuf_fd) {
+ return dmabuf;
+ }
+ }
+
+ return NULL;
+}
+
+void virtio_gpu_resource_wait_sync(VirtIOGPU *g,
+ struct virtio_gpu_simple_resource *res)
+{
+ struct virtio_gpu_scanout *scanout;
+ VGPUDMABuf *dmabuf;
+
+ dmabuf = virtio_gpu_find_dmabuf(g, res);
+ if (dmabuf) {
+ scanout = &g->parent_obj.scanout[dmabuf->scanout_id];
+ dpy_gl_wait_dmabuf(scanout->con, &dmabuf->buf);
+ }
+}
+
+bool virtio_gpu_resource_has_sync(VirtIOGPU *g,
+ struct virtio_gpu_simple_resource *res)
+{
+ VGPUDMABuf *dmabuf;
+
+ dmabuf = virtio_gpu_find_dmabuf(g, res);
+ if (dmabuf && dmabuf->buf.sync) {
+ return true;
+ }
+
+ return false;
+}
+
static VGPUDMABuf
*virtio_gpu_create_dmabuf(VirtIOGPU *g,
uint32_t scanout_id,
@@ -196,6 +237,7 @@ static VGPUDMABuf
dmabuf->buf.stride = fb->stride;
dmabuf->buf.fourcc = qemu_pixman_to_drm_format(fb->format);
dmabuf->buf.fd = res->dmabuf_fd;
+ dmabuf->buf.sync = NULL;
dmabuf->scanout_id = scanout_id;
QTAILQ_INSERT_HEAD(&g->dmabuf.bufs, dmabuf, next);
@@ -277,6 +277,10 @@ int virtio_gpu_update_dmabuf(VirtIOGPU *g,
uint32_t scanout_id,
struct virtio_gpu_simple_resource *res,
struct virtio_gpu_framebuffer *fb);
+void virtio_gpu_resource_wait_sync(VirtIOGPU *g,
+ struct virtio_gpu_simple_resource *res);
+bool virtio_gpu_resource_has_sync(VirtIOGPU *g,
+ struct virtio_gpu_simple_resource *res);
/* virtio-gpu-3d.c */
void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
@@ -168,6 +168,7 @@ typedef struct QemuDmaBuf {
uint64_t modifier;
uint32_t texture;
bool y0_top;
+ void *sync;
} QemuDmaBuf;
typedef struct DisplayState DisplayState;
@@ -240,6 +241,9 @@ typedef struct DisplayChangeListenerOps {
/* optional */
void (*dpy_gl_release_dmabuf)(DisplayChangeListener *dcl,
QemuDmaBuf *dmabuf);
+ /* optional */
+ void (*dpy_gl_wait_dmabuf)(DisplayChangeListener *dcl,
+ QemuDmaBuf *dmabuf);
/* required if GL */
void (*dpy_gl_update)(DisplayChangeListener *dcl,
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
@@ -312,6 +316,8 @@ void dpy_gl_cursor_position(QemuConsole *con,
uint32_t pos_x, uint32_t pos_y);
void dpy_gl_release_dmabuf(QemuConsole *con,
QemuDmaBuf *dmabuf);
+void dpy_gl_wait_dmabuf(QemuConsole *con,
+ QemuDmaBuf *dmabuf);
void dpy_gl_update(QemuConsole *con,
uint32_t x, uint32_t y, uint32_t w, uint32_t h);
@@ -1917,6 +1917,16 @@ void dpy_gl_release_dmabuf(QemuConsole *con,
}
}
+void dpy_gl_wait_dmabuf(QemuConsole *con,
+ QemuDmaBuf *dmabuf)
+{
+ assert(con->gl);
+
+ if (con->gl->ops->dpy_gl_wait_dmabuf) {
+ con->gl->ops->dpy_gl_wait_dmabuf(con->gl, dmabuf);
+ }
+}
+
void dpy_gl_update(QemuConsole *con,
uint32_t x, uint32_t y, uint32_t w, uint32_t h)
{
These helpers will be used in the next subsequent patches to wait until a dmabuf object (via a texture) has been used by the UI to render and submit its buffer. Cc: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com> --- hw/display/virtio-gpu-udmabuf.c | 42 +++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-gpu.h | 4 ++++ include/ui/console.h | 6 +++++ ui/console.c | 10 ++++++++ 4 files changed, 62 insertions(+)