Blender's GPU Accelerated UI, Decoupled from it's original codebase. Supports Rust, Python, JS, React, C & C++. Twice as good as GPUI
x11: restore the sleep after each frame
nusaturn2de6cdabeb33
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8d950e7..de9404d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -34,7 +34,6 @@ All notable changes to **blenderui** (BUI). The format follows`_buiimgui` extension is gone (the module is still named `_buiimgui`, created by`buipy.imgui_module()`). The public API is unchanged.- **CI:** the Apple Silicon runner is `macos-15` (GitHub retired `macos-14`).-- **Linux frame pacing:** an animation frame is due 16.7 ms (60 Hz) after the previous frame started, so the render time is part of the interval. Before, the X11 loop slept 16.7 ms after each frame.- **Linux GPU start:** the OpenGL context and device are created on a worker thread, as on Direct3D 11. The first frames draw on the CPU.- **Benchmarks on Linux:** `bindings/rust/bench/common/measure.rs` measures CPU time (`CLOCK_PROCESS_CPUTIME_ID`) and memory (`/proc/self/status`) on Linux, so `bui-bench`, `bench_frames` and `cargo test` build there; Windows is unchanged.diff --git a/kit/intern/kit_window_x11.c b/kit/intern/kit_window_x11.cindex 068a00c..8e7cad2 100644--- a/kit/intern/kit_window_x11.c+++ b/kit/intern/kit_window_x11.c@@ -176,7 +176,7 @@ struct BKWindow {GC gc;int render_pending, frames, cursor, tip_id, next_timer, full;int want_frame, frame_vsync;- double frame_start, frame_due;+ double frame_start;float scale;int w, h;Timer timers[MAX_TIMERS];@@ -465,9 +465,6 @@ static double refresh_ms(void)static void render_window(BKWindow *win){- const double start = now_ms();- const int animation = win->want_frame || BK_animating(win->ctx);- const int uncapped = win->want_frame && !win->frame_vsync;if (win->want_frame && win->cb.on_frame) {win->want_frame = 0;win->frame_start = now_ms();@@ -487,13 +484,7 @@ static void render_window(BKWindow *win)bk_frame_ms = 0.0;}if (BK_animating(win->ctx)) {- win->render_pending = 1;- }- /* The next frame is due one refresh after this animation frame started, so the render time is- * part of the interval. A host can request the next frame after this frame. Only a frame request- * without vsync does not wait. */- if (animation) {- win->frame_due = uncapped ? 0.0 : start + refresh_ms();+ win->render_pending = 1; /* paced by the loop's frame wait */}}@@ -958,28 +949,18 @@ static void run_timers(void)}}-static double frame_wait(void)-{- double wait = -1.0;- const double t = now_ms();- for (BKWindow *win = g_windows; win; win = win->next) {- if (win->xid && win->render_pending) {- const double d = BK_MAX(0.0, win->frame_due - t);- wait = wait < 0 ? d : BK_MIN(wait, d);- }- }- return wait;-}-/* Milliseconds until the next timer or frame (-1: nothing to wait for). */static double next_wait(void){- double wait = frame_wait();+ double wait = -1.0;const double t = now_ms();for (BKWindow *win = g_windows; win; win = win->next) {if (!win->xid) {continue;}+ if (win->render_pending) {+ return 0.0;+ }for (int i = 0; i < MAX_TIMERS; i++) {if (win->timers[i].id != 0) {const double d = BK_MAX(0.0, win->timers[i].due - t);@@ -1032,12 +1013,16 @@ static void turn(double block_ms)handle_event(&ev);}run_timers();- const double t = now_ms();+ int rendered = 0;for (BKWindow *win = g_windows; win; win = win->next) {- if (win->xid && win->render_pending && t >= win->frame_due) {+ if (win->xid && win->render_pending) {render_window(win);+ rendered |= win->render_pending; /* animating: another frame wanted */}}+ if (rendered) {+ usleep((useconds_t)(refresh_ms() * 1000.0)); /* pace animation frames */+ }}void BK_window_set_stop_check(int (*stop)(void))@@ -1068,8 +1053,7 @@ void BK_window_run(void)int BK_window_pump(void){if (g_dpy) {- /* Wait for a pending frame, so a caller that pumps in a loop does not spin. */- turn(BK_MAX(0.0, frame_wait()));+ turn(0.0);}return g_open;}diff --git a/website/src/content/docs/concepts/damage-rendering.mdx b/website/src/content/docs/concepts/damage-rendering.mdxindex b081fc8..80c2fba 100644--- a/website/src/content/docs/concepts/damage-rendering.mdx+++ b/website/src/content/docs/concepts/damage-rendering.mdx@@ -62,7 +62,7 @@ On the full components demo (520×900, Ryzen 7 5800U laptop), that's the differeSome things do need frames over time: a panel collapsing, a CSS transition, a React app calling `requestAnimationFrame`. BUI renders frames **only while something animates**, and stops as soon as it's done.-- **Paced to the display.** On Windows, animation frames wait for the display's next refresh (`DwmFlush`), at its refresh rate. On Linux, the next frame is due 16.7 ms (60 Hz) after the previous frame started, and the event loop waits for it. On macOS, the event loop paces them with a timer.+- **Paced to the display.** On Windows, animation frames wait for the display's next refresh (`DwmFlush`), at its refresh rate. On Linux and macOS, the event loop paces them with a timer.- **Late frames don't wait.** A frame that's already late starts right away instead of waiting for another refresh.- **One rebuild per frame.** Rust and JavaScript rebuild the scene right before the render (`BK_window_request_frame` in C), so changes made in an animation callback join that same frame.- **Damage still applies.** If one cell of a grid animates, only that cell is redrawn each frame.diff --git a/website/src/content/docs/concepts/window-hosts.mdx b/website/src/content/docs/concepts/window-hosts.mdxindex 2b08e59..80b32c3 100644--- a/website/src/content/docs/concepts/window-hosts.mdx+++ b/website/src/content/docs/concepts/window-hosts.mdx@@ -41,7 +41,7 @@ A plain Win32 window. Redraw requests coalesce into one render message, and the### Linux (X11)-The same API on Xlib. Button and key mapping follow Blender's `GHOST_SystemX11`. Damaged rectangles go to the window with `XPutImage`, or through GLX with the [GPU renderer](../rendering/). Timers, cross-thread wakes and frame pacing all run in one `select()` loop. An animation frame is due 16.7 ms (60 Hz) after the previous frame started.+The same API on Xlib. Button and key mapping follow Blender's `GHOST_SystemX11`. Damaged rectangles go to the window with `XPutImage`, or through GLX with the [GPU renderer](../rendering/). Timers, cross-thread wakes and frame pacing all run in one `select()` loop.Wayland sessions run it through XWayland, which every mainstream desktop provides.