Skip to content

Windows: a window's first frame is drawn on the CPU and shown before its GPU exists; the GPU takes over when it's ready - #689

Merged
Hona merged 1 commit into
devfrom
ib-3-cpu2
Nov 11, 2026
Merged

Hona merged 1 commit into
devfrom
ib-3-cpu2

Conversation

@Hona

@Hona Hona commented Nov 11, 2026

Copy link
Copy Markdown
Member

A Windows window now shows its first frame without waiting for a GPU. The CPU renderer draws frames until the GPU is ready, and then the GPU takes over with no visible change.

What changes

  • First frame: an opaque window opens with no GPU. The CPU renderer (cpu_boot's live painter) paints frame 1 into a DIB section the size of the display, with a fixed row length. A worker touches the first rows of the DIB while the frame is laid out.
  • Show: the window shows cloaked and takes the frame, one BitBlt per changed rect. It then uncloaks and activates. The cloak is needed because GDI draws nothing into a hidden window, and DWM composes a window that just showed with whatever its surface holds (white).
  • Live on the CPU: input, hover, scrolling and motion go through the runtime as they do on the GPU. Each later frame copies the bounding box of its changed rects in one BitBlt. An unchanged frame copies nothing.
  • Hand-over: after frame 1, a thread at below-normal priority makes the device and a swap chain on a DirectComposition visual that isn't committed yet. Both renderers draw the same frames until a GPU frame finishes. Then the visual is committed, and a worker frees the CPU buffer after it counts the pixels that differ from the GPU frame. A lost device rebinds on the same visual.
  • Also:
    • The UI Automation adapter is made after frame 1, unless a screen reader is running.
    • Scenes pass .compositor(..), and the half-float rounding of the primary display's GPU (the adapter's own once the GPU exists).
  • Switches:
    • RUNE_CPU_FIRST=0 turns this off.
    • RUNE_CPU_FIRST=only keeps the window on the CPU, to check the CPU path alone.
    • RUNE_CPU_COLOUR=1 fills the window with its clear colour first (CpuPainter::window_shows). It's off: it gave no gain on a small window.
  • When the window opens on the GPU as before: the window is transparent, or another window already has a live GPU.

Measured (visible desktop, Iris Xe, 2560x1440 at 150%, 982x656 window, Desktop Duplication watching it)

CPU first GPU first (RUNE_CPU_FIRST=0)
Window shown, ms after launch 75-103 187-251
First frame in process (frame.first.cpu / .presented), p50 µs 63,322 203,541
Resize step, SetWindowPos blocks the caller, p50 / p90 µs 3,900 / 7,065 51,501 / 86,813
Frames left unfilled during 40 resize steps 0 1 (47,000 px black)
  • Hand-over: in 24 of 24 launches with frames captured, the composed frame at the swap changed 0 px. The drift count at each hand-over: 2 of 576,000 px differ, by at most 1/255.
  • Tearing: one BitBlt per rect tore 1-15 frames in 600 on the visible desktop. One per frame (the bounding box) tore none.
  • Activation: activation costs 37-46 ms on the visible desktop, almost all inside DefWindowProc(WM_ACTIVATE)'s focus change (TSF). A bare Win32 window pays the same cost. It comes after the frame is on screen.

Checked: cargo check --workspace --all-targets --keep-going.

…its GPU exists; the GPU takes over when it's ready

An opaque window opens with no GPU. The CPU renderer (cpu_boot's live painter) paints frame 1 into a display-sized DIB section with a fixed row length, its first rows touched on a worker during layout. The window shows cloaked (GDI draws nothing into a hidden window, and DWM composes a just-shown window white), takes the frame rect by rect, uncloaks, then activates. Later frames copy their rects' bounding box in one BitBlt, which doesn't tear.

After frame 1 a below-normal thread makes the device and a swap chain on an uncommitted DirectComposition visual. Both renderers draw the same frames until a GPU frame finishes; the visual is then committed, and the CPU buffer is freed after a drift count against that GPU frame. A lost device rebinds on the same visual. The UI Automation adapter is made after frame 1 unless a screen reader is running.

Scenes pass the compositor flag and the half-float rounding of the primary display's GPU (then the adapter's own); an unchanged frame copies nothing. RUNE_CPU_FIRST=0 turns it off; RUNE_CPU_FIRST=only keeps the window on the CPU, for checking it alone; RUNE_CPU_COLOUR=1 fills the window with its clear colour first and lets the painter skip those tiles (measured no gain on a small window; kept off).
Copilot AI balanced review requested due to automatic review settings November 11, 2026 23:03
@Hona
Hona merged commit 223a965 into dev Nov 11, 2026
1 check passed

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 deleted the ib-3-cpu2 branch November 11, 2026 23:04
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