GPU: batch submission heap/memory steps and fast-scan bindless and page-table bitmaps #3487
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!3487
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3487"
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?
@Desamodeth on GitHub · 2026-11-27 08:27 UTC · original
Desamodeth:opt/submission-heap-memory-steps→main· +786 −103 · 4 files · 2 commits · openReduces submission-time CPU overhead in
Host::executeacross three closely coupled loops (part of the unclaimed submission-step / title-memory hotspot noted in #3425):Changes
watch::DIRTYscan for bindless buffer refresh (crates/victory-gpu/src/watch.rs,crates/victory-gpu/src/bindless.rs):watch::dirty_word(word)to load one 64-tracker word ofDIRTYat a time.Viewed's merged buffer hulls densely inVec<Hull>(hull_pos: HashMap<(usize, bool), u32>) indexed byactive_words: Vec<ActiveWord>((word, mask, sorted (bit_offset, hull_idx))) anduntracked_hulls: Vec<u32>.bindless::refreshchecks 64 copies per atomic word load and indexeshullsdirectly with zero hash lookups (plus a straight-through path when a word is 100% dirty).Viewed::hull_generation()bumped only whenInner::countmutateshulls.Step::Heap/Step::Memorydeduplication & allocation-freeDeferredscans (crates/victory-gpu/src/host.rs):heaps_seen: Vec<(usize, u64)>((viewed_ptr, hull_generation)) andmemories_seen: Vec<(usize, u64)>((heap_key, shadow::generation())) onBatchso multi-list submissions skip repeatingbindless::refreshandmemory::prepareacross lists while nothing changed, clearing both inBatch::title_written()onStep::Copy(and re-running if hull or shadow generation changes)..flat_map(... .collect::<Vec<_>>())allocations inHost::executewith a single flag-gated pass (has_heaps,has_textures) and skipped post-GPUdeferred.copiesscans when!has_gpu_writes.crates/victory-gpu/src/memory.rs):defer_missedanddefer_afterscans toactive_words(&layout)(blocks.len().max(1) * (BLOCK / 32)capped atBITMAP_WORDS) using 4-word chunked zero skips (as_chunks::<4>()/as_chunks_mut::<4>()).SCAN_ALL_ZEROfromdefer_missedtodefer_afterso clean lists skip the second bitmap scan andSTATSlock; when marks are present,defer_afterclears active words, skipsSTATSlock if all counters are zero, and marksPooledBitmapclean soPooledBitmap::dropskips re-scanning 256.5 KiB on pool return (unexecuted/direct bitmaps still run defensive full clearing).Benchmarks (RTX 5070, Release, 12 interleaved runs: 6
main -> opt+ 6opt -> main)origin/main:63bcca43c6a00a758510398fa43096ce7e4f7df0834dfc66c517ae28ba2af368e85f6cf4abd35e16mainmedian[min..max]optmedian[min..max]bindless::refresh4,096 hulls, 0 dirty (240 calls)1,169.9 us[812.3..1,341.8]8.6 us[6.0..12.9]-99.3%136.03xbindless::refresh4,096 hulls, 16 copies / 32 hulls dirty (240 calls)1,079.4 us[819.5..1,320.3]25.3 us[24.9..43.6]-97.7%42.66xbindless::refresh4,096 hulls, 100% dirty worst case (20 calls)132.3 us[86.1..154.1]24.2 us[19.7..45.3]-81.7%5.47xViewed::setinsert+remove churn (24,576 ops, no refresh — unfavourable case)4,994.6 us[3,196.1..5,670.3]5,303.9 us[3,854.8..6,107.7]+6.2%0.94xHost::execute16 lists (4,096-hullViewed+ 8memory::bind+ reset, 8 rounds)7,839.9 us[6,452.1..9,770.9]1,377.9 us[889.0..1,629.0]-82.4%5.69xHost::execute8 lists withStep::Copybetween every list (dedup worst case, 8 rounds)1,994.4 us[1,647.4..2,539.2]862.5 us[674.9..1,214.7]-56.8%2.31xHost::execute16memory::bindlists + execute + reset (12 rounds = 192 bitmaps)16,786.5 us[12,436.0..21,736.9]1,599.0 us[1,324.7..2,272.0]-90.5%10.50xmemory::has_missedfull 512-block layout (65,664 dwords), 0 marks (2,000 scans —active_wordsworst case)93,897.7 us[61,991.4..130,422.7]23,538.4 us[19,098.7..26,228.3]-74.9%3.99xmemory::has_missedfull 512-block layout, 16 scattered owned marks (2,000 scans)119,621.1 us[72,875.0..132,004.3]23,360.1 us[19,240.2..26,550.6]-80.5%5.12xTrade-offs
hull_pos+ActiveWordadds+6.2%overhead (~12.6 ns/op) on pureViewed::sethull insert/remove churn when no refresh happens, in exchange for5.5x–136xfasterbindless::refreshacross clean, sparse, and 100%-dirty states.active_words(&layout)assumes GPU shaders only index blocks< layout.blocks.len()from level-1 (guaranteed bywrite_table, which maps all unallocated 256 MiB regions to block 0).Verification
cargo clippy --locked -p victory-gpu --lib --tests -- -D warnings— cleancargo clippy --locked -p victory-gpu --features diagnostics --lib --tests -- -D warnings— cleancargo xtask policy—191 files ok--test-threads=1,bindless:: memory:: host:: watch::tests:: shadow::tests::, skipping only the 2 known NVIDIAFIND-9heap-cap tests):72 passed; 0 failedVICTORY_D3D12_WARP=1,--features diagnostics,--test-threads=1, full set including bothFIND-9tests):75 passed; 0 failedbindless::tests::refresh_word_scan_matches_dirty_srv_uav_untracked_and_removalshost::withholding::batch_deduplicates_heap_and_memory_steps_until_title_writememory::tests::active_words_scan_missed_and_clear_nonzero_wordsmemory::tests::clean_handoff_and_repeat_submission_preserve_bitmap_stateCoordination claim: #1633 (#1633).
AI-assisted with Gemini 4 Neon
@oni-swr on GitHub · 2026-11-27 09:37 UTC · original
Independent Windows/WARP verification of #3487 at
834dfc66c517ae28ba2af368e85f6cf4abd35e16Environment: Windows 11 Pro build 10.0.26200, rustc 1.98.1, no physical GPU:
VICTORY_WARP=1andVICTORY_D3D12_WARP=1(WARP only),dxil.dll1.8.2502.11 from the Windows SDK 10.0.26100.0. (An older 10.0.19041dxil.dllrejects SM 6.6 and crashes manyvictory-shaderGPU tests with an access violation; I discarded those runs.) Base ismain63bcca43c6; all three PR heads (#3487, #3488, #3489) sit directly on it.--locked, separate worktrees for base and head. Claim: #1633AI-assisted (Claude); I read the diff and the logs before posting. No game files were used. WARP is not hardware, so this says nothing about driver behaviour on AMD or NVIDIA.
Result: no regression found on WARP.
cargo test -p victory-gpu --lib:frame::tests::waits_end_on_ticks_and_count_frames(a wall-clock tolerance test). It is not new: the same test also failed on base in one of my earlier runs (25.5 ms observed), and the PR does not touchframe.rs. I count it as a timing flake, not a head regression.refresh_word_scan_matches_dirty_srv_uav_untracked_and_removals,batch_deduplicates_heap_and_memory_steps_until_title_write,active_words_scan_missed_and_clear_nonzero_words,clean_handoff_and_repeat_submission_preserve_bitmap_state.Timing: there is no existing bench for these paths (the only
#[ignore]bench invictory-gpuis unrelated), and the world-scale numbers need the title and a GPU, so I did not time it. Suite wall time (2.0 s vs 2.2 s) is not a measurement of the change.Risk worth a second look (read from the diff, not reproduced): in
memory.rs,defer_afterdoesscan_state.swap(SCAN_ALL_ZERO), which leaves the state atALL_ZEROafter every run.host.rsevaluates a list'smissedchecks with.any(|check| check()), which stops at the firsttrue. If one list binds more than one heap and is executed again withoutreset(), a later check skipped by that short-circuit keeps the staleALL_ZERO. Itsdefer_afterthen returns early, skips clearing and callsmark_clean(), so a bitmap that still has marks could go back toBITMAP_POOL. The first execution is safe (state startsUNKNOWN), and the new repeat-submission test covers only one bound heap. Resetting the state toUNKNOWNafter the consumer, or not short-circuiting, would close it. I do not know whether the real path ever re-executes an unreset multi-bind list.Minor:
Batch::need_heap/need_memoryskip a repeat walk until aStep::Copytitle write. A game-thread write between two lists of one submission is now picked up by the next submission instead of the next list; that is the same window a racing write already had.Overlap with #3488: both edit
victory-gpu/src/watch.rs. They merge with no conflict (git merge-tree). The hunks are disjoint (this PR addsdirty_word, 5 lines; #3488 only widens the visibility ofTracked,track,take,clean,arm,saved) and I see no semantic interaction. The merged tree builds and passes:victory-gpu235 passed / 0 failed,victory-hle154 passed / 0 failed, 3 runs each.@KainanP on GitHub · 2026-11-27 11:55 UTC · original
One concern at head
6c10101ethat I haven't seen raised yet. I read the code but did not run it.The scan and the clear now stop at
active_words(&layout(key)). That layout is read when the scan runs, not when the list ran. Marks past it are neither counted nor cleared, but the bitmap is still marked clean.memory.rs:618:active_words=blocks.len().max(1) * BLOCK / 32.memory.rs:703-713(defer_missed) and:718-726(defer_after) both takelayout(key)at that moment.layoutreturnsShared.layout"as the last submission using it left it", or the default (0 blocks) oncerelease(key)has dropped the entry.Shared::rewrite(:529on) rebuildsblocksfrom the copies that exist now. So the block count can go down between the list's run and its deferred scan: copies were let go and a laterpreparerewrote the table, or the heap was released (Heap::drop→memory::release).bind's own comment says lists outlive that ("lists that name it hold it").blocks.len()is outside the scanned prefix:scan_missedreturns(false, false)and storesSCAN_ALL_ZERO.defer_aftertakes the fast path and callsmark_clean()(:721-722). Even on the slow path it walks onlywords, then callsmark_clean()(:769).Drop for PooledBitmap(:197-202) then skipsclear_nonzero_words, and the bitmap goes back toBITMAP_POOLwith those bits still set.Two consequences, compared with
main(whosehas_missed/defer_afterwalk allBITMAP_WORDS):main, such a mark hitsl.blocks.get(block).is_none()→missed, so the list's writes are withheld. With this PR,missedis false, so the GpuWrite ranges go back to title memory although part of what the shader wrote was never accounted for.copy_back_pageof a page nothing wrote. Without one, it is a spurious miss that withholds the submission.Smallest fix I can see: keep the clear exact and limit only the scan shortcut. In
defer_after, always clear up to the largestactive_wordsthis bitmap has ever been scanned with. Or keep a high-water mark perPooledBitmapand haveDropclear up to it. Either way, a bitmap is never marked clean beyond what was actually scanned. Another option: captureblocks.len()inprepare, when the table the GPU reads is written, and scan with that instead of the layout found at defer time.AI use: Claude Code (Claude Opus 5.5).
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.