Skip to content

Windows: the CPU-first window's hand-over always ends, with deadlines, reasons and retries - #781

Merged
Hona merged 2 commits into
devfrom
ib-3-handover
Nov 12, 2026
Merged

Hona merged 2 commits into
devfrom
ib-3-handover

Conversation

@Hona

@Hona Hona commented Nov 12, 2026

Copy link
Copy Markdown
Member

A CPU-first window's hand-over to the GPU could stall with nothing logged. VIDEO-WIN saw it on the visible desktop: in ~25 launches the GPU arrived 3-9 s late twice and never in two more. This makes the hand-over a machine that always ends, and says how.

The stall reproduced: a window covered from its launch (by an overlapped window it owns: harness\perf\floor\handover\visible-covered.ts --owned) draws no frame, so the frame both renderers draw never came.

gpu.window.ready frame.first.gpu gpu.window.handed
Before (dev at #760) 285 ms 4,176 ms (after the uncover) 4,197 ms
This PR 264 ms 286 ms 308 ms (covered)

A window that stays behind another never handed over before.

Deadlines (Host::watch_handover; Win::handover_deadline wakes the loop for them):

  • Building: the GPU thread runs at normal priority after 500 ms (it starts below normal, and a busy machine held it off up to 2.1 s). Logged gpu.window.slow after 20 s; it can't be stopped.
  • Handing over, nothing drawn: a frame is asked for every 100 ms and draws in sight or not. Fails after 5 s.
  • Handing over, drawn: fails if the GPU hasn't finished that frame in 5 s.
  • Every failure (the thread, the device, the commit, a deadline): gpu.window.failed with note gpu.window.why, back to the CPU, and tried again after 30 s, three tries in all, then the CPU for good.
  • D3D12's idle-priority threads are raised when the GPU arrives, so they don't hold off the shared frame's shaders.

Hand-over over 400 launches (release, hidden desktop, empty profile, quiet and loaded in alternating chunks of 25; loaded = 20 busy processes at below normal, as other builds run; µs from resume; proof\ib-3\handover\{before,after}). The two arms ran an hour apart on different mains, so compare tails, not p50s:

Runs Never p50 p95 p99 Worst
Before, quiet 100 0 309,913 622,580 1,835,620 1,915,443
Before, loaded 100 0 244,981 425,845 1,818,815 2,312,719
This PR, quiet 100 0 367,104 730,288 1,316,740 1,857,675
This PR, loaded 100 0 338,517 641,473 849,358 1,372,035

The hidden desktop never covers a window, so its "never" is 0 either way; the covered case above is where it was.

cargo check -p rune --all-targets: no new warnings. No tests touched.

Hona added 2 commits November 12, 2026 22:06
…, reasons and retries

A window covered from launch drew no frame, so the frame both renderers draw never came and
the window stayed on the CPU until it was uncovered (4,197 ms in the repro; for good behind
another window). The shared frame now draws in sight or not.

Every step has a deadline (Host::watch_handover, Win::handover_deadline wakes the loop):
- Building: the GPU thread runs at normal priority after 500 ms; logged slow after 20 s.
- HandingOver, nothing drawn: a frame is asked for every 100 ms; fails after 5 s.
- HandingOver, drawn: fails if the GPU hasn't finished it in 5 s.
- A failure (also the thread or device failing, or the commit) logs gpu.window.failed with
  gpu.window.why, goes back to the CPU, and retries after 30 s, three tries in all.
D3D12's idle-priority threads are raised when the GPU arrives, not after the hand-over.
Copilot AI balanced review requested due to automatic review settings November 12, 2026 12:07

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. Try requesting a review at a lower effort level.

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 merged commit 89feebd into dev Nov 12, 2026
1 check passed
Hona added a commit that referenced this pull request Nov 12, 2026
… when it's ready

A full-window page no longer waits for WebGPU to draw: the CPU renderer (render::cpu_boot) paints the real view into a 2D canvas under the WebGPU canvas from the module's first frame, and the page is live from it (input, hover, typing and animation on every frame). The WebGPU canvas lies over it, see-through (opacity 0), and takes the input all along. Once the page has drawn nothing for 250 ms (3 s after its first frame at the latest) it asks for the GPU, so the browser makes the adapter and compiles the pipelines after the first frames are up, not while the first one waits to show. Then: a submit after the renderer's pipelines tells when they're built; frames go on drawing into the see-through canvas until every pipeline check has answered; one frame is drawn by both renderers from the same instances; nothing new is drawn until the GPU's is done; then the GPU's canvas shows and the CPU's goes, in one turn (the native hand-over's order, #689/#710/#781). Without WebGPU the page stays on the CPU; a device lost after the hand-over brings the CPU back (the device's glyph masks fill again on the CPU, Atlas::refill_gpu_masks). Pages that are the document or sit inline, and apps with a compositor, start on the GPU as before.

Measured (headless Chromium 1223, 1280x800, rune-desktop's Home): first frame presented 574-916 ms from navigation, was 1,427 on the GPU; the hand-over frame differs from the CPU's in 4,430 of 1,024,000 px by at most 1; a CPU first frame is fill 3 + paint 21 + put 10 ms with wasm SIMD, a typical later frame 0.5 ms.

cpu_boot reads the page's clock (crate::time::Instant). The CPU canvas puts only the changed rectangles, turned into RGBA (wasm SIMD when the build has it) through a buffer in the page's memory (an ImageData over the module's memory took the browser 60-70 ms to put). Rune's marks are the page's performance marks too. globalThis.RUNE_CPU_FIRST = off / only, __runeCpuFrames, __runeDrift and RUNE_LOSE_GPU_AFTER are for measuring harnesses.
Hona added a commit that referenced this pull request Nov 12, 2026
… when it's ready (#809)

* Web: a page draws its first frames on the CPU, and WebGPU takes over when it's ready (WIP)

* Web: a page paints its first frames on the CPU, and WebGPU takes over when it's ready

A full-window page no longer waits for WebGPU to draw: the CPU renderer (render::cpu_boot) paints the real view into a 2D canvas under the WebGPU canvas from the module's first frame, and the page is live from it (input, hover, typing and animation on every frame). The WebGPU canvas lies over it, see-through (opacity 0), and takes the input all along. Once the page has drawn nothing for 250 ms (3 s after its first frame at the latest) it asks for the GPU, so the browser makes the adapter and compiles the pipelines after the first frames are up, not while the first one waits to show. Then: a submit after the renderer's pipelines tells when they're built; frames go on drawing into the see-through canvas until every pipeline check has answered; one frame is drawn by both renderers from the same instances; nothing new is drawn until the GPU's is done; then the GPU's canvas shows and the CPU's goes, in one turn (the native hand-over's order, #689/#710/#781). Without WebGPU the page stays on the CPU; a device lost after the hand-over brings the CPU back (the device's glyph masks fill again on the CPU, Atlas::refill_gpu_masks). Pages that are the document or sit inline, and apps with a compositor, start on the GPU as before.

Measured (headless Chromium 1223, 1280x800, rune-desktop's Home): first frame presented 574-916 ms from navigation, was 1,427 on the GPU; the hand-over frame differs from the CPU's in 4,430 of 1,024,000 px by at most 1; a CPU first frame is fill 3 + paint 21 + put 10 ms with wasm SIMD, a typical later frame 0.5 ms.

cpu_boot reads the page's clock (crate::time::Instant). The CPU canvas puts only the changed rectangles, turned into RGBA (wasm SIMD when the build has it) through a buffer in the page's memory (an ImageData over the module's memory took the browser 60-70 ms to put). Rune's marks are the page's performance marks too. globalThis.RUNE_CPU_FIRST = off / only, __runeCpuFrames, __runeDrift and RUNE_LOSE_GPU_AFTER are for measuring harnesses.
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