Skip to content

GPU: heap buffer pass looks only at marked slots; time split in the fps line - #467

Open
LeonardoS11 wants to merge 2 commits into
fxceless:mainfrom
LeonardoS11:perf/heap-pass
Open

LeonardoS11 wants to merge 2 commits into
fxceless:mainfrom
LeonardoS11:perf/heap-pass

Conversation

@LeonardoS11

@LeonardoS11 LeonardoS11 commented Nov 25, 2026 •

Copy link
Copy Markdown

Draft until the still-scene A/B and the whole test suite on a GPU are done (see Not tested).

Problem

The heap buffer pass (heap_buffers in draw.rs, once a frame, inside a list call of a recording thread) serves shaders that pick a buffer by its index in the descriptor heap. Every 16 passes it looked at every view in the heap again (about 81,000 in the title's world, each with a mirror, a lock and a shadow::find), and on every pass it rebuilt the spans of the roughly 4,100 host copies from all the views. Its time was reported as one number that also contains the textures picked by index, so it could not be told what the buffer part cost.

What is in it

One commit on main (c96b4f2), five files:

  • crates/victory-gpu/src/heap_pass.rs (new, no D3D12, unit tested): which slots a pass has to look at. A slot is looked at again only when
    • it was written since the last pass (the changed set, as before),
    • the view-table entry it names was let go (descriptor::forget now notes the entries; take_forgotten),
    • its 12-byte record in title memory changed since the last visit (a compare without a lock: catches descriptors copied outside the API),
    • it has no host copy yet (tried again every 16 passes, as before);
    • and every slot every 256 passes, as a safety net.
      A copy's span is recomputed only when one of its slots leaves it.
  • draw.rs, descriptor.rs, host.rs, lib.rs: the pass uses it; the fps line splits the pass:
    heap buffers N passes X ms (marked|full: S slots looked at A ms, C copies refreshed B ms, textures T ms).
  • VICTORY_HEAP_PASS_FULL=1 keeps the old pass, for comparison.

Tested

Result

No measurable change in frame time so far. In the same runs the pass took 105–456 ms a frame, of it 88–338 ms the textures picked by index (heap_textures, 1,700–4,000 slots waiting each pass), which this PR does not touch, and 14–218 ms the slots. The runs before and after did not go through the same scene, so no frame-time number is claimed. What the PR gives today is the buffer part bounded by what changed, and the split that shows the texture part is the one to look at next.

Not tested

  • A/B with VICTORY_HEAP_PASS_FULL=1 on a still scene (a checkpoint for that exists now; to be added here).
  • The whole suite on a GPU for the rebased head (cargo test --workspace); before the rebase it passed with the stack named above.
  • Whether a view can stay stale for up to 256 passes where the old pass caught it within 16 (a buffer made later, in-place copies let go). The counter "buffer views of the heap whose slot showed another copy" should stay 0; not checked over a long run.
  • AMD / Intel cards.

AI use

Claude Code: Claude Opus 5.5 wrote the change and its tests; Claude Fable 5.2 rebased it, ran the measurements and wrote this description. Run in the title by the author on the hardware above.

@ryotdev

ryotdev commented Nov 25, 2026

Copy link
Copy Markdown

A dormant descriptor heap can accumulate freed indices indefinitely in Picked::note_forgotten. The broadcast in draw.rs reaches every cached heap, but only the heap passed to plan drains its list. The global limit on a single broadcast leaves the per-heap total unbounded.

I reproduced this on 37272aea with two initialized heaps. I sent both heaps 2,048 batches of 1,024 indices and called plan only on the active one. The active heap ended with zero pending indices. The dormant heap retained 2,097,152 entries (8 MiB of elements), even though I used the same index throughout.

A per-heap cap that switches to the existing full-rescan state on overflow fixed the regression locally. The next bind enumerated all slots, and the four existing tests still passed. This was an AI-assisted synthetic Rust test using the PR's heap_pass.rs; it needs no game files or GPU.

victory-local and others added 2 commits November 25, 2026 10:51
…t counts in the fps line

The pass for shaders that pick buffers by index looked again at every
buffer view of the heap (81,000 in the world) every 16 passes and rebuilt
every copy's span from all views every pass. Now (heap_pass.rs) a slot is
looked at again when its view was written, its view table entry was freed
(descriptor::forget, which leaves the record as it was), its record in
title memory differs from the one last seen (a 12-byte compare), or it
found no host copy (every 16 passes); all slots every 256 passes as a
safety net. A copy's span is worked out again only when one of its slots
went. VICTORY_HEAP_PASS_FULL=1 brings back the old pass for A/B.

The fps line now splits the pass's time: slots looked at, copies
refreshed, and the texture side (heap_textures, bounded at 250 ms a pass),
with the slots and copies per frame and the mode (marked/full).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… not run

Every heap's pass is told of the freed view table entries at the pass of
the heap that asks, but only the heap whose pass runs drains its list: a
heap the title stopped drawing with kept every entry (a review reproduced
2,097,152). Now only entries some slot's record named at its last look
are kept (the others change nothing), at most 65,536; past that the list
is dropped and that heap's next pass looks at all its slots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LeonardoS11

LeonardoS11 commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

@ryotdev thank you — that is a real leak, and it is fixed in dfb8ee3, now on this branch:

  • note_forgotten keeps an entry only if some slot of that heap named it the last time the heap was looked at (by_entry); an entry nothing named changes nothing and is not kept. Your two-heap case (2,097,152 entries nothing named, sent to a heap that is never planned) now keeps 0.
  • What is kept is at most 65,536 entries a heap (FORGOTTEN_MOST). Past that the list is dropped and that heap's next pass looks at all of its slots, which is always correct.
  • New test a_dormant_heap_keeps_few_forgotten_entries_and_falls_back_to_all: the 2,097,152 case, one named entry (the pass looks at that slot only), and 65,537 repeats (list dropped, full pass).

The branch is also rebased onto 0b0074e (two commits: the pass, then this fix); the only conflict was the counters of the frame line, where I kept main's and this PR's. cargo test --workspace --no-fail-fast on an RTX 3080 Ti: 570 passed, 12 ignored, 1 failed — warp_budget_saturates_without_wraparound_and_preserves_draw_fields, which fails the same way on plain 0b0074e (#847, #849).

Where the PR stands on speed, so nobody takes it for more than it is yet: on our branches over current main (f85101b and a253706 with other PRs) the buffer part of the heap pass is 38–75 ms a frame here in the first room (15,000 slots looked at), and with VICTORY_TABLED_SKIP_FRAMES=2 (#827) it is 85–155 ms over 37,000–78,000 slots, marked or full alike — the marks are inflated by the per-draw tables being mirrored again every frame, so this pass alone does not pay there. I am measuring the fix for that part and will post numbers with it; until then this stays a draft in spirit.

(Fix and rebase with Claude Code; tests run by me on the hardware above.)

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