perf(ui): hand a pop-out its picture without slowing the game's present #3195

Open
neotoxic wants to merge 6 commits from neotoxic/Longshot:perf/popout-handoff into main
Contributor

Summary

A follow-up to #3175, pushed to its branch after it was merged.

A mod window popped out of the game's picture gets a new picture every time its UI changes, every frame for a graph. Handing it to the system window was done on the thread the game waits for, and did more there than it needs:

  • Windows: hos_display_popout_show premultiplied every pixel under the lock and posted a paint message per picture; pop_paint created and deleted a DIB section per picture. Now the game's thread does a plain copy (one memcpy when the rows are packed) and posts one message until the window has painted. The premultiply moved to pop_paint, on the window's own thread, which swaps the picture out under the lock and premultiplies it after the lock is let go (as dyst suggested), and keeps its DIB section while the size holds and frees it when the window goes. A picture that could not be painted no longer leaves the window waiting for a message that never comes.
  • Linux: popouts_turn swaps the picture with a buffer of its own instead of a malloc and a copy per picture, and hos_sdl_window_blit blends over the background through three 256-entry tables, with no index division per pixel when the surface is the picture's size.

Also, a second commit: tests/test_ui_renderer.py fails on main. #3175 was merged with its pop-out reads changed to the present's fences, and the check still looked for the earlier slot count. It now checks the merged reads.

Read first: hos_display_popout_show and pop_paint in host/display.c, popouts_turn in host/posix/display_sdl.c, hos_sdl_window_blit in host/hos_sdl.c.

Testing

Tested:

  • Windows 11, RTX 5080: dev.py rt and dev.py smoke on this branch (PASS, in play from kokiri-start, the menu opened), and the FPS counter's graph popped out in Hyrule Field for 3 runs of 60 s (the measurements below): it showed and updated, no FATAL line.
  • CachyOS, RTX 3060 Laptop, Wayland: the same code on #3175's branch (6d8c02ea), dev.py rt and the graph popped out for 3 runs of 60 s uncapped and 3 capped at 60 fps.
  • At 2472246d (dyst's review: Linux's uncovered window, the premultiply after the lock): on Windows the hand-off measurement below, the graph popped out for 3 runs of 60 s, shown and updated, no FATAL line; on CachyOS dev.py rt and dev.py smoke PASS at 220b70eb (the Linux fix). tests/test_ui_renderer.py passes, its two new checks failing on the code before them.
  • Checks: run_all.py --changed origin/main on Windows, 38 passed; test_dlssg.py fails here and on main alike (its check of vk_draw.cpp's Upscaler row, a file this does not touch).

Still to test:

  • On Linux, X11: a still pop-out (not the graph) covered and uncovered, minimised and restored, shows its newest picture (by hand, a tester with an X11 desktop)
  • The hand-off timed on Linux: the measuring setup below did not pop the graph out on the laptop this time (Wayland), so only Windows is timed (by hand, the author)

Measurements

Verdict: on Windows, handing a picture to a popped-out window takes the present thread about a quarter less time: a median of 53-56 µs against 72-76 µs on main, the runs' spreads apart. That is about 20 µs of a 5.3 ms frame, under what the frame time can show, and the frame time indeed shows no change. The lock is never waited on, on either side, so the premultiply after the lock (dyst's suggestion) changes no number here; it keeps a slow paint from ever holding a present. Linux's hand-off is not timed yet (Still to test).

The hand-off itself (dyst's review, point 2). main at de6fb7b5 (A) against this PR at 2472246d (B), both with the same local timing patch, not in this PR: hos_display_popout_show timed on the present thread with QueryPerformanceCounter, the whole call and its wait on pop_lock, each 4,096 hand-offs written as a median, p99, max and mean. dev.py ab --a-runtime (two builds), Hyrule Field, the FPS counter's graph popped out (it changes every frame), 3 interleaved runs of 60 s, HOS_FPS_MAX=1000. Windows 11, RTX 5080; each cell: the three runs, each the median of its 3 or 4 blocks.

Before: main @ de6fb7b5 After: this PR @ 2472246d
hand-off, median 73.4 / 75.8 / 72.2 µs 56.0 / 53.5 / 53.5 µs
hand-off, p99 89.4-106.8 µs 74.9-86.8 µs
hand-off, mean 70.7-74.4 µs 54.8-57.2 µs
wait on the lock, median / p99 0 / 0.1 µs 0 / 0.1 µs
fps (1% low) 187.7 (159.7) / 190.2 (159.0) / 190.2 (161.1) 188.8 (156.2) / 187.7 (152.7) / 189.9 (160.0)

On Windows main premultiplies every pixel there; this PR copies the rows. The copy is most of what is left: the graph's picture is copied whole each frame.

Earlier, the frame time (before dyst's review):

Setup: dev.py ab, Hyrule Field, the FPS counter's graph in a window (it changes every frame), 3 interleaved runs of 60 s a side, uncapped (HOS_FPS_MAX=1000) unless said. Before: #3175's head before this change (e185922e), whose host code is what main has had since a87eb850; after: this change (6d8c02ea, the same host code as this PR).

Before: main @ e185922e After: this PR @ 6d8c02ea
PC (RTX 5080, Windows 11): in the picture / popped out 173.5 / 164.9 fps 173.5 / 164.9 fps
Laptop (RTX 3060 Laptop, CachyOS, Wayland): in the picture / popped out 81.1 / 75.1 fps (+0.95 ms) 81.1 / 74.6 fps (+0.81 ms)
Laptop capped at 60 fps: in the picture / popped out 60.0 / 60.0 fps

On the PC, popped out holds exactly 164.9 fps in every run, a display's refresh rate there: while a layered window is updated every frame the desktop compositor paces the game's presents. A window in the picture costs nothing measurable on either machine (173.6 fps with or without it on the PC, 80.5 and 81.2 on the laptop).

Risks

A pop-out window that shows no picture, or a stale one, on Windows or Linux; a revert is enough. The Windows window keeps one DIB section of its size while it is open. Nothing changes for a player without a popped-out window.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named). (test_dlssg.py fails on main too: its check of vk_draw.cpp's Upscaler row)
  • Measured against main, or Measurements says why there is nothing to measure. (measured: no gain the frame time shows)
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary A follow-up to #3175, pushed to its branch after it was merged. A mod window popped out of the game's picture gets a new picture every time its UI changes, every frame for a graph. Handing it to the system window was done on the thread the game waits for, and did more there than it needs: - **Windows:** `hos_display_popout_show` premultiplied every pixel under the lock and posted a paint message per picture; `pop_paint` created and deleted a DIB section per picture. Now the game's thread does a plain copy (one `memcpy` when the rows are packed) and posts one message until the window has painted. The premultiply moved to `pop_paint`, on the window's own thread, which swaps the picture out under the lock and premultiplies it after the lock is let go (as dyst suggested), and keeps its DIB section while the size holds and frees it when the window goes. A picture that could not be painted no longer leaves the window waiting for a message that never comes. - **Linux:** `popouts_turn` swaps the picture with a buffer of its own instead of a `malloc` and a copy per picture, and `hos_sdl_window_blit` blends over the background through three 256-entry tables, with no index division per pixel when the surface is the picture's size. Also, a second commit: `tests/test_ui_renderer.py` fails on `main`. #3175 was merged with its pop-out reads changed to the present's fences, and the check still looked for the earlier slot count. It now checks the merged reads. Read first: `hos_display_popout_show` and `pop_paint` in `host/display.c`, `popouts_turn` in `host/posix/display_sdl.c`, `hos_sdl_window_blit` in `host/hos_sdl.c`. ## Testing **Tested:** - Windows 11, RTX 5080: `dev.py rt` and `dev.py smoke` on this branch (PASS, in play from kokiri-start, the menu opened), and the FPS counter's graph popped out in Hyrule Field for 3 runs of 60 s (the measurements below): it showed and updated, no FATAL line. - CachyOS, RTX 3060 Laptop, Wayland: the same code on #3175's branch (6d8c02ea), `dev.py rt` and the graph popped out for 3 runs of 60 s uncapped and 3 capped at 60 fps. - At 2472246d (dyst's review: Linux's uncovered window, the premultiply after the lock): on Windows the hand-off measurement below, the graph popped out for 3 runs of 60 s, shown and updated, no FATAL line; on CachyOS `dev.py rt` and `dev.py smoke` PASS at 220b70eb (the Linux fix). `tests/test_ui_renderer.py` passes, its two new checks failing on the code before them. - Checks: `run_all.py --changed origin/main` on Windows, 38 passed; `test_dlssg.py` fails here and on `main` alike (its check of `vk_draw.cpp`'s Upscaler row, a file this does not touch). **Still to test:** - On Linux, X11: a still pop-out (not the graph) covered and uncovered, minimised and restored, shows its newest picture (by hand, a tester with an X11 desktop) - The hand-off timed on Linux: the measuring setup below did not pop the graph out on the laptop this time (Wayland), so only Windows is timed (by hand, the author) ## Measurements **Verdict:** on Windows, handing a picture to a popped-out window takes the present thread about a quarter less time: a median of 53-56 µs against 72-76 µs on `main`, the runs' spreads apart. That is about 20 µs of a 5.3 ms frame, under what the frame time can show, and the frame time indeed shows no change. The lock is never waited on, on either side, so the premultiply after the lock (dyst's suggestion) changes no number here; it keeps a slow paint from ever holding a present. Linux's hand-off is not timed yet (Still to test). **The hand-off itself** (dyst's review, point 2). `main` at de6fb7b5 (A) against this PR at 2472246d (B), both with the same local timing patch, not in this PR: `hos_display_popout_show` timed on the present thread with QueryPerformanceCounter, the whole call and its wait on `pop_lock`, each 4,096 hand-offs written as a median, p99, max and mean. `dev.py ab --a-runtime` (two builds), Hyrule Field, the FPS counter's graph popped out (it changes every frame), 3 interleaved runs of 60 s, `HOS_FPS_MAX=1000`. Windows 11, RTX 5080; each cell: the three runs, each the median of its 3 or 4 blocks. | | Before: main @ de6fb7b5 | After: this PR @ 2472246d | |---|---|---| | hand-off, median | 73.4 / 75.8 / 72.2 µs | 56.0 / 53.5 / 53.5 µs | | hand-off, p99 | 89.4-106.8 µs | 74.9-86.8 µs | | hand-off, mean | 70.7-74.4 µs | 54.8-57.2 µs | | wait on the lock, median / p99 | 0 / 0.1 µs | 0 / 0.1 µs | | fps (1% low) | 187.7 (159.7) / 190.2 (159.0) / 190.2 (161.1) | 188.8 (156.2) / 187.7 (152.7) / 189.9 (160.0) | On Windows `main` premultiplies every pixel there; this PR copies the rows. The copy is most of what is left: the graph's picture is copied whole each frame. **Earlier, the frame time** (before dyst's review): Setup: `dev.py ab`, Hyrule Field, the FPS counter's graph in a window (it changes every frame), 3 interleaved runs of 60 s a side, uncapped (`HOS_FPS_MAX=1000`) unless said. Before: #3175's head before this change (e185922e), whose host code is what `main` has had since a87eb850; after: this change (6d8c02ea, the same host code as this PR). | | Before: main @ e185922e | After: this PR @ 6d8c02ea | |---|---|---| | PC (RTX 5080, Windows 11): in the picture / popped out | 173.5 / 164.9 fps | 173.5 / 164.9 fps | | Laptop (RTX 3060 Laptop, CachyOS, Wayland): in the picture / popped out | 81.1 / 75.1 fps (+0.95 ms) | 81.1 / 74.6 fps (+0.81 ms) | | Laptop capped at 60 fps: in the picture / popped out | | 60.0 / 60.0 fps | On the PC, popped out holds exactly 164.9 fps in every run, a display's refresh rate there: while a layered window is updated every frame the desktop compositor paces the game's presents. A window in the picture costs nothing measurable on either machine (173.6 fps with or without it on the PC, 80.5 and 81.2 on the laptop). ## Risks A pop-out window that shows no picture, or a stale one, on Windows or Linux; a revert is enough. The Windows window keeps one DIB section of its size while it is open. Nothing changes for a player without a popped-out window. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). (`test_dlssg.py` fails on `main` too: its check of `vk_draw.cpp`'s Upscaler row) - [x] Measured against `main`, or Measurements says why there is nothing to measure. (measured: no gain the frame time shows) - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A pop-out window whose picture changes every frame (an FPS graph in a
window) cost 0.3 ms a frame on a desktop and about 1 ms on a laptop,
almost all of it in handing the picture to the system window, on the
thread the game waits for.

Windows: hos_display_popout_show now only copies the rows (one memcpy
when they are packed) and posts one paint message until the window has
painted, instead of one per picture. The premultiplied clamp moved to
pop_paint, on the window's thread, which now keeps its DIB section while
the size holds instead of creating and deleting one per picture; it is
freed when the window goes. A picture that could not be painted no
longer leaves the window waiting for a message that never comes.

Linux: popouts_turn swaps the picture with a buffer of its own instead
of a malloc and copy per picture, and hos_sdl_window_blit blends over
the background through three 256-entry tables and skips the per-pixel
index division when the surface is the picture's size.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
test(ui): the pop-out read check follows the fence-based reads main has
Some checks failed
PR description / Title and description (pull_request_target) Successful in 6s
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
c51774f2e0
#3175 was merged with its pop-out reads changed: a picture is read once
its present's fence has signalled, or once the present lets that fence
go before reusing it, with kPresentSlotsMax + 1 buffers. The test still
looked for the earlier slot count (kPopReads = 5, Read::done), so
test_ui_renderer.py fails on main. It now checks the merged reads: the
fence poll and the newest done picture alone in popouts_collect, never
one older than the shown one, and popouts_fence_done.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

Tested in game: Windows 11, RTX 5080: dev.py rt and smoke PASS on this branch, and the FPS counter's graph popped out in Hyrule Field for 3 runs of 60 s: it showed and updated every frame, no FATAL line. CachyOS, RTX 3060 Laptop, Wayland: the same host code (6d8c02ea) popped out for 6 runs of 60 s, uncapped and capped at 60 fps.

Tested in game: Windows 11, RTX 5080: dev.py rt and smoke PASS on this branch, and the FPS counter's graph popped out in Hyrule Field for 3 runs of 60 s: it showed and updated every frame, no FATAL line. CachyOS, RTX 3060 Laptop, Wayland: the same host code (6d8c02ea) popped out for 6 runs of 60 s, uncapped and capped at 60 fps.
neotoxic changed title from WIP: perf(ui): hand a pop-out its picture without slowing the game's present to perf(ui): hand a pop-out its picture without slowing the game's present 2026-12-04 20:15:06 +00:00
Author
Contributor

On why the numbers still hold on current main (18edd509): what main gained since the measured code (#3161's PCIe probe, #2423's fog controls, #3081's float paths off by default) changes none of the pop-out's code or the host's hand-off this PR touches. They may move the frame time on both sides alike; the comparison is in-picture against popped-out on the same build, and that difference is the system compositor's, as Measurements says.

On why the numbers still hold on current `main` (18edd509): what `main` gained since the measured code (#3161's PCIe probe, #2423's fog controls, #3081's float paths off by default) changes none of the pop-out's code or the host's hand-off this PR touches. They may move the frame time on both sides alike; the comparison is in-picture against popped-out on the same build, and that difference is the system compositor's, as Measurements says.
Owner
@review
BeanBot left a comment

Recommendation: Request changes. A failed Windows paint-message post can leave a pop-out permanently blank or stale. The reported runs also show no measurable performance gain, so the performance change has not met the repository’s merge standard.

The change coalesces Windows paint messages, keeps the Windows bitmap, swaps Linux picture buffers and uses lookup tables for Linux blending. It adds retained bitmap and buffer memory; the reported frame rates do not show a player-visible gain.

Blocking (1): must change before merging.

  1. L1 host/display.c:1175: A failed PostMessageW leaves fresh set, so subsequent pictures do not post another paint message. When: If the window thread’s message queue is full when a picture is posted, PostMessageW fails. Later calls replace the pixels but see fresh already set; no paint message arrives to clear it, so the pop-out stays blank or stale until it is reopened. Do: Handle posting failure with synchronized pending-message state and a retry path, so a later picture can schedule a paint without losing a concurrent update.

Should fix (1): not blocking, but worth doing before merging.

  • L3 tests/test_ui_renderer.py:225: The new swap checks only match source text and do not exercise the buffer hand-off or paint retry behavior. (more on the line) Do: Add a game-free behavioral test covering successive buffer swaps, the newest picture, cleanup and recovery after a failed paint-message post.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L2 host/display.c:1203: The measurements do not show whether the change reduces the hand-off cost or improves frame pacing. (more on the line) Do: Measure the targeted hand-off and lock-wait time, average and 1% low fps, and median and p99 frame times against the merge base over interleaved runs on Windows and Linux with the graph popped out. (@fix does its part first: Move the Windows clamp outside the shared lock using a separate picture buffer, so the presenting thread does not wait for that per-pixel work.)

@fix can do L1, L2 and L3.

Checks: Still running: 11 checks.

More: does it help, other systems, switches, what was read

Does it help: Unproven. The PR reports 164.9 fps before and after on Windows, where compositor pacing capped the result, and 75.1 versus 74.6 fps on Linux across three runs per side. It does not report the targeted hand-off time, 1% lows or frame-time distributions.

Other systems: The changed hand-off runs on Windows and Linux for popped-out windows, independent of GPU rendering. Windows was tested on an RTX 5080 and Linux Wayland on an RTX 3060 Laptop; other window-system and Tier 1 coverage is not reported. Gamescope disables pop-outs. Linux retains a second picture buffer per open pop-out; Windows retains a DIB.

Switches: None added, changed or removed.

Reviewed: c51774f2e0 against 18edd5097e: Read AGENTS.md, CONTRIBUTING.md, the PR template, the relevant standards, commits and complete diff; read the changed pop-out and blit functions, their callers and fence collection path, and the changed test. The large changed files were not all read in full. docs/review-checklist.md and the adjacent Tooling checkout were absent. No generated files, translations or recorded run files were changed.; nothing run (a code review).

Checked and fine:

  • The Linux buffer swap keeps the blitting buffer separate from the producer buffer and frees both on window removal.
  • The Linux lookup tables preserve the previous blend arithmetic.
  • Both commits record AI assistance, and the diff contains no game-derived output or generated files.

Testing: No code or tests were run for this review. The author reports in-game Windows and Linux runs; CI was still running.

Overlaps and merge order: No overlapping pull requests could be checked with the network closed. The PR is reported as not mergeable.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** A failed Windows paint-message post can leave a pop-out permanently blank or stale. The reported runs also show no measurable performance gain, so the performance change has not met the repository’s merge standard. The change coalesces Windows paint messages, keeps the Windows bitmap, swaps Linux picture buffers and uses lookup tables for Linux blending. It adds retained bitmap and buffer memory; the reported frame rates do not show a player-visible gain. **Blocking (1)**: must change before merging. 1. **L1** `host/display.c:1175`: A failed PostMessageW leaves fresh set, so subsequent pictures do not post another paint message. *When:* If the window thread’s message queue is full when a picture is posted, PostMessageW fails. Later calls replace the pixels but see fresh already set; no paint message arrives to clear it, so the pop-out stays blank or stale until it is reopened. **Do:** Handle posting failure with synchronized pending-message state and a retry path, so a later picture can schedule a paint without losing a concurrent update. **Should fix (1)**: not blocking, but worth doing before merging. - **L3** `tests/test_ui_renderer.py:225`: The new swap checks only match source text and do not exercise the buffer hand-off or paint retry behavior. (more on the line) **Do:** Add a game-free behavioral test covering successive buffer swaps, the newest picture, cleanup and recovery after a failed paint-message post. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L2** `host/display.c:1203`: The measurements do not show whether the change reduces the hand-off cost or improves frame pacing. (more on the line) **Do:** Measure the targeted hand-off and lock-wait time, average and 1% low fps, and median and p99 frame times against the merge base over interleaved runs on Windows and Linux with the graph popped out. *(`@fix` does its part first: Move the Windows clamp outside the shared lock using a separate picture buffer, so the presenting thread does not wait for that per-pixel work.)* `@fix` can do L1, L2 and L3. **Checks:** Still running: 11 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The PR reports 164.9 fps before and after on Windows, where compositor pacing capped the result, and 75.1 versus 74.6 fps on Linux across three runs per side. It does not report the targeted hand-off time, 1% lows or frame-time distributions. **Other systems:** The changed hand-off runs on Windows and Linux for popped-out windows, independent of GPU rendering. Windows was tested on an RTX 5080 and Linux Wayland on an RTX 3060 Laptop; other window-system and Tier 1 coverage is not reported. Gamescope disables pop-outs. Linux retains a second picture buffer per open pop-out; Windows retains a DIB. **Switches:** None added, changed or removed. **Reviewed:** c51774f2e03e against 18edd5097e36: Read AGENTS.md, CONTRIBUTING.md, the PR template, the relevant standards, commits and complete diff; read the changed pop-out and blit functions, their callers and fence collection path, and the changed test. The large changed files were not all read in full. docs/review-checklist.md and the adjacent Tooling checkout were absent. No generated files, translations or recorded run files were changed.; nothing run (a code review). **Checked and fine:** - The Linux buffer swap keeps the blitting buffer separate from the producer buffer and frees both on window removal. - The Linux lookup tables preserve the previous blend arithmetic. - Both commits record AI assistance, and the diff contains no game-derived output or generated files. **Testing:** No code or tests were run for this review. The author reports in-game Windows and Linux runs; CI was still running. **Overlaps and merge order:** No overlapping pull requests could be checked with the network closed. The PR is reported as not mergeable. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
host/display.c Outdated
@ -1201,0 +1200,4 @@
if (p->dib && p->dib_bits) {
/* (premultiplied as Windows takes it: no colour above its alpha, which an sRGB image's encoding can leave at
an edge's partly covered pixels) */
const uint8_t *s = p->pix;
Member

L2 (should fix): The measurements do not show whether the change reduces the hand-off cost or improves frame pacing.

When: On Windows the pixel clamp now runs on the window thread but still holds pop_lock, which the presenting thread also needs. The reported Windows frame rate is compositor-limited and the Linux difference is within noise, so neither result establishes a gain.

Do: Measure the targeted hand-off and lock-wait time, average and 1% low fps, and median and p99 frame times against the merge base over interleaved runs on Windows and Linux with the graph popped out.

**L2** (should fix): The measurements do not show whether the change reduces the hand-off cost or improves frame pacing. *When:* On Windows the pixel clamp now runs on the window thread but still holds pop_lock, which the presenting thread also needs. The reported Windows frame rate is compositor-limited and the Linux difference is within noise, so neither result establishes a gain. **Do:** Measure the targeted hand-off and lock-wait time, average and 1% low fps, and median and p99 frame times against the merge base over interleaved runs on Windows and Linux with the graph popped out.
@ -221,3 +224,2 @@
shown = turn[turn.find("if (p->fresh && p->pix) {"):turn.find("ReleaseSRWLockExclusive(&pop_lock);", turn.find("if (p->fresh && p->pix) {"))]
c.true("host/posix/display_sdl.c: a picture is marked shown only once its copy was made (no copy: still fresh)",
0 <= shown.find("if (pix) {") < shown.find("p->fresh = 0;") and shown.find("if (pix) {") < shown.find("p->shown = 1;"))
c.true("host/posix/display_sdl.c: a picture is taken by swapping buffers, no allocation or copy per picture",
Member

L3 (should fix): The new swap checks only match source text and do not exercise the buffer hand-off or paint retry behavior.

When: The test still passes if the swapped-out picture is corrupted before blitting or a failed Windows message post permanently prevents later paints, provided the checked strings remain present.

Do: Add a game-free behavioral test covering successive buffer swaps, the newest picture, cleanup and recovery after a failed paint-message post.

**L3** (should fix): The new swap checks only match source text and do not exercise the buffer hand-off or paint retry behavior. *When:* The test still passes if the swapped-out picture is corrupted before blitting or a failed Windows message post permanently prevents later paints, provided the checked strings remain present. **Do:** Add a game-free behavioral test covering successive buffer swaps, the newest picture, cleanup and recovery after a failed paint-message post.
hos_display_popout_show posts one paint message per painted picture and
marks the picture fresh until the window's thread paints it. When
PostMessageW failed (the thread's queue full), fresh stayed set and no
paint came to clear it, so every later picture skipped its post and the
pop-out stayed blank or stale until reopened. A failed post now clears
fresh, and the next picture posts again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merge remote-tracking branch 'origin/main' into perf/popout-handoff
Some checks failed
PR description / Title and description (pull_request_target) Has been cancelled
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
b597b4889b
# Conflicts:
#	tests/test_ui_renderer.py
Author
Contributor

L1 fixed in a567ced9: when PostMessageW fails, hos_display_popout_show clears fresh under pop_lock, so the next picture posts again. No paint message can be in flight then, because fresh was clear before this picture set it.

L3: tests/test_ui_renderer.py now also checks that a failed post clears fresh. A behavioural test of the retry would need a window thread whose message queue can be made full, which no game-free check here has, so it stays a source check.

Brought up to current main (de6fb7b5) by a merge, b597b488, nothing rewritten. The one conflict was the pop-out read check in tests/test_ui_renderer.py: main's version is kept, plus this branch's newest->at > p.shown_at line. On Windows 11, RTX 5080, dev.py rt and dev.py smoke pass on b597b488 (in play from kokiri-start, 900 frames, the menu opened), and tests/test_ui_renderer.py passes.

**L1** fixed in a567ced9: when `PostMessageW` fails, `hos_display_popout_show` clears `fresh` under `pop_lock`, so the next picture posts again. No paint message can be in flight then, because `fresh` was clear before this picture set it. **L3**: `tests/test_ui_renderer.py` now also checks that a failed post clears `fresh`. A behavioural test of the retry would need a window thread whose message queue can be made full, which no game-free check here has, so it stays a source check. Brought up to current `main` (de6fb7b5) by a merge, b597b488, nothing rewritten. The one conflict was the pop-out read check in `tests/test_ui_renderer.py`: `main`'s version is kept, plus this branch's `newest->at > p.shown_at` line. On Windows 11, RTX 5080, `dev.py rt` and `dev.py smoke` pass on b597b488 (in play from kokiri-start, 900 frames, the menu opened), and `tests/test_ui_renderer.py` passes.
dyst left a comment

Recommendation: Request changes. On Linux, a pop-out that has been uncovered or restored now redraws the picture before its newest one, or nothing at all, because the expose handler still reads the buffer the new swap has made the spare. And it is a performance change whose own measurement shows no gain ("No measured gain, no merge", standards).

For a player with a mod window popped out, this aims to make handing over each picture cheaper on the thread the game's present waits for. On Windows, the premultiply moves to the window's thread, the DIB is kept and there is one paint message until the window paints. On Linux, a buffer swap replaces a malloc and a copy, and the blend uses lookup tables. The code is a little more involved than main's, and the gain is not shown yet.

Does it help: Unproven. Measurements' own verdict is "no change the frame time shows". On Windows the compositor paces both sides at 164.9 fps, so these runs can't show a CPU-side gain. On Linux, popped-out goes from 75.1 to 74.6 fps over 3 runs a side with no spread given. By those fps the pop-out's cost rises from +0.99 to +1.07 ms, while the table's ms column says +0.95 to +0.81, so the two columns disagree. The earlier review's L2 (measure the hand-off itself) has no answer yet.
Other systems: the change is host-side, so the GPU vendor doesn't matter. What matters is the window system. X11 sends exposes whenever a window is uncovered or restored, and that is where blocking point 1 shows. No run so far uses X11, or a mod window whose picture stays still (a graph hides it: every frame brings a new picture). Gamescope has no pop-outs.
Switches: none.
Reviewed: b597b4889 against de6fb7b5 (the merge's main parent; the diff is the four files, +72/-40). Read in full where it changed and what it relies on:

  • Windows: hos_display_popout_show, pop_paint, pop_of_window, popouts_sync's close path, and the WM_APP+17/+18 dispatch.
  • Linux: Pop, hos_display_popout_show, popout_event, popouts_turn.
  • hos_sdl_window_blit, and the change to tests/test_ui_renderer.py.

Nothing was run.
Fixed in this review: nothing.
Checked and fine:

  • L1 is answered in a567ced9. A failed PostMessageW clears fresh under the lock. With one producer, no message can be in flight then. When no further picture comes, it behaves as main does.
  • The Windows DIB is created, selected and deleted only on the display thread: the pop windows are made in popouts_sync (WM_APP+17), and pop_paint runs on WM_APP+18. It is deselected before DeleteDC, and deleted on a size change and on close. A failed CreateDIBSection is tried again at the next picture and still clears fresh. A first DIB failure no longer marks the window shown without showing it (main sets shown before it checks the bitmap).
  • The Windows copy: need stays within uint32_t (w and h ≤ 8192). Packed rows take one memcpy, other rows one each, as on Linux.
  • The Linux swap: the producer writes only pix (reallocated past pcap), and the blit reads only spare, on the display thread. Both are freed on close. After the first swap pix is NULL with pcap 0, so the producer allocates.
  • hos_sdl_window_blit: the tables hold exactly the old per-pixel (bg*k+127)/255, and same picks the same rows and columns. That is 768 divisions a blit.
  • The merge resolves only tests/test_ui_renderer.py, and the if (newest->at > p.shown_at) { it checks is at gpu/vk/vk_paint.cpp:1379.

Blocking

  1. host/posix/display_sdl.c:827: case HOS_SDL_EV_EXPOSED: if (p->pix) p->fresh = 1; still treats pix as the picture on screen. After popouts_turn's swap (913-918), pix is the spare:

    • after the first picture it is NULL, so the expose is dropped and the uncovered window is not redrawn;
    • after that it holds the picture before the newest, so the window redraws one picture back, and each further expose flips between the two.

    This shows for any mod window whose picture stays still: on X11, when another window is moved off it or it is restored from minimised, it shows the wrong picture until its UI next changes. Main redraws the newest. One fix: when nothing newer is waiting, swap back. Nothing else is needed: popout_event runs on the same thread as popouts_turn, so no blit is reading spare then, and pw/ph still describe it while fresh is clear.

    case HOS_SDL_EV_EXPOSED:
        if (!p->fresh && p->spare) {   /* (the picture on screen is the spare: back in pix, blitted again next turn) */
            uint8_t *const t = p->pix;
            const uint32_t tcap = p->pcap;
            p->pix = p->spare, p->pcap = p->scap, p->spare = t, p->scap = tcap;
            p->fresh = 1;
        }
        break;
    

    Also add a check in tests/test_ui_renderer.py that the EXPOSED case shows the spare again; the new swap checks pass with this bug in place.

  2. Measurements: this is a perf PR, and the standards say "No measured gain, no merge". Measure what the title claims, main against this PR, interleaved, with medians and spreads. That means either the present thread's time in hos_display_popout_show and its wait on pop_lock, or the frame time (with 1% lows and p99) somewhere the compositor doesn't pace the game. If no gain shows, the change doesn't merge as a performance change.

Suggestions

  • host/display.c:1261: the premultiply now runs inside pop_lock on the window's thread. If the present thread's next hos_display_popout_show or hos_display_popouts comes during it, that thread waits for the whole per-pixel loop. Swapping pix with a window-thread buffer under the lock (as Linux now does) and premultiplying into the DIB after the lock is released would keep that loop off the lock. That is what the title promises.

Testing: By the author:

  • Windows 11, RTX 5080: dev.py rt and smoke on b597b488, and the graph popped out for 3×60 s.
  • CachyOS, RTX 3060 Laptop, Wayland: on 6d8c02ea (before a567ced9 and the merge).

Missing: X11, and a still (non-graph) pop-out that is covered and uncovered, minimised and restored, on both systems. The measurement in point 2. The Tier 1 box is unticked. CI on b597b488 has not started (11 checks waiting).
Overlaps and merge order:

  • #3116 changes the same pop-out code (host/display.c, host/posix/display_sdl.c, host/hos_sdl.c, vk_paint.cpp). Whichever lands second rebases.
  • #3080 renames across the same files and the test. It is mechanical and goes after.
  • #2816, #2542, #142 and #1690 touch the same files in other functions.
**Recommendation: Request changes.** On Linux, a pop-out that has been uncovered or restored now redraws the picture before its newest one, or nothing at all, because the expose handler still reads the buffer the new swap has made the spare. And it is a performance change whose own measurement shows no gain ("No measured gain, no merge", standards). For a player with a mod window popped out, this aims to make handing over each picture cheaper on the thread the game's present waits for. On Windows, the premultiply moves to the window's thread, the DIB is kept and there is one paint message until the window paints. On Linux, a buffer swap replaces a malloc and a copy, and the blend uses lookup tables. The code is a little more involved than main's, and the gain is not shown yet. **Does it help:** Unproven. Measurements' own verdict is "no change the frame time shows". On Windows the compositor paces both sides at 164.9 fps, so these runs can't show a CPU-side gain. On Linux, popped-out goes from 75.1 to 74.6 fps over 3 runs a side with no spread given. By those fps the pop-out's cost rises from +0.99 to +1.07 ms, while the table's ms column says +0.95 to +0.81, so the two columns disagree. The earlier review's L2 (measure the hand-off itself) has no answer yet. **Other systems:** the change is host-side, so the GPU vendor doesn't matter. What matters is the window system. X11 sends exposes whenever a window is uncovered or restored, and that is where blocking point 1 shows. No run so far uses X11, or a mod window whose picture stays still (a graph hides it: every frame brings a new picture). Gamescope has no pop-outs. **Switches:** none. **Reviewed:** b597b4889 against de6fb7b5 (the merge's main parent; the diff is the four files, +72/-40). Read in full where it changed and what it relies on: - Windows: `hos_display_popout_show`, `pop_paint`, `pop_of_window`, `popouts_sync`'s close path, and the WM_APP+17/+18 dispatch. - Linux: `Pop`, `hos_display_popout_show`, `popout_event`, `popouts_turn`. - `hos_sdl_window_blit`, and the change to `tests/test_ui_renderer.py`. Nothing was run. **Fixed in this review:** nothing. **Checked and fine:** - L1 is answered in a567ced9. A failed `PostMessageW` clears `fresh` under the lock. With one producer, no message can be in flight then. When no further picture comes, it behaves as main does. - The Windows DIB is created, selected and deleted only on the display thread: the pop windows are made in `popouts_sync` (WM_APP+17), and `pop_paint` runs on WM_APP+18. It is deselected before `DeleteDC`, and deleted on a size change and on close. A failed `CreateDIBSection` is tried again at the next picture and still clears `fresh`. A first DIB failure no longer marks the window shown without showing it (main sets `shown` before it checks the bitmap). - The Windows copy: `need` stays within `uint32_t` (w and h ≤ 8192). Packed rows take one `memcpy`, other rows one each, as on Linux. - The Linux swap: the producer writes only `pix` (reallocated past `pcap`), and the blit reads only `spare`, on the display thread. Both are freed on close. After the first swap `pix` is NULL with `pcap` 0, so the producer allocates. - `hos_sdl_window_blit`: the tables hold exactly the old per-pixel `(bg*k+127)/255`, and `same` picks the same rows and columns. That is 768 divisions a blit. - The merge resolves only `tests/test_ui_renderer.py`, and the `if (newest->at > p.shown_at) {` it checks is at `gpu/vk/vk_paint.cpp:1379`. **Blocking** 1. `host/posix/display_sdl.c:827`: `case HOS_SDL_EV_EXPOSED: if (p->pix) p->fresh = 1;` still treats `pix` as the picture on screen. After `popouts_turn`'s swap (913-918), `pix` is the spare: - after the first picture it is NULL, so the expose is dropped and the uncovered window is not redrawn; - after that it holds the picture before the newest, so the window redraws one picture back, and each further expose flips between the two. This shows for any mod window whose picture stays still: on X11, when another window is moved off it or it is restored from minimised, it shows the wrong picture until its UI next changes. Main redraws the newest. One fix: when nothing newer is waiting, swap back. Nothing else is needed: `popout_event` runs on the same thread as `popouts_turn`, so no blit is reading `spare` then, and `pw`/`ph` still describe it while `fresh` is clear. ```c case HOS_SDL_EV_EXPOSED: if (!p->fresh && p->spare) { /* (the picture on screen is the spare: back in pix, blitted again next turn) */ uint8_t *const t = p->pix; const uint32_t tcap = p->pcap; p->pix = p->spare, p->pcap = p->scap, p->spare = t, p->scap = tcap; p->fresh = 1; } break; ``` Also add a check in `tests/test_ui_renderer.py` that the EXPOSED case shows the spare again; the new swap checks pass with this bug in place. 2. Measurements: this is a `perf` PR, and the standards say "No measured gain, no merge". Measure what the title claims, main against this PR, interleaved, with medians and spreads. That means either the present thread's time in `hos_display_popout_show` and its wait on `pop_lock`, or the frame time (with 1% lows and p99) somewhere the compositor doesn't pace the game. If no gain shows, the change doesn't merge as a performance change. **Suggestions** - `host/display.c:1261`: the premultiply now runs inside `pop_lock` on the window's thread. If the present thread's next `hos_display_popout_show` or `hos_display_popouts` comes during it, that thread waits for the whole per-pixel loop. Swapping `pix` with a window-thread buffer under the lock (as Linux now does) and premultiplying into the DIB after the lock is released would keep that loop off the lock. That is what the title promises. **Testing:** By the author: - Windows 11, RTX 5080: `dev.py rt` and `smoke` on b597b488, and the graph popped out for 3×60 s. - CachyOS, RTX 3060 Laptop, Wayland: on 6d8c02ea (before a567ced9 and the merge). Missing: X11, and a still (non-graph) pop-out that is covered and uncovered, minimised and restored, on both systems. The measurement in point 2. The Tier 1 box is unticked. CI on b597b488 has not started (11 checks waiting). **Overlaps and merge order:** - [#3116](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/3116) changes the same pop-out code (`host/display.c`, `host/posix/display_sdl.c`, `host/hos_sdl.c`, `vk_paint.cpp`). Whichever lands second rebases. - [#3080](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/3080) renames across the same files and the test. It is mechanical and goes after. - [#2816](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2816), [#2542](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2542), [#142](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/142) and [#1690](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1690) touch the same files in other functions.
@ -1255,0 +1258,4 @@
p->dib = CreateDIBSection(mem, &bi, DIB_RGB_COLORS, &p->dib_bits, NULL, 0);
p->dw = p->dib && p->dib_bits ? pw : 0, p->dh = p->dib && p->dib_bits ? ph : 0;
}
if (p->dib && p->dib_bits) {
Member

Suggestion: this per-pixel loop runs under pop_lock, so a present-thread call that comes during it waits for all of it. Swap pix with a window-thread buffer under the lock and premultiply into the DIB after releasing it.

Suggestion: this per-pixel loop runs under pop_lock, so a present-thread call that comes during it waits for all of it. Swap pix with a window-thread buffer under the lock and premultiply into the DIB after releasing it.
@ -918,0 +913,4 @@
if (p->fresh && p->pix) { /* (swapped out, no copy: the blit runs without the lock on this thread's buffer) */
uint8_t *const t = p->spare;
const uint32_t tcap = p->scap;
p->spare = p->pix, p->scap = p->pcap, p->pix = t, p->pcap = tcap;
Member

After this swap, pix is the spare, but popout_event's HOS_SDL_EV_EXPOSED (line 827) still does if (p->pix) p->fresh = 1: NULL after the first picture (the expose is dropped), else the picture before the newest (an uncovered window redraws one back; exposes flip between the two). There: swap back when !p->fresh && p->spare, then set fresh (see the review body).

After this swap, pix is the spare, but popout_event's HOS_SDL_EV_EXPOSED (line 827) still does if (p->pix) p->fresh = 1: NULL after the first picture (the expose is dropped), else the picture before the newest (an uncovered window redraws one back; exposes flip between the two). There: swap back when !p->fresh && p->spare, then set fresh (see the review body).
fix(ui): an uncovered pop-out on Linux shows its newest picture again
Some checks failed
PR description / Title and description (pull_request_target) Has been cancelled
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
220b70ebbb
popouts_turn now swaps the newest picture into spare and blits it from
there, but the EXPOSED case still looked at pix: NULL after the first
picture, so an uncovered or restored window was not redrawn, or the
picture before the newest, so it redrew one picture back and each
further expose flipped between the two. With nothing newer waiting the
spare is swapped back into pix and blitted again. popout_event runs
under pop_lock on the display thread, as popouts_turn does, so no blit
reads the spare then, and pw/ph still describe it.

tests/test_ui_renderer.py checks the EXPOSED case; it fails on the old
line.

Reported by dyst's review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

@dyst: thanks. Blocking 1 is fixed in 220b70eb, as you proposed. The EXPOSED case swaps the spare back into pix when nothing newer is waiting, then sets fresh. popout_event holds pop_lock on the display thread, as popouts_turn does, so no blit reads the spare then. tests/test_ui_renderer.py now checks the case: it fails on the old line and passes with the fix. Checked on CachyOS (RTX 3060 Laptop, Wayland): dev.py rt and dev.py smoke pass on 220b70eb. A still pop-out covered and uncovered on X11 has not been tried yet.

Blocking 2: agreed, the frame time can't show this. Next I'll time the hand-off itself on the present thread, main against this PR, interleaved, with medians and spreads, on both systems: the time spent in hos_display_popout_show and its wait on pop_lock. I'll take your suggestion (premultiply after the lock is released) into that run, since it is what the title promises. If no gain shows, I'll say so and this stops being a perf change.

@dyst: thanks. **Blocking 1** is fixed in 220b70eb, as you proposed. The EXPOSED case swaps the spare back into `pix` when nothing newer is waiting, then sets `fresh`. `popout_event` holds `pop_lock` on the display thread, as `popouts_turn` does, so no blit reads the spare then. `tests/test_ui_renderer.py` now checks the case: it fails on the old line and passes with the fix. Checked on CachyOS (RTX 3060 Laptop, Wayland): `dev.py rt` and `dev.py smoke` pass on 220b70eb. A still pop-out covered and uncovered on X11 has not been tried yet. **Blocking 2:** agreed, the frame time can't show this. Next I'll time the hand-off itself on the present thread, `main` against this PR, interleaved, with medians and spreads, on both systems: the time spent in `hos_display_popout_show` and its wait on `pop_lock`. I'll take your suggestion (premultiply after the lock is released) into that run, since it is what the title promises. If no gain shows, I'll say so and this stops being a `perf` change.
perf(ui): premultiply a Windows pop-out's picture after the lock is let go
Some checks are pending
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Waiting to run
2472246d53
pop_paint premultiplied every pixel with pop_lock held, on the window's
thread: a present handing the next picture in the meantime waited for
the whole loop. The picture is now swapped out of pix into a buffer of
the window's thread under the lock, as Linux's popouts_turn does, and
premultiplied into the DIB after the lock is released. The spare, the
DIB and shown are touched only on the window's thread, where
popouts_sync frees them on close. fresh is still cleared under the
lock, so a picture that could not be painted still lets the next one
post.

tests/test_ui_renderer.py checks that the loop is outside the lock and
that both buffers are freed.

Suggested in dyst's review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

@dyst: point 2, measured, and your suggestion is in 2472246d. Measurements has the table.

  • The premultiply after the lock (2472246d): pop_paint swaps the picture out of pix under pop_lock, as Linux's popouts_turn does, and premultiplies into the DIB after the lock is released. fresh is still cleared under the lock. The spare, the DIB and shown are touched only on the window's thread, which frees them on close. A new check in tests/test_ui_renderer.py keeps the loop out of the lock.
  • The hand-off timed on the present thread, main (de6fb7b5) against 2472246d, with a local timing patch on both sides that is not in the PR. Two builds through dev.py ab --a-runtime, the graph popped out, 3 interleaved runs of 60 s, Windows 11 and an RTX 5080. The median hand-off is 72-76 µs on main and 53-56 µs here, the runs' spreads apart; the p99 is 89-107 µs against 75-87 µs. The wait on pop_lock is 0 at the median and 0.1 µs at the p99 on both sides. So the gain is the copy replacing the premultiply on the present thread, and the lock change shows no number here. It is about 20 µs of a 5.3 ms frame, and the frame time shows no change (fps 187.7-190.2 on both sides).
  • Linux is not timed yet: in the same setup on the laptop (Wayland) the graph did not pop out this time, so no hand-off was recorded. It is in Still to test, with the X11 cover / uncover check.

If ~20 µs a frame on Windows is too small to count as a performance change, I can retitle it as a fix: the window no longer waits forever when a paint message can't be posted, and Linux's uncovered window now redraws.

@dyst: point 2, measured, and your suggestion is in 2472246d. Measurements has the table. - **The premultiply after the lock** (2472246d): `pop_paint` swaps the picture out of `pix` under `pop_lock`, as Linux's `popouts_turn` does, and premultiplies into the DIB after the lock is released. `fresh` is still cleared under the lock. The spare, the DIB and `shown` are touched only on the window's thread, which frees them on close. A new check in `tests/test_ui_renderer.py` keeps the loop out of the lock. - **The hand-off timed** on the present thread, `main` (de6fb7b5) against 2472246d, with a local timing patch on both sides that is not in the PR. Two builds through `dev.py ab --a-runtime`, the graph popped out, 3 interleaved runs of 60 s, Windows 11 and an RTX 5080. The median hand-off is 72-76 µs on `main` and 53-56 µs here, the runs' spreads apart; the p99 is 89-107 µs against 75-87 µs. The wait on `pop_lock` is 0 at the median and 0.1 µs at the p99 on both sides. So the gain is the copy replacing the premultiply on the present thread, and the lock change shows no number here. It is about 20 µs of a 5.3 ms frame, and the frame time shows no change (fps 187.7-190.2 on both sides). - **Linux is not timed yet:** in the same setup on the laptop (Wayland) the graph did not pop out this time, so no hand-off was recorded. It is in Still to test, with the X11 cover / uncover check. If ~20 µs a frame on Windows is too small to count as a performance change, I can retitle it as a fix: the window no longer waits forever when a paint message can't be posted, and Linux's uncovered window now redraws.
Some checks are pending
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Waiting to run
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/popout-handoff:neotoxic-perf/popout-handoff'
git switch 'neotoxic-perf/popout-handoff'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!3195
No description provided.