Skip to content

Windows: the first GPU frames after the hand-over record on warmed D3D12 command allocators - #1082

Closed
Hona wants to merge 12 commits into
devfrom
ib-3-allocator-pool
Closed

Hona wants to merge 12 commits into
devfrom
ib-3-allocator-pool

Conversation

@Hona

@Hona Hona commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Closed, 19 Nov 2026: not merged

Decision: closed by the orchestrator at 00:33. Rune #1140 (pinned pipelines, merged in 78efd4a7) stands.

Why: the pass line was set before the results: a hand-over no later than dev's at two and four P-cores, no slower key, and a saving over the first three GPU frames of at least one 240 Hz refresh (4,167 µs). No arm met all three.

  • Windows: the first GPU frames after the hand-over record on warmed D3D12 command allocators #1082 as built keeps the saving but hands over 15.8-18.4 ms later. Its warm-up records the window's frame six times on the GPU thread before the hand-over (3 encoders × 2 rounds), about 2-4 times the allocator work dev meets after the hand-over.
  • The two cut-down arms hand over on time at four cores but 5.3-6.3 ms late at two. They keep 2,153.8-3,672.2 µs of the saving, under one refresh. They save the first frame and pay part of it back on the second.
  • What didn't change in any arm: the first real pixels (the CPU painter's first frame) and the first input the window can handle.

The four arms were shipping builds (release: fat LTO + PGO trained at 5877e042). Each is rune-desktop ef07741a with only the Rune pin moved, built with bun harness/measure-exe.ts <sha> --profile release:

Arm rune-desktop build Rune
base ef07741a 78efd4a7
#1082 as built 5071fd7a 78efd4a7 + 4e9a2373
1x2: the pool + one warm allocator through two cycles 5c0cf253 ff8123a0 = 78efd4a7 + 439dff53
pool only: the pool + dev's single warm frame c51ee6e8 e51e582a = 78efd4a7 + 560b6be2

Hand-over, ms from process start, p50 [range], ten tabs, the app pinned to P-cores:

Arm Two P-cores Four P-cores
base 200.7 [194.2-246.8] 174.9 [163.9-184.6]
#1082 219.1 [217.4-222.3] 190.7 [183-199.6]
1x2 206 [200.5-234.1] 171.1 [166-188.4]
pool only 207 [195.5-219.7] 170.5 [162.1-181]

The first three GPU frames after the hand-over, unpinned, wall µs, median of 8 (first / second / third):

Profile base #1082 1x2 pool only
Home 4,268.5 / 3,133.3 / 2,835.6 2,436.3 / 1,595.9 / 1,503.3 2,389.3 / 3,412.6 / 1,718.7 2,655.4 / 3,469.9 / 1,958.1
Restored session 4,146.6 / 2,712.2 / 2,227.6 2,119.8 / 995.1 / 1,405.3 1,774.4 / 2,414.3 / 1,225.6 1,928.9 / 2,337.6 / 1,250.3
Ten tabs 3,951.5 / 2,708.8 / 2,539.6 2,360.4 / 1,072.9 / 1,455.5 2,081.6 / 2,811.2 / 2,019.1 1,839.7 / 2,590.3 / 1,296.5

Ten-tabs key posted at +0, two P-cores, µs p50 [range]: base 5,452.9 [4,511.4-7,157.2], #1082 5,313.5 [4,512.4-5,761.5], 1x2 5,159.9 [4,655.7-5,623.3], pool only 4,755.5 [4,601.3-5,865.9]. None is slower, and no arm missed at either core count (limit: the arm's own median + 4,167 µs).

Dirt:

  • One launch per arm near a logged proof-farm tick was left out (n=7 where shown).
  • 4 of the 40 two-core launches are unpaired.
  • The owner's own OpenCode used 21-25% of the GPU at each window's start.
  • No floor or reference row was measured.
  • The fixture server stayed up through both windows.

Not proved:

  • What is on screen frame by frame: no pixel capture.
  • The frames after the third.
  • Recovery from a removed device: dxcap -forcetdr resets the driver for every program on the machine, so it is never run on the owner's machines. The RemoveDevice measuring build was not run.
  • Any number on an RTX or AMD adapter.

Proofs: proof\ib-3\four-takes-ef07, four-aff2-ef07, four-aff4-ef07 (this ticket); proof\ib-3\ship-takes-ef07, ship-aff4swap-ef07 (the earlier shipping ticket); proof\ib-3\allocator-opens (the per-list cost). Analysis: notes\ib-3-status.md in the operation-detox workspace.


The first two GPU frames after the Windows CPU-to-GPU hand-over cost 7-17 ms instead of 1.6-2.0 ms. The cost is in D3D12 command allocators, not back buffers: an allocator's first two cycles at a given number of lists cost about 0.5 ms a list on an Iris Xe, later ones about 20 µs.

flowchart LR
  W[GPU thread: warm_frame<br/>3 encoders x 2 rounds<br/>finished, then submitted<br/>+ one empty pass] --> P[(device allocator pool<br/>frames / pending writes)]
  P -->|most-recorded free allocator| F[UI thread: frame N]
  F -->|reset_all after the GPU| P
Loading

Change

  • vendor/wgpu-hal dx12: a CommandEncoder takes an allocator (with its lists) from DeviceShared::allocators as it begins and gives it back in reset_all. Frames get the free one that has recorded the most. wgpu's PendingWrites encoder keeps its own class and never takes a frame's allocator; a frame may take a pending-writes one before a new one is made. An allocator's class is set by what its cycle recorded. vendor/wgpu-hal.patch regenerated against wgpu-hal 30.0.1 (it reproduces vendor/wgpu-hal/src).
  • window/cpu_frame.rs warm_frame: records the window's frame on 3 encoders at once, 2 rounds, plus one empty pass. A render pass is two lists in wgpu-core 30, so a warm frame has one list more than a window's frame; an allocator is past its slow cycles for as many lists as it has had (measured: 8 extra empty passes took a first tab switch's list/allocator calls from 5,440 to 370 µs; those passes are not in this PR). Each round's frames are finished before any is submitted, so a round warms three different allocators. A frame may take a pending-writes allocator before making one; pending writes never take a frame's.

Why

Each command-list open, with its allocator, on Home (proof/ib-3/allocator-opens, Iris):

Cycle of an allocator at that list count Median p90
1st (CreateCommandList) 560-630 µs 0.9-1.0 ms
2nd (Reset) 570-630 µs 0.85-1.0 ms
3rd and later 18-21 µs 40-50 µs

wgpu-core keeps one allocator per encoder in a LIFO pool, and its pending-writes encoder swaps through the same pool, so frames 0-9 meet three new frame allocators, each slow twice. 2 vs 3 swap-chain buffers made no difference.

Results

At this head's code, 3 encoders x 2 cycles. "After" is a release-quick OpenCode build of Rune 73cba479: 34127a27 (this head's code; 4e9a2373 adds only the regenerate script's checks and the changelog) plus a stderr log of allocator takes. Exe 9EB1A7CD11C2, rune-desktop b22a2521 repinned. "Before" is release-quick rune-desktop b22a2521 (Rune 0796df5f), exe 13A5D6A3687B. Release-quick builds, not the shipping build (fat LTO + PGO). Iris Xe, 1280x800, whole-window redraws, n=8 launches per build and profile (n=7 where a launch moved before frame 12). Wall µs, median. The warm rows are each profile's floor: what a frame costs there once nothing is cold.

Profile Frame Before After
Home first after hand-over 4,057 2,871
Home second 2,548 1,816
Home warm 1,222 1,313
Restored session first 10,488 3,928
Restored session second 8,330 2,668
Restored session warm 2,583 2,382
Ten tabs first 15,103 3,361
Ten tabs second 13,896 2,048
Ten tabs warm 2,293 2,207

"Before" comes from an earlier ticket (proof/ib-3/allocator-pool-redraw, same exe). "After" comes from the ticket that also ran 3bf0d749 and 6482ec4e (proof/ib-3/takes).

Allocator takes in the first second after the hand-over (median per launch, every profile):

  • 3bf0d749 and this head: pending writes make one new allocator; frames make none.
  • 6482ec4e (two-way fall-back, superseded): pending writes took a warmed frame allocator once, and a frame then made a cold one once. That's why the fall-back is one way here.
  • First-frame medians at the three builds are within 0.3 ms of each other.
Cost, this head's code Before After
Hand-over after first present (median, ms) 138-171 216-259 in the takes ticket; 180-210 in the key-cell ticket
Private bytes at rest, Iris / RTX (MB) 66.6 / 213.1 67.7 / 216.4
GPU memory at rest, Iris / RTX (MB) 34.7 / 182.5 35.6 / 185.0

Memory: memprobe 12.5 s after launch, Home, release-quick, n=3 per cell except the RTX after (n=2: the capture loop ended after three windows), proof/ib-3/head-4e9a-footprint. Each warmed allocator keeps its lists, about a dozen, for the device's life.
macOS, Linux and the web don't run this code (cpu_frame.rs and the dx12 backend are Windows-only).

Key cells at 66c3bfe5 (3 encoders x 2 cycles, the same warm-up as this head), release-quick, not the shipping gate. Click and key posted together at +0/+100/+200 ms after uncloak, n=10 a cell, both builds alternating in the same quiet windows. Key handled, µs: median / max / misses over the build's rest + 4,167.

Profile Cell Before After
Home +0 3,286 / 6,147 / 1 4,034 / 5,039 / 0
Home +100 1,582 / 2,713 / 0 1,683 / 3,217 / 0
Home +200 1,451 / 1,761 / 0 1,771 / 6,462 / 1
Restored +0 4,675 / 23,862 / 2 3,997 / 5,337 / 0
Restored +100 3,995 / 5,828 / 0 4,572 / 9,133 / 1
Restored +200 3,355 / 4,381 / 0 2,933 / 3,894 / 0
Ten tabs +0 4,340 / 13,184 / 2 4,657 / 12,289 / 1
Ten tabs +100 3,614 / 6,799 / 0 4,208 / 6,326 / 0
Ten tabs +200 2,956 / 7,831 / 1 3,159 / 8,044 / 1

Misses across the nine cells: 6 before, 4 after. Hand-over: 138-171 ms after the first present before, 180-210 ms after.

What the later hand-over costs a user

The hand-over comes about 40 ms later at 3 x 2 (138-171 → 180-210 ms after the first present). Until then, the CPU painter draws the window:

  • Fully interactive for most frames: clicks, keys, scrolling, text and images are handled and drawn. The CPU painter draws the same instances, glyph masks and images as the GPU, and the drift check counts any pixel the GPU frame changes at the hand-over.
  • Not drawn by the CPU painter: a frame that needs a blurred or isolated layer, a backdrop blur, a compositor effect, a native surface (video) or a glyph drawn from its outline. That frame keeps the last frame on screen until the GPU takes over, up to about 40 ms longer than before.
  • The CPU frames a key waits behind cost 3.9-5.1 ms on session profiles (2.4-3.6 ms of that is the app's view, commit and layout, not the painter). That's why the key cells above don't improve yet.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 16: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.

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

Head moved to 54ef73f (WARM_ENCODERS 4 -> 3, WARM_ROUNDS 3 -> 2; changelog). PROOF-FARM: please run the Windows suite on this head; nothing in the vendored wgpu-hal changed since cab3325.

@Hona

Hona commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Head moved to 66c3bfe: warm_window orders the start-up warm-up (layer-pipeline step empty until FRAME-PERF fills it). PROOF-FARM: please test this head.

@Hona

Hona commented Nov 17, 2026 •

Copy link
Copy Markdown
Member Author

Windows whole suite (-p rune -p rune-kit) on adais, judged against dev's own failures at 32eb7811 (this lane, whole suite) and eb5ae6c9 (FUNCTION's run, rune only) and 3468f3a3 and cca5df6f: #1082 66c3bfe 66c3bfe5 (18 Nov 00:45): 2836 passed, 17 failed in 170 binaries; also on dev: alloc::disabled_trace_hooks_neither_format_nor_allocate, canvas_input::the_middle_button_drags_only_elements_that_take_it, rune::edit::tests::hidden_multiline_pristine_replace_and_delete, rune::edit::tests::pill_edge_cases_words_lines_bidi_and_direct_text_mutation, rune::edit::tests::the_caret_steps_over_a_pill_in_one_move, rune::input::keycaps::tests::repeated_chords_count_and_named_keys_use_glyphs, rune::native_surface::gpu_tests::mirrored_video_is_exact_cropped_centred_and_toggles_without_a_new_frame, rune::native_surface::gpu_tests::video_gpu_colour_sharpness_geometry_and_lifetime, rune::render::breaker::tests::a_refused_blur_pipeline_draws_unblurred, rune::render::layers::cache_tests::live_scale_zoom_sweep_buckets_during_motion_and_settles_crisp, rune::render::layers::rebind_tests::a_texture_switch_binds_no_parked_target_until_one_returns, rune::render::layers::tests::clipped_single_draw_fades_do_not_allocate_targets, rune::runtime::tests::layout_rows::send_flight_follows_the_measured_bubble_while_earlier_rows_land, rune::runtime::tests::picture_scale::a_changing_static_scale_keeps_the_glyph_atlas_bounded, rune::runtime::tests::picture_scale::text_inside_a_scale_draws_at_that_size, rune::text::macos::smoothing::tests::pipelines_never_share_masks, selectable_text::copy_select_all_and_the_context_menu; none new. Base 0796df5f. Proof 3c971b05.

Hona added 2 commits November 18, 2026 03:15
…eaves the pool, warm frames finished before submitting, and a regenerate mode for the wgpu-hal patch
@Hona

Hona commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Head moved to 5e741b1 for the review's fixes (notes/review-1082.md): the empty layer-pipeline step is removed; allocators are classed by what a cycle recorded, with the label only as a first guess; a failed allocator reset leaves the pool; warm frames are finished before any is submitted (three distinct allocators by construction); 8 spare passes per warm frame (first tab switch 5,440 -> 370 us of list/allocator calls); scripts/vendor-wgpu-hal.sh --regenerate. PROOF-FARM: please test this head.

@Hona

Hona commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Windows whole suite (-p rune -p rune-kit) on adais, judged against dev's own failures at 32eb7811 (this lane, whole suite) and eb5ae6c9 (FUNCTION's run, rune only) and 3468f3a3 and cca5df6f: #1082 5e741b1 5e741b1d (18 Nov 06:43): 2835 passed, 18 failed in 170 binaries; also on dev: alloc::disabled_trace_hooks_neither_format_nor_allocate, canvas_input::the_middle_button_drags_only_elements_that_take_it, rune::edit::tests::hidden_multiline_pristine_replace_and_delete, rune::edit::tests::pill_edge_cases_words_lines_bidi_and_direct_text_mutation, rune::edit::tests::the_caret_steps_over_a_pill_in_one_move, rune::input::keycaps::tests::repeated_chords_count_and_named_keys_use_glyphs, rune::native_surface::gpu_tests::mirrored_video_is_exact_cropped_centred_and_toggles_without_a_new_frame, rune::render::breaker::tests::a_refused_blur_pipeline_draws_unblurred, rune::render::layers::cache_tests::cache_matches_uncached_at_rest_and_skips_rerasterize_on_ancestor_live_offset, rune::render::layers::cache_tests::live_scale_zoom_sweep_buckets_during_motion_and_settles_crisp, rune::render::layers::filter_tests::filtered_video_and_image_page_match_primitive_source, rune::render::layers::rebind_tests::a_texture_switch_binds_no_parked_target_until_one_returns, rune::render::layers::tests::clipped_single_draw_fades_do_not_allocate_targets, rune::runtime::tests::layout_rows::send_flight_follows_the_measured_bubble_while_earlier_rows_land, rune::runtime::tests::picture_scale::a_changing_static_scale_keeps_the_glyph_atlas_bounded, rune::runtime::tests::picture_scale::text_inside_a_scale_draws_at_that_size, rune::text::macos::smoothing::tests::pipelines_never_share_masks, selectable_text::copy_select_all_and_the_context_menu; none new. Base 0796df5f. Proof 53ba9339.

Hona added 2 commits November 18, 2026 06:45
…e, and the patch regenerates only against the vendored version with git's diff options pinned and the vendored bytes kept as committed
@Hona

Hona commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Head moved to 6482ec4 (review re-read, notes/review-1082.md): the eight spare passes are reverted (f691727) and come back as their own PR on idle turns after the hand-over; a take falls back across classes before a new allocator is made (no allocator stranded if labels are ever dropped; Rune's instance flags never include DISCARD_HAL_LABELS, built without with_env()); the regenerate mode checks the version against vendor/wgpu-hal/Cargo.toml, pins git's diff options, and .gitattributes keeps vendor/wgpu-hal/** and *.patch byte-exact (-text: the published crate has one CRLF file). PROOF-FARM: please test this head.

@Hona

Hona commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Windows whole suite (-p rune -p rune-kit) on adais, judged against dev's own failures at 32eb7811 (this lane, whole suite) and eb5ae6c9 (FUNCTION's run, rune only) and 3468f3a3 and cca5df6f: #1082 6482ec4 6482ec4e (18 Nov 07:35): 2836 passed, 17 failed in 170 binaries; also on dev: alloc::disabled_trace_hooks_neither_format_nor_allocate, canvas_input::the_middle_button_drags_only_elements_that_take_it, rune::edit::tests::hidden_multiline_pristine_replace_and_delete, rune::edit::tests::pill_edge_cases_words_lines_bidi_and_direct_text_mutation, rune::edit::tests::the_caret_steps_over_a_pill_in_one_move, rune::input::keycaps::tests::repeated_chords_count_and_named_keys_use_glyphs, rune::native_surface::gpu_tests::mirrored_video_is_exact_cropped_centred_and_toggles_without_a_new_frame, rune::native_surface::gpu_tests::video_gpu_colour_sharpness_geometry_and_lifetime, rune::render::breaker::tests::a_refused_blur_pipeline_draws_unblurred, rune::render::layers::cache_tests::live_scale_zoom_sweep_buckets_during_motion_and_settles_crisp, rune::render::layers::rebind_tests::a_texture_switch_binds_no_parked_target_until_one_returns, rune::render::layers::tests::clipped_single_draw_fades_do_not_allocate_targets, rune::runtime::tests::layout_rows::send_flight_follows_the_measured_bubble_while_earlier_rows_land, rune::runtime::tests::picture_scale::a_changing_static_scale_keeps_the_glyph_atlas_bounded, rune::runtime::tests::picture_scale::text_inside_a_scale_draws_at_that_size, rune::text::macos::smoothing::tests::pipelines_never_share_masks, selectable_text::copy_select_all_and_the_context_menu; none new. Base 0796df5f. Proof e272459a.

…ns git without the user's or system's config
@Hona

Hona commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Head moved to 4e9a237 (third read, notes/review-1082.md): the fall-back is one way (a frame may take a pending-writes allocator; pending writes stay in their class and make a new one); patch regenerated; the regenerate script refuses converted line endings and runs git without user/system config. PROOF-FARM: please test this head.

@Hona

Hona commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Windows whole suite (-p rune -p rune-kit) on adais, judged against dev's own failures at 32eb7811 (this lane, whole suite) and eb5ae6c9 (FUNCTION's run, rune only) and 3468f3a3 and cca5df6f: #1082 4e9a237 4e9a2373 (18 Nov 08:46): 2836 passed, 17 failed in 170 binaries; also on dev: alloc::disabled_trace_hooks_neither_format_nor_allocate, canvas_input::the_middle_button_drags_only_elements_that_take_it, rune::edit::tests::hidden_multiline_pristine_replace_and_delete, rune::edit::tests::pill_edge_cases_words_lines_bidi_and_direct_text_mutation, rune::edit::tests::the_caret_steps_over_a_pill_in_one_move, rune::input::keycaps::tests::repeated_chords_count_and_named_keys_use_glyphs, rune::native_surface::gpu_tests::mirrored_video_is_exact_cropped_centred_and_toggles_without_a_new_frame, rune::native_surface::gpu_tests::video_gpu_colour_sharpness_geometry_and_lifetime, rune::render::breaker::tests::a_refused_blur_pipeline_draws_unblurred, rune::render::layers::cache_tests::live_scale_zoom_sweep_buckets_during_motion_and_settles_crisp, rune::render::layers::rebind_tests::a_texture_switch_binds_no_parked_target_until_one_returns, rune::render::layers::tests::clipped_single_draw_fades_do_not_allocate_targets, rune::runtime::tests::layout_rows::send_flight_follows_the_measured_bubble_while_earlier_rows_land, rune::runtime::tests::picture_scale::a_changing_static_scale_keeps_the_glyph_atlas_bounded, rune::runtime::tests::picture_scale::text_inside_a_scale_draws_at_that_size, rune::text::macos::smoothing::tests::pipelines_never_share_masks, selectable_text::copy_select_all_and_the_context_menu; none new. Base 0796df5f. Proof a8af0e45.

@Hona Hona closed this Nov 18, 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