Repository navigation
Moving many objects: the patch's writes reach the GPU queue joined, not one per object - #3462
Merged
HakanSeven12 merged 2 commits intoNov 23, 2026
Merged
Conversation
A patch of the wire arena or of the analytical slots sends each changed object to the queue as a write of its own. These tests ask for pieces lying side by side to go out as one write, for a hidden circle or ellipse to be written whole so that a run of them joins too, and for a patch left with more separate writes than a rebuild costs to say so. The patches now collect their writes in a batch, which still passes each one on as it came: the tests fail. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Moving 100,000 objects took 1.5 s to show on Direct3D 12, one second of it in `Queue::write_buffer`: the wire arena wrote each object's instances on their own, and the analytical slots each circle. The queue makes a staging buffer for every call, about 11 µs each there and 1.5 µs on Vulkan whatever the size, so 86,000 writes cost far more than their bytes, while building the same buffers again takes a tenth of a second. A patch now collects its writes and sends them at its end, in buffer order, each run of pieces lying side by side as one write. The constants of an appended or resized slab go with the merged constant upload the arena already had. A hidden circle or ellipse is written whole, as a shown one is, so a run of hidden ones joins as well; only its depth is read while it is hidden. Objects apart in the buffer still need a write each. When more than a few hundred are left and they outnumber a thirty-second of the buffer's instances, the patch reports that the rebuild is cheaper, and the existing fallback builds the buffers again. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
How it shows up
Refs #3231, for its second point: "a lot of lag when copying, moving and stretching groups". There is no file there, so this is a synthetic drawing of 100,800 objects (14,400 cells of five lines, a circle and a text). With the 100,440 in view selected, MOVE takes 1.5 s to show its result on Direct3D 12 and 0.7 s on Vulkan, and Undo takes the same again.
Cause
A move keeps the shape of every object, so the retained GPU buffers are patched in place. Both patches send each object to the queue as a call of its own:
WireArena::patch, and the packed variant): oneQueue::write_bufferper changed object, 72,000 here;AnalyticSlots::apply): one per circle, 14,400 here.wgpu makes a staging buffer for every
write_buffercall. On this machine a call takes about 11 µs on Direct3D 12 and 1.5 µs on Vulkan, whatever its size from 4 bytes to 1 KiB, and about as long again when the queue frees the staging buffer. Building the whole wire arena again takes 14 ms for these 72,000 instances (arena-build-detail).The change
src/scene/pipeline/gpu_upload.rs:WriteBatchcollects the pieces a patch writes into one buffer and gives them back in buffer order, each run of pieces lying side by side as one write. Pieces over the same bytes go out one by one as they came.wire_arena.rs, both arenas: the instances of a patch go through a batch and reach the queue at the end of the patch. The constants of an appended or resized slab go with the merged constant upload the arena already has (merge_const_ranges).analytic_slots.rs: the same for the block, circle and ellipse buffers. A hidden circle or ellipse is now written whole, as a shown one is, so a run of hidden ones joins too. Only its depth is read while it is hidden (apply_draw_ordersends it outside the clip volume), and showing it again writes every field.rebuild_is_cheaper: when more than 256 separate writes are left and they outnumber a thirty-second of the buffer's instances, the patch says so (falsefrom the arena,Errfrom the slots) and the existing fallback builds the buffers again. A patch that gives up part-way has written nothing.Measured
Release builds, Windows 11, RTX 3070,
PERF=1.mainis 0ca0345 with the lock file of #3459 so that it builds. "Frame" isnav-prepare elapsed, from the command to the prepared frame; each cell is one run.The drawing of 100,800 objects, Direct3D 12, two runs of each build:
main[perf] wire)analytic-patch)The same on Vulkan, one run of each:
mainA second drawing of 90,000 objects on eight layers (walls, hatches, arcs, circles, texts). A layer of 10,000 circles switched off and on: its circles lie apart in their buffer, between the arcs of another layer, so this is the case that goes to the rebuild.
mainWhat is left of the MOVE frame is not touched here: about 270 ms to tessellate the moved objects again (
resident-patch) and about 190 ms in the command.Same picture
The same view captured after each step in both builds: MOVE of everything, its undo, ERASE of everything, its undo, MOVE of scattered objects, its undo (11 captures), and on the second drawing an erase of scattered objects, its undo and two layers off and on (6 captures). In the first drawing's captures the drawing area is the same pixel for pixel. In the second drawing's, one pixel is one level of 255 apart between the two builds, the same pixel in all six, the undone states included.
mainTests
The tests are the first commit, with the patches already going through a batch that passes each write on as it came; the change is the second.
gpu_upload.rs:pieces_side_by_side_go_out_as_one_write,pieces_apart_stay_apart_and_go_out_in_buffer_order,pieces_over_the_same_bytes_go_out_one_by_one_as_given,an_empty_piece_is_no_write,many_separate_writes_cost_more_than_the_rebuild.analytic_slots.rs:curves_side_by_side_are_one_write,hidden_curves_side_by_side_are_one_write,block_placements_are_joined_within_their_own_arena.gpu_tests.rs, needs a GPU adapter:a_wire_patch_of_many_scattered_objects_asks_for_the_rebuildpatches 4,096 lines in both arenas: every one (one write), one in 64 (64 writes) and every other (2,048 writes, which asks for the rebuild). Run here on the RTX 3070 withblock_edits_preserve_cache_coordinates_and_arena_partition: both pass.gpu_upload, three ofanalytic_slotsand the GPU one.cargo test --workspace --no-fail-fast, with the lock file of Cargo.lock: gpu-allocator is back on thewindowscrate wgpu-hal uses, somainbuilds on Windows #3459: 7,763 passed, 1 failed, 50 ignored.app::control::spellcheck::tests::speller_survives_com_unload_reload_cyclesfails the same way onmainon this machine.cargo check --target wasm32-unknown-unknown --libpasses.Limits
maindoes until Cargo.lock: gpu-allocator is back on thewindowscrate wgpu-hal uses, somainbuilds on Windows #3459 is in.OCS
mainat 0ca0345, Windows 11.🤖 Generated with Claude Code