Skip to content

feat(rune): a visible Windows window's swap chain has a third buffer - #1132

Closed
Hona wants to merge 4 commits into
devfrom
present-depth-pr
Closed

Hona wants to merge 4 commits into
devfrom
present-depth-pr

Conversation

@Hona

@Hona Hona commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Stacked on #1063 (MEMORY's shared 60 s rest timer): merge that first. This PR's own changes are its last two commits; the second makes that timer build on macOS. With two buffers at frame latency 1, the GPU can't start a frame until DWM gives back the buffer it will draw into. While another app keeps the GPU busy, that round trip takes two refreshes, so a scroll shows a new image every other refresh. A third buffer removes the wait. The frame latency stays 1, so input never queues behind an extra frame. mermaid stateDiagram-v2 [*] --> Three: created visible and opaque [*] --> Two: created hidden or with alpha Three --> Two: hidden, minimised or covered whole for 60 s (Rest DropThirdBuffer) Two --> Three: free turn while visible, no input waiting, 250 ms after the last input Two --> Off: third buffer refused Three --> Two: resize or remade (grows back on a free turn) - window/depth.rs: the buffer-count state machine (Depth, DepthEvent, depth_turn, configure_depth). - Grow: only on a free turn: nothing to draw, no input waiting, and the swap chain's room free. Never within HOLD (250 ms) of a wheel, key, press, touch or resize step, because ResizeBuffers remakes every buffer (7–20 ms, scaling with the window's size). - Shrink: on RestEffect::DropThirdBuffer from the rest's one long timer (window/rest.rs, #1063). There is no second timer. - Refused allocation: the window keeps two buffers for its life, and the process never exits for it. - vendor/wgpu-hal: dx12::Surface::set_extra_buffers adds buffers beyond maximum_frame_latency + 1 at the next configure; buffer_count reports them. Both are in vendor/wgpu-hal.patch. ### Missed refreshes list scrolling at 240 Hz beside the OpenCode desktop, blade (Iris Xe), release, per-swap-chain GetFrameStatistics, 4 interleaved runs per arm, median: | | Two buffers (dev) | Three buffers (this PR) | |---|---:|---:| | Missed refreshes of ~717 | 292 | 3 | | Read-then-scroll on list | 306 | 5 | ### Input during motion Posted key or click to its frame seen on screen, focused, pooled ABBA, n=20 per arm, median µs: | | Two | Three | |---|---:|---:| | Key during a scroll | 16,660 | 12,290 | | Click during a scroll | 15,901 | 11,338 | | Key during a slide | 11,341 | 11,399 | | Click during a slide | 12,555 | 10,555 | ### Start-up A window created visible configures three buffers in its first configure, so there is no ResizeBuffers after launch. Blade (Iris Xe), launches alternating ABBA, medians:nn| | Arm | n | First configure | GPU's first present, from the spawn |n|---|---|---:|---:|---:|n| list | Two | 10 | 5.6 ms | 193.8 ms |n| | Three | 10 | 6.8 ms | 191.6 ms |n| The app | Two | 8 | 5.8 ms | 239.5 ms |n| | Three | 8 | 6.5 ms | 236.1 ms |nnThe first configure takes about 1 ms more; the first frame on screen comes no later. In the app that configure runs on the GPU thread, off the UI thread. No window grew after launch. ### Memory One window-sized BGRA8 buffer while visible: 5,529,600 B at 1440×960, 14,745,600 B at 2560×1440. None after 60 s out of sight. hello` on blade (Iris Xe), GPU bytes, 3 runs per arm, median. Two buffers is the same build with the third turned off. | | Size | Two buffers | Three buffers | Difference | |---|---|---:|---:|---:| | Visible, 15 s after input | 1440×960 | 34,656,256 | 39,661,568 | +5,005,312 | | Visible, 15 s after input | 2538×1384 | 58,830,848 | 73,089,024 | +14,258,176 | | Minimised for 70 s | 1440×960 | 27,209,728 | 27,217,920 | +8,192 | | Minimised for 70 s | 2538×1384 | 44,060,672 | 44,064,768 | +4,096 |

Hona added 4 commits November 17, 2026 21:12
…rame; an idle turn makes it again

The kept last frame (`render::damaged`, 9.2 MB at 1920x1200) stayed for the window's life. After `LONG_REST_AFTER` (60 s) with no frame, the rest machine gives it back and polls the device once without waiting, so wgpu frees it then. The first frame back draws whole straight into the drawable, making and copying nothing (frame-profile `whole`: "given back"). On Windows, the next idle turn with no input waiting (`post_frame`) makes it again and draws the frame whole into it, with no present.
With two buffers at frame latency 1 the GPU can't start a frame until DWM gives back the buffer it draws into; while another window keeps the GPU busy that round trip takes two refreshes, and a scrolling list shows a new image every other refresh. A window created visible is created with three buffers (the frame latency stays 1, so input never waits behind a queued frame). Out of sight for the rest's long timer (60 s, shared with the kept last frame) it goes back to two; it grows back on a free turn once it can be seen again, never with input waiting and never within 250 ms of input. A refused third buffer keeps two for the window's life.
`Renderer::give_back_kept` lives in `render::damaged`, which only Windows and wasm build; the rest's GiveBackKept arm and GiveBackAll's call now build on Windows only (macOS keeps no frame).
Copilot AI balanced review requested due to automatic review settings November 17, 2026 12:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@Hona

Hona commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Commits, by author package:

Commit Package What
846079da MEMORY Rest: a window that draws nothing for 60 s gives back its kept last frame (#1063's change)
f65b558b MEMORY Rest: one 60 s timer for the kept frame (visible) and the third buffer (unseen)
903af9da PRESENT Windows: a visible window's swap chain has a third buffer (this PR's change)
15c5dbc7 PRESENT The rest's kept-frame drop builds on macOS (a fix to MEMORY's rest.rs)

The head isn't final yet: #1082 merges first. Then I merge dev into this branch, take the vendored source merge, and regenerate vendor/wgpu-hal.patch with scripts/vendor-wgpu-hal.sh, not by hand. I'll say here when the head is final, for the independent read.

@Hona

Hona commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Latency while animating: two buffers against three

Same measuring builds, frame latency 1 and the waitable swap chain in both arms; two buffers is RUNE_DEPTH=0. Blade (Iris Xe, 240 Hz). Each input's present is matched to the refresh that showed it through the swap chain's GetFrameStatistics. Arm orders alternate ticket by ticket. Medians:

Input during animation Arm n Frames queued ahead Present → screen Input → seen
Tab press during the Working shine (the app) Two 36 0 10.3 ms 24.1 ms
Three 36 0 9.2 ms 21.0 ms
Key during a slide (midinput) Two 20 — 7.4 / 6.9 ms 13.2 / 12.9 ms
Three 20 — 7.4 / 7.0 ms 14.9 / 14.2 ms
Click during a slide (midinput) Two 20 — 8.6 / 11.1 ms 15.1 / 19.0 ms
Three 20 — 7.5 / 6.7 ms 14.8 / 15.7 ms

Slide rows are two tickets of 10 each, shown separately; their "seen" is a Desktop Duplication capture.

  • Nothing queues ahead of an input's frame with either count. The frame latency stays 1, and Rune builds a frame only when the swap chain's waitable object says a slot is free. So the third buffer adds throughput, not depth.
  • Present → screen is about two refreshes in both arms. That's the GPU's work, the compositor taking the frame at the next refresh, and showing it at the one after.

@Hona

Hona commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Closing: shelved (third swap-chain buffer, stacked on #1063); 13 files conflict with dev after the window/surface rework, no path to merge as is. Branch kept.

@Hona Hona closed this Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants