This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository efl.
View the commit online.
commit c103a770ebb6ac2f62bda0af0174206324f0a842
Author: Alastair Poole <[email protected]>
AuthorDate: Wed Dec 2 01:56:15 2026 +0000
ecore_drm2: preserve framebuffer state across page flips
Software rendering can stall when a tick drops the queued frame or
a flip to the current framebuffer leaves an extra reference behind.
Keep the queued frame while a flip is pending and release each slot
reference when it is retired.
Retry timed-out atomic flips with the submitted request. Propagate
legacy page-flip failures so a rejected submission cannot leave a
frame marked pending.
Co-Authored-By: Codex (GPT-6) <[email protected]>
---
src/lib/ecore_drm2/ecore_drm2_fb.c | 71 ++++++++++------
src/tests/ecore/ecore_test_ecore_drm2_fb.c | 132 ++++++++++++++++++++++++++++-
2 files changed, 174 insertions(+), 29 deletions(-)
diff --git a/src/lib/ecore_drm2/ecore_drm2_fb.c b/src/lib/ecore_drm2/ecore_drm2_fb.c
index a90d13bbf6..fa07b4ed0c 100644
--- a/src/lib/ecore_drm2/ecore_drm2_fb.c
+++ b/src/lib/ecore_drm2/ecore_drm2_fb.c
@@ -242,15 +242,20 @@ ecore_drm2_fb_dirty(Ecore_Drm2_Fb *fb, Eina_Rectangle *rects, unsigned int count
/* perhaps output is no longer a necessary parameter for this function */
void
-_ecore_drm2_fb_buffer_release(Ecore_Drm2_Output *output EINA_UNUSED, Ecore_Drm2_Output_State *s)
+_ecore_drm2_fb_buffer_release(Ecore_Drm2_Output *output, Ecore_Drm2_Output_State *s)
{
Ecore_Drm2_Fb *fb = s->fb;
- if (fb->status_handler)
- fb->status_handler(fb, ECORE_DRM2_FB_STATUS_RELEASE, fb->status_data);
+ if (fb)
+ {
+ s->fb = NULL;
+ if (fb->status_handler &&
+ (fb != output->current.fb) && (fb != output->pending.fb) &&
+ (fb != output->next.fb) && (fb != output->prep.fb))
+ fb->status_handler(fb, ECORE_DRM2_FB_STATUS_RELEASE, fb->status_data);
- _ecore_drm2_fb_deref(fb);
- s->fb = NULL;
+ _ecore_drm2_fb_deref(fb);
+ }
if (_ecore_drm2_use_atomic)
{
if (s->atomic_req)
@@ -291,8 +296,13 @@ ecore_drm2_fb_flip_complete(Ecore_Drm2_Output *output)
WRN("Flip event received with no flip pending");
return !!output->next.fb;
}
- if (output->current.fb && (output->current.fb != output->pending.fb))
- _ecore_drm2_fb_buffer_release(output, &output->current);
+ if (output->current.fb == output->pending.fb)
+ {
+ /* Both slots own a reference, but the buffer stays on scanout. */
+ _ecore_drm2_fb_deref(output->current.fb);
+ output->current.fb = NULL;
+ }
+ _ecore_drm2_fb_buffer_release(output, &output->current);
output->current.fb = output->pending.fb;
output->pending.fb = NULL;
@@ -484,7 +494,7 @@ err:
return EINA_FALSE;
}
-static int _fb_atomic_commit(Ecore_Drm2_Output *output, int tries);
+static int _fb_atomic_commit(Ecore_Drm2_Output *output, drmModeAtomicReq *req, int tries);
static int _fb_flip(Ecore_Drm2_Output *output);
static Eina_Bool
@@ -512,7 +522,8 @@ _cb_flip_timeout(void *data)
if (!wait_for_event)
{
if (_ecore_drm2_use_atomic)
- wait_for_event = (_fb_atomic_commit(output, 1) == -EBUSY);
+ wait_for_event = (_fb_atomic_commit(output, output->pending.atomic_req,
+ 1) == -EBUSY);
else
_fb_flip(output);
}
@@ -531,7 +542,7 @@ _cb_mainloop_async_timer_reset(void *data)
/* Returns 0, or the negative errno of the last failed commit. */
static int
-_fb_atomic_commit(Ecore_Drm2_Output *output, int tries)
+_fb_atomic_commit(Ecore_Drm2_Output *output, drmModeAtomicReq *req, int tries)
{
int res = 0;
uint32_t flags =
@@ -540,20 +551,14 @@ _fb_atomic_commit(Ecore_Drm2_Output *output, int tries)
if (!_ecore_drm2_use_atomic) return -1;
- /* If we have no req yet, we're flipping to current state.
- * rebuild the current state in the prep state */
- if (!output->prep.atomic_req) _fb_atomic_flip_test(output);
-
- /* Still no req is a bad situation */
- EINA_SAFETY_ON_NULL_RETURN_VAL(output->prep.atomic_req, -1);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(req, -1);
// sometimes we get a EBUSY ... so try again a few times.
int i;
for (i = 0; i < tries; i++)
{
res =
- sym_drmModeAtomicCommit(output->fd, output->prep.atomic_req, flags,
- output);
+ sym_drmModeAtomicCommit(output->fd, req, flags, output);
if (res == 0) break;
else ERR("DRM atomic commit failed - retry #%i", i + 1);
usleep(100);
@@ -577,7 +582,10 @@ _fb_atomic_commit(Ecore_Drm2_Output *output, int tries)
static int
_fb_atomic_flip(Ecore_Drm2_Output *output)
{
- return _fb_atomic_commit(output, 10) ? -1 : 0;
+ /* A tick without a prepared request uses the current plane state. */
+ if (!output->prep.atomic_req) _fb_atomic_flip_test(output);
+
+ return _fb_atomic_commit(output, output->prep.atomic_req, 10) ? -1 : 0;
}
static int
@@ -655,7 +663,7 @@ _fb_flip(Ecore_Drm2_Output *output)
if (count > 500)
{
ERR("Pageflip EBUSY for %i tries - give up", count);
- break;
+ return ret;
}
usleep(100);
}
@@ -677,11 +685,7 @@ _fb_flip(Ecore_Drm2_Output *output)
output->crtc_id, output->conn_id);
return ret;
}
- else if (ret < 0)
- {
- output->next.fb = fb;
- _ecore_drm2_fb_ref(output->next.fb);
- }
+
return 0;
}
@@ -696,10 +700,13 @@ ecore_drm2_fb_flip(Ecore_Drm2_Fb *fb, Ecore_Drm2_Output *output)
if (!output->enabled) return -1;
+ if (fb && (fb == output->next.fb)) fb = NULL;
if (fb) _ecore_drm2_fb_ref(fb);
if (output->pending.fb)
{
+ /* A tick request can wait for the pending flip's event. */
+ if (!fb) return 0;
if (output->next.fb)
_ecore_drm2_fb_buffer_release(output, &output->next);
output->next.fb = fb;
@@ -712,7 +719,11 @@ ecore_drm2_fb_flip(Ecore_Drm2_Fb *fb, Ecore_Drm2_Output *output)
}
/* So we can generate a tick by flipping to the current fb */
- if (!fb) fb = output->current.fb;
+ if (!fb && output->current.fb)
+ {
+ fb = output->current.fb;
+ _ecore_drm2_fb_ref(fb);
+ }
if (output->next.fb)
_ecore_drm2_fb_buffer_release(output, &output->next);
@@ -729,8 +740,12 @@ ecore_drm2_fb_flip(Ecore_Drm2_Fb *fb, Ecore_Drm2_Output *output)
if (ret)
{
- if (output->prep.fb != output->current.fb)
- _ecore_drm2_fb_buffer_release(output, &output->prep);
+ if (output->prep.fb == output->current.fb)
+ {
+ _ecore_drm2_fb_deref(output->prep.fb);
+ output->prep.fb = NULL;
+ }
+ _ecore_drm2_fb_buffer_release(output, &output->prep);
return ret;
}
output->pending.fb = output->prep.fb;
diff --git a/src/tests/ecore/ecore_test_ecore_drm2_fb.c b/src/tests/ecore/ecore_test_ecore_drm2_fb.c
index ee01ceff3c..a2351df591 100644
--- a/src/tests/ecore/ecore_test_ecore_drm2_fb.c
+++ b/src/tests/ecore/ecore_test_ecore_drm2_fb.c
@@ -14,13 +14,14 @@ Eina_Bool _ecore_drm2_use_atomic = EINA_TRUE;
static int _commit_attempts = 0;
static int _commits_accepted = 0;
static int _commit_result = 0;
+static int _test_commit_result = 0;
static char _fake_atomic_req;
static int
_fake_atomic_commit(int fd EINA_UNUSED, drmModeAtomicReqPtr req EINA_UNUSED, uint32_t flags,
void *user_data EINA_UNUSED)
{
- if (flags & DRM_MODE_ATOMIC_TEST_ONLY) return 0;
+ if (flags & DRM_MODE_ATOMIC_TEST_ONLY) return _test_commit_result;
_commit_attempts++;
if (_commit_result) return _commit_result;
@@ -89,6 +90,7 @@ _flip_fixture_init(Flip_Fixture *f)
_commit_attempts = 0;
_commits_accepted = 0;
_commit_result = 0;
+ _test_commit_result = 0;
memset(f, 0, sizeof(Flip_Fixture));
ck_assert_int_eq(pipe(f->event_fds), 0);
@@ -128,6 +130,50 @@ _flip_timeout_fire(Flip_Fixture *f)
_cb_flip_timeout(&f->output);
}
+static int
+_fake_page_flip_busy(int fd EINA_UNUSED, uint32_t crtc_id EINA_UNUSED,
+ uint32_t fb_id EINA_UNUSED, uint32_t flags EINA_UNUSED,
+ void *data EINA_UNUSED)
+{
+ errno = EBUSY;
+ return -1;
+}
+
+static void
+_fake_page_flip_log(const Eina_Log_Domain *domain EINA_UNUSED,
+ Eina_Log_Level level EINA_UNUSED, const char *file EINA_UNUSED,
+ const char *fn EINA_UNUSED, int line EINA_UNUSED,
+ const char *fmt EINA_UNUSED, void *data EINA_UNUSED,
+ va_list args EINA_UNUSED)
+{
+ errno = EBUSY;
+}
+
+EFL_START_TEST(ecore_test_drm2_fb_legacy_busy_does_not_mark_pending)
+{
+ Flip_Fixture f;
+ int ret;
+
+ _flip_fixture_init(&f);
+ ecore_drm2_fb_flip_complete(&f.output);
+ _ecore_drm2_use_atomic = EINA_FALSE;
+ sym_drmModePageFlip = _fake_page_flip_busy;
+
+ eina_log_print_cb_set(_fake_page_flip_log, NULL);
+ ret = ecore_drm2_fb_flip(NULL, &f.output);
+ eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
+
+ sym_drmModePageFlip = NULL;
+ _ecore_drm2_use_atomic = EINA_TRUE;
+ ck_assert_int_eq(ret, -1);
+ ck_assert_ptr_null(f.output.pending.fb);
+ ck_assert_ptr_null(f.output.next.fb);
+ ck_assert_ptr_eq(f.output.current.fb, f.fb);
+ ck_assert_int_eq(f.fb->ref, 2);
+ _flip_fixture_shutdown(&f);
+}
+EFL_END_TEST
+
EFL_START_TEST(ecore_test_drm2_fb_extra_flip_event_keeps_current)
{
Flip_Fixture f;
@@ -146,12 +192,92 @@ EFL_START_TEST(ecore_test_drm2_fb_extra_flip_event_keeps_current)
}
EFL_END_TEST
+EFL_START_TEST(ecore_test_drm2_fb_repeated_flip_releases_buffer)
+{
+ Flip_Fixture f;
+ Ecore_Drm2_Fb *replacement;
+
+ _flip_fixture_init(&f);
+ ecore_drm2_fb_flip_complete(&f.output);
+
+ ck_assert_int_eq(ecore_drm2_fb_flip(f.fb, &f.output), 0);
+ ecore_drm2_fb_flip_complete(&f.output);
+ ck_assert_int_eq(ecore_drm2_fb_flip(NULL, &f.output), 0);
+ ecore_drm2_fb_flip_complete(&f.output);
+
+ replacement = calloc(1, sizeof(Ecore_Drm2_Fb));
+ ck_assert_ptr_nonnull(replacement);
+ replacement->ref = 1;
+ replacement->gbm = EINA_TRUE;
+ ck_assert_int_eq(ecore_drm2_fb_flip(replacement, &f.output), 0);
+ ecore_drm2_fb_flip_complete(&f.output);
+
+ ck_assert_int_eq(ecore_drm2_fb_busy_get(f.fb), EINA_FALSE);
+ _flip_fixture_shutdown(&f);
+ ecore_drm2_fb_discard(replacement);
+}
+EFL_END_TEST
+
+EFL_START_TEST(ecore_test_drm2_fb_tick_preserves_queued_frame)
+{
+ Flip_Fixture f;
+ Ecore_Drm2_Fb *queued;
+
+ _flip_fixture_init(&f);
+ queued = calloc(1, sizeof(Ecore_Drm2_Fb));
+ ck_assert_ptr_nonnull(queued);
+ queued->ref = 1;
+ queued->gbm = EINA_TRUE;
+
+ ck_assert_int_eq(ecore_drm2_fb_flip(queued, &f.output), 0);
+ ck_assert_int_eq(ecore_drm2_fb_flip(NULL, &f.output), 0);
+ ck_assert_int_eq(_commits_accepted, 1);
+ ck_assert(ecore_drm2_fb_flip_complete(&f.output));
+ ck_assert_int_eq(ecore_drm2_fb_flip(NULL, &f.output), 0);
+ ck_assert_ptr_eq(f.output.pending.fb, queued);
+ ck_assert_int_eq(_commits_accepted, 2);
+
+ _flip_fixture_shutdown(&f);
+ ck_assert(!ecore_drm2_fb_busy_get(queued));
+ ecore_drm2_fb_discard(queued);
+}
+EFL_END_TEST
+
+static void
+_count_release(Ecore_Drm2_Fb *fb EINA_UNUSED, Ecore_Drm2_Fb_Status status, void *data)
+{
+ int *releases = data;
+
+ if (status == ECORE_DRM2_FB_STATUS_RELEASE) (*releases)++;
+}
+
+EFL_START_TEST(ecore_test_drm2_fb_drop_duplicate_queued_frame)
+{
+ Flip_Fixture f;
+ int releases = 0;
+
+ _flip_fixture_init(&f);
+ f.fb->status_handler = _count_release;
+ f.fb->status_data = &releases;
+
+ ck_assert_int_eq(ecore_drm2_fb_flip(f.fb, &f.output), 0);
+ ck_assert(ecore_drm2_fb_release(&f.output, EINA_FALSE));
+ ck_assert_int_eq(releases, 0);
+
+ ecore_drm2_fb_flip_complete(&f.output);
+ ck_assert(ecore_drm2_fb_release(&f.output, EINA_TRUE));
+ ck_assert_int_eq(releases, 1);
+ _flip_fixture_shutdown(&f);
+}
+EFL_END_TEST
+
EFL_START_TEST(ecore_test_drm2_fb_timeout_waits_while_busy)
{
Flip_Fixture f;
_flip_fixture_init(&f);
+ _test_commit_result = -EBUSY;
_commit_result = -EBUSY;
_flip_timeout_fire(&f);
ck_assert_int_eq(_commit_attempts, 2);
@@ -209,7 +335,11 @@ EFL_END_TEST
void
ecore_test_ecore_drm2_fb(TCase *tc)
{
+ tcase_add_test(tc, ecore_test_drm2_fb_legacy_busy_does_not_mark_pending);
tcase_add_test(tc, ecore_test_drm2_fb_extra_flip_event_keeps_current);
+ tcase_add_test(tc, ecore_test_drm2_fb_repeated_flip_releases_buffer);
+ tcase_add_test(tc, ecore_test_drm2_fb_tick_preserves_queued_frame);
+ tcase_add_test(tc, ecore_test_drm2_fb_drop_duplicate_queued_frame);
tcase_add_test(tc, ecore_test_drm2_fb_timeout_waits_while_busy);
tcase_add_test(tc, ecore_test_drm2_fb_timeout_leaves_queued_event);
tcase_add_test(tc, ecore_test_drm2_fb_timeout_recovers_lost_event);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.