GPU: release descriptor tables after a rejected bind #1126
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1126"
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?
Imported from Marvisak/VIctory. Originally posted by EatCodeSleep2 on 2026-11-24T15:59:55Z.
Summary
Refs #911. This addresses the partial reservation described there. The frequency and performance impact during gameplay remain unmeasured.
Verification
cargo test --locked -p victory-gpu --lib --features diagnostics -- --quiet(54 passed, 1 ignored)VICTORY_D3D12_WARP=1. Disabling rollback reproduced the retained table on native D3D12.cargo clippy --locked -p victory-gpu --all-targets --features diagnostics -- -D warningsAI-assisted. Synthetic inputs only.
upstream-sync referenced this pull request2026-11-24 17:02:41 +00:00
Imported from Marvisak/VIctory. Originally posted by adamdotpy on 2026-11-24T16:07:19Z.
Grepping the reviews for this one turns up nothing yet, so here is one with the failure reproduced both ways. Reviewed on Windows 11 / Rust 1.98.1,
bb65bc3onffe310e(currentmain, merges as it stands).The leak is real and the test proves it. With
self.release_rejected_tables(reserved_before_bind);replaced by nothing and the test unchanged:That is
assert_eq!(state.dynamic.len(), 1)— the table the accepted stage reserved plus the one the rejected stage left behind. So the test pins the fix rather than passing next to it. It also really reaches the device here: I checked, because the earlyreturnin the no-host case would make it a vacuous pass, and the probe printed "host device present". Green on the branch as pushed:cargo test -p victory-gpu51 passed / 1 ignored, clippy--all-targets --all-features -D warningsclean,cargo build --release -p victorybuilds.The shape is better than the flag it replaces.
FreshTable'sDropmeans the rollback path and the list-teardown path are literally the same code, so they cannot drift — the oldimpl Drop for Stateloop was a second place to keep the same list in sync. Anddrain(reserved_before_bind..)gives back exactly what this bind reserved: a table reused from an earlier successful bind is not in that tail, so it survives, which is right, because it was already accounted for.Nothing else needs rolling back, and it is worth saying so in the function. I went looking for the second half of the leak and there is not one: the constant data for an abandoned fresh table goes through
list.scratch(host.rs:1081), which bump-allocates from the list's own upload chunks and is reclaimed with the list, and thetable_entry/readablecalls already made for non-fresh tables only record diagnostics. Descriptor slots are the only thing that has to be given back. One sentence inrelease_rejected_tablessaves the next reader the same search.Two things I would change in the test, both about surviving machines that are not this one.
capacity - 8underflows (and panics in a debug test) if a host's dynamic region is smaller than nine slots;GetDesc().NumDescriptors - count()is vendor-dependent. Alet Some(room) = capacity.checked_sub(8) else { return };keeps the test honest rather than failing on a host with a small view heap.view_heap.dynamic(2),dynamic(4)) and releasing by hand, then assertingreturned + 4 == tail. That tests the allocator's cursor as much as the fix, and your own comment says the scan splits runs at the cursor (#871) — so an allocator change would break this test while the fix stayed correct. A#[cfg(test)] fn free_dynamic(&self) -> u32that counts the untaken slots would let the test say what it means: the count before a rejected bind comes back after it, andstate.fresh_tableskeeps the accepted key. The layout arithmetic could go.Minor.
test_view_heap's heap is released through the vtable (object::slot(..., 0x10)) at the end of the test, so a failing assert leaks it in the test process. Harmless, but a small guard struct whoseDropdoes that would make the test robust to its own failure, which is when you most want to re-run it.Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T16:12:03Z.
The authored reservation test also passed under Wine/GE 3.2 on an RTX 4090. The checkpoint sits before the stage loop, so if a later stage runs out of room, the bind returns the ranges acquired since that checkpoint and preserves the cached table from the earlier accepted bind.
One qualification to the earlier review:
table_entrycallsreadablefor a mirrored view, andreadabledoes more than log. Depending on the view, it can record a texture upload or state transition, refresh a shadow buffer, or register a UAV range for copyback. Fresh constant views can also schedule a deferred fill. Releasing the new descriptor reservations leaves those list operations in place. The regression uses empty descriptor slots and checks ownership without submitting the list, so it establishes the reservation fix. Whether preparation from rejected binds affects a title is still open.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-24T16:45:08Z.
Reviewed and tested rejected descriptor reservation rollback on RTX 5090 and WARP (
VICTORY_D3D12_DEBUG=1). Three remaining gaps to watch out for on top of rolling backtables():State::bindhas already recordedSetDescriptorHeaps/SetPipelineState/ root constants, allocatedlist.scratch, queueddefer_fill, and runreadable()(ensure_statetransitions +shadow.gpu_writes(), which copies stale host buffer contents back over title memory after submission even though the draw/dispatch never ran). Splitting stage reservation (reserve_stage) before anyHostListmutation keeps rejected binds side-effect-free.bindearly-return leaks & null index buffer:prepare_forchecksindexedafterself.bind()(and without av.address == 0 || v.size == 0guard, a null index buffer falls intoshadow::find(0, 0)allocating a 4 MiB loose shadow window),drawvalidatesRECTANGLESvertex buffers afterself.prepare(), anddispatch_meshcastsID3D12GraphicsCommandList6afterprepare_for(). Any rejection there still retains the dynamic tables just reserved bybind().HostHeap::dynamic'snextcursor: In#911's 8-slot repro (2 used, 6 contiguous free[2..8]), reserving4 + 3advances*nextto6before rolling back[2..6]. Without allowing the wrap-around scan to span across*next(#871), an immediate contiguousdynamic(6)request still fails because[2..8]is split at6.Reference commit with synthetic SM 6.6 GPU readback + multi-stage/post-bind regression tests:
github.com/fuzeofficlal/VIctory@4fd6e2c7a7Imported from Marvisak/VIctory. Originally posted by DoubleD17 on 2026-11-24T17:21:40Z.
Review: COMMENTED
On
bb65bc3, the rollback makes the descriptor slots reusable. A populated slot can still hold itsID3D12Resourcereference after rollback and command-list reset.HostHeap::make_atstores that reference inkept, andHostHeap::releaseclears only the occupancy bits. The heap can therefore retain the reference until the slot is rewritten or the heap is destroyed. This behavior is also present onffe310e. The empty-slot fixture checks reservation recovery and leaves resource lifetime untested. This is a source inspection. I did not measure runtime memory impact.AI-assisted.
Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T17:24:47Z.
@EatCodeSleep2 The composition with #562 kept your original commit. In a capped 65,536-slot fixture, 16 and 178 slots fit before a 256-slot request rejected the bind. The rollback returned all 194 slots, restored the prior CBV version and accepted a retry after the blocker was removed. The reservation and separate mixed replay checks passed on AMD, NVIDIA and WARP with GBV.
Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T18:01:36Z.
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
bb65bc3:cargo test -p victory-gpupasses, 51 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
Imported from Marvisak/VIctory. Originally posted by FunWithFlagsDev on 2026-11-24T18:23:08Z.
Following up on #911 and the descriptor rollback implemented here, I found a potentially related but distinct preparation-side effect.
During
State::bind,readable()can enqueueStep::GpuWritebefore a later table allocation fails. Although the draw or dispatch is rejected, these deferred write declarations remain and can subsequently participate in shadow snapshots, pending-range exclusions and copy-back.The current #1126 diff releases descriptor reservations but does not remove these declarations.
I prepared an experimental opt-in census measuring rejected write declarations per submission, including:
The diagnostic patch preserves baseline behavior. The interval analysis passed nine Python tests, including 20,000 synthetic submissions and 240,183 range declarations, with no discrepancies against an independent oracle.
Native compilation and end-to-end bind validation remain pending.
#1322 may mitigate the stale-data consequence on the synchronous path, but the unnecessary write declarations and their potential bookkeeping costs are a separate question.
I suggest measuring their actual frequency before extending the rollback.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:36:02Z.
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-gpu/src/draw.rs,crates/victory-gpu/src/pipeline.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by JurajSimicevic on 2026-11-25T07:34:35Z.
@EatCodeSleep2, in case it saves you the rebase the triage asked for: your commit on today's
main(940d32f), with you as the author: https://github.com/JurajSimicevic/VIctory/tree/rebase/1126 (30248b9). Use it or ignore it.It is not a mechanical rebase, so here is what changed:
mainnow makes a table afresh only where it reaches past a host heap smaller than the title's (the capped heap on NVIDIA and WARP). Constant buffer tables are read from the title's slots, so your test's tables would no longer be made afresh. The test now uses a 1,000,000-view title heap, which the host caps, and puts its tables past the host's slots. It skips where the host takes the whole heap.MEMORY_HEAP) keep their own release.On an RTX 5080 (driver 32.0.16.1742), the test passes, and it fails with the rollback turned off (
left: 2, right: 1).cargo test -p victory-gpu: 142 passed (146 with--features diagnostics) and 2 failed, the two capped-heap tests that also fail onmainthere (#1751). Clippy is clean with and without--all-features, and there are no new rustfmt hunks.In the world, which the description lists as unmeasured. The base is
940d32f+ #1775's typed-UAV check + #1762, with #1968's program A skipped and DRED on, on the same card. The drop counter is logged at each power of two:Fewer drops in the first minutes, and about the same after five; one run each. On this card most of the drops come from the 2^16 dynamic slots of the capped heap running out (#747), which this change does not touch.
AI-assisted.
Imported from Marvisak/VIctory. Originally posted by Machad3x on 2026-11-25T10:59:38Z.
Merge note: the offered rebase (
30248b9, on940d32f) conflicts with #688 incrates/victory-gpu/src/draw.rs. Both change whatState::dynamicis: #688 makes it a shareddescriptor::lease::Lease(so slots can be taken back from lists that ran), while this change makes it aVec<Held>so that a rejected bind can release only its own fresh tables. The conflicting places are the field, the release inDrop/reset, the three pushes (root-view run, single slot, fresh table) and the two test blocks.Checked by cherry-picking
30248b9onto a local stack (940d32fplus #688 and other open fixes); I did not resolve or run it. Whichever lands second needs the lease to be able to give back the entries of one bind.AI-assisted (Claude Code).
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.