GPU: a changed heap slot's view census costs ~25% less of its mirror (#3425) #3522
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3522
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3522"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@KainanP on GitHub · 2026-11-27 13:37 UTC · original
KainanP:perf/mirror-census→main· +276 −47 · 2 files · 1 commits · openPart of #3425, the "Descriptor heap mirroring (384k slots), 18.1 ms,
HostHeap::sync_slots" row.Where a changed slot's ~1 µs goes
I timed each step of
HostHeap::mirror(serializedrdtsc, temporary, not in this PR) in thesync_slots_benchshape from my #3425 comment: 393k slots a frame, ~9.5k changed, 1/8 null views, 1/8 constant buffers, 6/8 placed buffer views. That's the "other" mix #3233 measured in the world, where 68 % of the views made are constant buffers and memory views. Per changed slot onmain, RTX 4060 Laptop:bindless::Viewed::set(the census of what slots view)HashMapinsert/removeBTreeMapentry + remove, tallies, hull rebuilt with anArcclone)make(buffer_srv)CreateShaderResourceViewkeep(+host::retireof the old resource)VIEWSlocks andview_atprepareThe driver call is only about 10 % of the cost. A host-descriptor cache that turns
Create*ViewintoCopyDescriptorsSimplewould save at most ~100 ns of the ~1 µs. The largest single cost is the census bookkeeping.Change
Viewed.slots: aHashMap<u32, Seen>holding the heap's ~600k-1M slots (2^20-2^21 buckets) is replaced by pages of 1024 entries indexed by slot, created when a slot in them is first set. That is one memory access instead of hash probes that miss the cache, and it uses less memory once a heap is mostly set (32 B per slot vs ~37 B per bucket at 2x capacity).Inner::count:HashMap. Their order was only read by thediagnosticscensus, which now sorts beforededup.Arcclone. The key's copy is the same object whileendsholds it.HostHeap::keep: when the slot gets a view of the resource it already holds, the old reference is not retired. Most buffer views sit on a few host copies. The slot still holds the resource, and any later change retires it as before, so it is freed only after the submissions in flight have run. This drops theRETIREDlock and one extra reference per slot until the next submission.There is no change in what is made. The census's hulls, ranges and textures are identical.
Bench
sync_slots_benchfrombench/sync-slots(f233390e), base =main63bcca4. I ran 7 interleaved runs per tree, 20 frames each, and report medians with [min-max] across runs. RTX 4060 Laptop, Windows. The measured tree isbench/mirror-fix, whose code is this PR's before rustfmt.mainShare of the in-game 18.1 ms row: roughly 3 ms of the 18.1 ms is the scan, so if the other ~15 ms is changed-slot mirrors like these, this should take off about 3-4 ms (~20 %). The same
mirroralso runs for descriptor copies with new records (borosf's "heap slots the title copied" row) and for draws'make_read. @neonbyte1 (or anyone with the world loaded), could you A/B the frame line's heap sync onmainvs this branch?Tests
bindless::tests::slots_keep_what_each_index_seescovers set, replace, clear and retain across page boundaries, including a far slot that doesn't create the pages before it.hulls_follow_the_rangesnow also covers a slot rewritten with its own range, a range inside the hull, ranges sharing a start, the first start going and the far end going.descriptor::host::tests::a_slot_made_again_on_its_resource_retires_nothing. It fails onmain("the same buffer again": 1 retire instead of 0) and checks that a view of another buffer and a null view still retire the old one.cargo test -p victory-gpu --lib, results identical tomain:main's knowndynamic_slots_are_held_until_releasedandlists_share_a_table_and_copies_keep_their_views; I skippedheap_direct_texture_reads_mark_their_heap_index, which crashes onmain.mainwith the hook (3/3 runs onmaintoo): the two above plusa_texture_written_in_one_format_reads_in_another_through_a_placed_view.--features diagnostics,VICTORY_D3D12_WARP=1): 248 passed, 0 failed.cargo clippy -p victory-gpu --all-targets -D warnings, default and--all-features: clean.cargo xtask policy: ok. rustfmt applied to the changed lines only.Overlaps
Viewed::setwith #3055 (set_with/set_batch) and #3213 (liveness re-check), and indescriptor::host::testswith #2895. Each resolves by keeping both sides, withInner::putreplacing the remove/insert pair. I'm happy to rebase on whichever lands first.AI use: profiled, written, tested and benchmarked with Claude Code (Claude Opus 5.5).
🤖 Generated with Claude Code
@oni-swr on GitHub · 2026-11-27 14:17 UTC · original
Independent verification of
babd4873(base63bcca4), claimed in #1633. WARP + CPU only.Environment: AMD Ryzen 7 5700X3D (8C/16T), Windows 11 25H2 build 10.0.26200.9974, rustc/cargo 1.98.1,
VICTORY_WARP=1+VICTORY_D3D12_WARP=1,--features diagnostics, system WARPd3d10warp.dll10.0.26100.9818. No physical GPU. The machine was shared with other verification builds, so absolute times are noisy; the runs were interleaved base/head.Trees: base =
63bcca4; head =babd4873. Both plus KainanP's bench commitsf34bcfb+f233390(cherry-picked; they only add#[ignore]d tests and a 1-line change).Tests (
cargo test -p victory-gpu --lib --features diagnostics -- bindless descriptor --test-threads=1):bindless::tests::slots_keep_what_each_index_seesanddescriptor::host::tests::a_slot_made_again_on_its_resource_retires_nothing;hulls_follow_the_ranges(extended) passes. I did not re-run the "fails on main" claim for the retire test, and did not run the wholevictory-gpulib.Bench (
sync_slots_bench,--release, 7 interleaved runs per tree, 20 frames each, WARP device). ns per changed slot = (median frame − the same run's 0-changed median) / changed slots; median over the 7 runs:Ranges across runs do not overlap in the 0-thread rows (9.5k: base 40.5-43.6 ms, head 37.0-42.1 ms). 0 slots lost / 0 stale in all 14 runs. Saving is about 0.4-0.5 us per changed slot, which matches the PR's ~0.24 us absolute saving per slot up to the larger per-view cost here: on WARP
CreateShaderResourceViewis a software call, so the whole slot costs ~4 us and the census saving is a ~10% share, not 25%. It says the direction holds on a second CPU; it does not confirm the 25% on a hardware driver.Diff read (bindless.rs, host.rs): no correctness problem found.
putcounts the new view in before the old one out. Final counts are identical to remove-then-add; a same-range rewrite no longer hits 0, so no hull work. Different ranges are unaffected.count: the single-lookup entry paths match the old behaviour: a decrement of a missing range is a no-op (old:saturating_subon a fresh 0),tallynever underflows because entries are removed at 0. The hull is rebuilt only when a range comes or goes, as before.Arc; safe because the key is the copy's pointer andendsholds that Arc while any range for it exists; the hull andendsentries are removed together.dirty_bitis still refreshed.HashMapranges: order was only used bydiagnostics; it now sorts beforededup(needed, and done).Slots: pages of 1024;retaindoes not count ranges down, same as the oldretainon textures. Notes only: a page is never freed once created, and a bogus huge slot index would size the page vector byindex/1024(heap indices are bounded, so fine).keep: skipping the retire when the slot's new resource is the same object is safe: the slot still holds it, and its later replacement retires it after submissions in flight at that time.AI-assisted: Claude Code, Claude Sonnet 5.5.
@neonbyte1 on GitHub · 2026-11-27 14:18 UTC · original
@KainanP yes, happy to. I'm merging it onto our test stack now (it carries a few heap-sync changes of its own in
descriptor/host.rs: the sync holds the heaps' lock a chunk of pages at a time, stops at the host heap's count (#3512), and skips the view lookup for unchanged slots), and it'll get an in-game A/B against an adjacent control, judged on the frame line's heap-sync time and slot counts first and frame time second. Our GPU queue is booked for the next couple of hours, so expect the numbers later today; I'll post them here.AI-assisted (Claude); measured on my machine, no game data shared.
@pickles976 on GitHub · 2026-11-27 14:21 UTC · original
Physical Wine/NVIDIA correctness check of exact clean head
babd487363e56203efae1b02850884c446271c2e(base63bcca4). RTX 4060 Laptop 8 GiB, NVIDIA 590.48.1, Wine 11.0, vkd3d-proton diagnostic build2576c0b4adfae4a+(relaxed-vtable; not stock certification), Rust 1.98.1 MSVC target,dxgi.hideNvidiaGpu = False, one test thread.Fresh intended-worktree compilation was confirmed (
Compiling victory-gpu .../VIctory-pr3522/crates/victory-gpu, 9.31 s). Focused results:bindless::tests::slots_keep_what_each_index_sees: 1/1 pass — page boundary, far sparse page, replace/retain/remove.bindless::tests::hulls_follow_the_ranges: 1/1 pass — actual RTX/vkd3d device initialized; no skip line; same-range rewrite and start/end/inside hull transitions all completed.descriptor::host::tests::a_slot_made_again_on_its_resource_retires_nothing: 1/1 pass — actual RTX/vkd3d device initialized; same resource was not retired, replacement and null each retired once.Total focused result: 3 passed, 0 failed, 0 ignored. No source edits, no title launch. I did not port the new retirement fixture to the parent, run the full library, or benchmark this host, so this confirms the changed ownership/range behavior on physical Wine/NVIDIA but not the claimed 25%/frame-time saving or a RAM-floor improvement.
Evidence:
.compat-runtime/logs/verify-pr3522-changed-slot-fixtures.log.AI-assisted verification; review-only, no code contribution.
@oddmaniv on GitHub · 2026-11-27 15:39 UTC · original
Independent verification of the PR author's concurrent WARP pipeline/draw test at
babd487363e56203efae1b02850884c446271c2e.cargo test --locked -p victory-shader --lib emit::host::tests::parallel_warp_pipelines_and_draws -- --exact --nocaptureMain baseline pin:
63bcca43c6a00a758510398fa43096ce7e4f7df0.Windows x86_64 MSVC native runs. Local and remote source snapshots matched before and after each check. The adaptation applies the PR diff without additional source edits.
This is focused regression coverage, not the full workspace suite, a gameplay test, or an independent validation of every behavior in the PR. No new fix is claimed.
AI-assisted verification.
@neonbyte1 on GitHub · 2026-11-27 20:28 UTC · original
@KainanP in-game result as promised. RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's prison yard, Series X profile at 2560×1440. Base:
mainplus the unmerged PRs this setup needs (listed in #3425), with our own heap-sync changes (stop at the host heap's count as in #3512; skip unchanged view lookups). This PR merged on top; adjacent 420 s runs, medians of the last 30 frame-rate lines:heap slots the title copied)The heap sync is 1.5 ms cheaper, in the direction your benchmark predicts but smaller here, probably because our base already skips unchanged slots and stops at the host heap's count. The frame doesn't move outside run-to-run noise on this setup: preparing still runs serially with the GPU and copy-back, so a 1-2 ms saving is within the spread. No faults, pictures unchanged.
AI-assisted (Claude); measured on my machine, no game data shared.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.