Skip to content

sync_heaps 21.7 -> 8.2 ms a frame (ideas of fxceless#1043 ported): 15.1 -> 16.8 fps - #8

Merged
dkdknight merged 8 commits into
dkdknight:feature/levels-on-demandfrom
tibzejoker:claude/sync-heaps
Nov 25, 2026
Merged

dkdknight merged 8 commits into
dkdknight:feature/levels-on-demandfrom
tibzejoker:claude/sync-heaps

Conversation

@tibzejoker

Copy link
Copy Markdown

Built on #4 (so #3 and #2); one commit, 240d464.

descriptor::sync_heaps was the largest piece of the submitting thread here: 21.7 ms a frame (~68,000 slots looked at, ~10,000 mirrored, ~150 changed heap pages), while the card sat ~18 ms a frame waiting on that thread. This ports the ideas of fxceless#1043 (UwUCammie) by hand onto this branch's HostHeap::mirror (its lock-free fast key and the made-lock dropped while a view is made are kept):

  • per-slot flags (in textures / placed / buffers), changed under their set's lock, so note_buffer skips a set's lock when the slot is not in it (a test checks flags and sets agree);
  • no view_at(0,0) when nothing was made in the slot (generations start at 1);
  • no null view written over the same null: only for a buffer view left for later whose slot already holds the null buffer view and was not written since (upstream skips any null over any null, which could change a texture slot's null);
  • the 64 KiB page copy, slot list and due list reused across pages; one lock per page/heap for the fingerprint table instead of one per slot;
  • choosing a page's slots was a contains per slot (quadratic, up to 2,048 a page): now one ordered walk.

Skipped from fxceless#1043: holding made for a whole page (you release it on purpose), batching changed inserts, the heap_buffers changes (they change when a slot is looked at again).

The sync line now also says where the time goes (reading/walking pages, mirror calls, lock waits).

Measured (RTX 4090, i9-13900K, release, settings of #7 incl. VICTORY_BIG_CARD-sized memory, same scene, mean of 11-12 lines once whole, one run):

sync_heaps submit thread at work fps ms/frame
before 21.7 ms 50.5 ms 15.09 66.3
this 8.2 ms (4.6 pages, 3.6 mirror, 0.3 locks) 40.4 ms 16.75 59.7

No device loss; behavior meant to be unchanged (only fewer locks, allocations and redundant writes). Checks: release and diagnostics builds, cargo test -p victory-gpu --lib 182 passed, clippy no new warnings.

🤖 Generated with Claude Code

TG0000 and others added 8 commits November 25, 2026 15:51
…EAP_WORKER=1, off)

The pass over textures picked by index asks what of each due texture is mapped, makes the host
texture, makes a staging buffer and records the copy, on whichever thread of the title records the
frame's first shader that picks textures by index. With a backlog that is up to 250 ms of a frame,
and the threads waiting for that list wait with it.

With VICTORY_HEAP_WORKER=1 (needs VICTORY_LATE_WAIT) the pass runs on a thread of its own and the
recording thread only wakes it. Its uploads go into host lists of our own, which the next late
submission runs ahead of the title's lists; a texture's host slot is given its view at that
submission, not before; the title's texture and heap are held while the worker uses them; the
uploads before the decoration bake stay on the recording thread.

Off by default; the numbers go in the pull request.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
On WARP the second group's draws can win the budget; the test asserts what holds either way,
that the record that is no draw runs empty.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…x uploaded on a thread of their own (VICTORY_HEAP_WORKER=1, off)

Conflicts: both list helpers kept (defer_texture_upload and
refresh_textures_ahead); a staging texture keeps both its last change and
its ahead read, hashed when either says so; this branch's indirect budget
test, bench field and resource cfg kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… per source write

VICTORY_ALIAS_ONCE=1 (off by default). The title writes R9G9B9E5 targets as
R32_UINT and reads them through views placed in the same memory, and every
list that read one copied it again through a buffer: 78 copies a frame,
26-31 ms of the card's time on an RTX 4050 Laptop. A copy a list needs
before it touches the source or the placed texture is now recorded in the
list's prelude at submission (preludes are recorded in the queue's order,
with both textures already in the copy states the list starts with). Each
submission gets a number; lists mark the host copies they put in a writing
state; a prelude leaves a copy out if it ran in a submission after the
source's last write. Copies later in a list stay where they were.

Series X, lit world, with the window, 1080p, copy-queue fetch and rehash
runs switches: 358 -> 333 ms a frame (2.8 -> 3.0 fps); 26 alias copies made
and 20 left out a frame in preludes. The picture looked the same.
…e line

What changed:
- The fingerprint lock is taken once per heap (default path,
  HostHeap::mirror_copied_all) and once per page for the choice of slots
  (HostHeap::slots_to_look_at), not once per slot. Same slots mirrored in
  the same order: making a slot changes no fingerprint and no table stamp.
- The choice of a page's slots no longer looks each slot up in a Vec of
  the moved ones (quadratic per page); it walks the page's slots in order.
- The page copy kept in seen_pages is overwritten in place instead of a
  new 64 KiB Vec per changed page; the slot and due lists are reused.
- HostHeap::mirror: no view_at(0, 0) for a slot with nothing made (it is
  always none: generations start at 1); a buffer view left for later in a
  slot that already holds the null buffer view, written by the same path
  and untouched since (SLOT_NULL_BUFFER, cleared by HostHeap::cpu, which
  every write goes through), skips writing that null again and keep(None).
- Per-slot flags (SLOT_IN_TEXTURES / SLOT_IN_PLACED / SLOT_IN_BUFFERS),
  changed under the set's own lock with every insert and removal, let
  note_buffer skip the texture queue, placed spans and buffer set locks
  for a slot that is not in them (or already in, for buffers). New test
  slot_flags_follow_the_sets.
- Timing: SYNCED gains mirror-call and lock-wait microseconds
  (host::lock_timed: try_lock first, the wait timed only when contended);
  the frame line now says total ms, reading and walking pages, mirror
  calls, and lock waits.

Ported by hand from fxceless#1043 (author UwUCammie): the slot flags,
skipping view_at(0, 0), the null-over-null skip, buffer reuse across
pages, one lock per page. Kept this branch's mirror design (fast key
without the lock, made lock dropped while the view is made).

Skipped:
- Taking the made lock once per page: this branch drops it while views are
  made so recording threads do not wait behind the sync; holding it for a
  page would bring that wait back.
- Null-over-null for every view kind: upstream skips any null; here only
  when the slot is known to hold the very same null (buffer view), so a
  texture slot's null keeps its dimension.
- Batching `changed` inserts per page: needs the batch threaded through
  mirror and note_buffer for one uncontended lock per buffer mirror.
- heap_buffers (draw.rs): not re-queuing slots it mirrors and reusing the
  shadow found by make() change when the buffer pass looks at a slot again
  and need make() to return the copy through every view kind; not on the
  sync_heaps path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dkdknight
dkdknight merged commit 8a738ef into dkdknight:feature/levels-on-demand Nov 25, 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.

6 participants