victory-gpu: opt-in batched worker resource retirement (VICTORY_BATCH_RETIRE=1) #295
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/TaynanGT--Vice-Tay!295
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-295"
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?
@Vladimir-Human on GitHub · 2026-11-27 14:05 UTC · original
Vladimir-Human:perf/opt-in-batched-retire→main· +443 −5 · 2 files · 4 commits · merged 2026-11-27 16:30 UTCSummary
Split out of #268 so the
ID3D12Resourceretirement lifetime can be reviewed and measured independently against a matched baseline.Adds opt-in thread-local batching for retired
ID3D12Resourceobjects on command-list translation worker threads behindVICTORY_BATCH_RETIRE=1(default off; liveVICTORY_ABtoggle supported indiagnosticsbuilds).Adapted from
voidopcode/vilocitycommit4315c77.Changes (
2 files: crates/victory-gpu/src/host.rs,crates/victory-gpu/src/list/thin.rs)host.rs):batch_retire_enabled()defaults tofalseand enables batching only whenVICTORY_BATCH_RETIRE=1(orVICTORY_ABselects it indiagnostics). When off,retire_resource_withhands entries directly toRETIREDand immediately flushes any buffered leftovers if toggled off mid-run.host.rs):RetiredBatch { eligible, entries }accumulates up toBATCH_MOST(256) retired resources per eligible worker thread before handing them over toRETIREDin one lock acquisition.retire_in_batches()is idempotent and never discards already-buffered entries;RetiredBatch::dropflushes remaining entries on thread exit (safe under TLS teardown viaPART.try_with(...).unwrap_or(0)).host.rs): Every insertion into aRETIREDshard (retire, directretire_resource_with,flush_retired,RetiredBatch::drop) routes throughinsert_retired/merge_retired_batch, keeping each shard ordered by ascending submission stamp sobury()'s prefix drain always releases older resources at their own fence deadline.list/thin.rs): Marks command-list translation worker threads eligible at startup (retire_in_batches()) and flushes buffered retirements after everyrecording.run()(flush_retired()).Tests & Verification
Verified with
VICTORY_D3D12_DEBUG=1(0 D3D12 debug errors):cargo clippy -p victory-gpu --all-targets --locked -- -D warnings(default &--features diagnostics): 0 warningsxtask policy --staged&cargo test -p xtask --locked: 11/11 passedhost::retire_batch_tests:a_late_batch_does_not_hide_eligible_retirementsbatch_retire_switch_defaults_off_and_accepts_only_onea_thread_without_a_batch_keeps_nothing_and_a_full_batch_signals_flushbatched_retirement_off_hands_over_immediately_and_flushes_leftoversretire_in_batches_is_idempotent_with_buffered_entriesbatched_resource_retirement_flushes_concurrently_without_losing_entriesbatched_retirement_preserves_resource_lifetime_until_bury_on_gpumixed_batched_and_direct_retirement_releases_older_resource_at_its_own_deadline_on_gpu(reproduces the same-threadNbatched resource ->N + 1directretire(())+ resource handover across batching off, explicitflush_retired(), andRetiredBatch::drop, verifying refcount drops to1atbury(N + bury_lag())whileN + 1stays alive untilbury(N + 1 + bury_lag()))--features diagnostics,VICTORY_D3D12_DEBUG=1,--test-threads=1): off 11/11 (retire_batch_tests+late_tests);VICTORY_BATCH_RETIRE=159/59 (retire_batch_tests+late_tests+descriptor::host::tests)VICTORY_D3D12_WARP=1,--features diagnostics,VICTORY_D3D12_DEBUG=1,--test-threads=1):VICTORY_BATCH_RETIRE=111/11@efsebayern on GitHub · 2026-11-27 14:17 UTC · original
I reviewed
3e83d9don Windows with an RTX 4080 SUPER. I’d address one retirement-ordering case before merging.flush_retired()appends the batch to the shard’s deque.bury()drains only the eligible prefix. A newer entry can therefore block an older, eligible resource behind it.I reproduced this in a focused test with the D3D12 debug layer enabled. On the same thread, I retired a resource at stamp N, advanced the stamp by one, called
retire(()), flushed the batch, and calledbury(N + bury_lag()). With batching off, the resource’s COM refcount dropped to 1 (the probe’s reference). With batching on, it stayed at 2 untilbury(N + 1 + bury_lag()). The repro shows delayed release. I suggest preserving stamp order when handing off a batch, or making reclamation handle out-of-order entries, and adding this mixed-retirement case to the tests.The local diagnostics run with batching enabled on the RTX passed 140 host and descriptor tests (17 ignored). The six focused retirement tests also passed with batching disabled on the RTX and with batching enabled under WARP. Gameplay performance remains unmeasured.
@TaynanGT on GitHub · 2026-11-27 14:29 UTC · original
@efsebayern The mixed-retirement test shows exactly where the eligible entry gets stuck. @Vladimir-Human Each shard needs to keep the original stamp order when a batch is handed over. The regression should check that the older resource releases at its own fence deadline. Keeping #295 separate lets #268 be measured on its own.
f31478fca7to2f27f38f56@Vladimir-Human on GitHub · 2026-11-27 15:03 UTC · original
@efsebayern @TaynanGT Thanks for the sharp catch and clear repro — updated #295 (rebased onto
mainb67e8d8, commit2f27f38):crates/victory-gpu/src/host.rs): Routed everyRETIREDshard insertion (retire, directretire_resource_with,flush_retired, andRetiredBatch::drop) throughpush_retired_ordered/extend_retired_ordered. The monotonic fast path still performs a zero-allocationextend; when older batched entries arrive behind newer direct entries,extend_retired_orderedperforms a stable two-pointer merge over onlyqueue[split..]so each shard keeps ascending stamp order andbury()releases older resources at their own fence deadline.host::retire_batch_tests):ordered_handover_preserves_ascending_stamps_across_mixed_and_unsorted_batches(unit coverage for fast-path append, out-of-order single insert, interleaved/unsorted merges, and equal-stamp FIFO stability).mixed_batched_and_direct_retirement_releases_older_resource_at_its_own_deadline_on_gpu(reproduces the exact same-threadNbatched resource ->N + 1directretire(())+ resource -> handover case across batching off, explicitflush_retired(), andRetiredBatch::drop, asserting refcount stays>= 2beforeN + bury_lag(), drops to1immediately atbury(N + bury_lag())whileN + 1remains>= 2, and releasesN + 1atbury(N + 1 + bury_lag())with 0 D3D12 debug errors on both HW and WARP).@TaynanGT on GitHub · 2026-11-27 15:08 UTC · original
@Vladimir-Human The GPU test now covers the exact case the reviewer found, including handoff at thread exit.
2f27f38is the revision to use for the next timing run. Keep the same scene and track both retirement counts and frame time so we can see the cost of the ordered handoff.2f27f38f56to19828f3ce5@Vladimir-Human on GitHub · 2026-11-27 15:12 UTC · original
Quick follow-up @TaynanGT @efsebayern: I noticed your commits
f31478fand045236elanded on the PR branch right before my previous push, so I restored3e83d9d -> f31478f -> 045236eintact (insert_retired,merge_retired_batch, anda_late_batch_does_not_hide_eligible_retirementsuntouched) and layered only the D3D12 COM-refcount mixed-retirement GPU regression test (mixed_batched_and_direct_retirement_releases_older_resource_at_its_own_deadline_on_gpu) plusRETIRE_TEST_LOCKon top in19828f3.@TaynanGT on GitHub · 2026-11-27 15:18 UTC · original
@Vladimir-Human Thanks for restoring the two commits and adding the COM refcount check on top.
19828f3is synced locally. The GPU test now exercises the release deadline itself, alongside the queue-local ordering test.