From 54d5f30ee714b1808165512cca9d3b117f6323b2 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 15 Oct 2026 18:36:40 -0400 Subject: [PATCH] fix: pace adaptive frame generation on the game's frame rate, not the compositor loop's (#927) --- app/src/main/cpp/waylandcomp/src/compositor.c | 5 ++++- app/src/main/cpp/waylandcomp/src/framegen_bridge.c | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/cpp/waylandcomp/src/compositor.c b/app/src/main/cpp/waylandcomp/src/compositor.c index 2b3b66d096..27e2aee9e7 100644 --- a/app/src/main/cpp/waylandcomp/src/compositor.c +++ b/app/src/main/cpp/waylandcomp/src/compositor.c @@ -657,6 +657,7 @@ static void take_pixel(struct surface *s, const uint8_t bgra[4], struct wl_resou static struct surface *g_hud_surface; static int64_t g_hud_last_ns, g_hud_alive_ns; static int g_hud_fresh; +static uint64_t g_game_frames; extern void droiddeck_on_game_surface(const char *window, const char *gpu); extern void droiddeck_on_game_frame(void); extern void droiddeck_on_game_program(int pid, const char *program); @@ -740,10 +741,12 @@ static void take_dmabuf(struct surface *s, struct dmabuf_buffer *b, struct wl_re } if (s == g_hud_surface) { g_hud_alive_ns = now_ns(); - if (!repeat) { g_hud_last_ns = g_hud_alive_ns; g_hud_fresh = 1; droiddeck_on_game_frame(); } + if (!repeat) { g_hud_last_ns = g_hud_alive_ns; g_hud_fresh = 1; g_game_frames++; droiddeck_on_game_frame(); } } } +uint64_t droiddeck_game_frames(void) { return g_game_frames; } + struct dmabuf_buffer *droiddeck_dmabuf_from_resource(struct wl_resource *buffer) { return get_dmabuf(buffer); } int droiddeck_dmabuf_fd(const struct dmabuf_buffer *b) { return b && b->n_planes > 0 ? b->fd[0] : -1; } void droiddeck_dmabuf_size(const struct dmabuf_buffer *b, int *w, int *h) { *w = b->width; *h = b->height; } diff --git a/app/src/main/cpp/waylandcomp/src/framegen_bridge.c b/app/src/main/cpp/waylandcomp/src/framegen_bridge.c index 3c311b54f7..379087045e 100644 --- a/app/src/main/cpp/waylandcomp/src/framegen_bridge.c +++ b/app/src/main/cpp/waylandcomp/src/framegen_bridge.c @@ -11,6 +11,7 @@ #include void droiddeck_log(const char *tag, const char *fmt, ...) __attribute__((format(printf, 2, 3))); +uint64_t droiddeck_game_frames(void); #define FGLOG(...) droiddeck_log("framegen", __VA_ARGS__) #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "DroidDeckWayland", __VA_ARGS__) @@ -372,7 +373,11 @@ int vkp_framegen_run(VkCommandBuffer cmd, VkImage scene, VkImageView scene_view, return 0; } - uint32_t n_gen = fge_plan(g_ring_n, ++g_source_frames, g_presented_rate); + /* The pacer's source rate must be the game's, not this loop's: a loop slowed by its own + * generations would otherwise read as a slower game and justify even more generations. */ + ++g_source_frames; + const uint64_t game_frames = droiddeck_game_frames(); + uint32_t n_gen = fge_plan(g_ring_n, game_frames ? game_frames : g_source_frames, g_presented_rate); if (n_gen > g_ring_n) n_gen = g_ring_n; g_planned = n_gen;