Consolidate create-sync and create-fence
cover Consolidate create-sync and create-fence
From: Dongwon Kim <[email protected]>
Sync object itself is never used as is so can be removed from QemuDmaBuf struct. So now sync is only temporarily needed when creating fence for the object which means what was done in egl_dmabuf_create_sync can now be a part of egl_dmabuf_create_fence function. And egl_dmabuf_create_fence returns fence_fd so the better function name will be egl_dmabuf_create_fence_fd.
Dongwon Kim (2):
ui/egl-helpers: Consolidate create-sync and create-fence ui/dmabuf: Remove 'sync' from QemuDmaBuf struct
include/ui/dmabuf.h | 2 -- include/ui/egl-helpers.h | 3 +-- ui/dmabuf.c | 14 -------------- ui/egl-helpers.c | 27 +++++++++++---------------- ui/gtk-egl.c | 15 +++------------ ui/gtk-gl-area.c | 10 ++-------- 6 files changed, 17 insertions(+), 54 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 ui/egl-helpers: Consolidate create-sync and create-fence
From: Dongwon Kim <[email protected]>
There is no reason to split those two operations so combining two functions - egl_dmabuf_create_sync and egl_dmabuf_create_fence.
v2: egl_dmabuf_create_fence -> egl_dmabuf_create_fence_fd
(Marc-André Lureau <[email protected]>)
--- include/ui/egl-helpers.h | 3 +-- ui/egl-helpers.c | 27 +++++++++++---------------- ui/gtk-egl.c | 15 +++------------ ui/gtk-gl-area.c | 10 ++-------- 4 files changed, 17 insertions(+), 38 deletions(-)
include/ui/egl-helpers.h +1 -2
@@ -51,8 +51,7 @@ int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc,void egl_dmabuf_import_texture (QemuDmaBuf *dmabuf);void egl_dmabuf_release_texture (QemuDmaBuf *dmabuf); -void egl_dmabuf_create_sync (QemuDmaBuf *dmabuf); -void egl_dmabuf_create_fence (QemuDmaBuf *dmabuf); +int egl_dmabuf_create_fence_fd (QemuDmaBuf *dmabuf);#endif
ui/egl-helpers.c +11 -16
@@ -371,34 +371,29 @@ void egl_dmabuf_release_texture(QemuDmaBuf *dmabuf) qemu_dmabuf_set_texture(dmabuf, 0); } -void egl_dmabuf_create_sync (QemuDmaBuf *dmabuf) +int egl_dmabuf_create_fence_fd (QemuDmaBuf *dmabuf) {EGLSyncKHR sync; +int fence_fd =-1 ;if (epoxy_has_egl_extension (qemu_egl_display,"EGL_KHR_fence_sync" ) &&epoxy_has_egl_extension (qemu_egl_display, -"EGL_ANDROID_native_fence_sync" )) { +"EGL_ANDROID_native_fence_sync" ) && +qemu_dmabuf_get_fence_fd (dmabuf) ==-1 ) { sync =eglCreateSyncKHR (qemu_egl_display,EGL_SYNC_NATIVE_FENCE_ANDROID ,NULL );if (sync !=EGL_NO_SYNC_KHR ) { -qemu_dmabuf_set_sync (dmabuf, sync); + fence_fd =eglDupNativeFenceFDANDROID (qemu_egl_display, + sync); +if (fence_fd >=0 ) { +qemu_dmabuf_set_fence_fd (dmabuf, fence_fd); + } +eglDestroySyncKHR (qemu_egl_display, sync); } } -} - -void egl_dmabuf_create_fence (QemuDmaBuf *dmabuf) -{ -void *sync =qemu_dmabuf_get_sync (dmabuf); -int fence_fd; -if (sync) { - fence_fd =eglDupNativeFenceFDANDROID (qemu_egl_display, - sync); -qemu_dmabuf_set_fence_fd (dmabuf, fence_fd); -eglDestroySyncKHR (qemu_egl_display, sync); -qemu_dmabuf_set_sync (dmabuf,NULL ); - } +return fence_fd; }#endif /* CONFIG_GBM */
ui/gtk-egl.c +3 -12
@@ -68,7 +68,6 @@ void gd_egl_draw(VirtualConsole *vc)GdkWindow *window;#ifdef CONFIG_GBM QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf; -int fence_fd;#endif int ww, wh, ws;
@@ -99,13 +98,12 @@ void gd_egl_draw(VirtualConsole *vc)glFlush ();#ifdef CONFIG_GBM if (dmabuf) { -egl_dmabuf_create_fence (dmabuf); - fence_fd =qemu_dmabuf_get_fence_fd (dmabuf); +int fence_fd =egl_dmabuf_create_fence_fd (dmabuf);if (fence_fd >=0 ) {qemu_set_fd_handler (fence_fd, gd_hw_gl_flushed,NULL , vc); -return ; + }else { +graphic_hw_gl_block (vc->gfx.dcl.con, false); } -graphic_hw_gl_block (vc->gfx.dcl.con, false); }#endif }else {
@@ -364,12 +362,6 @@ void gd_egl_scanout_flush(DisplayChangeListener *dcl,egl_fb_blit (&vc->gfx.win_fb, &vc->gfx.guest_fb, !vc->gfx.y0_top); } -#ifdef CONFIG_GBM -if (vc->gfx.guest_fb.dmabuf) { -egl_dmabuf_create_sync (vc->gfx.guest_fb.dmabuf); - } -#endif -eglSwapBuffers (qemu_egl_display, vc->gfx.esurface); }
@@ -387,7 +379,6 @@ void gd_egl_flush(DisplayChangeListener *dcl,gtk_widget_queue_draw_area (area, x, y, w, h);return ; } -gd_egl_scanout_flush (&vc->gfx.dcl, x, y, w, h); }
ui/gtk-gl-area.c +2 -8
@@ -77,17 +77,10 @@ void gd_gl_area_draw(VirtualConsole *vc)glBlitFramebuffer (0 , y1, vc->gfx.w, y2,0 ,0 , ww, wh,GL_COLOR_BUFFER_BIT ,GL_NEAREST ); -#ifdef CONFIG_GBM -if (dmabuf) { -egl_dmabuf_create_sync (dmabuf); - } -#endif -glFlush ();#ifdef CONFIG_GBM if (dmabuf) {int fence_fd; -egl_dmabuf_create_fence (dmabuf); - fence_fd =qemu_dmabuf_get_fence_fd (dmabuf); + fence_fd =egl_dmabuf_create_fence_fd (dmabuf);if (fence_fd >=0 ) {qemu_set_fd_handler (fence_fd, gd_hw_gl_flushed,NULL , vc);return ;
@@ -95,6 +88,7 @@ void gd_gl_area_draw(VirtualConsole *vc) graphic_hw_gl_block(vc->gfx.dcl.con, false); }#endif +glFlush (); }else {if (!vc->gfx.ds) {return ;
Signature · 1 line
2.34.1
Re: [PATCH 1/2] ui/egl-helpers: Consolidate create-sync and create-fence
Hi
Quoted 100 lines · On Wed, Jul 3, 2024 at 12:57 AM <[email protected]> wrote:
From: Dongwon Kim <[email protected]>
There is no reason to split those two operations so combining two functions -
egl_dmabuf_create_syncandegl_dmabuf_create_fence.v2:
egl_dmabuf_create_fence->egl_dmabuf_create_fence_fd
(Marc-André Lureau <[email protected]>)Cc Gerd Hoffmann <[email protected]>Cc Marc-André Lureau <[email protected]>Cc Vivek Kasireddy <[email protected]>Signed-off-by Dongwon Kim <[email protected]>--- include/ui/egl-helpers.h | 3 +-- ui/egl-helpers.c | 27 +++++++++++---------------- ui/gtk-egl.c | 15 +++------------ ui/gtk-gl-area.c | 10 ++-------- 4 files changed, 17 insertions(+), 38 deletions(-)include/ui/egl-helpers.h +1
-2@@ -51,8 +51,7 @@ int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc, void egl_dmabuf_import_texture(QemuDmaBuf *dmabuf);void egl_dmabuf_release_texture (QemuDmaBuf *dmabuf); -void egl_dmabuf_create_sync (QemuDmaBuf *dmabuf); -void egl_dmabuf_create_fence (QemuDmaBuf *dmabuf); +int egl_dmabuf_create_fence_fd (QemuDmaBuf *dmabuf);#endif ui/egl-helpers.c +11
-16@@ -371,34 +371,29 @@ void egl_dmabuf_release_texture(QemuDmaBuf *dmabuf) qemu_dmabuf_set_texture(dmabuf, 0); } -void egl_dmabuf_create_sync (QemuDmaBuf *dmabuf) +int egl_dmabuf_create_fence_fd (QemuDmaBuf *dmabuf) {EGLSyncKHR sync; +int fence_fd =-1 ;if (epoxy_has_egl_extension (qemu_egl_display,"EGL_KHR_fence_sync" ) &&epoxy_has_egl_extension (qemu_egl_display, -"EGL_ANDROID_native_fence_sync" )) { +"EGL_ANDROID_native_fence_sync" ) && +qemu_dmabuf_get_fence_fd (dmabuf) ==-1 ) { sync =eglCreateSyncKHR (qemu_egl_display,EGL_SYNC_NATIVE_FENCE_ANDROID ,NULL );if (sync !=EGL_NO_SYNC_KHR ) { -qemu_dmabuf_set_sync (dmabuf, sync); + fence_fd =eglDupNativeFenceFDANDROID (qemu_egl_display, + sync); +if (fence_fd >=0 ) { +qemu_dmabuf_set_fence_fd (dmabuf, fence_fd); + } +eglDestroySyncKHR (qemu_egl_display, sync); } } -} - -void egl_dmabuf_create_fence (QemuDmaBuf *dmabuf) -{ -void *sync =qemu_dmabuf_get_sync (dmabuf); -int fence_fd; -if (sync) { - fence_fd =eglDupNativeFenceFDANDROID (qemu_egl_display, - sync); -qemu_dmabuf_set_fence_fd (dmabuf, fence_fd); -eglDestroySyncKHR (qemu_egl_display, sync); -qemu_dmabuf_set_sync (dmabuf,NULL ); - } +return fence_fd; }#endif /* CONFIG_GBM */ ui/gtk-egl.c +0
-1@@ -68,7 +68,6 @@ void gd_egl_draw(VirtualConsole *vc)GdkWindow *window;#ifdef CONFIG_GBM QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf; -int fence_fd;#endif int ww, wh, ws;@@ -99,13 +98,12 @@ void gd_egl_draw(VirtualConsole *vc)glFlush ();#ifdef CONFIG_GBM if (dmabuf) {
ui/gtk-egl.c void gd_egl_draw(VirtualConsole *vc) · line 107
Quoted 10 lines
ui/gtk-egl.c +3
-3-egl_dmabuf_create_fence (dmabuf); - fence_fd =qemu_dmabuf_get_fence_fd (dmabuf); +int fence_fd =egl_dmabuf_create_fence_fd (dmabuf);if (fence_fd >=0 ) {qemu_set_fd_handler (fence_fd, gd_hw_gl_flushed,NULL , vc); -return ; + }else { +graphic_hw_gl_block (vc->gfx.dcl.con, false); }
If gd_egl_draw()/gd_egl_refresh() is called multiple times before the flushed callback, create_fence_fd() is going to return -1 and unblock the hw. This is probably not desired. I think you need to comment on the code to explain the interaction between dmabuf_get_draw_submitted, gd_egl_flush(), fences and hw_block, I can't make sense of it.
thanks
Quoted 61 lines
ui/gtk-egl.c +0
-1- graphic_hw_gl_block(vc->gfx.dcl.con, false); }#endif } else {ui/gtk-egl.c +0
-7@@ -364,12 +362,6 @@ void gd_egl_scanout_flush(DisplayChangeListener *dcl,egl_fb_blit (&vc->gfx.win_fb, &vc->gfx.guest_fb, !vc->gfx.y0_top); } -#ifdef CONFIG_GBM -if (vc->gfx.guest_fb.dmabuf) { -egl_dmabuf_create_sync (vc->gfx.guest_fb.dmabuf); - } -#endif -eglSwapBuffers (qemu_egl_display, vc->gfx.esurface); }@@ -387,7 +379,6 @@ void gd_egl_flush(DisplayChangeListener *dcl,gtk_widget_queue_draw_area (area, x, y, w, h);return ; } -gd_egl_scanout_flush (&vc->gfx.dcl, x, y, w, h); }ui/gtk-gl-area.c +2
-9@@ -77,17 +77,10 @@ void gd_gl_area_draw(VirtualConsole *vc)glBlitFramebuffer (0 , y1, vc->gfx.w, y2,0 ,0 , ww, wh,GL_COLOR_BUFFER_BIT ,GL_NEAREST ); -#ifdef CONFIG_GBM -if (dmabuf) { -egl_dmabuf_create_sync (dmabuf); - } -#endif -glFlush ();#ifdef CONFIG_GBM if (dmabuf) {int fence_fd; -egl_dmabuf_create_fence (dmabuf); - fence_fd =qemu_dmabuf_get_fence_fd (dmabuf); + fence_fd =egl_dmabuf_create_fence_fd (dmabuf);if (fence_fd >=0 ) {qemu_set_fd_handler (fence_fd, gd_hw_gl_flushed,NULL , vc);return ;@@ -95,6 +88,7 @@ void gd_gl_area_draw(VirtualConsole *vc) graphic_hw_gl_block(vc->gfx.dcl.con, false); }#endif +glFlush (); }else {if (!vc->gfx.ds) {return ; --2.34.1
Signature · 1 line
Marc-André Lureau
Re: [PATCH 1/2] ui/egl-helpers: Consolidate create-sync and create-fence
Hi Marc-André,
Quoted 121 lines · Marc-André Lureau
Hi
On Wed, Jul 3, 2024 at 12:57 AM <[email protected] <mailto:[email protected]>> wrote:
From: Dongwon Kim <[email protected] <mailto:[email protected]>> There is no reason to split those two operations so combining two functions - egl_dmabuf_create_sync and egl_dmabuf_create_fence. v2: egl_dmabuf_create_fence -> egl_dmabuf_create_fence_fd (Marc-André Lureau <[email protected] <mailto:[email protected]>>) Cc: Gerd Hoffmann <[email protected] <mailto:[email protected]>> Cc: Marc-André Lureau <[email protected] <mailto:[email protected]>> Cc: Vivek Kasireddy <[email protected] <mailto:[email protected]>> Signed-off-by: Dongwon Kim <[email protected] <mailto:[email protected]>> --- include/ui/egl-helpers.h | 3 +-- ui/egl-helpers.c | 27 +++++++++++---------------- ui/gtk-egl.c | 15 +++------------ ui/gtk-gl-area.c | 10 ++-------- 4 files changed, 17 insertions(+), 38 deletions(-) diff --git a/include/ui/egl-helpers.h b/include/ui/egl-helpers.h index 4b8c0d2281..221548e3c9 100644 --- a/include/ui/egl-helpers.h +++ b/include/ui/egl-helpers.h @@ -51,8 +51,7 @@ int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc, void egl_dmabuf_import_texture(QemuDmaBuf *dmabuf); void egl_dmabuf_release_texture(QemuDmaBuf *dmabuf); -void egl_dmabuf_create_sync(QemuDmaBuf *dmabuf); -void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf); +int egl_dmabuf_create_fence_fd(QemuDmaBuf *dmabuf); #endif diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c index 99b2ebbe23..ddbf52bf5f 100644 --- a/ui/egl-helpers.c +++ b/ui/egl-helpers.c @@ -371,34 +371,29 @@ void egl_dmabuf_release_texture(QemuDmaBuf *dmabuf) qemu_dmabuf_set_texture(dmabuf, 0); } -void egl_dmabuf_create_sync(QemuDmaBuf *dmabuf) +int egl_dmabuf_create_fence_fd(QemuDmaBuf *dmabuf) { EGLSyncKHR sync; + int fence_fd = -1; if (epoxy_has_egl_extension(qemu_egl_display, "EGL_KHR_fence_sync") && epoxy_has_egl_extension(qemu_egl_display, - "EGL_ANDROID_native_fence_sync")) { + "EGL_ANDROID_native_fence_sync") && + qemu_dmabuf_get_fence_fd(dmabuf) == -1) { sync = eglCreateSyncKHR(qemu_egl_display, EGL_SYNC_NATIVE_FENCE_ANDROID, NULL); if (sync != EGL_NO_SYNC_KHR) { - qemu_dmabuf_set_sync(dmabuf, sync); + fence_fd = eglDupNativeFenceFDANDROID(qemu_egl_display, + sync); + if (fence_fd >= 0) { + qemu_dmabuf_set_fence_fd(dmabuf, fence_fd); + } + eglDestroySyncKHR(qemu_egl_display, sync); } } -} - -void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf) -{ - void *sync = qemu_dmabuf_get_sync(dmabuf); - int fence_fd; - if (sync) { - fence_fd = eglDupNativeFenceFDANDROID(qemu_egl_display, - sync); - qemu_dmabuf_set_fence_fd(dmabuf, fence_fd); - eglDestroySyncKHR(qemu_egl_display, sync); - qemu_dmabuf_set_sync(dmabuf, NULL); - } + return fence_fd; } #endif /* CONFIG_GBM */ diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index 9831c10e1b..8869cdee4f 100644 --- a/ui/gtk-egl.c +++ b/ui/gtk-egl.c @@ -68,7 +68,6 @@ void gd_egl_draw(VirtualConsole *vc) GdkWindow *window; #ifdef CONFIG_GBM QemuDmaBuf *dmabuf = vc->gfx.guest_fb.dmabuf; - int fence_fd; #endif int ww, wh, ws; @@ -99,13 +98,12 @@ void gd_egl_draw(VirtualConsole *vc) glFlush(); #ifdef CONFIG_GBM if (dmabuf) { - egl_dmabuf_create_fence(dmabuf); - fence_fd = qemu_dmabuf_get_fence_fd(dmabuf); + int fence_fd = egl_dmabuf_create_fence_fd(dmabuf); if (fence_fd >= 0) { qemu_set_fd_handler(fence_fd, gd_hw_gl_flushed, NULL, vc); - return; + } else { + graphic_hw_gl_block(vc->gfx.dcl.con, false); }
Quoted 3 lines
If gd_egl_draw()/gd_egl_refresh() is called multiple times before the flushed callback,
create_fence_fd()is going to return -1 and unblock the hw. This is probably not desired. I think you need to comment on the code to explain the interaction betweendmabuf_get_draw_submitted,gd_egl_flush(), fences andhw_block, I can't make sense of it.thanks
Yes, indeed it is not desired flow. Let me have some time to take a look at this case and get back with a better patch.
Quoted 68 lines
- graphic_hw_gl_block(vc->gfx.dcl.con, false); } #endif } else { @@ -364,12 +362,6 @@ void gd_egl_scanout_flush(DisplayChangeListener *dcl, egl_fb_blit(&vc->gfx.win_fb, &vc->gfx.guest_fb, !vc->gfx.y0_top); } -#ifdef CONFIG_GBM - if (vc->gfx.guest_fb.dmabuf) { - egl_dmabuf_create_sync(vc->gfx.guest_fb.dmabuf); - } -#endif - eglSwapBuffers(qemu_egl_display, vc->gfx.esurface); } @@ -387,7 +379,6 @@ void gd_egl_flush(DisplayChangeListener *dcl, gtk_widget_queue_draw_area(area, x, y, w, h); return; } - gd_egl_scanout_flush(&vc->gfx.dcl, x, y, w, h); } diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c index b628b35451..a3c21c3c59 100644 --- a/ui/gtk-gl-area.c +++ b/ui/gtk-gl-area.c @@ -77,17 +77,10 @@ void gd_gl_area_draw(VirtualConsole *vc) glBlitFramebuffer(0, y1, vc->gfx.w, y2, 0, 0, ww, wh, GL_COLOR_BUFFER_BIT, GL_NEAREST); -#ifdef CONFIG_GBM - if (dmabuf) { - egl_dmabuf_create_sync(dmabuf); - } -#endif - glFlush(); #ifdef CONFIG_GBM if (dmabuf) { int fence_fd; - egl_dmabuf_create_fence(dmabuf); - fence_fd = qemu_dmabuf_get_fence_fd(dmabuf); + fence_fd = egl_dmabuf_create_fence_fd(dmabuf); if (fence_fd >= 0) { qemu_set_fd_handler(fence_fd, gd_hw_gl_flushed, NULL, vc); return; @@ -95,6 +88,7 @@ void gd_gl_area_draw(VirtualConsole *vc) graphic_hw_gl_block(vc->gfx.dcl.con, false); } #endif + glFlush(); } else { if (!vc->gfx.ds) { return; -- 2.34.1Signature · 1 line
Marc-André Lureau
PATCH 2/2 ui/dmabuf: Remove 'sync' from QemuDmaBuf struct
In reply to [email protected]From: Dongwon Kim <[email protected]>
Sync object is not used so removing it from QemuDmaBuf struct
--- include/ui/dmabuf.h | 2 -- ui/dmabuf.c | 14 -------------- 2 files changed, 16 deletions(-)
include/ui/dmabuf.h +0 -2
@@ -36,13 +36,11 @@ uint32_t qemu_dmabuf_get_y(QemuDmaBuf *dmabuf);uint32_t qemu_dmabuf_get_backing_width (QemuDmaBuf *dmabuf);uint32_t qemu_dmabuf_get_backing_height (QemuDmaBuf *dmabuf);bool qemu_dmabuf_get_y0_top (QemuDmaBuf *dmabuf); -void *qemu_dmabuf_get_sync (QemuDmaBuf *dmabuf);int32_t qemu_dmabuf_get_fence_fd (QemuDmaBuf *dmabuf);bool qemu_dmabuf_get_allow_fences (QemuDmaBuf *dmabuf);bool qemu_dmabuf_get_draw_submitted (QemuDmaBuf *dmabuf);void qemu_dmabuf_set_texture (QemuDmaBuf *dmabuf,uint32_t texture);void qemu_dmabuf_set_fence_fd (QemuDmaBuf *dmabuf,int32_t fence_fd); -void qemu_dmabuf_set_sync (QemuDmaBuf *dmabuf,void *sync);void qemu_dmabuf_set_draw_submitted (QemuDmaBuf *dmabuf,bool draw_submitted);void qemu_dmabuf_set_fd (QemuDmaBuf *dmabuf,int32_t fd);
ui/dmabuf.c +0 -14
@@ -23,7 +23,6 @@ struct QemuDmaBuf {uint32_t backing_width;uint32_t backing_height;bool y0_top; -void *sync;int fence_fd;bool allow_fences;bool draw_submitted;
@@ -170,13 +169,6 @@ bool qemu_dmabuf_get_y0_top(QemuDmaBuf *dmabuf)return dmabuf->y0_top; } -void *qemu_dmabuf_get_sync (QemuDmaBuf *dmabuf) -{ -assert (dmabuf !=NULL ); - -return dmabuf->sync; -} -int32_t qemu_dmabuf_get_fence_fd (QemuDmaBuf *dmabuf) {assert (dmabuf !=NULL );
@@ -210,12 +202,6 @@ void qemu_dmabuf_set_fence_fd(QemuDmaBuf *dmabuf, int32_t fence_fd) dmabuf->fence_fd = fence_fd; } -void qemu_dmabuf_set_sync (QemuDmaBuf *dmabuf,void *sync) -{ -assert (dmabuf !=NULL ); - dmabuf->sync = sync; -} -void qemu_dmabuf_set_draw_submitted (QemuDmaBuf *dmabuf,bool draw_submitted) {assert (dmabuf !=NULL );
Signature · 1 line
2.34.1