Skip to content

LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.

Per-frame phase timing in LordBench's desktop test (wake, before render, paint, uploads, swap, flip ioctl, GPU finish from a native fence, vblank wait; each frame classed on time, CPU-late or GPU-late; G0 refusals by cause), G0 textures catch up in 1 MB slices between frames instead of whole uploads inside one, the paint thread pool also turns on when the whole frame passes 60 % of the refresh period; review fixes (scanned-out frames record no stale times, stale GL errors cleared before the catch-up upload, context check by eglGetCurrentContext); CHANGELOG, GPU, BENCHMARK, paper (en/es/pt)

Federico Pereirafb3fd2bd8148
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 22efd19..a51909b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -477,6 +477,64 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),
- `make -j8` (GPU=1) and lord-server with GPU=0: no warnings; `make test`: 23 passed, 0 failed, 13 skipped;
`engine-test`: 3,690 checks, 0 failures, `drag_golden_{cpu,gpu}.txt` unchanged (250 of 1,856 frames that
use the copy still G0); `canvas-test`: 8,621,376 cases, 0 differ.
+ - **Where a frame's time goes, measured per frame** (0.8.6, in development; `docs/BENCHMARK.md`, "Frame phases").
+ On the Pi 5 with its monitor a loaded frame is built in about 13 ms and still the monitor shows 30 frames a
+ second, 98 % of them late: the time outside the "build" number (JS before the frame, the GPU's own work, the wait
+ for the vblank) was not measured. lord-server now records, for every frame the main display shows, while
+ LordBench records or a scripted move runs (`bench/lbframes.c`, filled only by `main.c` and `gpu.c`; nothing comes
+ from a helper, and `lb_msg_valid` is unchanged since no new result id exists):
+ - the flip event to lord-server running (`wake`), that wake to `render()` (input, LordBench's scripted step, JS),
+ `render()` itself, its layout and paint, the UI texture's upload (time and pixels), G0's texture uploads (time,
+ pixels, whether one was whole), `eglSwapBuffers`, the framebuffer and page flip ioctl, the GPU's finish time
+ after the flip was queued, the wait to the vblank, and wake to flip;
+ - the GPU's finish time is a native fence taken after `eglSwapBuffers` (`EGL_ANDROID_native_fence_sync`) and read
+ once at the frame's flip with `SYNC_IOC_FILE_INFO` (the sync file's signal time): one ioctl a frame, no wait, no
+ polling, and nothing at all while not recording; without the extension it is "unknown"; a frame scanned out
+ straight (a fullscreen app's buffer) has no upload, swap or GPU time of its own, so it records none and drops a
+ fence left from before instead of reporting the last composed frame's;
+ - each frame against the first vblank after it started: on time (shown within half a period of it), CPU-late
+ (the flip was queued after that vblank), GPU-late (queued before it, the GPU finished after it) or other;
+ - per frame whether the paint threads were on, whether G0 composed it or why not (each refusal and, for `layer`,
+ its cause: `invalid`, `rendering`, `holes`, `surfaces`, `premul`, `opacity`, `part` and the rest, `G0L_*` in
+ `ui/ui.h`), G0's whole uploads and their pixels, and frames not shown (`gpu_frame_ex`'s -2).
+ LordBench's desktop result has them as `frames.phases.alone` and `frames.phases.load` (p50 and p99 in ms, and
+ counts), and the session log gets `lordbench: desktop alone|under load: phases, …`; the `drag (scripted): …` line
+ ends with the same text, and its G0 part now lists `… catching up` and the layer's causes. Without a monitor the
+ frame's end is its presentation, on the pacing grid. The System Information page is unchanged (it does not show
+ them). Checked on VM 116: `lordbench-test` (1,192 ok) feeds known frames and checks each class, percentile and
+ count, the text and a short buffer; and a desktop run in an isolated headless session of the worktree's
+ lord-server (a test theme moving one window with `lord.wm.script`, CPU composition, one viewer on its
+ `remote.sock`) wrote both phase objects in three runs (alone 601 frames, all on time; under load 720–721, 715–721 on time) and
+ the drag line. The
+ GPU fields (uploads, swap, fence) were 0 there: that path was built, not run.
+ - **G0's textures catch up between frames instead of inside one** (0.8.6, in development; `docs/GPU.md`, "Uploads without a
+ stall"). A drag's start, or a copy of what is below built again whole, made the first G0 frame send the whole
+ copy (a screen, 8.3 MB at 1920 × 1080) and the layer; on V3D `glTexSubImage2D` converts to the GPU's tiled layout
+ on the CPU, inside the frame. Now a frame G0 would compose but whose textures lack more than 262,144 pixels
+ (`G0_FEED_PX`, 1 MB) is painted by the CPU (`G0R_FEED`, "catching up"; the same pixels), and after its flip is
+ queued, while the CPU waits for the vblank, a slice of up to that many pixels goes up (`paint_g0_feed`,
+ `gpu_g0_feed`: rectangles cut by rows; each texture is asked first whether it holds that display's pixels at that
+ size, else it is allocated and all of it is sent in slices; GL errors left by earlier calls are cleared first, so
+ they cannot turn G0 off there). Only frames refused for that reason send slices. A G0 frame can still send a
+ texture whole when it finds one that is another display's or the wrong size (after the GPU context is made
+ again, or the layer's first frame within the budget), as before.
+ Each texture now knows whose pixels it holds; the dirty list keeps 16 rectangles and, when full, merges the two
+ whose box adds the fewest pixels (the last one used to grow, which could make a few small changes most of the
+ screen). Frames don't overlap (the next starts after the flip), so the textures need no second copy. Checked on
+ VM 116: `engine-test`'s stub GPU does the same (a texture made again is filled with a pattern no frame has); all
+ 2,417 frames of `drag_golden_gpu.txt` match and the five extra runs match the GPU path frame by frame; no G0
+ frame sent a texture whole, and the most one G0 frame sent fell from 934,022 to 170,330 pixels in the long run
+ (1024 × 640); 241 of 1,856 frames that use the copy are G0 (250 before: 9 catch up), 2,358,312 pixels went up
+ between frames; `pause` 45 of 61 (54), `two` 148 of 240 (150), `app` 2 of 180 (5), `ancedge` 12 of 90 (15),
+ `corner` 0 of 90. Not run on a GPU yet.
+ - **The paint threads turn on by the whole frame too** (0.8.6, in development): on when the frame (`render_frame`:
+ layout, paint, upload, submit) takes more than 60 % of a period, or painting more than 70 % as before; off after
+ 60 frames in a row with painting under 25 % and the frame under 45 %. On the Pi 5 under load painting took about
+ 7.5 ms (under 70 %) while the frame took about 13 ms, so the threads, which run at real-time priority, stayed off.
+ The pixels are the same (the pool's bands are exact). On VM 116 headless under load they were on for 0, 10 and 91
+ of 720–721 frames in three runs; the gain on the Pi is not measured yet.
+ - `make -j8` and lord-server with `GPU=0` (no EGL, GBM or GLES linked): no warnings; `make test`: 23 passed, 0
+ failed, 13 skipped, every suite's checks passing; `engine-test`: 4,146 checks, 0 failures.
- **`js: unsupported style '<key>'` is logged once per key** (`style_warn` in `ui/js.c`), not on every
`setStyle` call: a style an animation sends every frame wrote a line to the session log every frame (as
`transform` did before LordBench's square and the fans moved to `rotate`). The first 64
diff --git a/docs/BENCHMARK.md b/docs/BENCHMARK.md
index 937021a..1aba865 100644
--- a/docs/BENCHMARK.md
+++ b/docs/BENCHMARK.md
@@ -563,6 +563,66 @@ matrix products, and the CPU and the GPU share the Pi's memory, but that has not
**What remains.** Under load a frame takes about twice as long to build on the Pi (15–16 ms instead of 7 ms), for
a cause not measured yet, which no priority fixes; the Pi kernel at `CONFIG_HZ=1000` (`tools/rpi/build-kernel.sh`, a rebuild) is not built.
+#### Frame phases (0.8.6, in development)
+
+A frame is started only after the last flip completed (one frame in flight), so any frame whose whole chain (the
+work before `render()`, the build, the GPU's own part, the flip) takes more than one period is shown a vblank late,
+and the rate locks at half the refresh. The build time alone (`desk.p50`/`p99`) can't tell which part was too long.
+So lord-server also records, for every frame the main display shows, while LordBench records or while a scripted
+move runs (`bench/lbframes.c`: `lbf_phase_built` when `render()` ends, `lbf_phase_shown` at that frame's flip; all
+of it measured by lord-server itself, never by a helper):
+
+| Phase (JSON key, `[p50, p99]` ms) | From → to |
+|---|---|
+| `wakeMs` | the flip's kernel timestamp → `poll()` returned with it (frames started by a flip) |
+| `beforeRenderMs` | that wake → `render()`: pointer motion, LordBench's scripted step, the JS timers |
+| `renderMs` | `render()` itself (the same as the build time) |
+| `paintMs` | its layout and paint |
+| `uploadMs`, `g0UploadMs` | the UI texture's upload; G0's texture uploads in a G0 frame (`docs/GPU.md`) |
+| `swapMs`, `flipIoctlMs` | `eglSwapBuffers`; the front buffer, its framebuffer and the page flip ioctl |
+| `gpuMs` | the flip queued → the GPU finished the frame (below) |
+| `vblankWaitMs` | the later of those two → the flip |
+| `wakeToFlipMs` | the wake → the flip |
+| `catchUpMs` | G0's textures catching up after the flip was queued (`docs/GPU.md`, "Uploads without a stall") |
+
+The GPU's finish time comes from a native fence taken right after `eglSwapBuffers`
+(`EGL_ANDROID_native_fence_sync`, `gpu.c`) and read once at the frame's flip with `SYNC_IOC_FILE_INFO`: the
+kernel's signal time of the sync file, one ioctl a frame, no wait. Fences are taken only while recording. Without
+the extension `gpuKnown` stays 0. Each frame is also put in one class against the first vblank after it started
+(the vblanks fall on the previous flip plus whole periods):
+
+- `onTime`: shown within half a period of that vblank;
+- `cpuLate`: late, and its flip was queued after that vblank;
+- `gpuLate`: queued before it, but the GPU finished after it;
+- `otherLate`: late with both before it, or with the GPU time unknown.
+
+And counted per frame: `paintThreads` (the pool was on), `unshown` (`gpu_frame_ex` returned -2), `uploadMpx`,
+`g0UploadMpx` and `catchUpMpx` (pixels per frame, average), and `g0`: `tried`, `taken`, `refused` by reason
+(`layer`, `clip`, `ancestor`, `app`, `after`, `post`, `feed`), `layer` refusals by cause (`invalid`, `rendering`,
+`holes`, `surfaces`, `premul`, `opacity`, `part`…), `wholeUploads` and `wholeMpx`. The result's `frames` object has
+`phases.alone` and `phases.load`; the session log gets `lordbench: desktop alone: phases, N frames (ms p50/p99): …`
+and `… under load: …`, and the `drag (scripted): …` line ends with the same text for the whole move. Without a
+monitor a frame is "shown" when it ends (on the pacing grid), so `gpuMs` and the wait are 0. System Information does
+not show these yet; results keep comparing as before (no new result ids, LordBench 1).
+
+**Checked** on VM 116: `lordbench-test` feeds known frames (one on time, one queued after its vblank, one whose GPU
+finished after it, one not shown) and checks each class, percentile, count and the text. A desktop run of the
+worktree's lord-server in an isolated headless session (a test theme moving one window with `lord.wm.script` over
+40 cards, CPU composition, one viewer on its `remote.sock`) wrote both objects: alone 601 frames, all on time,
+render 0.84/1.78 ms, paint 0.55/1.21 ms; under load 720–721 frames, 715–721 on time (three runs). Those are a check
+that it works, not a measurement (a small scene, no GPU). The GPU fields were not exercised: VM 116 sessions are
+headless, so the fence, the uploads' times and G0's counts have been built, not run.
+
+**What to run on the Pi 5 next** (the package from this work installed, the monitor on, logged in):
+1. LordBench → Desktop impact, twice with G0 (default) and twice with `LORD_G0=0` in the session's environment.
+2. From `~/.cache/lordos/session.log`: the `lordbench: desktop … phases` lines and the `drag (scripted):` line, and
+ from `~/.local/state/lordos/lordbench-desktop.json` `frames.phases`.
+3. Read under load: if most frames are `cpuLate`, the build is too long (`paintMs`, `uploadMs`, `beforeRenderMs`
+ say which part, and `paintThreads` whether the pool helped); if `gpuLate`, the GPU's own work (`gpuMs`) is; if
+ `onTime` is high and the rate still 30, the classification is wrong and the flip times must be looked at.
+ With G0, `g0.refused`/`g0.layer` say what keeps it off and `catchUpMpx` what the slices cost.
+4. `LORD_GPU_VERIFY=1` once with G0 over a Desktop impact run: `gpu-verify: … differ=0` on every line.
+
Boot: the Pi 5 reaches the login screen on its monitor 5.99 s after the kernel starts (lord-sessiond's record;
systemd-analyze gives 2.1 s kernel + 4.2 s userspace). Boots where the monitor was connected late took 61 and
103 s, which is the wait for the monitor, not the boot. The N-boot test was checked by its unit tests
diff --git a/docs/GPU.md b/docs/GPU.md
index b1cd7ac..a922fa9 100644
--- a/docs/GPU.md
+++ b/docs/GPU.md
@@ -157,6 +157,31 @@ returns -2 before presenting: no frame is shown with a stale W, the display keep
`main.c` paints W on the CPU in the next frame without trying G0 (`g0cpu`). `LORD_PAINT_VERIFY` leaves W
out of its count on G0 frames.
+**Uploads without a stall (0.8.6, in development).** The two textures get only what changed (paint.c's dirty
+rectangles, in their own pixels). A drag's start, or the copy of what is below built again whole, changes all of the
+copy: a screen of pixels (8.3 MB at 1920 × 1080), and on V3D `glTexSubImage2D` converts it to the GPU's tiled layout
+on the CPU inside the call, so the first G0 frame after such a change missed its vblank. Now:
+
+- `paint_root_body` refuses a frame G0 would compose when the textures still lack more than `G0_FEED_PX` pixels
+ (262,144, 1 MB; both textures counted) as `G0R_FEED` ("catching up"): the CPU paints W, the same pixels.
+- After such a frame's flip is queued (`main.c`, after `gpu_frame_ex`), while the CPU waits for the vblank anyway,
+ `paint_g0_feed` sends up to `G0_FEED_PX` pixels of what is missing through `gpu_g0_feed`: the copy first, then the
+ layer, rectangles cut by rows, each sent rectangle (or part) dropped from the dirty list. Each texture is asked
+ first with an empty rectangle whether it holds that display's pixels at that size; if not, it is allocated
+ (`glTexImage2D` with no data), marked as that display's, and all of it is sent in slices. Only frames refused for
+ `G0R_FEED` send slices: sent while G0 is refused for another reason (the menu bar or the Dock in the damage),
+ most of it would change again before it is used (`engine-test`: 162.8 million pixels against 2.4 million).
+- Each texture knows whose pixels it holds (`g0tout[2]`); a G0 frame that would find another display's or the
+ wrong size still sends all of it (correct, and rare now). The dirty list keeps `G0_DIRTY` (16) rectangles and,
+ when full, merges the two whose box adds the fewest pixels (it used to grow the last one).
+- Frames don't overlap (a frame starts after the last flip), so the job that read the textures has finished when
+ they are written: no second copy of them is needed. If frames are ever built while a flip is pending, each
+ texture needs a pair, each with its own dirty list. GLES3 pixel buffers (the GPU doing the tiling) are not used.
+
+`engine-test`'s stub GPU does the same as `main.c` and `gpu.c` (a texture made again is filled with a pattern no
+frame has, so a pixel the slices missed shows): every frame matches, and it checks that no G0 frame has more than
+`G0_FEED_PX` of the copy left to send.
+
**Off unless it proves itself:** `gpu_init` sets G0 up. It needs a fragment shader with at least 24-bit
`highp` floats (`glGetShaderPrecisionFormat`) and then a self-test, drawn into a framebuffer, read back
and compared with `canvas_blit` on the CPU (the NEON row on the Pi):
@@ -180,9 +205,12 @@ with the reason.
| `LORD_GPU_VERIFY=N` | every N-th G0 frame W is also painted on the CPU (a walk clipped to W on a scratch canvas) and compared with the framebuffer read back: `gpu-verify: frame N W=wxh differ=K worst=D` |
The `drag: …` and `drag (scripted): …` lines end with `G0: N of M frames (Q quads), strips … Mpx,
-uploaded below … Mpx, layer … Mpx (not: … layer, … clip, … ancestor, … app, … after, … post)`: frames
-composited, of those that used the copy; quads drawn; what the CPU painted around W; what went up to the
-two textures; and why the others were not.
+uploaded below … Mpx, layer … Mpx (not: … layer, … clip, … ancestor, … app, … after, … post, … catching up;
+layer: invalid …, holes …, …)`: frames composited, of those that used the copy; quads drawn; what the CPU painted
+around W; what went up to the two textures (in G0 frames and in slices between frames); why the others were not;
+and the `layer` refusals by cause (`G0L_*` in `ui/ui.h`: `gone`, `invalid`, `resize`, `rendering`, `capture`,
+`view`, `transform`, `raw`, `holes`, `surfaces`, `premul`, `nobuf`, `tree`, `opacity`, `part`). The
+`drag (scripted): …` line then ends with the frames' phases (`docs/BENCHMARK.md`, "Frame phases").
**Checked** (VM 116, x86_64):
- `canvas-test`: the shader written in C with the same float operations (`canvas_g0_model`) against
@@ -191,7 +219,8 @@ two textures; and why the others were not.
- `engine-test`'s `g0` path: `test_drag_exact` with G0 and a stub GPU (the UI texture, the two textures
with only their dirty rectangles, `main.c`'s bookkeeping, W written by `canvas_g0_model`) gives every
one of the 2,417 frames of `drag_golden_gpu.txt`; 250 of 1,856 frames that use the copy are G0 frames
- there. Five more runs are compared frame by frame with the GPU path: a pause with no damage, two
+ there (241 with the uploads in slices: 9 frames catch up; no G0 frame sends a texture whole, and the most one
+ sends fell from 934,022 to 170,330 pixels). Five more runs are compared frame by frame with the GPU path: a pause with no damage, two
displays side by side, the window over an app window below, the window against a rounded,
bordered container's corner, and (`corner`) a rounded `overflow: hidden` box with no colour painted
after the window. Taking out the after-node, app-window or ancestor check fails it; without counting
@@ -238,7 +267,10 @@ pixels are the same as on one thread (`blurbench`/`rrbench` compare them byte fo
Waking the pool costs CPU, so it is used only while frames are heavy: it turns on when painting takes
more than 70 % of a frame at the target rate (the monitor's refresh, or the fastest remote viewer's
-screen without a monitor) and off after 60 light frames in a row. On VM 116 (8 cores, Xeon 1.8 GHz), a
+screen without a monitor), or (0.8.6, in development) when the whole frame (layout, paint, upload and submit)
+takes more than 60 % of it, and off after 60 frames in a row with painting under 25 % and the frame under 45 %.
+The second rule is for the GPU path under load: on the Pi 5 painting took about 7.5 ms there while the frame took
+about 13 ms and missed the vblank, and the pool stayed off. Its gain there is not measured yet. On VM 116 (8 cores, Xeon 1.8 GHz), a
1920×1080 session with a 60 fps video under blurred windows: 45 frames a second on one thread, 55–58
with the pool. `canvas.c` builds at -O3 (its loops vectorize); the blur itself went from 28 ms to
2.7 ms over the day's work.
diff --git a/docs/PAPER.md b/docs/PAPER.md
index 837ec56..9eef365 100644
--- a/docs/PAPER.md
+++ b/docs/PAPER.md
@@ -155,7 +155,7 @@ LordOS speaks to several Debian services over their own protocols with its own c
### 3.2 Two ways to build a frame
-- **CPU path.** The UI and app windows are copied into a canvas, and a "dumb" buffer is presented with a page flip. It needs nothing but the kernel. It is the default when there is no 3D-capable card, and `LORD_GPU=0` forces it (the boot menu's safe mode uses it). Since 0.8.5, heavy frames paint on a pool of up to 8 threads (`par.c`), only while painting takes more than 70 % of a frame at the target rate: the backdrop blur in phases and the row-local primitives split by bands of rows, with the same pixels as one thread (§7.2).
+- **CPU path.** The UI and app windows are copied into a canvas, and a "dumb" buffer is presented with a page flip. It needs nothing but the kernel. It is the default when there is no 3D-capable card, and `LORD_GPU=0` forces it (the boot menu's safe mode uses it). Since 0.8.5, heavy frames paint on a pool of up to 8 threads (`par.c`), only while painting takes more than 70 % of a frame at the target rate (in 0.8.6, in development, also while the whole frame takes more than 60 %): the backdrop blur in phases and the row-local primitives split by bands of rows, with the same pixels as one thread (§7.2).
- **GPU path.** Mesa's GBM, EGL and GLES2 (`server/src/gpu/gpu.c`). The UI becomes one texture, and only the changed region is uploaded each frame. App windows are not copied into the UI canvas: the UI leaves a transparent hole where each window goes, and window textures are drawn underneath, so an app that only changes its own content doesn't cause a UI repaint. Apps can hand over GPU buffers (`linux-dmabuf`) with no copies, and a fullscreen app with a suitable buffer is scanned out directly. The cursor uses the hardware cursor plane.
The path is chosen at start-up: a card without 3D (simpledrm, bochs, virtio-gpu without virgl, and others) uses the CPU without even loading Mesa; a software OpenGL renderer also falls back to the CPU, because composing with it costs more than LordOS's own CPU path. If a GPU frame fails, the GPU is turned off and the CPU path takes over.
diff --git a/server/src/bench/lbframes.c b/server/src/bench/lbframes.c
index 15cc93a..a3bf9b5 100644
--- a/server/src/bench/lbframes.c
+++ b/server/src/bench/lbframes.c
@@ -3,6 +3,7 @@
#include <pthread.h>
#include <stdatomic.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -21,6 +22,221 @@ static int nlat;
static uint64_t applied[BATCH], inframe[BATCH]; /* events applied, not yet in a frame; in the frame being shown */
static int napplied, ninframe;
+static int cmp_d(const void *a, const void *b) { double x = *(const double *)a, y = *(const double *)b; return (x > y) - (x < y); }
+
+/* the p-th percentile of sorted v[0..n) (nearest rank) */
+static double pct(const double *v, int n, double p) {
+ if (n <= 0) return 0;
+ int k = (int)(p / 100.0 * n + 0.999999) - 1;
+ return v[k < 0 ? 0 : k >= n ? n - 1 : k];
+}
+
+/* ---- frame phases (lbframes.h) ---- */
+
+enum { PH_WAKE, PH_PRE, PH_PAINT, PH_UP, PH_G0UP, PH_SWAP, PH_SUBC, PH_BUILD, PH_GPU, PH_WAIT, PH_CHAIN, PH_FEED, PH_N };
+typedef struct {
+ atomic_int on;
+ float v[PH_N][MAXF]; /* ms */
+ int nv[PH_N];
+ int n, on_time, cpu_late, gpu_late, other_late, gpu_known;
+ int built, par, g0_tried, g0_taken, g0_refused[LBF_G0R], g0_layer[LBF_G0L], g0_full, unshown;
+ double up_px, g0_px, feed_px, g0_full_px;
+} Rec;
+static Rec rec_lb, rec_drag; /* LordBench's recording, the scripted drag's */
+static LbPhase pend; /* the main display's frame waiting for its flip */
+static int have_pend;
+
+static void rec_clear(Rec *r) { /* everything but on and the values (nv says how many count) */
+ memset(r->nv, 0, sizeof r->nv);
+ r->n = r->on_time = r->cpu_late = r->gpu_late = r->other_late = r->gpu_known = 0;
+ r->built = r->par = r->g0_tried = r->g0_taken = r->g0_full = r->unshown = 0;
+ memset(r->g0_refused, 0, sizeof r->g0_refused);
+ memset(r->g0_layer, 0, sizeof r->g0_layer);
+ r->up_px = r->g0_px = r->feed_px = r->g0_full_px = 0;
+}
+static void rec_put(Rec *r, int ph, double ms) {
+ if (ms >= 0 && r->nv[ph] < MAXF) r->v[ph][r->nv[ph]++] = (float)ms;
+}
+static int rec_on(Rec *r) { return atomic_load_explicit(&r->on, memory_order_relaxed); }
+int lbf_recording(void) { return rec_on(&rec_lb) || rec_on(&rec_drag); }
+
+static void rec_built(Rec *r, const LbPhase *p) {
+ if (!rec_on(r)) return;
+ r->built++;
+ r->par += p->par != 0;
+ r->unshown += p->unshown != 0;
+ if (p->g0 >= 0) {
+ r->g0_tried++;
+ if (p->g0 > 0) r->g0_taken++;
+ else if (p->g0_why >= 0 && p->g0_why < LBF_G0R) {
+ r->g0_refused[p->g0_why]++;
+ if (p->g0_sub >= 0 && p->g0_sub < LBF_G0L) r->g0_layer[p->g0_sub]++;
+ }
+ }
+ if (p->g0_full) { r->g0_full++; r->g0_full_px += (double)p->g0_px; }
+ r->up_px += (double)p->up_px;
+ r->g0_px += (double)p->g0_px;
+ r->feed_px += (double)p->feed_px;
+ rec_put(r, PH_FEED, p->feed_ms);
+}
+
+void lbf_phase_built(const LbPhase *p) {
+ if (!lbf_recording()) return;
+ pthread_mutex_lock(&mu);
+ rec_built(&rec_lb, p);
+ rec_built(&rec_drag, p);
+ pend = *p;
+ have_pend = p->submit != 0; /* no flip queued: no presentation will complete it */
+ pthread_mutex_unlock(&mu);
+}
+
+static double ms_between(uint64_t a, uint64_t b) { return a && b && b >= a ? (double)(b - a) / 1e6 : -1; }
+
+static void rec_shown(Rec *r, const LbPhase *p, uint64_t flip, uint64_t gpu) {
+ if (!rec_on(r)) return;
+ r->n++;
+ if (p->from_flip) rec_put(r, PH_WAKE, ms_between(p->prev_flip, p->wake));
+ rec_put(r, PH_PRE, ms_between(p->wake, p->render0));
+ rec_put(r, PH_PAINT, p->paint_ms);
+ rec_put(r, PH_UP, p->up_ms);
+ if (p->g0 > 0) rec_put(r, PH_G0UP, p->g0_ms);
+ rec_put(r, PH_SWAP, p->swap_ms);
+ rec_put(r, PH_SUBC, p->submit_ms);
+ rec_put(r, PH_BUILD, ms_between(p->render0, p->built));
+ uint64_t ready = p->submit;
+ if (gpu) {
+ r->gpu_known++;
+ rec_put(r, PH_GPU, gpu > p->submit ? (double)(gpu - p->submit) / 1e6 : 0);
+ if (gpu > ready) ready = gpu;
+ }
+ rec_put(r, PH_WAIT, ms_between(ready, flip));
+ rec_put(r, PH_CHAIN, ms_between(p->wake, flip));
+ /* the first vblank after the frame started (the vblanks fall on prev_flip + k periods) */
+ if (!p->prev_flip || !p->period || !p->wake || p->wake < p->prev_flip) { r->other_late++; return; }
+ uint64_t k = (p->wake - p->prev_flip) / p->period + 1, target = p->prev_flip + k * p->period;
+ if (flip <= target + p->period / 2) r->on_time++;
+ else if (p->submit > target) r->cpu_late++;
+ else if (gpu && gpu > target) r->gpu_late++;
+ else r->other_late++;
+}
+
+void lbf_phase_shown(uint64_t flip_ns, uint64_t gpu_done_ns) {
+ if (!lbf_recording()) return;
+ pthread_mutex_lock(&mu);
+ if (have_pend && flip_ns >= pend.submit) {
+ rec_shown(&rec_lb, &pend, flip_ns, gpu_done_ns);
+ rec_shown(&rec_drag, &pend, flip_ns, gpu_done_ns);
+ }
+ have_pend = 0;
+ pthread_mutex_unlock(&mu);
+}
+
+static LbPct rec_pct(const Rec *r, int ph) {
+ static double t[MAXF];
+ int n = r->nv[ph];
+ for (int i = 0; i < n; i++) t[i] = r->v[ph][i];
+ qsort(t, (size_t)n, sizeof *t, cmp_d);
+ return (LbPct){ pct(t, n, 50), pct(t, n, 99) };
+}
+
+static void rec_stats(const Rec *r, LbPhaseStats *st) {
+ memset(st, 0, sizeof *st);
+ st->n = r->n;
+ st->wake = rec_pct(r, PH_WAKE);
+ st->pre = rec_pct(r, PH_PRE);
+ st->paint = rec_pct(r, PH_PAINT);
+ st->up = rec_pct(r, PH_UP);
+ st->g0up = rec_pct(r, PH_G0UP);
+ st->swap = rec_pct(r, PH_SWAP);
+ st->submit_call = rec_pct(r, PH_SUBC);
+ st->build = rec_pct(r, PH_BUILD);
+ st->gpu = rec_pct(r, PH_GPU);
+ st->wait = rec_pct(r, PH_WAIT);
+ st->chain = rec_pct(r, PH_CHAIN);
+ st->feed = rec_pct(r, PH_FEED);
+ int b = r->built ? r->built : 1;
+ st->up_mpx = r->up_px / b / 1e6;
+ st->g0_mpx = r->g0_px / b / 1e6;
+ st->feed_mpx = r->feed_px / b / 1e6;
+ st->on_time = r->on_time;
+ st->cpu_late = r->cpu_late;
+ st->gpu_late = r->gpu_late;
+ st->other_late = r->other_late;
+ st->gpu_known = r->gpu_known;
+ st->par = r->par;
+ st->g0_tried = r->g0_tried;
+ st->g0_taken = r->g0_taken;
+ memcpy(st->g0_refused, r->g0_refused, sizeof st->g0_refused);
+ memcpy(st->g0_layer, r->g0_layer, sizeof st->g0_layer);
+ st->g0_full = r->g0_full;
+ st->g0_full_px = (long)r->g0_full_px;
+ st->unshown = r->unshown;
+}
+
+/* lbf_begin and lbf_end start and stop LordBench's recorder with the frame times */
+static void lbf_phases_begin(void) {
+ pthread_mutex_lock(&mu);
+ rec_clear(&rec_lb);
+ atomic_store(&rec_lb.on, 1);
+ pthread_mutex_unlock(&mu);
+}
+
+void lbf_phases(LbPhaseStats *st) {
+ pthread_mutex_lock(&mu);
+ atomic_store(&rec_lb.on, 0);
+ rec_stats(&rec_lb, st);
+ pthread_mutex_unlock(&mu);
+}
+
+void lbf_drag_begin(void) {
+ pthread_mutex_lock(&mu);
+ rec_clear(&rec_drag);
+ atomic_store(&rec_drag.on, 1);
+ pthread_mutex_unlock(&mu);
+}
+
+void lbf_drag_end(LbPhaseStats *st) {
+ pthread_mutex_lock(&mu);
+ atomic_store(&rec_drag.on, 0);
+ rec_stats(&rec_drag, st);
+ pthread_mutex_unlock(&mu);
+}
+
+static const char *const g0r_names[LBF_G0R] = { "layer", "clip", "ancestor", "app", "after", "post", "feed", "" };
+static const char *const g0l_names[LBF_G0L] = { "gone", "invalid", "resize", "rendering", "capture", "view", "transform", "raw",
+ "holes", "surfaces", "premul", "nobuf", "tree", "opacity", "part", "" };
+const char *lbf_g0r_name(int i) { return i >= 0 && i < LBF_G0R && g0r_names[i][0] ? g0r_names[i] : NULL; }
+const char *lbf_g0l_name(int i) { return i >= 0 && i < LBF_G0L && g0l_names[i][0] ? g0l_names[i] : NULL; }
+
+void lbf_phases_text(const LbPhaseStats *st, char *buf, size_t n) {
+ size_t k = 0;
+#define PUT(...) do { if (k < n) { int w_ = snprintf(buf + k, n - k, __VA_ARGS__); if (w_ > 0) k += (size_t)w_; } } while (0)
+ PUT("phases, %d frames (ms p50/p99): wake %.2f/%.2f, before render %.2f/%.2f, render %.2f/%.2f (paint %.2f/%.2f, "
+ "upload %.2f/%.2f, G0 upload %.2f/%.2f, swap %.2f/%.2f, flip ioctl %.2f/%.2f), GPU after the flip was queued "
+ "%.2f/%.2f, to the vblank %.2f/%.2f, wake to flip %.2f/%.2f, G0 catch-up %.2f/%.2f; per frame upload %.3f Mpx, "
+ "G0 %.3f, catch-up %.3f; on time %d, CPU-late %d, GPU-late %d, other %d (GPU time known for %d); paint threads "
+ "on %d; G0 %d of %d (", st->n, st->wake.p50, st->wake.p99, st->pre.p50, st->pre.p99, st->build.p50, st->build.p99,
+ st->paint.p50, st->paint.p99, st->up.p50, st->up.p99, st->g0up.p50, st->g0up.p99, st->swap.p50, st->swap.p99,
+ st->submit_call.p50, st->submit_call.p99, st->gpu.p50, st->gpu.p99, st->wait.p50, st->wait.p99, st->chain.p50,
+ st->chain.p99, st->feed.p50, st->feed.p99, st->up_mpx, st->g0_mpx, st->feed_mpx, st->on_time, st->cpu_late,
+ st->gpu_late, st->other_late, st->gpu_known, st->par, st->g0_taken, st->g0_tried);
+ int first = 1;
+ for (int i = 0; i < LBF_G0R; i++) {
+ if (!st->g0_refused[i] || !lbf_g0r_name(i)) continue;
+ PUT("%snot %s %d", first ? "" : ", ", lbf_g0r_name(i), st->g0_refused[i]);
+ first = 0;
+ if (i == 0) { /* G0R_LAYER: its causes */
+ int f2 = 1;
+ for (int j = 0; j < LBF_G0L; j++)
+ if (st->g0_layer[j] && lbf_g0l_name(j)) { PUT("%s%s %d", f2 ? " [" : ", ", lbf_g0l_name(j), st->g0_layer[j]); f2 = 0; }
+ if (!f2) PUT("]");
+ }
+ }
+ PUT("), whole G0 uploads %d (%.2f Mpx), unshown %d", st->g0_full, st->g0_full_px / 1e6, st->unshown);
+#undef PUT
+ if (n) buf[k < n ? k : n - 1] = 0;
+}
+
void lbf_frame(double work_ms) {
if (!atomic_load_explicit(&on, memory_order_relaxed)) return;
pthread_mutex_lock(&mu);
@@ -63,15 +279,7 @@ void lbf_begin(void) {
period = 0;
atomic_store(&on, 1);
pthread_mutex_unlock(&mu);
-}
-
-static int cmp_d(const void *a, const void *b) { double x = *(const double *)a, y = *(const double *)b; return (x > y) - (x < y); }
-
-/* the p-th percentile of sorted v[0..n) (nearest rank) */
-static double pct(const double *v, int n, double p) {
- if (n <= 0) return 0;
- int k = (int)(p / 100.0 * n + 0.999999) - 1;
- return v[k < 0 ? 0 : k >= n ? n - 1 : k];
+ lbf_phases_begin();
}
int lbf_end(LbFrameStats *st) {
@@ -79,6 +287,7 @@ int lbf_end(LbFrameStats *st) {
static double w[MAXF], l[MAXI];
pthread_mutex_lock(&mu);
atomic_store(&on, 0);
+ atomic_store(&rec_lb.on, 0); /* its phases stay for lbf_phases */
int nw = nwork, ns = nshown, nl = nlat;
memcpy(w, work, (size_t)nw * sizeof *w);
memcpy(l, lat, (size_t)nl * sizeof *l);
diff --git a/server/src/bench/lbframes.h b/server/src/bench/lbframes.h
index 2f16d02..90423b0 100644
--- a/server/src/bench/lbframes.h
+++ b/server/src/bench/lbframes.h
@@ -6,6 +6,7 @@
#ifndef LORD_BENCH_LBFRAMES_H
#define LORD_BENCH_LBFRAMES_H
+#include <stddef.h>
#include <stdint.h>
typedef struct {
@@ -34,4 +35,64 @@ void lbf_built(int main_drawn);
void lbf_begin(void);
int lbf_end(LbFrameStats *st);
+/* ---- where a frame's time goes (docs/BENCHMARK.md, "Frame phases") ----
+ * main.c fills one LbPhase for each frame the main display gets, when render() ends (lbf_phase_built),
+ * and completes it at that frame's presentation (lbf_phase_shown). Times are CLOCK_MONOTONIC ns, 0 =
+ * unknown. All measured by lord-server itself; nothing comes from a helper. Two recorders take them:
+ * LordBench's (lbf_begin/lbf_end, lbf_phases) and the scripted drag's (lbf_drag_begin/lbf_drag_end), for
+ * its "drag (scripted):" line. Off, each call is one atomic read. */
+#define LBF_G0R 8 /* G0R_N (ui/ui.h), checked in main.c */
+#define LBF_G0L 16 /* G0L_N */
+typedef struct {
+ uint64_t prev_flip; /* the main display's presentation before this frame */
+ uint64_t wake; /* poll() returned, before this frame was started */
+ int from_flip; /* that wake handled the main display's flip (else input or a timer) */
+ uint64_t render0, built; /* render() started and ended */
+ double paint_ms; /* layout and paint */
+ double up_ms, g0_ms, swap_ms, submit_ms; /* the UI texture's upload, the G0 textures', eglSwapBuffers,
+ * the buffer's framebuffer and the page flip ioctl */
+ long up_px, g0_px;
+ int g0_full; /* a G0 texture was sent whole in this frame */
+ double feed_ms; /* G0's textures catching up after the flip was queued */
+ long feed_px;
+ uint64_t submit; /* the page flip was queued (0: none, a modeset or no monitor) */
+ uint32_t period; /* the refresh period, ns */
+ int par; /* the paint threads were on */
+ int g0; /* 1 G0 composed it, 0 refused (g0_why, g0_sub), -1 not tried */
+ int g0_why, g0_sub;
+ int unshown; /* gpu_frame_ex's -2: nothing shown, a vblank lost */
+} LbPhase;
+typedef struct { double p50, p99; } LbPct;
+typedef struct {
+ int n; /* frames with their phases */
+ LbPct wake; /* the flip to lord-server running (frames started by a flip) */
+ LbPct pre; /* that wake to render(): input, LordBench's scripted step, JS */
+ LbPct paint, up, g0up, swap, submit_call;
+ LbPct build; /* render() */
+ LbPct gpu; /* the flip queued to the GPU done (the fence's signal time) */
+ LbPct wait; /* the later of the two to the flip: the vblank */
+ LbPct chain; /* the wake to the flip */
+ LbPct feed;
+ double up_mpx, g0_mpx, feed_mpx; /* pixels sent per frame, average, millions */
+ int on_time; /* shown by the first vblank after the frame started (+ half a period) */
+ int cpu_late; /* late, and queued after that vblank */
+ int gpu_late; /* late, queued before it but the GPU finished after it */
+ int other_late; /* late with both before it (or the GPU time unknown) */
+ int gpu_known; /* frames with the GPU's finish time */
+ int par; /* frames with the paint threads on */
+ int g0_tried, g0_taken, g0_refused[LBF_G0R], g0_layer[LBF_G0L], g0_full;
+ long g0_full_px;
+ int unshown;
+} LbPhaseStats;
+void lbf_phase_built(const LbPhase *p);
+void lbf_phase_shown(uint64_t flip_ns, uint64_t gpu_done_ns);
+int lbf_recording(void); /* either recorder is on (main.c takes the GPU's fences only then) */
+void lbf_phases(LbPhaseStats *st); /* LordBench's, of the recording lbf_end just stopped */
+void lbf_drag_begin(void);
+void lbf_drag_end(LbPhaseStats *st);
+/* names of G0R_* and G0L_* (ui/ui.h's order) and the phases as text for a log line */
+const char *lbf_g0r_name(int i);
+const char *lbf_g0l_name(int i);
+void lbf_phases_text(const LbPhaseStats *st, char *buf, size_t n);
+
#endif
diff --git a/server/src/bench/lbrun.c b/server/src/bench/lbrun.c
index f014d1a..b48531a 100644
--- a/server/src/bench/lbrun.c
+++ b/server/src/bench/lbrun.c
@@ -108,6 +108,8 @@ typedef struct {
double throttle_at, throttle_temp;
LbRpiWatch rpi; /* the Pi firmware's under-voltage and throttling during the run */
double budget_ms, gap_max; /* desktop: the refresh period and the longest wait between frames */
+ LbPhaseStats phases[2]; /* desktop: where the frames' time went, alone and under the load */
+ int have_phases[2];
int sbx_have[LB_SBX_COUNT], sbx_refused[LB_SBX_COUNT], sbx_errno[LB_SBX_COUNT]; /* the helper-sandbox self-test */
} Res;
@@ -135,6 +137,28 @@ static void cond_json(HBuf *b, const LbCond *c) {
hb_printf(b, "}");
}
+/* the frame phases lord-server recorded itself (bench/lbframes.h): [p50, p99] in ms, and counts */
+static void phases_json(HBuf *b, const LbPhaseStats *p) {
+ const struct { const char *k; LbPct v; } t[] = {
+ { "wakeMs", p->wake }, { "beforeRenderMs", p->pre }, { "renderMs", p->build }, { "paintMs", p->paint },
+ { "uploadMs", p->up }, { "g0UploadMs", p->g0up }, { "swapMs", p->swap }, { "flipIoctlMs", p->submit_call },
+ { "gpuMs", p->gpu }, { "vblankWaitMs", p->wait }, { "wakeToFlipMs", p->chain }, { "catchUpMs", p->feed },
+ };
+ hb_printf(b, "{\"frames\":%d", p->n);
+ for (size_t i = 0; i < sizeof t / sizeof *t; i++) hb_printf(b, ",\"%s\":[%.3f,%.3f]", t[i].k, t[i].v.p50, t[i].v.p99);
+ hb_printf(b, ",\"uploadMpx\":%.4f,\"g0UploadMpx\":%.4f,\"catchUpMpx\":%.4f,\"onTime\":%d,\"cpuLate\":%d,\"gpuLate\":%d,"
+ "\"otherLate\":%d,\"gpuKnown\":%d,\"paintThreads\":%d,\"unshown\":%d,\"g0\":{\"tried\":%d,\"taken\":%d,"
+ "\"wholeUploads\":%d,\"wholeMpx\":%.3f,\"refused\":{",
+ p->up_mpx, p->g0_mpx, p->feed_mpx, p->on_time, p->cpu_late, p->gpu_late, p->other_late, p->gpu_known, p->par,
+ p->unshown, p->g0_tried, p->g0_taken, p->g0_full, p->g0_full_px / 1e6);
+ for (int i = 0, k = 0; i < LBF_G0R; i++)
+ if (p->g0_refused[i] && lbf_g0r_name(i)) hb_printf(b, "%s\"%s\":%d", k++ ? "," : "", lbf_g0r_name(i), p->g0_refused[i]);
+ hb_printf(b, "},\"layer\":{");
+ for (int i = 0, k = 0; i < LBF_G0L; i++)
+ if (p->g0_layer[i] && lbf_g0l_name(i)) hb_printf(b, "%s\"%s\":%d", k++ ? "," : "", lbf_g0l_name(i), p->g0_layer[i]);
+ hb_printf(b, "}}}");
+}
+
static char *build_result(const Job *j, int st, const char *why, const Res *r, const LbCond *c0, const LbCond *c1,
double busy_pct, double waited, int quiet, int threads, const char *storage, unsigned storage_mb,
double secs) {
@@ -190,7 +214,18 @@ static char *build_result(const Job *j, int st, const char *why, const Res *r, c
first = 0;
}
hb_printf(&b, "}");
- if (r->budget_ms > 0) hb_printf(&b, ",\"frames\":{\"budgetMs\":%.3f,\"gapMaxMs\":%.1f}", r->budget_ms, r->gap_max);
+ if (r->budget_ms > 0) {
+ hb_printf(&b, ",\"frames\":{\"budgetMs\":%.3f,\"gapMaxMs\":%.1f", r->budget_ms, r->gap_max);
+ if (r->have_phases[0] || r->have_phases[1]) {
+ hb_printf(&b, ",\"phases\":{");
+ for (int i = 0, k = 0; i < 2; i++) if (r->have_phases[i]) {
+ hb_printf(&b, "%s\"%s\":", k++ ? "," : "", i ? "load" : "alone");
+ phases_json(&b, &r->phases[i]);
+ }
+ hb_printf(&b, "}");
+ }
+ hb_printf(&b, "}");
+ }
if (r->nsamples) {
hb_printf(&b, ",\"sustained\":{\"samples\":[");
for (int i = 0; i < r->nsamples; i++)
@@ -369,10 +404,19 @@ static int put_frames(Res *r, int first) {
put_result(r, first + 4, fs.in_p50, 0);
put_result(r, first + 5, fs.in_p99, 0);
} else for (int i = 4; i < 6; i++) put_skip(r, first + i, LB_SKIP_FAILED);
+ LbPhaseStats ph;
+ lbf_phases(&ph);
pthread_mutex_lock(&mu);
r->budget_ms = fs.budget_ms;
if (fs.gap_max > r->gap_max) r->gap_max = fs.gap_max;
+ int k = first == LB_DESK_FPS;
+ if (ph.n) { r->phases[k] = ph; r->have_phases[k] = 1; }
pthread_mutex_unlock(&mu);
+ if (ph.n) { /* also in the session's log, as the drag's line has them */
+ char t[1024];
+ lbf_phases_text(&ph, t, sizeof t);
+ fprintf(stderr, "lordbench: desktop %s: %s\n", k ? "under load" : "alone", t);
+ }
return 0;
}
diff --git a/server/src/gpu/gpu.c b/server/src/gpu/gpu.c
index 6ec12c0..24fc152 100644
--- a/server/src/gpu/gpu.c
+++ b/server/src/gpu/gpu.c
@@ -46,6 +46,13 @@ int gpu_frame_ex(int out, const Canvas *s, const Rect *d, int n, const GpuG0 *g
}
int gpu_g0_holds(int out) { (void)out; return 0; }
void gpu_g0_stats(long *b, long *l, long *q) { *b = *l = *q = 0; }
+int gpu_g0_feed(int out, int which, const uint32_t *px, int w, int h, Rect r) {
+ (void)out; (void)which; (void)px; (void)w; (void)h; (void)r;
+ return -1;
+}
+void gpu_frame_times(int out, GpuFrameTimes *t) { (void)out; *t = (GpuFrameTimes){ 0 }; }
+void gpu_fence_on(int on) { (void)on; }
+int gpu_fence_time(int out, uint64_t *ns) { (void)out; *ns = 0; return 0; }
void gpu_draw(GpuTex *t, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh, Rect c, float o) {
(void)t; (void)dx; (void)dy; (void)dw; (void)dh; (void)sx; (void)sy; (void)sw; (void)sh; (void)c; (void)o;
}
@@ -72,6 +79,7 @@ int gpu_read_done(void) { return 0; }
#include <GLES2/gl2ext.h>
#include <drm/drm_fourcc.h>
#include <drm/virtgpu_drm.h>
+#include <linux/sync_file.h>
#include <sys/ioctl.h>
/* Does the card have 3D acceleration? The kernel is asked before loading Mesa, so a machine
@@ -121,6 +129,8 @@ typedef struct {
EGLSurface surf;
GpuTex canvas;
Shown front, pending;
+ GpuFrameTimes times; /* the last frame's (gpu_frame_times) */
+ int fence; /* its native fence's fd + 1 (a sync file), 0 none (so a wiped GOut has none) */
} GOut;
static struct {
@@ -146,12 +156,19 @@ static struct {
char render_node[64]; /* where Mesa renders (on the Pi 5: v3d, not vc4) */
unsigned gen; /* this context's generation (0 = none) */
/* G0, the dragged window composited here (gpu_g0_ready): 0 off, 1 on (g0_setup, at gpu_init) */
- int g0, g0out; /* g0out: the output whose upload the textures hold (-1: none) */
+ int g0;
+ int g0tout[2]; /* the output whose pixels each texture holds (-1: none); what it
+ * still lacks is paint.c's dirty rectangles */
GLuint g0prog, g0tex[2]; /* 0: the copy of what is below, 1: the layer */
int g0tw[2], g0th[2]; /* their sizes (0: nothing uploaded) */
int g0lw, g0lh; /* the largest output the self-test's placement covered */
GLint gu_below, gu_layer, gu_bsize, gu_lrect, gu_swap;
+ /* EGL_ANDROID_native_fence_sync: when the GPU finished a frame (gpu_fence_on) */
+ PFNEGLCREATESYNCKHRPROC create_sync;
+ PFNEGLDESTROYSYNCKHRPROC destroy_sync;
+ PFNEGLDUPNATIVEFENCEFDANDROIDPROC dup_fence;
} G;
+static int fence_wanted; /* gpu_fence_on (outlives the context) */
/* These outlive the context (G is wiped by gpu_shutdown). */
static unsigned last_gen;
@@ -165,6 +182,13 @@ void gpu_set_hooks(void (*lost)(void), void (*changed)(void)) { hook_lost = lost
unsigned gpu_generation(void) { return G.on ? G.gen : 0; }
int gpu_tex_current(const GpuTex *t) { return t && G.on && t->gen == G.gen; }
+static double mono_ms(void) {
+ struct timespec t;
+ clock_gettime(CLOCK_MONOTONIC, &t);
+ return t.tv_sec * 1000.0 + t.tv_nsec / 1e6;
+}
+static void take_fence(GOut *o);
+
static void dbg(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
static void dbg(const char *fmt, ...) {
if (!G.debug) return;
@@ -407,6 +431,7 @@ static void out_texture(GOut *o) {
static void out_teardown(GOut *o) {
if (!o->used) return;
+ if (o->fence > 0) close(o->fence - 1);
release(o, &o->pending);
release(o, &o->front);
if (o->surf && eglMakeCurrent(G.dpy, o->surf, o->surf, G.ctx)) glDeleteTextures(1, &o->canvas.id);
@@ -504,12 +529,20 @@ int gpu_init(Kms *k) {
G.query_modifiers = (PFNEGLQUERYDMABUFMODIFIERSEXTPROC)eglGetProcAddress("eglQueryDmaBufModifiersEXT");
}
+ if (has_ext(exts, "EGL_ANDROID_native_fence_sync") && has_ext(exts, "EGL_KHR_fence_sync")) {
+ G.create_sync = (PFNEGLCREATESYNCKHRPROC)eglGetProcAddress("eglCreateSyncKHR");
+ G.destroy_sync = (PFNEGLDESTROYSYNCKHRPROC)eglGetProcAddress("eglDestroySyncKHR");
+ G.dup_fence = (PFNEGLDUPNATIVEFENCEFDANDROIDPROC)eglGetProcAddress("eglDupNativeFenceFDANDROID");
+ if (!G.create_sync || !G.destroy_sync || !G.dup_fence) G.create_sync = NULL;
+ }
+ dbg("native fences (frame phases): %s", G.create_sync ? "yes" : "no");
+
out_texture(&G.out[0]);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
G.on = 1;
- G.g0out = -1;
+ G.g0tout[0] = G.g0tout[1] = -1;
last_why = "on";
if (G.debug) {
GpuFormat f[64];
@@ -835,10 +868,13 @@ static GLuint g0_texture(void) {
return t;
}
-/* Texture i gets px (w × h, stride w): all of it if its size changed or full, else the n rectangles. */
-static long g0_upload(int i, const uint32_t *px, int w, int h, const Rect *r, int n, int full) {
+/* Texture i gets output out's px (w × h, stride w): all of it if its size changed, it held another
+ * output's (or nothing) or full, else the n rectangles. */
+static long g0_upload(int i, int out, const uint32_t *px, int w, int h, const Rect *r, int n, int full) {
glBindTexture(GL_TEXTURE_2D, G.g0tex[i]);
- if (full || G.g0tw[i] != w || G.g0th[i] != h) {
+ int other = G.g0tout[i] != out;
+ G.g0tout[i] = out;
+ if (full || other || G.g0tw[i] != w || G.g0th[i] != h) {
GLenum fmt = G.bgra ? GL_BGRA_EXT : GL_RGBA;
if (G.g0tw[i] != w || G.g0th[i] != h) glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE, px);
else glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, fmt, GL_UNSIGNED_BYTE, px);
@@ -933,8 +969,8 @@ static long g0_pass(int fw, int fh, const uint32_t *bel, const uint32_t *lay, in
for (int y = 0; y < fh; y++)
for (int x = 0; x < fw; x++)
if (x < w.x0 || x >= w.x1 || y < w.y0 || y >= w.y1) ref[(size_t)y * fw + x] = 0;
- g0_upload(0, bel, fw, fh, NULL, 0, 1);
- g0_upload(1, lay, lw, lh, NULL, 0, 1);
+ g0_upload(0, -1, bel, fw, fh, NULL, 0, 1);
+ g0_upload(1, -1, lay, lw, lh, NULL, 0, 1);
glViewport(0, 0, fw, fh);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
@@ -1011,6 +1047,7 @@ static int g0_selftest(int fw, int fh, long *cases, long *differ) {
if (fbo) glDeleteFramebuffers(1, &fbo);
if (ft) glDeleteTextures(1, &ft);
G.g0tw[0] = G.g0tw[1] = G.g0th[0] = G.g0th[1] = 0; /* hold nothing of an output */
+ G.g0tout[0] = G.g0tout[1] = -1;
glDeleteTextures(2, G.g0tex);
G.g0tex[0] = g0_texture();
G.g0tex[1] = g0_texture();
@@ -1061,7 +1098,7 @@ static int g0_setup(void) {
G.gu_swap = glGetUniformLocation(G.g0prog, "u_swap");
G.g0tex[0] = g0_texture();
G.g0tex[1] = g0_texture();
- G.g0out = -1;
+ G.g0tout[0] = G.g0tout[1] = -1;
/* the placement part's size: the largest output now, at least 4096 × 2048, within the GPU's limits */
GLint maxtex = 0, vp[2] = { 0, 0 };
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxtex);
@@ -1123,7 +1160,7 @@ int gpu_g0_ready(int out) {
G.out[out].H <= G.g0lh;
}
-int gpu_g0_holds(int out) { return G.on && G.g0 == 1 && G.g0out == out && out >= 0; }
+int gpu_g0_holds(int out) { return G.on && G.g0 == 1 && out >= 0 && G.g0tout[0] == out && G.g0tout[1] == out; }
void gpu_g0_stats(long *below_px, long *layer_px, long *quads) {
*below_px = g0_bpx;
@@ -1161,7 +1198,7 @@ static void g0_verify(GOut *o, const GpuG0 *g) {
/* G0 off for this context, for a reason that would come back every frame */
static int g0_off(const char *why) {
- G.g0out = -1;
+ G.g0tout[0] = G.g0tout[1] = -1;
G.g0 = 0;
fprintf(stderr, "gpu: G0 off: %s\n", why);
return 0;
@@ -1174,17 +1211,24 @@ static int g0_frame(GOut *o, int out, const GpuG0 *g) {
/* coordinates past what the self-test's placement covered are not trusted */
int tested = o->W <= G.g0lw && o->H <= G.g0lh && g->lw <= G.g0lw - G0_LX && g->lh <= G.g0lh - G0_LY &&
g->bw <= G.g0lw && g->bh <= G.g0lh;
- int other = G.g0out != out; /* another output's (or nothing yet): all of both */
if (g->lpx && g->bpx) {
if (!sane) return g0_off("a window rectangle outside the output");
if (!tested) return g0_off("a layer or output larger than its self-test covered");
for (int i = 0; i < 16 && glGetError() != GL_NO_ERROR; i++) {}
- g0_bpx += g0_upload(0, g->bpx, g->bw, g->bh, g->bdirty, g->nb, g->bfull || other);
- g0_lpx += g0_upload(1, g->lpx, g->lw, g->lh, g->ldirty, g->nl, g->lfull || other);
+ double t0 = mono_ms();
+ /* another output's texture (or nothing yet), or full: all of it (paint.c sends what the textures
+ * lack between frames first, so this is rare) */
+ o->times.g0_full = g->bfull || g->lfull || G.g0tout[0] != out || G.g0tout[1] != out || G.g0tw[0] != g->bw ||
+ G.g0th[0] != g->bh || G.g0tw[1] != g->lw || G.g0th[1] != g->lh;
+ long b = g0_upload(0, out, g->bpx, g->bw, g->bh, g->bdirty, g->nb, g->bfull);
+ long l = g0_upload(1, out, g->lpx, g->lw, g->lh, g->ldirty, g->nl, g->lfull);
+ g0_bpx += b;
+ g0_lpx += l;
+ o->times.g0_px = b + l;
+ o->times.g0_ms = mono_ms() - t0;
if (glGetError() != GL_NO_ERROR) return g0_off("an upload failed");
- G.g0out = out;
- } else if (!sane || !tested || other || G.g0tw[1] != g->lw || G.g0th[1] != g->lh || G.g0tw[0] != g->bw ||
- G.g0th[0] != g->bh)
+ } else if (!sane || !tested || !gpu_g0_holds(out) || G.g0tw[1] != g->lw || G.g0th[1] != g->lh ||
+ G.g0tw[0] != g->bw || G.g0th[0] != g->bh)
return 0;
g0_draw(o->W, o->H, g->w, (float)g->lx, (float)g->ly, (float)g->lw, (float)g->lh, (float)g->bw, (float)g->bh);
g0_quads++;
@@ -1197,12 +1241,15 @@ int gpu_frame_ex(int out, const Canvas *scene, const Rect *dmg, int n, const Gpu
if (g0_drawn) *g0_drawn = 0;
if (!G.on || out < 0 || out >= OUT_MAX || !G.out[out].used) return -1;
GOut *o = &G.out[out];
+ o->times = (GpuFrameTimes){ 0 };
if (!eglMakeCurrent(G.dpy, o->surf, o->surf, G.ctx)) { fprintf(stderr, "gpu: eglMakeCurrent failed\n"); return -1; }
G.cur = o;
glViewport(0, 0, o->W, o->H);
/* what changed in the UI */
+ double t0 = mono_ms();
glBindTexture(GL_TEXTURE_2D, o->canvas.id);
- for (int i = 0; i < n; i++) upload_rect(scene->px, scene->stride, scene->w, o->W, dmg[i]);
+ for (int i = 0; i < n; i++) o->times.up_px += upload_rect(scene->px, scene->stride, scene->w, o->W, dmg[i]);
+ o->times.up_ms = mono_ms() - t0;
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
Rect all = { 0, 0, o->W, o->H };
@@ -1222,13 +1269,96 @@ int gpu_frame_ex(int out, const Canvas *scene, const Rect *dmg, int n, const Gpu
if (rb.w == o->W && rb.h == o->H) read_back(o->W, o->H);
rb.px = NULL;
}
+ double t1 = mono_ms();
if (!eglSwapBuffers(G.dpy, o->surf)) { fprintf(stderr, "gpu: eglSwapBuffers failed\n"); return -1; }
+ double t2 = mono_ms();
+ o->times.swap_ms = t2 - t1;
+ take_fence(o);
struct gbm_bo *bo = gbm_surface_lock_front_buffer(o->gs);
if (!bo) { fprintf(stderr, "gpu: no GBM buffer\n"); return -1; }
uint32_t fb = fb_for_bo(bo);
if (!fb) { gbm_surface_release_buffer(o->gs, bo); return -1; }
G.frames++;
- return present(o, (Shown){ .kind = 1, .bo = bo, .fb = fb });
+ int r = present(o, (Shown){ .kind = 1, .bo = bo, .fb = fb });
+ o->times.submit_ms = mono_ms() - t2;
+ return r;
+}
+
+void gpu_frame_times(int out, GpuFrameTimes *t) {
+ *t = G.on && out >= 0 && out < OUT_MAX && G.out[out].used ? G.out[out].times : (GpuFrameTimes){ 0 };
+}
+
+/* ---- G0's textures between frames (paint_g0_feed) ---- */
+
+int gpu_g0_feed(int out, int which, const uint32_t *px, int w, int h, Rect r) {
+ if (!G.on || G.g0 != 1 || out < 0 || out >= OUT_MAX || !G.out[out].used || which < 0 || which > 1) return -1;
+ GOut *o = &G.out[out];
+ /* a texture upload needs the context, not a given surface (G.cur is not updated by every
+ * eglMakeCurrent, so the context actually current is asked) */
+ if (eglGetCurrentContext() != G.ctx) {
+ if (!eglMakeCurrent(G.dpy, o->surf, o->surf, G.ctx)) return -1;
+ G.cur = o;
+ }
+ /* errors left by earlier calls (an import, the cursor) are not this upload's: without this one
+ * of them would turn G0 off below */
+ for (int i = 0; i < 16 && glGetError() != GL_NO_ERROR; i++) {}
+ glBindTexture(GL_TEXTURE_2D, G.g0tex[which]);
+ if (G.g0tout[which] != out || G.g0tw[which] != w || G.g0th[which] != h) {
+ if (G.g0tw[which] != w || G.g0th[which] != h) { /* its storage, filled by the slices that follow */
+ GLenum fmt = G.bgra ? GL_BGRA_EXT : GL_RGBA;
+ glTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, fmt, GL_UNSIGNED_BYTE, NULL);
+ G.g0tw[which] = w;
+ G.g0th[which] = h;
+ }
+ G.g0tout[which] = out;
+ if (glGetError() != GL_NO_ERROR) { g0_off("a texture could not be made"); return -1; }
+ return 1;
+ }
+ Rect q = { r.x0 < 0 ? 0 : r.x0, r.y0 < 0 ? 0 : r.y0, r.x1 > w ? w : r.x1, r.y1 > h ? h : r.y1 };
+ long sent = upload_rect(px, w, w, w, q);
+ if (which) g0_lpx += sent;
+ else g0_bpx += sent;
+ if (sent && glGetError() != GL_NO_ERROR) { g0_off("an upload failed"); return -1; }
+ return 0;
+}
+
+/* ---- when the GPU finished a frame (LordBench's frame phases) ---- */
+
+void gpu_fence_on(int on) { fence_wanted = on != 0; }
+
+/* after eglSwapBuffers: a native fence that signals when everything submitted so far (the frame) is done */
+static void take_fence(GOut *o) {
+ if (o->fence > 0) { close(o->fence - 1); o->fence = 0; }
+ if (!fence_wanted || !G.create_sync) return;
+ EGLSyncKHR sy = G.create_sync(G.dpy, EGL_SYNC_NATIVE_FENCE_ANDROID, NULL);
+ if (sy == EGL_NO_SYNC_KHR) return;
+ glFlush(); /* the fence's fd exists once it is flushed */
+ int fd = G.dup_fence(G.dpy, sy);
+ G.destroy_sync(G.dpy, sy);
+ o->fence = fd >= 0 ? fd + 1 : 0;
+}
+
+int gpu_fence_time(int out, uint64_t *ns) {
+ *ns = 0;
+ if (!G.on || out < 0 || out >= OUT_MAX || !G.out[out].used || G.out[out].fence <= 0) return 0;
+ GOut *o = &G.out[out];
+ struct sync_fence_info fi[4];
+ struct sync_file_info info;
+ memset(&info, 0, sizeof info);
+ memset(fi, 0, sizeof fi);
+ int ok = 0;
+ int fd = o->fence - 1;
+ if (!ioctl(fd, SYNC_IOC_FILE_INFO, &info) && info.num_fences > 0 && info.num_fences <= 4) {
+ info.sync_fence_info = (uint64_t)(uintptr_t)fi;
+ if (!ioctl(fd, SYNC_IOC_FILE_INFO, &info) && info.status == 1) {
+ for (uint32_t i = 0; i < info.num_fences; i++) /* the last of its fences to signal */
+ if (fi[i].timestamp_ns > *ns) *ns = fi[i].timestamp_ns;
+ ok = *ns != 0;
+ }
+ }
+ close(fd);
+ o->fence = 0;
+ return ok;
}
int gpu_frame(int out, const Canvas *scene, Rect dmg, void (*draw_layer)(int layer)) {
diff --git a/server/src/gpu/gpu.h b/server/src/gpu/gpu.h
index d7f886a..1712f25 100644
--- a/server/src/gpu/gpu.h
+++ b/server/src/gpu/gpu.h
@@ -72,7 +72,11 @@ int gpu_frame(int out, const Canvas *scene, Rect damage, void (*draw_layer)(int
* scene and fills this; one shader then writes, inside w, the layer (lpx) over the copy of what is
* below (bpx) exactly as canvas_blit's blit_row does. The two are textures of their own, uploaded
* only where they changed (ldirty, bdirty; *full: all of it). */
-#define G0_DIRTY 8
+#define G0_DIRTY 16
+/* At most this many pixels of the two textures are sent in one frame: a frame that would need more is
+ * painted by the CPU, and the rest is sent after its flip is queued (paint_g0_feed, gpu_g0_feed), a slice
+ * a frame, so no frame uploads a whole screen (docs/GPU.md, "Uploads without a stall"). 1 MB. */
+#define G0_FEED_PX 262144L
typedef struct GpuG0 {
Rect w; /* where the shader writes (the output's physical px, top-down) */
const uint32_t *lpx; /* the layer: lw × lh, its pixel (0, 0) at (lx, ly) */
@@ -99,6 +103,26 @@ int gpu_g0_ready(int out);
int gpu_frame_ex(int out, const Canvas *scene, const Rect *dmg, int n, const GpuG0 *g0, int *g0_drawn,
void (*draw_layer)(int layer));
int gpu_g0_holds(int out); /* the G0 textures hold that output's last upload, in this context */
+/* Texture which (0 the copy of what is below, 1 the layer) of output out gets r of px (w × h, stride w),
+ * between frames (paint_g0_feed's up). 1: it held nothing of that output at that size: it is now that
+ * output's, and the caller sends all of it again; 0 sent; -1 failed (G0 is then off). */
+int gpu_g0_feed(int out, int which, const uint32_t *px, int w, int h, Rect r);
+/* Where the last gpu_frame_ex of an output spent its time (LordBench's frame phases, bench/lbframes.h) */
+typedef struct {
+ double up_ms; /* the UI texture's rectangles */
+ long up_px;
+ double g0_ms; /* the G0 textures' uploads for the quad */
+ long g0_px;
+ int g0_full; /* one of them was sent whole */
+ double swap_ms; /* eglSwapBuffers */
+ double submit_ms; /* the front buffer, its framebuffer and the page flip */
+} GpuFrameTimes;
+void gpu_frame_times(int out, GpuFrameTimes *t);
+/* While on, each frame takes a native fence after eglSwapBuffers (EGL_ANDROID_native_fence_sync); at
+ * the frame's flip gpu_fence_time gives when the GPU finished it (the sync file's signal time): 1 known,
+ * 0 unknown (no fence, or not signalled yet). Each fence is read once and closed. Off: nothing is taken. */
+void gpu_fence_on(int on);
+int gpu_fence_time(int out, uint64_t *ns);
/* uploaded pixels of the copy of what is below and of the layer, and G0 quads drawn, since the last call */
void gpu_g0_stats(long *below_px, long *layer_px, long *quads);
/* Another display (docs/DISPLAYS.md): its own GBM/EGL surface on the same context; gpu_init made
diff --git a/server/src/main.c b/server/src/main.c
index 2452e21..3e3718e 100644
--- a/server/src/main.c
+++ b/server/src/main.c
@@ -116,11 +116,20 @@ static void g0_stats_text(char *buf, size_t len) {
long bpx, lpx, quads;
paint_g0_stats(&g);
gpu_g0_stats(&bpx, &lpx, &quads);
- snprintf(buf, len, "G0: %ld of %ld frames (%ld quads), strips %.2f Mpx, uploaded below %.2f Mpx, layer %.2f Mpx "
- "(not: %ld layer, %ld clip, %ld ancestor, %ld app, %ld after, %ld post)",
- g.frames, g.tried, quads, g.strip_px / 1e6, bpx / 1e6, lpx / 1e6, g.refused[G0R_LAYER], g.refused[G0R_CLIP],
- g.refused[G0R_ANCESTOR], g.refused[G0R_APP], g.refused[G0R_AFTER], g.refused[G0R_POST]);
+ int k = snprintf(buf, len, "G0: %ld of %ld frames (%ld quads), strips %.2f Mpx, uploaded below %.2f Mpx, layer %.2f Mpx "
+ "(not: %ld layer, %ld clip, %ld ancestor, %ld app, %ld after, %ld post, %ld catching up",
+ g.frames, g.tried, quads, g.strip_px / 1e6, bpx / 1e6, lpx / 1e6, g.refused[G0R_LAYER], g.refused[G0R_CLIP],
+ g.refused[G0R_ANCESTOR], g.refused[G0R_APP], g.refused[G0R_AFTER], g.refused[G0R_POST], g.refused[G0R_FEED]);
+ /* the layer's refusals by cause (G0L_*) */
+ for (int i = 0, first = 1; i < G0L_N && k > 0 && (size_t)k < len; i++)
+ if (g.layer[i]) {
+ int w = snprintf(buf + k, len - (size_t)k, "%s%s %ld", first ? "; layer: " : ", ", lbf_g0l_name(i), g.layer[i]);
+ if (w > 0) k += w;
+ first = 0;
+ }
+ if (k > 0 && (size_t)k < len) snprintf(buf + k, len - (size_t)k, ")");
}
+_Static_assert(G0R_N <= LBF_G0R && G0L_N <= LBF_G0L, "lbframes.c names every G0R_* and G0L_*");
/* One display (docs/DISPLAYS.md): its KMS head, where it sits in the global logical space, and the
* frame the UI paints for it at its own resolution. out[0]'s head owns the card's fd; the main display
@@ -425,7 +434,7 @@ static void dispatch_pointer(Server *s) {
double span = dstat.last - dstat.t0;
long lr = 0, lb = 0, lp = paint_layer_parts();
paint_layer_stats(&lr, &lb);
- char bs[192], gs[256];
+ char bs[192], gs[512];
below_stats_text(bs, sizeof bs);
g0_stats_text(gs, sizeof gs);
fprintf(stderr, "drag: %ld frames in %.0f ms = %.1f FPS (%ld moves); per frame: work %.2f ms "
@@ -1274,13 +1283,42 @@ static void gpu_layer(int layer) {
}
}
+static uint64_t mono_ns(void) {
+ struct timespec t;
+ clock_gettime(CLOCK_MONOTONIC, &t);
+ return (uint64_t)t.tv_sec * 1000000000ull + (uint64_t)t.tv_nsec;
+}
+/* LordBench's frame phases (bench/lbframes.h): the poll() return before this frame and whether it handled
+ * the main display's flip; render_frame fills the main display's part of fph */
+static uint64_t loop_wake;
+static int loop_wake_flip;
+static LbPhase fph;
+static int fph_main;
+
static void render_frame(Server *s);
+static void g0_feed_now(Server *s);
static void render(Server *s) {
+ int phases = lbf_recording();
+ gpu_fence_on(phases); /* the GPU's finish time of each frame, only while recording */
+ uint64_t r0 = phases ? mono_ns() : 0;
double t0 = now_ms();
+ fph = (LbPhase){ .g0 = -1, .g0_why = -1, .g0_sub = -1 };
+ fph_main = 0;
render_frame(s);
- lbf_frame(now_ms() - t0); /* LordBench's compositor measurement (bench/lbframes.c) */
+ double t1 = now_ms();
+ uint64_t r1 = phases ? mono_ns() : 0;
+ lbf_frame(t1 - t0); /* LordBench's compositor measurement (bench/lbframes.c) */
+ g0_feed_now(s); /* after the frame's time: its flip is queued already */
+ if (phases && fph_main) {
+ fph.wake = loop_wake;
+ fph.from_flip = loop_wake_flip;
+ fph.render0 = r0;
+ fph.built = r1;
+ lbf_phase_built(&fph);
+ if (s->headless) lbf_phase_shown(fph.submit, 0);
+ }
if (dstat.active) {
- double t1 = now_ms(), js = dstat.js - dstat.work_js;
+ double js = dstat.js - dstat.work_js;
double work = (t1 - t0) + js;
dstat.work_js = dstat.js;
dstat.frames++;
@@ -1476,6 +1514,24 @@ static int outs_have_work(const Server *s) {
return 0;
}
+/* paint_g0_feed's way to the GPU: ctx is the display's GPU output */
+static int g0_feed_up(void *ctx, int which, const uint32_t *px, int w, int h, Rect r) {
+ return gpu_g0_feed(*(const int *)ctx, which, px, w, h, r);
+}
+/* the displays whose G0 textures catch up after this frame: after its flips are queued and its time is
+ * taken, while the CPU would wait for the vblank anyway (docs/GPU.md, "Uploads without a stall") */
+static int feed_idx[OUT_MAX], nfeed;
+static void g0_feed_now(Server *s) {
+ for (int k = 0; k < nfeed; k++) {
+ Out *o = &s->out[feed_idx[k]];
+ if (!o->on || o->gpu < 0 || !gpu_g0_ready(o->gpu) || paint_g0_backlog(feed_idx[k]) <= 0) continue;
+ double f0 = now_ms();
+ long sent = paint_g0_feed(feed_idx[k], G0_FEED_PX, g0_feed_up, &o->gpu);
+ if (o == main_out(s)) { fph.feed_ms = now_ms() - f0; fph.feed_px = sent; }
+ }
+ nfeed = 0;
+}
+
static void render_frame(Server *s) {
double t0 = now_ms();
ui.layout_ms = ui.paint_ms = 0;
@@ -1510,7 +1566,9 @@ static void render_frame(Server *s) {
if (s->headless) {
Out *o = &s->out[0];
Rect drawn = paint_out(s, o, 0, 1);
+ if (drawn.x1 > drawn.x0) fph.g0 = paint_g0_last(&fph.g0_why, &fph.g0_sub);
present_memory(s, o, 0, 1, drawn);
+ fph_main = 1; /* presented at the end of this frame (below) */
} else {
for (int i = 0; i < OUT_MAX; i++) {
Out *o = &s->out[i];
@@ -1520,6 +1578,8 @@ static void render_frame(Server *s) {
* this display's; otherwise its rectangle is painted by the CPU now */
if (o->g0on && box_empty(o->pend) && !o->full && !gpu_g0_holds(o->gpu)) g0_stale(o);
Rect r = paint_out(s, o, i, o == feed);
+ int g0why = -1, g0sub = -1, g0last = r.x1 > r.x0 ? paint_g0_last(&g0why, &g0sub) : -1;
+ if (o == mo) { fph.g0 = g0last; fph.g0_why = g0why; fph.g0_sub = g0sub; }
if (gpu_active() && o->gpu >= 0) { /* (the loop above skips what has nothing new) */
update_cursor(s);
gpu_server = s;
@@ -1558,6 +1618,25 @@ static void render_frame(Server *s) {
int res = scanned ? 0 : gpu_frame_ex(o->gpu, &o->scene, up, nup, g0, &g0drawn, gpu_layer);
int failed = res == -1, unshown = res == -2;
if (o->g0taken && g0drawn) paint_g0_done(); /* the textures have what paint.c had */
+ if (o == mo) {
+ /* a frame scanned out straight has no times of its own (gpu_frame_times keeps the last
+ * composed frame's) and no fence (one left from before would give an old GPU time) */
+ GpuFrameTimes ft = { 0 };
+ if (!scanned) gpu_frame_times(o->gpu, &ft);
+ else if (lbf_recording()) { uint64_t old; gpu_fence_time(o->gpu, &old); }
+ fph.up_ms = ft.up_ms;
+ fph.up_px = ft.up_px;
+ fph.g0_ms = ft.g0_ms;
+ fph.g0_px = ft.g0_px;
+ fph.g0_full = ft.g0_full;
+ fph.swap_ms = ft.swap_ms;
+ fph.submit_ms = ft.submit_ms;
+ fph.unshown = unshown;
+ }
+ /* G0's textures catch up after the frame (render, g0_feed_now): only when this frame
+ * would have been G0's but for what they lack (paint.c, paint_g0_feed); sent while G0 is
+ * refused for another reason, most of it would be sent again before it is used */
+ if (!failed && !g0drawn && g0last == 0 && g0why == G0R_FEED && nfeed < OUT_MAX) feed_idx[nfeed++] = i;
if (unshown) {
/* the quad could not be drawn: nothing was shown (the display keeps the frame before,
* which was right); W joins the damage and the next frame paints it on the CPU */
@@ -1598,6 +1677,12 @@ static void render_frame(Server *s) {
}
} else present_cpu(s, o, i, r, o == feed);
if (o == mo) main_shown = 1;
+ if (o == mo) {
+ fph_main = 1;
+ fph.prev_flip = o->kms.flip_ns;
+ fph.submit = o->kms.flip_pending ? o->kms.flip_submit_ns : 0;
+ fph.period = o->kms.mode.vrefresh ? 1000000000u / o->kms.mode.vrefresh : 16666667u;
+ }
}
/* every display in one frame for the remote desktop and recording (capture view) */
Out *c = &s->cap;
@@ -1625,16 +1710,30 @@ static void render_frame(Server *s) {
Out *pm = main_out(s);
int hz = s->headless ? (mirror_fps() > 60 ? mirror_fps() : 60) : pm && pm->kms.mode.vrefresh ? (int)pm->kms.mode.vrefresh : 60;
double frame_ms = 1000.0 / hz;
- if (!par_on && ui.paint_ms > frame_ms * 0.7 && par_threads() > 1) { par_on = 1; light = 0; canvas_parallel(par_rows); }
+ fph.paint_ms = ui.layout_ms + ui.paint_ms;
+ fph.par = par_on;
+ /* (0.8.6) The whole frame counts too, not only its paint: what has to fit before the vblank is the
+ * frame (layout, paint, the upload, the GPU's own part), and on the Pi 5 under an all-core load the
+ * paint alone (about 7.5 ms) stayed under 70 % while the frame (about 13 ms) missed every vblank. On
+ * when the frame takes more than 60 % of the period; light only with both paint and frame short. */
+ double built = now_ms() - t0;
+ if (!par_on && (ui.paint_ms > frame_ms * 0.7 || built > frame_ms * 0.6) && par_threads() > 1) { par_on = 1; light = 0; canvas_parallel(par_rows); }
else if (par_on) {
- light = ui.paint_ms < frame_ms * 0.25 ? light + 1 : 0;
+ light = ui.paint_ms < frame_ms * 0.25 && built < frame_ms * 0.45 ? light + 1 : 0;
if (light >= 60) { par_on = 0; canvas_parallel(NULL); }
}
wl_frame_done((unsigned)now_ms());
if (s->headless) { /* no flip without a monitor: the frame is out now */
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
- lbf_presented((uint64_t)t.tv_sec * 1000000000ull + (uint64_t)t.tv_nsec, (uint32_t)(1000000000u / (unsigned)hz));
+ uint64_t ns = (uint64_t)t.tv_sec * 1000000000ull + (uint64_t)t.tv_nsec;
+ lbf_presented(ns, (uint32_t)(1000000000u / (unsigned)hz));
+ /* its phases: "queued" and "shown" now, the vblanks on the pacing grid of 1000/hz ms (render) */
+ static uint64_t headless_prev;
+ fph.prev_flip = headless_prev;
+ fph.submit = ns;
+ fph.period = (uint32_t)(1000000000u / (unsigned)hz);
+ headless_prev = ns;
}
/* No flip event will come (a modeset instead of a page flip: the first frame, or a driver
* without page flip): the frame is on screen already, so its presentation feedback goes now.
@@ -1968,11 +2067,14 @@ int main(int argc, char **argv) {
if (scripted && !grab_scripted()) {
long lr = 0, lb = 0, lp = paint_layer_parts();
paint_layer_stats(&lr, &lb);
- char bs[192], gs[256];
+ char bs[192], gs[512], ps[1024];
below_stats_text(bs, sizeof bs);
g0_stats_text(gs, sizeof gs);
- fprintf(stderr, "drag (scripted): layer: %ld painted (%ld of them a part), %ld copied (%s); %s; %s\n",
- lr, lp, lb, gpu_active() ? "GPU" : "CPU", bs, gs);
+ LbPhaseStats ph;
+ lbf_drag_end(&ph);
+ lbf_phases_text(&ph, ps, sizeof ps);
+ fprintf(stderr, "drag (scripted): layer: %ld painted (%ld of them a part), %ld copied (%s); %s; %s; %s\n",
+ lr, lp, lb, gpu_active() ? "GPU" : "CPU", bs, gs, ps);
}
if (!scripted && grab_scripted()) { /* its start: what came before is not counted */
long lr, lb;
@@ -1984,6 +2086,7 @@ int main(int argc, char **argv) {
paint_g0_stats(&g);
long q[3];
gpu_g0_stats(&q[0], &q[1], &q[2]);
+ lbf_drag_begin(); /* its frames' phases (bench/lbframes.h) */
}
scripted = grab_scripted();
/* Timers del tema (React agenda su trabajo con setTimeout/setImmediate). */
@@ -2096,6 +2199,8 @@ int main(int argc, char **argv) {
int hwbase = n, nhw = hw_pollfds(pfd + n, 4); /* uevents and the system bus (src/hw) */
n += nhw;
if (poll(pfd, n, wait) < 0 && errno != EINTR) { perror("poll"); break; }
+ loop_wake = mono_ns(); /* LordBench's frame phases: the next frame starts from here */
+ loop_wake_flip = 0;
if (pfd[0].revents & POLLIN) {
Kms *heads[OUT_MAX], *mk = &main_out(&s)->kms;
int nh = 0, was = mk->flip_pending;
@@ -2114,6 +2219,12 @@ int main(int argc, char **argv) {
wl_presented(mk->flip_ns, mk->flip_seq, mk->mode.vrefresh ? 1000000000u / mk->mode.vrefresh : 16666667u);
lbf_presented(mk->flip_ns, mk->mode.vrefresh ? 1000000000u / mk->mode.vrefresh : 16666667u);
if (keylag_enabled) keylag_presented(mk->flip_ns);
+ if (lbf_recording()) {
+ uint64_t done = 0;
+ if (gpu_active() && main_out(&s)->gpu >= 0) gpu_fence_time(main_out(&s)->gpu, &done);
+ lbf_phase_shown(mk->flip_ns, done);
+ loop_wake_flip = 1;
+ }
}
}
if (pfd[1].revents & POLLIN) break;
diff --git a/server/src/ui/paint.c b/server/src/ui/paint.c
index bf5f974..545a0bc 100644
--- a/server/src/ui/paint.c
+++ b/server/src/ui/paint.c
@@ -526,11 +526,28 @@ static struct {
typedef struct { Rect r[G0_DIRTY]; int n, full; } G0Dirty;
static G0Dirty g0_ld, g0_bd;
static G0Stats g0stat;
+static Rect g0_join(Rect a, Rect b) {
+ return (Rect){ a.x0 < b.x0 ? a.x0 : b.x0, a.y0 < b.y0 ? a.y0 : b.y0, a.x1 > b.x1 ? a.x1 : b.x1, a.y1 > b.y1 ? a.y1 : b.y1 };
+}
+static long g0_area(Rect r) { return r.x1 > r.x0 && r.y1 > r.y0 ? (long)(r.x1 - r.x0) * (r.y1 - r.y0) : 0; }
static void g0_dirty(G0Dirty *d, Rect r) {
if (d->full || r.x1 <= r.x0 || r.y1 <= r.y0) return;
+ for (int i = 0; i < d->n; i++) /* already inside one */
+ if (r.x0 >= d->r[i].x0 && r.y0 >= d->r[i].y0 && r.x1 <= d->r[i].x1 && r.y1 <= d->r[i].y1) return;
if (d->n < G0_DIRTY) { d->r[d->n++] = r; return; }
- Rect *l = &d->r[G0_DIRTY - 1]; /* no room: the last one grows */
- *l = (Rect){ l->x0 < r.x0 ? l->x0 : r.x0, l->y0 < r.y0 ? l->y0 : r.y0, l->x1 > r.x1 ? l->x1 : r.x1, l->y1 > r.y1 ? l->y1 : r.y1 };
+ /* no room: of the rectangles and r, the two whose box adds the fewest pixels become that box (the
+ * last one growing, as before, could turn a few small changes into most of the screen) */
+ int bi = 0, bj = G0_DIRTY; /* bj == G0_DIRTY: r itself */
+ long best = -1;
+ for (int i = 0; i < G0_DIRTY; i++)
+ for (int j = i + 1; j <= G0_DIRTY; j++) {
+ Rect b = j < G0_DIRTY ? d->r[j] : r;
+ long w = g0_area(g0_join(d->r[i], b)) - g0_area(d->r[i]) - g0_area(b);
+ if (best < 0 || w < best) { best = w; bi = i; bj = j; }
+ }
+ if (bj == G0_DIRTY) { d->r[bi] = g0_join(d->r[bi], r); return; }
+ d->r[bi] = g0_join(d->r[bi], d->r[bj]);
+ d->r[bj] = r;
}
static void g0_dirty_all(void) { g0_ld = (G0Dirty){ .full = 1 }; g0_bd = (G0Dirty){ .full = 1 }; }
void paint_g0_done(void) { g0_ld = (G0Dirty){ 0 }; g0_bd = (G0Dirty){ 0 }; }
@@ -538,6 +555,13 @@ void paint_g0_stats(G0Stats *out) {
*out = g0stat;
memset(&g0stat, 0, sizeof g0stat);
}
+typedef struct { int taken, why, sub; } G0Last;
+static G0Last g0_last = { -1, -1, -1 };
+int paint_g0_last(int *why, int *sub) {
+ *why = g0_last.why;
+ *sub = g0_last.sub;
+ return g0_last.taken;
+}
void paint_layer_begin(int node, int resize) {
layer.node = node;
@@ -566,6 +590,7 @@ void paint_layer_external_damage(void) { layer.valid = 0; }
* below; the others paint the window as usual. Moving to another display rebuilds both. */
int paint_layer_node(void) { return layer.want ? layer.node : 0; }
+
void paint_layer_view(int index) {
if (layer.view == index) return;
layer.view = index;
@@ -799,6 +824,67 @@ static int layer_render(Node *n, float opacity) {
return 1;
}
+/* ---- G0's textures catching up between frames (docs/GPU.md, "Uploads without a stall") ----
+ * A whole copy of what is below (a drag's start, a copy built again whole) is a screen of pixels: sent in
+ * one frame it took that frame past its vblank. Now a frame that uses G0 sends at most G0_FEED_PX
+ * (g0_backlog_now; else the CPU paints it, the same pixels), and what is left is sent after a frame's
+ * flip is queued, a slice a frame (paint_g0_feed), while the CPU waits for the vblank anyway. */
+static long g0_backlog_one(const G0Dirty *d, int w, int h) {
+ if (d->full) return (long)w * h;
+ long a = 0;
+ for (int i = 0; i < d->n; i++) {
+ Rect q = d->r[i];
+ a += g0_area((Rect){ q.x0 < 0 ? 0 : q.x0, q.y0 < 0 ? 0 : q.y0, q.x1 > w ? w : q.x1, q.y1 > h ? h : q.y1 });
+ }
+ return a;
+}
+static long g0_backlog_now(void) {
+ return g0_backlog_one(&g0_bd, layer.bw, layer.bh) + (layer.px ? g0_backlog_one(&g0_ld, layer.w, layer.h) : 0);
+}
+/* whether G0 could use the layer on display view soon: else sending it is wasted work */
+static int g0_feedable(int view) {
+ return gpu_active() && layer.want && layer.node && layer.view == view && !layer.resize && !layer.rendering &&
+ layer.below && !layer.bdmg_full && !layer.has_holes && !layer.premul_bad && !nlsurf && !lsurf_all;
+}
+long paint_g0_backlog(int view) { return g0_feedable(view) ? g0_backlog_now() : 0; }
+
+long paint_g0_feed(int view, long budget, int (*up)(void *ctx, int which, const uint32_t *px, int w, int h, Rect r),
+ void *ctx) {
+ if (!g0_feedable(view)) return 0;
+ long sent = 0;
+ for (int which = 0; which < 2 && sent < budget; which++) {
+ G0Dirty *d = which ? &g0_ld : &g0_bd;
+ const uint32_t *px = which ? layer.px : layer.below;
+ int w = which ? layer.w : layer.bw, h = which ? layer.h : layer.bh;
+ if (!px || w <= 0 || h <= 0 || (which && !layer.valid)) continue;
+ /* an empty rectangle first: does the texture hold this at all? */
+ int k = up(ctx, which, px, w, h, (Rect){ 0, 0, 0, 0 });
+ if (k < 0) return sent;
+ if (k > 0) *d = (G0Dirty){ .full = 1 };
+ while (d->full || d->n) {
+ if (d->full) *d = (G0Dirty){ .r = { { 0, 0, w, h } }, .n = 1 };
+ Rect *l = &d->r[d->n - 1];
+ Rect q = { l->x0 < 0 ? 0 : l->x0, l->y0 < 0 ? 0 : l->y0, l->x1 > w ? w : l->x1, l->y1 > h ? h : l->y1 };
+ long a = g0_area(q), room = budget - sent;
+ if (!a) { d->n--; continue; }
+ if (room <= 0) break;
+ Rect part = q;
+ if (a > room) { /* its top rows, as many as fit */
+ int rows = (int)(room / (q.x1 - q.x0));
+ if (rows < 1) break;
+ part.y1 = q.y0 + rows;
+ }
+ k = up(ctx, which, px, w, h, part);
+ if (k < 0) return sent;
+ if (k > 0) { *d = (G0Dirty){ .full = 1 }; break; } /* lost meanwhile: all again, next time */
+ sent += g0_area(part);
+ if (part.y1 >= q.y1) d->n--;
+ else *l = (Rect){ q.x0, part.y1, q.x1, q.y1 };
+ }
+ }
+ return sent;
+}
+
/* Repinta solo layer.part (lo que cambió adentro: una línea de la terminal, el cursor que parpadea).
* 0: a part with a node's change (layer.tree_part) cut a transformed node's image on its left edge,
* which a full paint would not have cut (canvas_affine_watch): the caller paints the layer whole. */
@@ -1697,20 +1783,31 @@ static int g0_bx, g0_by; /* where the layer's pixel (0, 0) lands
/* W for this frame (-1), or why there is none (G0R_*): where layer_paint's blit lands, cut by the
* ancestors' clips and by c->clip, the frame's box (inside the canvas). */
+static int g0_sub; /* the G0L_* of g0_gate's last G0R_LAYER */
+#define G0_NO_LAYER(why) do { g0_sub = (why); return G0R_LAYER; } while (0)
static int g0_gate(const Canvas *c, Node *root, Rect *wout) {
Node *w = node_get(layer.node);
- if (!w || !layer.want || !layer.valid || layer.resize || layer.rendering || paint_capture_mode ||
- paint_view.index != layer.view || w->has_tf || w->type == NODE_RAW || w->s.display_none)
- return G0R_LAYER;
- if (layer.has_holes || nlsurf || lsurf_all || layer.premul_bad || !layer.px || !layer.below) return G0R_LAYER;
+ g0_sub = -1;
+ if (!w || !layer.want) G0_NO_LAYER(G0L_GONE);
+ if (!layer.valid) G0_NO_LAYER(G0L_INVALID);
+ if (layer.resize) G0_NO_LAYER(G0L_RESIZE);
+ if (layer.rendering) G0_NO_LAYER(G0L_RENDERING);
+ if (paint_capture_mode) G0_NO_LAYER(G0L_CAPTURE);
+ if (paint_view.index != layer.view) G0_NO_LAYER(G0L_VIEW);
+ if (w->has_tf) G0_NO_LAYER(G0L_TRANSFORM);
+ if (w->type == NODE_RAW || w->s.display_none) G0_NO_LAYER(G0L_RAW);
+ if (layer.has_holes) G0_NO_LAYER(G0L_HOLES);
+ if (nlsurf || lsurf_all) G0_NO_LAYER(G0L_SURFACES);
+ if (layer.premul_bad) G0_NO_LAYER(G0L_PREMUL);
+ if (!layer.px || !layer.below) G0_NO_LAYER(G0L_NOBUF);
const Node *anc[SKIP_PATH_MAX];
int na = 0;
for (const Node *a = w->parent; a; a = a->parent) {
if (na == SKIP_PATH_MAX) return G0R_ANCESTOR;
- if (a->type == NODE_RAW || a->s.display_none) return G0R_LAYER;
+ if (a->type == NODE_RAW || a->s.display_none) G0_NO_LAYER(G0L_RAW);
anc[na++] = a;
}
- if (!na || anc[na - 1] != root) return G0R_LAYER;
+ if (!na || anc[na - 1] != root) G0_NO_LAYER(G0L_TREE);
const float k = paint_view.k;
int bx = (int)lroundf(VX(w->ax) + layer.pox), by = (int)lroundf(VY(w->ay) + layer.poy);
Rect r = { bx, by, bx + layer.w, by + layer.h };
@@ -1719,15 +1816,15 @@ static int g0_gate(const Canvas *c, Node *root, Rect *wout) {
for (int i = na - 1; i >= 0; i--) {
const Node *a = anc[i];
op = op * a->s.opacity;
- if (op < 0.004f) return G0R_LAYER;
+ if (op < 0.004f) G0_NO_LAYER(G0L_OPACITY);
if (a->s.overflow_hidden) {
float x = VX(a->ax), y = VY(a->ay), aw = a->w * k, ah = a->h * k;
r = rect_and(r, (Rect){ (int)floorf(x), (int)floorf(y), (int)ceilf(x + aw), (int)ceilf(y + ah) });
}
}
- if (op != layer.op) return G0R_LAYER;
+ if (op != layer.op) G0_NO_LAYER(G0L_OPACITY);
Box pb;
- if (layer.tree_part && !layer_part_exact(w, &pb)) return G0R_LAYER; /* it would be painted whole */
+ if (layer.tree_part && !layer_part_exact(w, &pb)) G0_NO_LAYER(G0L_PART); /* it would be painted whole */
r = rect_and(r, c->clip); /* the blit is clipped to the frame's box too */
if (!rect_area(r)) return G0R_CLIP;
if (!below_ancestors_ok(w, r)) return G0R_ANCESTOR;
@@ -1845,16 +1942,24 @@ static int paint_root_body(Canvas *c, Node *root, int clear, uint32_t rgb, GpuG0
int below = !skip_until && below_ready(c, root, clear && rgb == 0x000000);
uint32_t *pre = below && layer.switched && paint_below_verify ? below_snapshot(c) : NULL;
int done = 0, taken = 0;
+ g0_last = (G0Last){ -1, -1, -1 };
if (below && g && gpu_active()) { /* G0: only after below_ready, so its decisions are the same */
Rect w;
int why = g0_gate(c, root, &w);
+ /* what the textures still lack goes first, a slice a frame after the flip (paint_g0_feed): a
+ * frame that would have to send more is painted here, the same pixels */
+ if (why < 0 && g0_backlog_now() > G0_FEED_PX) why = G0R_FEED;
g0stat.tried++;
if (why < 0) {
done = 1;
taken = g0_paint(c, root, w, g);
if (!taken) why = G0R_POST;
}
- if (!taken) g0stat.refused[why]++;
+ if (!taken) {
+ g0stat.refused[why]++;
+ if (why == G0R_LAYER && g0_sub >= 0) g0stat.layer[g0_sub]++;
+ }
+ g0_last = (G0Last){ taken, taken ? -1 : why, !taken && why == G0R_LAYER ? g0_sub : -1 };
}
if (!done) {
if (below) {
diff --git a/server/src/ui/ui.h b/server/src/ui/ui.h
index fd706c8..e6547b3 100644
--- a/server/src/ui/ui.h
+++ b/server/src/ui/ui.h
@@ -324,9 +324,30 @@ void paint_g0_done(void);
* windows or invalid pixels in it, other opacity, a transform), its rectangle not inside the damage,
* an ancestor painting over it, an app window under it, a node painted after the window in the
* damage, or something changed while painting (post) */
-enum { G0R_LAYER, G0R_CLIP, G0R_ANCESTOR, G0R_APP, G0R_AFTER, G0R_POST, G0R_N };
-typedef struct { long frames, strip_px, tried, refused[G0R_N]; } G0Stats;
+enum { G0R_LAYER, G0R_CLIP, G0R_ANCESTOR, G0R_APP, G0R_AFTER, G0R_POST,
+ G0R_FEED, /* the textures still lack more than G0_FEED_PX (paint_g0_feed) */
+ G0R_N };
+/* G0R_LAYER split by its cause, in g0_gate's order: no window or not wanted, not valid (painted whole
+ * next), being resized, being rendered, capture mode, another display's, transformed, the window or an
+ * ancestor raw or hidden, app holes in it, app surfaces in it, a colour above its alpha, no buffer, not
+ * under the root, another opacity, a part that would make it paint whole */
+enum { G0L_GONE, G0L_INVALID, G0L_RESIZE, G0L_RENDERING, G0L_CAPTURE, G0L_VIEW, G0L_TRANSFORM, G0L_RAW,
+ G0L_HOLES, G0L_SURFACES, G0L_PREMUL, G0L_NOBUF, G0L_TREE, G0L_OPACITY, G0L_PART, G0L_N };
+typedef struct { long frames, strip_px, tried, refused[G0R_N], layer[G0L_N]; } G0Stats;
void paint_g0_stats(G0Stats *s); /* since the last call */
+/* The last paint_root_* call: -1 G0 not tried (no copy used, or not a G0 call), 1 taken, 0 refused
+ * (*why a G0R_*, *sub a G0L_* when it is G0R_LAYER, else -1) */
+int paint_g0_last(int *why, int *sub);
+/* G0's textures catching up (docs/GPU.md, "Uploads without a stall"): what of the layer and of the copy
+ * of what is below the GPU still lacks, in pixels (both; 0 nothing, or no layer on display view) */
+long paint_g0_backlog(int view);
+/* Sends at most budget pixels of it, rectangles cut by rows, through up(ctx, which, px, w, h, r) (which:
+ * 0 the copy, 1 the layer; px w × h, stride w), and forgets what was sent. Each texture is asked first
+ * with an empty r. up returns 0 sent, 1 its texture held nothing of this (now it is ready for it: all of
+ * it is needed again), -1 failed (stop). Only the display that has the layer (view), and only while G0
+ * could use it. Returns the pixels sent. */
+long paint_g0_feed(int view, long budget, int (*up)(void *ctx, int which, const uint32_t *px, int w, int h, Rect r),
+ void *ctx);
Node *hit_test(Node *root, float x, float y);
/* Capture mode (media/capture.c): protected nodes are painted black and app windows
* are copied even when compositing on the GPU. paint_capture paints the whole tree this way. */
diff --git a/server/tests/engine_test.c b/server/tests/engine_test.c
index 626fb8a..6d7f342 100644
--- a/server/tests/engine_test.c
+++ b/server/tests/engine_test.c
@@ -1598,7 +1598,9 @@ typedef struct {
GpuG0 g;
} DOut;
static int test_g0;
-static struct { uint32_t *b, *l; int bw, bh, lw, lh, owner; } g0tex; /* the stub GPU's G0 textures */
+static struct { uint32_t *b, *l; int bw, bh, lw, lh, owner[2]; } g0tex; /* the stub GPU's G0 textures (owner: 0 the copy, 1 the layer) */
+static long g0_fed; /* pixels sent between frames (paint_g0_feed) */
+static long g0_whole; /* G0 frames that had to send a texture whole */
static long g0_quads;
typedef struct { Node *root, *win, *spin, *edge, *child, *term, *caption, *below, *btitle, *fill, *mtext, *square, *ptext, *dot; } DScene;
@@ -1630,6 +1632,7 @@ static void copy_rect(uint32_t *dst, int dstride, const uint32_t *src, int sstri
/* The stub GPU's texture t (*tw × *th): all of px if its size changed, it was another display's or
* full, else the dirty rectangles (gpu.c's g0_upload). */
+static long g0_frame_px, g0_frame_max; /* pixels the G0 frames sent: this one, the most one did */
static void g0_tex_up(uint32_t **t, int *tw, int *th, const uint32_t *px, int w, int h, const Rect *r, int n, int full) {
if (*tw != w || *th != h) {
free(*t);
@@ -1639,26 +1642,65 @@ static void g0_tex_up(uint32_t **t, int *tw, int *th, const uint32_t *px, int w,
full = 1;
}
if (!*t) return;
- if (full) { memcpy(*t, px, (size_t)w * h * 4); return; }
+ if (full) { memcpy(*t, px, (size_t)w * h * 4); g0_frame_px += (long)w * h; return; }
for (int i = 0; i < n; i++) {
Rect q = { r[i].x0 < 0 ? 0 : r[i].x0, r[i].y0 < 0 ? 0 : r[i].y0, r[i].x1 > w ? w : r[i].x1, r[i].y1 > h ? h : r[i].y1 };
- if (q.x1 > q.x0 && q.y1 > q.y0) copy_rect(*t, w, px, w, q);
+ if (q.x1 > q.x0 && q.y1 > q.y0) { copy_rect(*t, w, px, w, q); g0_frame_px += (long)(q.x1 - q.x0) * (q.y1 - q.y0); }
+ }
+}
+
+/* gpu.c's gpu_g0_feed on the stub GPU (ctx: the display's index): a texture that is not this display's
+ * at this size is made again, filled with a pattern no frame has (so a pixel the feed missed shows) */
+static int g0_tex_feed(void *ctx, int which, const uint32_t *px, int w, int h, Rect r) {
+ int index = *(const int *)ctx;
+ uint32_t **t = which ? &g0tex.l : &g0tex.b;
+ int *tw = which ? &g0tex.lw : &g0tex.bw, *th = which ? &g0tex.lh : &g0tex.bh;
+ if (g0tex.owner[which] != index || *tw != w || *th != h) {
+ if (*tw != w || *th != h) {
+ free(*t);
+ *t = malloc((size_t)w * h * 4);
+ *tw = *t ? w : 0;
+ *th = *t ? h : 0;
+ if (!*t) return -1;
+ for (size_t i = 0; i < (size_t)w * h; i++) (*t)[i] = 0x7f13ff13u;
+ }
+ g0tex.owner[which] = index;
+ return 1;
+ }
+ Rect q = { r.x0 < 0 ? 0 : r.x0, r.y0 < 0 ? 0 : r.y0, r.x1 > w ? w : r.x1, r.y1 > h ? h : r.y1 };
+ if (q.x1 > q.x0 && q.y1 > q.y0) {
+ copy_rect(*t, w, px, w, q);
+ g0_fed += (long)(q.x1 - q.x0) * (q.y1 - q.y0);
}
+ return 0;
}
/* main.c's presentation on the GPU (render_frame, gpu_frame_ex): the painted rectangles (pr, or the
* strips) go to the UI texture; with G0 the two textures get their dirty rectangles and the window is
- * written over the texture's stale rectangle in the composed frame. */
+ * written over the texture's stale rectangle in the composed frame. A frame refused only for what the
+ * textures lack (G0R_FEED) then sends a slice of it (paint_g0_feed), as main.c does after queueing the flip. */
static void g0_present(DOut *o, int index, Rect pr, int taken) {
int W = o->c.w, H = o->c.h;
- if (!taken) copy_rect(o->tex, W, o->c.px, o->c.stride, pr);
- else {
+ if (!taken) {
+ copy_rect(o->tex, W, o->c.px, o->c.stride, pr);
+ int why, sub;
+ if (paint_g0_last(&why, &sub) == 0 && why == G0R_FEED && paint_g0_backlog(index) > 0)
+ paint_g0_feed(index, G0_FEED_PX, g0_tex_feed, &index);
+ } else {
const GpuG0 *g = &o->g;
for (int i = 0; i < g->nstrip; i++) copy_rect(o->tex, W, o->c.px, o->c.stride, g->strip[i]);
- int other = g0tex.owner != index;
- g0_tex_up(&g0tex.b, &g0tex.bw, &g0tex.bh, g->bpx, g->bw, g->bh, g->bdirty, g->nb, g->bfull || other);
- g0_tex_up(&g0tex.l, &g0tex.lw, &g0tex.lh, g->lpx, g->lw, g->lh, g->ldirty, g->nl, g->lfull || other);
- g0tex.owner = index;
+ /* paint.c sent the rest first: a G0 frame never has more than G0_FEED_PX left */
+ long left = 0;
+ if (g->bfull) left += (long)g->bw * g->bh;
+ else for (int i = 0; i < g->nb; i++) left += (long)(g->bdirty[i].x1 - g->bdirty[i].x0) * (g->bdirty[i].y1 - g->bdirty[i].y0);
+ CHECK(left <= G0_FEED_PX, "a G0 frame with %ld px of the copy left to send", left);
+ int bother = g0tex.owner[0] != index, lother = g0tex.owner[1] != index;
+ if (bother || lother || g->bfull || g->lfull) g0_whole++;
+ g0_tex_up(&g0tex.b, &g0tex.bw, &g0tex.bh, g->bpx, g->bw, g->bh, g->bdirty, g->nb, g->bfull || bother);
+ g0_tex_up(&g0tex.l, &g0tex.lw, &g0tex.lh, g->lpx, g->lw, g->lh, g->ldirty, g->nl, g->lfull || lother);
+ g0tex.owner[0] = g0tex.owner[1] = index;
+ if (g0_frame_px > g0_frame_max) g0_frame_max = g0_frame_px;
+ g0_frame_px = 0;
paint_g0_done();
g0_quads++;
}
@@ -1683,7 +1725,7 @@ static void drag_paint_out(Node *root, DOut *o, int index, Box d) {
float gx0, gy0, gx1, gy1;
out_logical_box(&o->v, o->g0w, &gx0, &gy0, &gx1, &gy1);
if (!empty) d = (Box){ fminf(d.x0, gx0), fminf(d.y0, gy0), fmaxf(d.x1, gx1), fmaxf(d.y1, gy1) };
- else if (g0tex.owner != index) { d = (Box){ gx0, gy0, gx1, gy1 }; o->g0on = 0; } /* g0_stale */
+ else if (g0tex.owner[0] != index || g0tex.owner[1] != index) { d = (Box){ gx0, gy0, gx1, gy1 }; o->g0on = 0; } /* g0_stale */
/* else: drawn again from the textures, the frame stays as it is */
}
if (d.x1 <= d.x0 || d.y1 <= d.y0) return;
@@ -2000,7 +2042,7 @@ static void drag_run_n(int dc, DOut *const *os, int nos, uint64_t *hash, long *f
canvas_clear(&os[i]->c, 0x000000);
os[i]->g0on = 0;
}
- g0tex.owner = -1;
+ g0tex.owner[0] = g0tex.owner[1] = -1;
damage_add((Box){ 0, 0, DW, DH });
ui.dirty = 1;
drag_paint_n(s.root, os, nos);
@@ -2143,12 +2185,13 @@ static void g0_report(const char *what, int some_g0) {
G0Stats g;
paint_g0_stats(&g);
printf("drag-exact %s: G0 composed %ld of %ld frames that used the copy (%ld presented), strips %ld px "
- "(not: %ld layer, %ld clip, %ld ancestor, %ld app, %ld after, %ld post)\n", what, g.frames, g.tried, g0_quads,
+ "(not: %ld layer, %ld clip, %ld ancestor, %ld app, %ld after, %ld post, %ld catching up); %ld px sent between "
+ "frames, %ld G0 frames sent a texture whole, the most one G0 frame sent %ld px\n", what, g.frames, g.tried, g0_quads,
g.strip_px, g.refused[G0R_LAYER], g.refused[G0R_CLIP], g.refused[G0R_ANCESTOR], g.refused[G0R_APP],
- g.refused[G0R_AFTER], g.refused[G0R_POST]);
+ g.refused[G0R_AFTER], g.refused[G0R_POST], g.refused[G0R_FEED], g0_fed, g0_whole, g0_frame_max);
CHECK((g.frames > 0 || !some_g0) && g.frames == g0_quads, "drag-exact %s: G0 frames %ld, presented %ld", what, g.frames,
g0_quads);
- g0_quads = 0;
+ g0_quads = g0_fed = g0_whole = g0_frame_max = 0;
}
/* The runs without golden hashes (pause, two displays): G0 must show what the GPU path shows, frame by
diff --git a/server/tests/lordbench_test.c b/server/tests/lordbench_test.c
index 78660d9..c5201e0 100644
--- a/server/tests/lordbench_test.c
+++ b/server/tests/lordbench_test.c
@@ -169,6 +169,89 @@ int main(void) {
lbf_presented(6000, 0);
CHECK(lbf_end(&fs) == 0 && fs.inputs == 0, "no negative latency");
+ /* ---- frame phases: what each part of a frame took, and why it was late ---- */
+ {
+ LbPhaseStats ps;
+ const uint64_t P = 16666667, F0 = 1000000000ull; /* the vblanks: F0 + k P */
+ lbf_phase_built(&(LbPhase){ .submit = 1 }); /* not recording: ignored */
+ lbf_phase_shown(F0, 0);
+ CHECK(!lbf_recording(), "not recording");
+ lbf_drag_begin();
+ CHECK(lbf_recording(), "the drag records");
+ /* on time: woke 0.1 ms after a flip, render 0.5 ms later for 9 ms, queued at 10 ms, GPU done at 12, shown at the next vblank */
+ LbPhase a = { .prev_flip = F0, .wake = F0 + 100000, .from_flip = 1, .render0 = F0 + 600000, .built = F0 + 9600000,
+ .paint_ms = 6, .up_ms = 2, .swap_ms = 0.1, .submit_ms = 0.2, .up_px = 1000, .submit = F0 + 10000000,
+ .period = (uint32_t)P, .par = 1, .g0 = 1 };
+ lbf_phase_built(&a);
+ lbf_phase_shown(F0 + P, F0 + 12000000);
+ /* CPU-late: queued 18 ms after that flip, past the next vblank */
+ LbPhase b = a;
+ b.prev_flip = F0 + P;
+ b.wake = F0 + P + 100000;
+ b.render0 = b.wake + 500000;
+ b.built = b.wake + 17000000;
+ b.submit = b.wake + 18000000;
+ b.par = 0;
+ b.g0 = 0;
+ b.g0_why = 0; /* G0R_LAYER, G0L_INVALID */
+ b.g0_sub = 1;
+ lbf_phase_built(&b);
+ lbf_phase_shown(F0 + 3 * P, b.submit + 2000000);
+ /* GPU-late: queued at 12 ms, the GPU finished at 17, past the vblank at 16.7 */
+ LbPhase c = a;
+ c.prev_flip = F0 + 3 * P;
+ c.wake = c.prev_flip + 100000;
+ c.render0 = c.wake + 500000;
+ c.built = c.wake + 11000000;
+ c.submit = c.prev_flip + 12000000;
+ c.g0 = 0;
+ c.g0_why = 6; /* G0R_FEED */
+ c.g0_sub = -1;
+ c.unshown = 0;
+ c.feed_ms = 1.5;
+ c.feed_px = 262144;
+ lbf_phase_built(&c);
+ lbf_phase_shown(F0 + 5 * P, c.prev_flip + 17000000);
+ /* unshown: no flip queued, no presentation */
+ LbPhase d = a;
+ d.submit = 0;
+ d.unshown = 1;
+ d.g0 = -1;
+ lbf_phase_built(&d);
+ lbf_phase_shown(F0 + 6 * P, 0); /* a flip of something else: nothing waits for it */
+ lbf_drag_end(&ps);
+ CHECK(!lbf_recording(), "the drag stopped");
+ CHECK(ps.n == 3 && ps.on_time == 1 && ps.cpu_late == 1 && ps.gpu_late == 1 && ps.other_late == 0 && ps.gpu_known == 3,
+ "classes: %d frames, %d on time, %d CPU-late, %d GPU-late, %d other, %d known", ps.n, ps.on_time, ps.cpu_late,
+ ps.gpu_late, ps.other_late, ps.gpu_known);
+ CHECK(fabs(ps.wake.p50 - 0.1) < 1e-6 && fabs(ps.pre.p50 - 0.5) < 1e-6 && fabs(ps.paint.p50 - 6) < 1e-6, "wake %f, before %f, paint %f",
+ ps.wake.p50, ps.pre.p50, ps.paint.p50);
+ CHECK(fabs(ps.build.p50 - 10.5) < 1e-3 && fabs(ps.build.p99 - 16.5) < 1e-3, "render %f/%f", ps.build.p50, ps.build.p99);
+ CHECK(fabs(ps.gpu.p50 - 2) < 1e-3 && fabs(ps.gpu.p99 - 5) < 1e-3, "GPU %f/%f", ps.gpu.p50, ps.gpu.p99);
+ CHECK(fabs(ps.wait.p50 - 13.233333) < 1e-3 && fabs(ps.wait.p99 - 16.333333) < 1e-3, "to the vblank %f/%f", ps.wait.p50, ps.wait.p99);
+ CHECK(ps.par == 3 && ps.g0_tried == 3 && ps.g0_taken == 1 && ps.g0_refused[0] == 1 && ps.g0_layer[1] == 1 &&
+ ps.g0_refused[6] == 1 && ps.unshown == 1, "counts: par %d, G0 %d of %d, refused %d %d (%d), unshown %d", ps.par,
+ ps.g0_taken, ps.g0_tried, ps.g0_refused[0], ps.g0_refused[6], ps.g0_layer[1], ps.unshown);
+ CHECK(fabs(ps.feed_mpx - 262144 / 4.0 / 1e6) < 1e-9 && fabs(ps.feed.p99 - 1.5) < 1e-6, "catch-up %f Mpx %f ms", ps.feed_mpx, ps.feed.p99);
+ char pt[1024];
+ lbf_phases_text(&ps, pt, sizeof pt);
+ CHECK(strstr(pt, "CPU-late 1") && strstr(pt, "not layer 1 [invalid 1]") && strstr(pt, "not feed 1") && strstr(pt, "unshown 1"),
+ "phases text: %s", pt);
+ CHECK(!strcmp(lbf_g0r_name(6), "feed") && !lbf_g0r_name(7) && !lbf_g0r_name(-1) && !strcmp(lbf_g0l_name(14), "part") &&
+ !lbf_g0l_name(15), "G0 names");
+ char small[16];
+ lbf_phases_text(&ps, small, sizeof small);
+ CHECK(strlen(small) == 15, "a short buffer is cut, terminated");
+ lbf_begin(); /* LordBench's recorder: its own, read after lbf_end */
+ lbf_phase_built(&a);
+ lbf_phase_shown(F0 + P, 0);
+ lbf_end(&fs);
+ lbf_phase_built(&a); /* stopped: ignored */
+ lbf_phase_shown(F0 + P, 0);
+ lbf_phases(&ps);
+ CHECK(ps.n == 1 && ps.on_time == 1 && ps.gpu_known == 0 && ps.gpu.p50 == 0, "LordBench's phases: %d frames", ps.n);
+ }
+
/* ---- the synthetic pointer: its path, and the thread's events through the eventfd ---- */
float dx, dy;
lbi_path(200, 100, 4000, 1000, &dx, &dy); /* a quarter turn: x = rx, y = ry sin(π) / 2 = 0 */
diff --git a/web/content/paper/paper.en.md b/web/content/paper/paper.en.md
index c457d77..a4aaf02 100644
--- a/web/content/paper/paper.en.md
+++ b/web/content/paper/paper.en.md
@@ -107,7 +107,7 @@ LordOS speaks to several Debian services over their own protocols with its own c
### 3.2 Two ways to build a frame
-- **CPU path.** The UI and app windows are copied into a canvas, and a "dumb" buffer is presented with a page flip. It needs nothing but the kernel. It is the default when there is no 3D-capable card, and `LORD_GPU=0` forces it (the boot menu's safe mode uses it). Since 0.8.5, heavy frames paint on a pool of up to 8 threads (`par.c`), only while painting takes more than 70 % of a frame at the target rate: the backdrop blur in phases and the row-local primitives split by bands of rows, with the same pixels as one thread (§7.2).
+- **CPU path.** The UI and app windows are copied into a canvas, and a "dumb" buffer is presented with a page flip. It needs nothing but the kernel. It is the default when there is no 3D-capable card, and `LORD_GPU=0` forces it (the boot menu's safe mode uses it). Since 0.8.5, heavy frames paint on a pool of up to 8 threads (`par.c`), only while painting takes more than 70 % of a frame at the target rate (in 0.8.6, in development, also while the whole frame takes more than 60 %): the backdrop blur in phases and the row-local primitives split by bands of rows, with the same pixels as one thread (§7.2).
- **GPU path.** Mesa's GBM, EGL and GLES2 (`server/src/gpu/gpu.c`). The UI becomes one texture, and only the changed region is uploaded each frame. App windows are not copied into the UI canvas: the UI leaves a transparent hole where each window goes, and window textures are drawn underneath, so an app that only changes its own content doesn't cause a UI repaint. Apps can hand over GPU buffers (`linux-dmabuf`) with no copies, and a fullscreen app with a suitable buffer is scanned out directly. The cursor uses the hardware cursor plane.
The path is chosen at start-up: a card without 3D (simpledrm, bochs, virtio-gpu without virgl, and others) uses the CPU without even loading Mesa; a software OpenGL renderer also falls back to the CPU, because composing with it costs more than LordOS's own CPU path. If a GPU frame fails, the GPU is turned off and the CPU path takes over.
diff --git a/web/content/paper/paper.es.md b/web/content/paper/paper.es.md
index f9a67a0..cabff5f 100644
--- a/web/content/paper/paper.es.md
+++ b/web/content/paper/paper.es.md
@@ -107,7 +107,7 @@ LordOS habla con varios servicios de Debian por sus propios protocolos, con clie
### 3.2 Dos formas de armar un cuadro
-- **Camino por CPU.** La interfaz y las ventanas de las apps se copian a un lienzo, y se presenta un buffer "dumb" con un cambio de página. No necesita nada más que el kernel. Es el predeterminado cuando no hay una placa con 3D, y `LORD_GPU=0` lo fuerza (el modo seguro del menú de arranque lo usa). Desde la 0.8.5, los cuadros pesados se pintan en un grupo de hasta 8 hilos (`par.c`), solo mientras pintar lleva más del 70 % de un cuadro a la frecuencia objetivo: el desenfoque del fondo por fases y las primitivas locales a cada fila repartidas en bandas de filas, con los mismos píxeles que con un solo hilo (§7.2).
+- **Camino por CPU.** La interfaz y las ventanas de las apps se copian a un lienzo, y se presenta un buffer "dumb" con un cambio de página. No necesita nada más que el kernel. Es el predeterminado cuando no hay una placa con 3D, y `LORD_GPU=0` lo fuerza (el modo seguro del menú de arranque lo usa). Desde la 0.8.5, los cuadros pesados se pintan en un grupo de hasta 8 hilos (`par.c`), solo mientras pintar lleva más del 70 % de un cuadro a la frecuencia objetivo (en la 0.8.6, en desarrollo, también mientras el cuadro entero lleva más del 60 %): el desenfoque del fondo por fases y las primitivas locales a cada fila repartidas en bandas de filas, con los mismos píxeles que con un solo hilo (§7.2).
- **Camino por GPU.** GBM, EGL y GLES2 de Mesa (`server/src/gpu/gpu.c`). La interfaz pasa a ser una textura, y en cada cuadro se sube solo la región que cambió. Las ventanas de las apps no se copian al lienzo de la interfaz: la interfaz deja un hueco transparente donde va cada ventana, y las texturas de las ventanas se dibujan debajo, así una app que solo cambia su contenido no provoca un repintado de la interfaz. Las apps pueden entregar buffers de GPU (`linux-dmabuf`) sin copias, y una app a pantalla completa con un buffer adecuado se muestra directamente (scanout directo). El cursor usa el plano de cursor por hardware.
El camino se elige al arrancar: una placa sin 3D (simpledrm, bochs, virtio-gpu sin virgl y otras) usa la CPU sin siquiera cargar Mesa; un renderizador OpenGL por software también vuelve a la CPU, porque componer con él cuesta más que el camino por CPU propio de LordOS. Si un cuadro por GPU falla, la GPU se apaga y el camino por CPU toma el control.
diff --git a/web/content/paper/paper.pt.md b/web/content/paper/paper.pt.md
index 15f3a25..7867238 100644
--- a/web/content/paper/paper.pt.md
+++ b/web/content/paper/paper.pt.md
@@ -107,7 +107,7 @@ O `lord-server` configura os modos de tela com os ioctls DRM do kernel diretamen
### 3.2 Duas formas de montar um quadro
-- **Caminho pela CPU.** A interface e as janelas dos apps são copiadas para um canvas, e um buffer "dumb" é apresentado com uma troca de página. Não precisa de nada além do kernel. É o padrão quando não há placa com 3D, e `LORD_GPU=0` o força (o modo de segurança do menu de boot o usa). Desde a 0.8.5, quadros pesados são pintados num pool de até 8 threads (`par.c`), só enquanto a pintura leva mais de 70 % de um quadro na taxa alvo: o desfoque do fundo em fases e as primitivas locais a cada linha divididas em faixas de linhas, com os mesmos pixels de uma só thread (§7.2).
+- **Caminho pela CPU.** A interface e as janelas dos apps são copiadas para um canvas, e um buffer "dumb" é apresentado com uma troca de página. Não precisa de nada além do kernel. É o padrão quando não há placa com 3D, e `LORD_GPU=0` o força (o modo de segurança do menu de boot o usa). Desde a 0.8.5, quadros pesados são pintados num pool de até 8 threads (`par.c`), só enquanto a pintura leva mais de 70 % de um quadro na taxa alvo (na 0.8.6, em desenvolvimento, também enquanto o quadro inteiro leva mais de 60 %): o desfoque do fundo em fases e as primitivas locais a cada linha divididas em faixas de linhas, com os mesmos pixels de uma só thread (§7.2).
- **Caminho pela GPU.** GBM, EGL e GLES2 do Mesa (`server/src/gpu/gpu.c`). A interface vira uma textura, e só a região alterada é enviada a cada quadro. As janelas dos apps não são copiadas para o canvas da interface: a interface deixa um buraco transparente onde cada janela fica, e as texturas das janelas são desenhadas por baixo, de modo que um app que só muda o próprio conteúdo não provoca repintura da interface. Os apps podem entregar buffers de GPU (`linux-dmabuf`) sem cópias, e um app em tela cheia com um buffer adequado é exibido diretamente (scanout direto). O cursor usa o plano de cursor do hardware.
O caminho é escolhido na inicialização: uma placa sem 3D (simpledrm, bochs, virtio-gpu sem virgl e outras) usa a CPU sem nem carregar o Mesa; um renderizador OpenGL por software também volta para a CPU, porque compor com ele custa mais que o caminho de CPU próprio do LordOS. Se um quadro na GPU falha, a GPU é desligada e o caminho pela CPU assume.