From fdc8c1b7ef05e2f9d54cf1b8e0dca4c3eac5de9d Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 1 Jun 2020 20:11:29 +0900 Subject: [PATCH 01/16] Added an internal API to get release fence from buf_info. Change-Id: I56e536cea0f56368e8519d79082327fd8f052242 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 22 ++++++++++++++++++++++ src/tpl_wayland_egl_thread.h | 4 ++++ src/tpl_wl_egl_thread.c | 14 ++++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 3b4fdce..291afa0 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1897,6 +1897,7 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source, buf_info->sync_timeline = -1; buf_info->is_vk_image = surf_source->disp_source->is_vulkan_dpy; buf_info->commit_sync_ts_backup = ++surf_source->commit_sync_timestamp; + buf_info->release_fence_fd = -1; if (buf_info->is_vk_image) { buf_info->sync_timeline = tbm_sync_timeline_create(); @@ -3730,6 +3731,27 @@ twe_surface_create_sync_fd(tbm_surface_h tbm_surface) return sync_fd; } +tbm_fd +twe_surface_get_buffer_release_fence_fd(twe_surface_h twe_surface, + tbm_surface_h tbm_surface) +{ + twe_wl_buffer_info *buf_info = NULL; + twe_wl_surf_source *surf_source = (twe_wl_surf_source *)twe_surface; + tbm_fd release_fence_fd = -1; + + tbm_surface_internal_get_user_data(tbm_surface, KEY_BUFFER_INFO, + (void **)&buf_info); + if (surf_source->use_surface_sync && + surf_source->disp_source->use_explicit_sync && + buf_info) { + release_fence_fd = buf_info->release_fence_fd; + TPL_DEBUG("surf_source(%p) buf_info(%p) release_fence_fd(%d)", + surf_source, buf_info, release_fence_fd); + } + + return release_fence_fd; +} + tpl_result_t twe_surface_wait_dequeueable(twe_surface_h twe_surface, uint64_t timeout_ns) { diff --git a/src/tpl_wayland_egl_thread.h b/src/tpl_wayland_egl_thread.h index 9252fa9..208e243 100755 --- a/src/tpl_wayland_egl_thread.h +++ b/src/tpl_wayland_egl_thread.h @@ -91,6 +91,10 @@ twe_surface_set_sync_fd(twe_surface_h twe_surface, tbm_fd twe_surface_create_sync_fd(tbm_surface_h tbm_surface); +tbm_fd +twe_surface_get_buffer_release_fence_fd(twe_surface_h twe_surface, + tbm_surface_h tbm_surface); + tpl_result_t twe_surface_wait_dequeueable(twe_surface_h twe_surface, uint64_t timeout_ns); diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index 1915fc9..67ed2eb 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -670,7 +670,7 @@ __tpl_wl_egl_surface_cancel_dequeued_buffer(tpl_surface_t *surface, static tbm_surface_h __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, - tbm_fd *sync_fence) + tbm_fd *sync_fence) { TPL_ASSERT(surface); TPL_ASSERT(surface->backend.data); @@ -688,9 +688,6 @@ __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, int bo_name = 0; tpl_result_t lock_ret = TPL_FALSE; - if (sync_fence) - *sync_fence = -1; - TPL_OBJECT_UNLOCK(surface); tsq_err = tbm_surface_queue_can_dequeue_wait_timeout( wayland_egl_surface->tbm_queue, CAN_DEQUEUE_TIMEOUT_MS); @@ -777,6 +774,15 @@ __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, } tbm_surface_internal_ref(tbm_surface); + + /* If twe_surface_get_buffer_release_fence_fd return -1, + * the tbm_surface can be used immediately. + * If not, user(EGL) have to wait until signaled. */ + if (sync_fence) { + *sync_fence = twe_surface_get_buffer_release_fence_fd( + wayland_egl_surface->twe_surface, tbm_surface); + } + bo_name = tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0)); if (surface->is_frontbuffer_mode && is_activated) -- 2.7.4 From c503bcee9f5e5279aaabff317861fa1f11960dd0 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 3 Jun 2020 18:25:45 +0900 Subject: [PATCH 02/16] Fixed to add release listener before wl_surface_commit. Change-Id: Iffaac088a0699680bfeb7caefeca7873b71e6e0f Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 291afa0..22795ca 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1811,14 +1811,6 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source, g_mutex_unlock(&surf_source->surf_mutex); } - if (surf_source->disp_source->use_explicit_sync && - surf_source->use_surface_sync) { - buf_info->buffer_release = - zwp_linux_surface_synchronization_v1_get_release(surf_source->surface_sync); - zwp_linux_buffer_release_v1_add_listener( - buf_info->buffer_release, &explicit_sync_release_listner, tbm_surface); - } - TRACE_MARK("[SET_BUFFER_INFO] BO(%d)", tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0))); @@ -1912,17 +1904,6 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source, buf_info->sync_timeline); } - if (surf_source->disp_source->use_explicit_sync && - surf_source->use_surface_sync) { - buf_info->buffer_release = - zwp_linux_surface_synchronization_v1_get_release(surf_source->surface_sync); - zwp_linux_buffer_release_v1_add_listener( - buf_info->buffer_release, &explicit_sync_release_listner, tbm_surface); - } else { - wl_buffer_add_listener((void *)buf_info->wl_buffer, - &wl_buffer_release_listener, tbm_surface); - } - tbm_surface_internal_add_user_data(tbm_surface, KEY_BUFFER_INFO, (tbm_data_free)__cb_twe_buffer_free_callback); tbm_surface_internal_set_user_data(tbm_surface, KEY_BUFFER_INFO, @@ -2463,6 +2444,20 @@ _twe_thread_wl_surface_commit(twe_wl_surf_source *surf_source, buf_info->need_to_release = TPL_TRUE; + if (surf_source->disp_source->use_explicit_sync && + surf_source->use_surface_sync) { + buf_info->buffer_release = + zwp_linux_surface_synchronization_v1_get_release(surf_source->surface_sync); + if (!buf_info->buffer_release) { + TPL_ERR("Failed to get buffer_release. twe_surface(%p)", surf_source); + } else { + zwp_linux_buffer_release_v1_add_listener( + buf_info->buffer_release, &explicit_sync_release_listner, tbm_surface); + TPL_DEBUG("add explicit_sync_release_listener."); + } + + } + wl_surface_commit(wl_surface); wl_display_flush(surf_source->disp_source->disp); -- 2.7.4 From 3837de7de76089a1821a15002631ab00f11ec5a5 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Fri, 5 Jun 2020 12:46:35 +0900 Subject: [PATCH 03/16] Fixed to do not wait sync_fence in tbm backend. Change-Id: Ic316cc0843bccbdbed077e6c9b7f97cc8efaa355 Signed-off-by: Joonbum Ko --- src/tpl_tbm.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tpl_tbm.c b/src/tpl_tbm.c index cabdf9d..a41187c 100644 --- a/src/tpl_tbm.c +++ b/src/tpl_tbm.c @@ -255,7 +255,6 @@ __tpl_tbm_surface_enqueue_buffer(tpl_surface_t *surface, tbm_surface_internal_unref(tbm_surface); if (sync_fence != -1) { - tbm_sync_fence_wait(sync_fence, -1); close(sync_fence); } -- 2.7.4 From ed473bd1305c824b7cb91243fd48c029b90970b5 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Fri, 5 Jun 2020 12:51:16 +0900 Subject: [PATCH 04/16] Added acquire_fence_fd to buf_info. Change-Id: Idc1d6357de97b54d30486ad7c53c6e9ce9f403f6 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 56 ++++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 22795ca..54f65ad 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -202,8 +202,12 @@ struct _twe_wl_buffer_info { struct zwp_linux_buffer_release_v1 *buffer_release; /* each buffers own its release_fence_fd, until it passes ownership - * to it to EGL (see wait_for_buffer_release_fence) */ + * to it to EGL */ int release_fence_fd; + + /* each buffers own its acquire_fence_fd. until it passes ownership + * to it to SERVER */ + int acquire_fence_fd; }; struct _twe_fence_wait_source { @@ -1801,6 +1805,7 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source, buf_info->draw_done = TPL_FALSE; buf_info->need_to_commit = TPL_TRUE; buf_info->sync_fd = -1; + buf_info->acquire_fence_fd = -1; buf_info->commit_sync_ts_backup = ++surf_source->commit_sync_timestamp; @@ -1890,6 +1895,10 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source, buf_info->is_vk_image = surf_source->disp_source->is_vulkan_dpy; buf_info->commit_sync_ts_backup = ++surf_source->commit_sync_timestamp; buf_info->release_fence_fd = -1; + buf_info->acquire_fence_fd = -1; + + wl_buffer_add_listener((void *)buf_info->wl_buffer, + &wl_buffer_release_listener, tbm_surface); if (buf_info->is_vk_image) { buf_info->sync_timeline = tbm_sync_timeline_create(); @@ -2446,6 +2455,14 @@ _twe_thread_wl_surface_commit(twe_wl_surf_source *surf_source, if (surf_source->disp_source->use_explicit_sync && surf_source->use_surface_sync) { + + zwp_linux_surface_synchronization_v1_set_acquire_fence(surf_source->surface_sync, + buf_info->acquire_fence_fd); + TPL_DEBUG("[SET_ACQUIRE_FENCE] surf_source(%p) tbm_surface(%p) acquire_fence(%d)", + surf_source, tbm_surface, buf_info->acquire_fence_fd); + close(buf_info->acquire_fence_fd); + buf_info->acquire_fence_fd = -1; + buf_info->buffer_release = zwp_linux_surface_synchronization_v1_get_release(surf_source->surface_sync); if (!buf_info->buffer_release) { @@ -2455,7 +2472,6 @@ _twe_thread_wl_surface_commit(twe_wl_surf_source *surf_source, buf_info->buffer_release, &explicit_sync_release_listner, tbm_surface); TPL_DEBUG("add explicit_sync_release_listener."); } - } wl_surface_commit(wl_surface); @@ -2639,14 +2655,10 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) int sync_fd = surf_source->sync_info.sync_fd; tbm_surface_h tbm_surface = surf_source->sync_info.tbm_surface; - if (surf_source->use_surface_sync) { - zwp_linux_surface_synchronization_v1_set_acquire_fence( - surf_source->surface_sync, sync_fd); - close(sync_fd); - } else { + if (!surf_source->use_surface_sync) { res = _twe_thread_fence_wait_source_attach(surf_source, tbm_surface, sync_fd); if (res != TPL_ERROR_NONE) { - TPL_ERR("Failed to attach source with fence_fd(%d) ret(%d)", + TPL_ERR("Failed to attach source with fence_fd(%d) result(%d)", sync_fd, res); surf_source->use_sync_fence = TPL_FALSE; return res; @@ -3676,6 +3688,7 @@ twe_surface_set_sync_fd(twe_surface_h twe_surface, { twe_wl_surf_source *surf_source = (twe_wl_surf_source *)twe_surface; tpl_result_t ret = TPL_ERROR_NONE; + twe_wl_buffer_info *buf_info = NULL; if (!surf_source) { TPL_ERR("Invalid parameter. twe_surface(%p)", twe_surface); @@ -3687,13 +3700,26 @@ twe_surface_set_sync_fd(twe_surface_h twe_surface, return TPL_ERROR_INVALID_PARAMETER; } - g_mutex_lock(&surf_source->surf_mutex); - surf_source->sync_info.sync_fd = sync_fd; - surf_source->sync_info.tbm_surface = tbm_surface; - surf_source->use_sync_fence = TPL_TRUE; - TPL_DEBUG("[SET_SYNC_FD] surf_source(%p) tbm_surface(%p) sync_fd(%d)", - surf_source, tbm_surface, sync_fd); - g_mutex_unlock(&surf_source->surf_mutex); + tbm_surface_internal_get_user_data(tbm_surface, KEY_BUFFER_INFO, + (void **)&buf_info); + if (!buf_info) { + TPL_ERR("Invalid parameter. tbm_surface(%p)", tbm_surface); + return TPL_ERROR_INVALID_PARAMETER; + } + + if (surf_source->use_surface_sync) { + if (buf_info->acquire_fence_fd != -1) + close(buf_info->acquire_fence_fd); + buf_info->acquire_fence_fd = sync_fd; + } else { + g_mutex_lock(&surf_source->surf_mutex); + surf_source->sync_info.sync_fd = sync_fd; + surf_source->sync_info.tbm_surface = tbm_surface; + surf_source->use_sync_fence = TPL_TRUE; + TPL_DEBUG("[SET_SYNC_FD] surf_source(%p) tbm_surface(%p) sync_fd(%d)", + surf_source, tbm_surface, sync_fd); + g_mutex_unlock(&surf_source->surf_mutex); + } return ret; } -- 2.7.4 From d816b6164de6095c5ca901e5691cae3935f76540 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 17 Jun 2020 13:48:10 +0900 Subject: [PATCH 05/16] Fixed the name of async trace point. Change-Id: Ic9af088f6010968cff41539c560e229ed91bd7be Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 54f65ad..1ec61c9 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1675,9 +1675,9 @@ __cb_buffer_fenced_release(void *data, TRACE_MARK("[FENCED_RELEASE] BO(%d) fence(%d)", tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0)), fence); - TRACE_ASYNC_END((int)tbm_surface, "[COMMIT ~ FENCED_RELEASE] BO(%d)", + TRACE_ASYNC_END((int)tbm_surface, "[COMMIT ~ RELEASE] BO(%d)", tbm_bo_export(tbm_surface_internal_get_bo( - tbm_surface, 0))); + tbm_surface, 0))); TPL_LOG_T(BACKEND, "[FENCED_RELEASE] wl_buffer(%p) tbm_surface(%p) bo(%d) fence(%d)", @@ -1728,9 +1728,9 @@ __cb_buffer_immediate_release(void *data, TRACE_MARK("[IMMEDIATE_RELEASE] BO(%d)", tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0))); - TRACE_ASYNC_END((int)tbm_surface, "[COMMIT ~ IMMEDIATE_RELEASE] BO(%d)", + TRACE_ASYNC_END((int)tbm_surface, "[COMMIT ~ RELEASE] BO(%d)", tbm_bo_export(tbm_surface_internal_get_bo( - tbm_surface, 0))); + tbm_surface, 0))); TPL_LOG_T(BACKEND, "[IMMEDIATE_RELEASE] wl_buffer(%p) tbm_surface(%p) bo(%d)", -- 2.7.4 From 684591ef0de5246b4150809997b4b5fd989871d5 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 20 Jul 2020 13:46:01 +0900 Subject: [PATCH 06/16] Print sync_fence value when dequeue. Change-Id: Id4d8080461ca082008eeab2b1a1e8befd92b056f Signed-off-by: Joonbum Ko --- src/tpl_wl_egl_thread.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tpl_wl_egl_thread.c b/src/tpl_wl_egl_thread.c index 67ed2eb..feb420e 100755 --- a/src/tpl_wl_egl_thread.c +++ b/src/tpl_wl_egl_thread.c @@ -792,8 +792,8 @@ __tpl_wl_egl_surface_dequeue_buffer(tpl_surface_t *surface, uint64_t timeout_ns, TRACE_MARK("[DEQ][NEW]BO_NAME:%d", bo_name); TRACE_ASYNC_BEGIN((int)tbm_surface, "[DEQ]~[ENQ] BO_NAME:%d", bo_name); - TPL_LOG_T("WL_EGL", "[DEQ][N] tbm_surface(%p) bo(%d)", - tbm_surface, bo_name); + TPL_LOG_T("WL_EGL", "[DEQ][N] tbm_surface(%p) bo(%d) fence(%d)", + tbm_surface, bo_name, sync_fence ? *sync_fence : -1); if (lock_ret == TPL_ERROR_NONE) twe_display_unlock(wayland_egl_display->twe_display); -- 2.7.4 From 5eea8e6a1d4cd4abba322d94febe1b6c1ce9a780 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 22 Jul 2020 19:43:54 +0900 Subject: [PATCH 07/16] Allows to decide whether to use explicit fence sync as env. Change-Id: I4631cc4e1a39e740ed7102863d19e9a76c1a6a75 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 1ec61c9..e353862 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -928,11 +928,14 @@ __cb_wl_resistry_global_callback(void *data, struct wl_registry *wl_registry, name, &wp_presentation_interface, 1); TPL_DEBUG("bind wp_presentation_interface"); } else if (strcmp(interface, "zwp_linux_explicit_synchronization_v1") == 0) { - disp_source->explicit_sync = + char env = tpl_getenv("TPL_EFS"); + if (env && atoi(env)) { + disp_source->explicit_sync = wl_registry_bind(wl_registry, name, - &zwp_linux_explicit_synchronization_v1_interface, 1); - disp_source->use_explicit_sync = TPL_TRUE; - TPL_DEBUG("bind zwp_linux_explicit_synchronization_v1_interface"); + &zwp_linux_explicit_synchronization_v1_interface, 1); + disp_source->use_explicit_sync = TPL_TRUE; + TPL_DEBUG("bind zwp_linux_explicit_synchronization_v1_interface"); + } } } -- 2.7.4 From 6ecf20552c96899c25c45cab3629b50f43cd15ff Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 6 Aug 2020 15:37:22 +0900 Subject: [PATCH 08/16] Disabled the explicit fence sync defaultly. - If you want to enable the explicit fence sync feature, 1. touch /opt/usr/tpl_env (only to do it once) 2. export TPL_EFS=1 3. run any gl app with command line. Change-Id: I1618f6e6f8c2deac8e2226a013e63c7fac44b228 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index e353862..885c0e3 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -928,13 +928,15 @@ __cb_wl_resistry_global_callback(void *data, struct wl_registry *wl_registry, name, &wp_presentation_interface, 1); TPL_DEBUG("bind wp_presentation_interface"); } else if (strcmp(interface, "zwp_linux_explicit_synchronization_v1") == 0) { - char env = tpl_getenv("TPL_EFS"); + char *env = tpl_getenv("TPL_EFS"); if (env && atoi(env)) { disp_source->explicit_sync = wl_registry_bind(wl_registry, name, &zwp_linux_explicit_synchronization_v1_interface, 1); disp_source->use_explicit_sync = TPL_TRUE; TPL_DEBUG("bind zwp_linux_explicit_synchronization_v1_interface"); + } else { + disp_source->use_explicit_sync = TPL_FALSE; } } } -- 2.7.4 From 55662de0ec996030b9ea03b0a5e0b468e5bbe691 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Mon, 10 Aug 2020 17:05:50 +0900 Subject: [PATCH 09/16] Package version up to 1.7.10 Change-Id: I24734562e410a34ad3679ba27ec30175e234a83c Signed-off-by: Joonbum Ko --- packaging/libtpl-egl.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtpl-egl.spec b/packaging/libtpl-egl.spec index d5a8f4a..7fdd493 100644 --- a/packaging/libtpl-egl.spec +++ b/packaging/libtpl-egl.spec @@ -4,7 +4,7 @@ #TPL VERSION MACROS %define TPL_VERSION_MAJOR 1 %define TPL_VERSION_MINOR 7 -%define TPL_VERSION_PATCH 9 +%define TPL_VERSION_PATCH 10 %define TPL_VERSION %{TPL_VERSION_MAJOR}.%{TPL_VERSION_MINOR}.%{TPL_VERSION_PATCH} #TPL WINDOW SYSTEM DEFINITION -- 2.7.4 From 1914136d33cf0a30dc31af98629a7fc0b6b06255 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 19 Aug 2020 15:37:35 +0900 Subject: [PATCH 10/16] Fixed wrong exception checking. Change-Id: I41ca475e80625b9ae6168cfd3d05b71bfe3af3ad Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 885c0e3..2fe051d 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -2666,15 +2666,16 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) TPL_ERR("Failed to attach source with fence_fd(%d) result(%d)", sync_fd, res); surf_source->use_sync_fence = TPL_FALSE; - return res; + } else { + surf_source->use_sync_fence = TPL_TRUE; } - - surf_source->use_sync_fence = TPL_TRUE; } surf_source->sync_info.sync_fd = -1; surf_source->sync_info.tbm_surface = NULL; - } else { + } + + if (!surf_source->use_sync_fence){ _twe_thread_wl_surface_acquire_and_commit(surf_source); } } -- 2.7.4 From a59d74fb5048cbbfa2fbd16a093fb63d877c13e7 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 19 Aug 2020 19:41:16 +0900 Subject: [PATCH 11/16] Fixed a bug related to render sync fd. - Very occasionally, when twe_thread is pushed down by scheduling, a sync_fd cannot be attached to twe_thread. - In this case, queue_can_acquire and render_done_cnt are different and the commit is delayed by one frame. - This problem may cause can_dequeue_timeout depending on the hwc situation. - Even if queue_flush is performed after can_dequeue_timeout, the commit latency cannot be restored until another interrupt occurs. Change-Id: I32bc48d523e815a944cbfb935277adc1bcc2bf44 Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 82 +++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index 2fe051d..bb75442 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -97,6 +97,12 @@ struct _twe_del_source { void (*destroy_target_source_func)(void *); }; + +struct sync_info { + tbm_surface_h tbm_surface; + int sync_fd; +}; + struct _twe_wl_surf_source { GSource gsource; gpointer tag; @@ -118,6 +124,7 @@ struct _twe_wl_surf_source { tpl_list_t *in_use_buffers; /* Trace tbm_surface from DEQUEUE to ENQUEUE */ tpl_list_t *fence_waiting_sources; /* Trace fence_wait_source from ENQUEUE to fence signaled */ tpl_list_t *vblank_waiting_buffers; /* for FIFO/FIFO_RELAXED modes */ + tpl_list_t *render_done_fences; /* for attaching to twe_thread with fences passed by enqueue */ tbm_surface_h draw_done_buffer; /* for MAILBOX mode */ int render_done_cnt; @@ -154,11 +161,6 @@ struct _twe_wl_surf_source { int post_interval; - struct { - tbm_surface_h tbm_surface; - int sync_fd; - } sync_info; - struct zwp_linux_surface_synchronization_v1 *surface_sync; }; @@ -2654,28 +2656,27 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer data) } if (surf_source->use_sync_fence && - surf_source->sync_info.sync_fd > 0 && - surf_source->sync_info.tbm_surface) { - - int sync_fd = surf_source->sync_info.sync_fd; - tbm_surface_h tbm_surface = surf_source->sync_info.tbm_surface; - - if (!surf_source->use_surface_sync) { - res = _twe_thread_fence_wait_source_attach(surf_source, tbm_surface, sync_fd); - if (res != TPL_ERROR_NONE) { - TPL_ERR("Failed to attach source with fence_fd(%d) result(%d)", - sync_fd, res); - surf_source->use_sync_fence = TPL_FALSE; - } else { - surf_source->use_sync_fence = TPL_TRUE; + surf_source->render_done_fences) { + + while (__tpl_list_get_count(surf_source->render_done_fences)) { + struct sync_info *sync = __tpl_list_pop_front(surf_source->render_done_fences, + NULL); + if (sync) { + res = _twe_thread_fence_wait_source_attach(surf_source, + sync->tbm_surface, + sync->sync_fd); + if (res != TPL_ERROR_NONE) { + TPL_ERR("Failed to attach source with fence_fd(%d) result(%d)", + sync->sync_fd, res); + surf_source->use_sync_fence = TPL_FALSE; + } + + sync->sync_fd = -1; + sync->tbm_surface = NULL; + free(sync); } } - - surf_source->sync_info.sync_fd = -1; - surf_source->sync_info.tbm_surface = NULL; - } - - if (!surf_source->use_sync_fence){ + } else { _twe_thread_wl_surface_acquire_and_commit(surf_source); } } @@ -3112,6 +3113,7 @@ twe_surface_add(twe_thread* thread, source->committed_buffers = __tpl_list_alloc(); source->in_use_buffers = __tpl_list_alloc(); source->fence_waiting_sources = __tpl_list_alloc(); + source->render_done_fences = __tpl_list_alloc(); source->render_done_cnt = 0; source->cb_data = NULL; @@ -3138,9 +3140,6 @@ twe_surface_add(twe_thread* thread, source->presentation_sync_ts_backup = 0; source->presentation_sync_req_cnt = 0; - source->sync_info.tbm_surface = NULL; - source->sync_info.sync_fd = -1; - if (!disp_source->is_vulkan_dpy) { struct wl_egl_window *wl_egl_window = (struct wl_egl_window *)native_handle; @@ -3718,13 +3717,26 @@ twe_surface_set_sync_fd(twe_surface_h twe_surface, close(buf_info->acquire_fence_fd); buf_info->acquire_fence_fd = sync_fd; } else { - g_mutex_lock(&surf_source->surf_mutex); - surf_source->sync_info.sync_fd = sync_fd; - surf_source->sync_info.tbm_surface = tbm_surface; - surf_source->use_sync_fence = TPL_TRUE; - TPL_DEBUG("[SET_SYNC_FD] surf_source(%p) tbm_surface(%p) sync_fd(%d)", - surf_source, tbm_surface, sync_fd); - g_mutex_unlock(&surf_source->surf_mutex); + /* The sync_info being pushed will be popped when surface_dispatch + * is called and attached to the twe_thread. */ + struct sync_info *sync = (struct sync_info *)calloc(1, sizeof(struct sync_info)); + if (sync) { + sync->sync_fd = sync_fd; + sync->tbm_surface = tbm_surface; + + if (surf_source->render_done_fences) { + g_mutex_lock(&surf_source->surf_mutex); + __tpl_list_push_back(surf_source->render_done_fences, + (void *)sync); + surf_source->use_sync_fence = TPL_TRUE; + TPL_DEBUG("[SET_SYNC_FD] surf_source(%p) tbm_surface(%p) sync_fd(%d)", + surf_source, tbm_surface, sync_fd); + g_mutex_unlock(&surf_source->surf_mutex); + } else { + surf_source->use_sync_fence = TPL_FALSE; + free(sync); + } + } } return ret; -- 2.7.4 From eea8387527bcf50ff4fd2ad7821b79642369e6f1 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Wed, 19 Aug 2020 19:46:51 +0900 Subject: [PATCH 12/16] Package version up to 1.7.11 Change-Id: Iaf37706b20fb16539c3cb4511574f1f1e7dd18be Signed-off-by: Joonbum Ko --- packaging/libtpl-egl.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtpl-egl.spec b/packaging/libtpl-egl.spec index 7fdd493..16495d3 100644 --- a/packaging/libtpl-egl.spec +++ b/packaging/libtpl-egl.spec @@ -4,7 +4,7 @@ #TPL VERSION MACROS %define TPL_VERSION_MAJOR 1 %define TPL_VERSION_MINOR 7 -%define TPL_VERSION_PATCH 10 +%define TPL_VERSION_PATCH 11 %define TPL_VERSION %{TPL_VERSION_MAJOR}.%{TPL_VERSION_MINOR}.%{TPL_VERSION_PATCH} #TPL WINDOW SYSTEM DEFINITION -- 2.7.4 From fca3077daabf68f1dfe116fe9691a75d85a54cc9 Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Thu, 3 Sep 2020 15:33:36 +0900 Subject: [PATCH 13/16] wayland-egl-tizen: changed to use dlog to print logs. Change-Id: Ia248ca9b2ca3c6877a5e0844efa357be7f39ecba Signed-off-by: Joonbum Ko --- configure.ac | 4 ++- packaging/libtpl-egl.spec | 1 + src/wayland-egl-tizen/wayland-egl-tizen.c | 58 ++++++++----------------------- 3 files changed, 18 insertions(+), 45 deletions(-) diff --git a/configure.ac b/configure.ac index 71e4070..e59d587 100644 --- a/configure.ac +++ b/configure.ac @@ -102,7 +102,9 @@ AS_IF([test "${enable_dlog}" = "yes" || test "${enable_dlog}" = "1"], [PKG_CHECK_MODULES([DLOG], [dlog]) TPL_CFLAGS+="$DLOG_CFLAGS" TPL_CFLAGS+=" -DDLOG_DEFAULT_ENABLE " - TPL_LIBS+="$DLOG_LIBS"], + TPL_LIBS+="$DLOG_LIBS" + WL_EGL_TIZEN_CFLAGS+="$DLOG_CFLAGS" + WL_EGL_TIZEN_LIBS+="$DLOG_LIBS"], []) AM_CONDITIONAL([ENABLE_DLOG], [test "${enable_dlog}" = "yes" || test "${enable_dlog}" = "1"]) diff --git a/packaging/libtpl-egl.spec b/packaging/libtpl-egl.spec index 16495d3..f360f7d 100644 --- a/packaging/libtpl-egl.spec +++ b/packaging/libtpl-egl.spec @@ -112,6 +112,7 @@ the GPU Vendor DDK's EGL. Version: %{WL_EGL_TIZEN_VERSION} Release: 0 Summary: Wayland EGL TIZEN backend +BuildRequires: pkgconfig(dlog) %description -n libwayland-egl-tizen This package provides tizen specific extension of wayland-egl. diff --git a/src/wayland-egl-tizen/wayland-egl-tizen.c b/src/wayland-egl-tizen/wayland-egl-tizen.c index b4e679c..2fb876c 100644 --- a/src/wayland-egl-tizen/wayland-egl-tizen.c +++ b/src/wayland-egl-tizen/wayland-egl-tizen.c @@ -3,9 +3,6 @@ #include "wayland-egl-tizen.h" #include "wayland-egl-tizen-priv.h" -#define WL_EGL_DEBUG 1 -#if WL_EGL_DEBUG - #include #include #include @@ -13,41 +10,16 @@ #include #include -unsigned int wl_egl_log_level; - -/* WL-EGL Log Level - 0:unintialized, 1:initialized(no logging), 2:min log, 3:more log */ -#define WL_EGL_LOG(lvl, f, x...) { \ - if (wl_egl_log_level == 1) { \ - } \ - else if (wl_egl_log_level > 1) { \ - if (wl_egl_log_level <= lvl) \ - WL_EGL_LOG_PRINT(f, ##x) \ - } \ - else { \ - char *env = getenv("WL_EGL_LOG_LEVEL"); \ - if (env == NULL) \ - wl_egl_log_level = 1; \ - else \ - wl_egl_log_level = atoi(env); \ - \ - if (wl_egl_log_level > 1 && wl_egl_log_level <= lvl)\ - WL_EGL_LOG_PRINT(f, ##x) \ - } \ - } +#define LOG_TAG "WL_EGL" +#include -#define WL_EGL_LOG_PRINT(fmt, args...) { \ - printf("[\x1b[32mWL-EGL\x1b[0m %d:%d|\x1b[32m%s\x1b[0m|%d] " fmt "\n", \ - getpid(), (int)syscall(SYS_gettid), __func__, __LINE__, ##args); \ - } - -#define WL_EGL_ERR(f, x...) { \ - printf("[\x1b[31mWL-EGL_ERR\x1b[0m %d:%d|\x1b[31m%s\x1b[0m|%d] " f "\n",\ - getpid(), (int)syscall(SYS_gettid), __func__, __LINE__, ##x); \ - } +#define FONT_DEFAULT "\033[0m" /* for reset to default color */ +#define FONT_RED "\033[31m" /* for error logs */ +#define FONT_YELLOW "\033[33m" /* for warning logs */ -#else -#define WL_EGL_LOG(lvl, f, x...) -#endif +#define WL_EGL_LOG(f, x...) LOGI(f, ##x) +#define WL_EGL_ERR(f, x...) LOGE(FONT_RED f FONT_DEFAULT, ##x) +#define WL_EGL_WARN(f, x...) LOGW(FONT_YELLOW f FONT_DEFAULT, ##x) void wl_egl_window_tizen_set_rotation(struct wl_egl_window *egl_window, @@ -72,8 +44,8 @@ wl_egl_window_tizen_set_rotation(struct wl_egl_window *egl_window, } if (private->rotation == rotation) { - WL_EGL_LOG(2, "rotation(%d) egl_window->rotation(%d) already rotated", - rotation, private->rotation); + WL_EGL_WARN("wl_egl_window(%p) rotation(%d) already rotated", + egl_window, rotation); return; } @@ -137,9 +109,8 @@ wl_egl_window_tizen_set_buffer_transform(struct wl_egl_window *egl_window, } if (private->transform == wl_output_transform) { - WL_EGL_LOG(2, - "wl_output_transform(%d) private->transform(%d) already rotated", - wl_output_transform, private->transform); + WL_EGL_WARN("wl_egl_window(%p) wl_output_transform(%d) already rotated", + egl_window, wl_output_transform); return; } @@ -198,9 +169,8 @@ wl_egl_window_tizen_set_window_transform(struct wl_egl_window *egl_window, } if (private->window_transform == window_transform) { - WL_EGL_LOG(2, - "window_transform(%d) already rotated", - window_transform); + WL_EGL_WARN("wl_egl_window(%p) window_transform(%d) already rotated", + egl_window, window_transform); return; } -- 2.7.4 From 35c4a2c948c999f0c1ee39702bfdd40667b85e4b Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Fri, 11 Sep 2020 16:23:59 +0900 Subject: [PATCH 14/16] set resize/destroy callback to null when wl_egl_window destroy. Change-Id: Icba12cf793918944567466465ae04720c16d062b Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index bb75442..d817dd1 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1299,6 +1299,8 @@ __cb_destroy_callback(void *private) TPL_LOG_T(BACKEND, "[DESTROY_CB] wl_egl_window(%p) surf_source(%p)", surf_source->wl_egl_window, surf_source); g_mutex_lock(&surf_source->surf_mutex); + surf_source->wl_egl_window->destroy_window_callback = NULL; + surf_source->wl_egl_window->resize_callback = NULL; surf_source->wl_egl_window->driver_private = NULL; surf_source->wl_egl_window = NULL; surf_source->surf = NULL; -- 2.7.4 From 84eb6445fd4e1c041d940329f3c378ee459d69ec Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Fri, 11 Sep 2020 16:23:59 +0900 Subject: [PATCH 15/16] Replaced assert used in wl_egl_window callback functions. Change-Id: I25f4aa5263d11656d2f40999a69f539f3c27c27c Signed-off-by: Joonbum Ko --- src/tpl_wayland_egl_thread.c | 45 +++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/src/tpl_wayland_egl_thread.c b/src/tpl_wayland_egl_thread.c index d817dd1..27adc14 100755 --- a/src/tpl_wayland_egl_thread.c +++ b/src/tpl_wayland_egl_thread.c @@ -1332,11 +1332,14 @@ __cb_resize_callback(struct wl_egl_window *wl_egl_window, void *private) TPL_ASSERT(wl_egl_window); struct tizen_private *tizen_private = (struct tizen_private *)private; + twe_wl_surf_source *source = (twe_wl_surf_source *)tizen_private->data; int cur_w, cur_h, req_w, req_h, format; - TPL_ASSERT(tizen_private->data); - - twe_wl_surf_source *source = (twe_wl_surf_source *)tizen_private->data; + if (!source) { + TPL_ERR("Invalid wl_egl_window(%p) tizen_private->data is null.", + wl_egl_window); + return; + } format = tbm_surface_queue_get_format(source->tbm_queue); cur_w = tbm_surface_queue_get_width(source->tbm_queue); @@ -1364,7 +1367,11 @@ __cb_rotate_callback(struct wl_egl_window *wl_egl_window, void *private) twe_wl_surf_source *source = (twe_wl_surf_source *)tizen_private->data; int rotation = tizen_private->rotation; - TPL_ASSERT(source); + if (!source) { + TPL_ERR("Invalid wl_egl_window(%p) tizen_private->data is null.", + wl_egl_window); + return; + } TPL_LOG_T(BACKEND, "[ROTATE_CB] wl_egl_window(%p) (%d) -> (%d)", wl_egl_window, source->rotation, rotation); @@ -1384,15 +1391,20 @@ __cb_get_rotation_capability(struct wl_egl_window *wl_egl_window, int rotation_capability = WL_EGL_WINDOW_TIZEN_CAPABILITY_NONE; struct tizen_private *tizen_private = (struct tizen_private *)private; + twe_wl_surf_source *source = (twe_wl_surf_source *)tizen_private->data; - if (tizen_private->data) { - twe_wl_surf_source *source = (twe_wl_surf_source *)tizen_private->data; - if (source->rotation_capability == TPL_TRUE) - rotation_capability = WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_SUPPORTED; - else - rotation_capability = WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_UNSUPPORTED; + if (!source) { + TPL_ERR("Invalid wl_egl_window(%p) tizen_private->data is null.", + wl_egl_window); + return rotation_capability; } + if (source->rotation_capability == TPL_TRUE) + rotation_capability = WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_SUPPORTED; + else + rotation_capability = WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_UNSUPPORTED; + + return rotation_capability; } @@ -1404,13 +1416,16 @@ __cb_set_window_serial_callback(struct wl_egl_window *wl_egl_window, TPL_ASSERT(wl_egl_window); struct tizen_private *tizen_private = (struct tizen_private *)private; + twe_wl_surf_source *source = (twe_wl_surf_source *)tizen_private->data; - if (tizen_private->data) { - twe_wl_surf_source *source = (twe_wl_surf_source *)tizen_private->data; - - source->set_serial_is_used = TPL_TRUE; - source->serial = serial; + if (!source) { + TPL_ERR("Invalid wl_egl_window(%p) tizen_private->data is null.", + wl_egl_window); + return; } + + source->set_serial_is_used = TPL_TRUE; + source->serial = serial; } static int -- 2.7.4 From 758ae697356c4ff50c4c973ea87810038d9543bb Mon Sep 17 00:00:00 2001 From: Joonbum Ko Date: Fri, 11 Sep 2020 16:40:52 +0900 Subject: [PATCH 16/16] Package version up to 1.7.12 Change-Id: If3b4764fb09fb25f073fe6f418c77c6d7a49f413 Signed-off-by: Joonbum Ko --- packaging/libtpl-egl.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/libtpl-egl.spec b/packaging/libtpl-egl.spec index f360f7d..86c3b5b 100644 --- a/packaging/libtpl-egl.spec +++ b/packaging/libtpl-egl.spec @@ -4,7 +4,7 @@ #TPL VERSION MACROS %define TPL_VERSION_MAJOR 1 %define TPL_VERSION_MINOR 7 -%define TPL_VERSION_PATCH 11 +%define TPL_VERSION_PATCH 12 %define TPL_VERSION %{TPL_VERSION_MAJOR}.%{TPL_VERSION_MINOR}.%{TPL_VERSION_PATCH} #TPL WINDOW SYSTEM DEFINITION -- 2.7.4