GPU: retain and retire released host textures, staging, shadow buffers, and descriptor resources across submissions #609
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!609
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-609"
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?
@LAKSHYA-cmd-tech on GitHub · 2026-11-24 05:34 UTC · original
LAKSHYA-cmd-tech:fix/gpu-deferred-resource-retirement→main· +246 −64 · 5 files · 1 commits · openSummary
Fixes #557.
When the title streams textures or reuses title buffer ranges, it drops CPU-side objects as soon as recording completes. On PC D3D12, dropping the corresponding host resources immediately deallocates GPU virtual address ranges and underlying physical memory, while GPU work (particularly multi-list submissions, indirect draws, and mesh
ExecuteIndirectdispatches reading via descriptor tables) may still be executing or queued on the GPU. This resulted in DRED page faults:Root Cause & Solution
Resourcedroppedself.host: Option<Arc<HostTexture>>. When no active command list named the texture (e.g. indirect mesh draws or compute shaders reading via bindless descriptor heaps),HostTexturewas freed immediately on the CPU. ImplementedDrop for HostTextureto forward itsID3D12Resourcetocrate::host::release_late.texture::forgetremoved entries fromSTAGING, droppingStagingand releasing upload buffers whileCopyTextureRegionmight still be in-flight. ImplementedDrop for Stagingto forward its buffer torelease_late.shadow::unregisterdropped title buffer shadows. ImplementedDrop for Shadowto forwardshadow.buffertorelease_late.HostHeap::keepnow routes displaced resources torelease_lateinstead of inline CPU destruction.RETIREMENT_QUEUEincrates/victory-gpu/src/host.rswith a submission retirement window (RETAIN_SUBMISSIONS = 3). Resources are held across multi-list submissions and drained only after the GPU fence has confirmed execution past their retirement window.Verification
host::tests::deferred_retirement_retains_resources_across_submissionsadded and passing.cargo test -p victory-gpu -- --test-threads=1: 44 passed, 0 failed, 1 ignored.cargo clippy -p victory-gpu --lib -- -D warnings: 0 warnings.cargo clippy -p victory-gpu --features diagnostics --lib -- -D warnings: 0 warnings.cargo run -p xtask -- policy: 151 files ok.@fromthemoonx on GitHub · 2026-11-24 09:41 UTC · original
Tested
6d8c72bmerged onto currentmain(8e79c80, merges cleanly) on NVIDIA.Environment: Windows 11 Pro build 26300, AMD Ryzen 7 5700X, 16 GB, NVIDIA GeForce RTX 3060 12 GB (driver 610.88), Rust 1.98.1
x86_64-pc-windows-msvc.CI's commands, on the merge
cargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo test --workspace --locked: 312 passed, 0 failed, 6 ignoredcargo test -p victory-gpu --libin parallel, 15 runs: all passed, includingdeferred_retirement_retains_resources_across_submissionsOne problem:
release_latetakes the submission lock.current_submission()reads the counter throughhost.submitted.lock(), andHost::executeholds that sameMutexfrom preparation through the GPU wait to copy-back. Now thatDrop for HostTexture,Drop for ShadowandDrop for Stagingcallrelease_late, a release waits for whatever submission is in flight. A throwaway test (not pushed) shows both cases on the merge:release_latewhile the lock is held for 500 ms (standing in for a submission's GPU wait)release_latestd::sync::Mutexis not reentrantexecutethat drops the lastArcof one of these objects (theShadowclones inbackare also held by the lists' deferred steps). But anything added toexecutelater that does would deadlock.AtomicU64bumped next to*submitted += 1, or the fence'sGetCompletedValue()for the drain.Smaller notes
host.rsare rustfmt reflow of code this PR doesn't otherwise touch (SUBMISSION_US,COPY_BACK, the timing and DRED helpers,mod batch). It does reducecargo fmt --checkoutput for the crate (82 → 45 places), but it hides the actual change and will conflict with the other open PRs inhost.rs.retire_at == sub + 3and is still queued after one submission. It doesn't cover the drain (that the resource is dropped once the window passes) or that theDropimpls route throughrelease_late.Not tested: the DRED page fault from #557 (needs the title); no game data used.
AI-assisted (Claude Code) ran the checks and drafted this comment.
@d1ll3x3 on GitHub · 2026-11-24 09:49 UTC · original
checked: #609 on RDNA3 | base:
main@8e79c80+ #609 + #568 + #67 (applied locally; one conflict with #568 indescriptor/host.rsdescribe_slot, resolved with #568'sSlotStateversion) | on: Windows 11, RX 7800 XT (RDNA3, 16 GB), 32 GB RAM, diag build,VICTORY_D3D12_DRED=1, Xbox Series 1.0.2.1result: the first mission's intro cutscene runs (0–1 fps), then the device is removed after 5 min 16 s with the signature #609 targets:
At 0–1 fps the cutscene makes about 13 submissions a frame, so
RETAIN_SUBMISSIONS = 3is a fraction of a frame. Raising it locally to 512 (about 40 frames) did not help: removed after 2 min 39 s,inside freed ["texture 2048x2048 f98 …"], DRED stopped atcommand 418 of 562 (op 15), a ResourceBarrier. Earlier stops on other bases were op 8 (CopyTextureRegion) and op 6 (Dispatch). So some freed textures are named directly by recorded commands (barriers, copies), not only through heap slots, and a longer window does not cover them.For comparison on the same machine and base, #431 + #568 + #67 (without #609) ran 11 min 39 s; details on #431.
Run-to-run duration varies (2.5–6 min with the same build), so treat the timings as a weak signal.
AI-assisted (Claude Code).
@dpalacios69 on GitHub · 2026-11-24 09:57 UTC · original
Thanks for putting this together! Looking through the diff, locking
Host::submittedinsidecurrent_submission()introduces two deadlocks and heavy lock contention that should be fixed before this can land:Same-thread self-deadlock in
Host::execute(crates/victory-gpu/src/host.rs):Host::executeacquireslet mut submitted = self.submitted.lock()...at line 550 and holds it until the end of the function (line 689).back: Vec<(Arc<Shadow>, usize, usize)>is declared later (line 655), so Rust dropsbackbeforesubmitted. Wheneverbackholds the lastArc<Shadow>(for example, if a title thread unregisters the buffer and resets the command list after the bottom-of-pipe completion writes at lines 673–677), droppingbackat line 689 triggersShadow::drop→release_late→current_submission()→h.submitted.lock()on the same thread already holding the non-reentrantMutex, deadlocking permanently. The same applies to anyArc<Shadow>,HostTexture, orStagingdropped whileHost::executeholdssubmitted.AB-BA deadlock between
shadow::BUFFERSandHost::submitted:shadow::unregister(shadow.rs:401) runsbuffers().remove(&(start, resource));, which drops the removedEntry(and thusShadow::drop→release_late→host.submitted.lock()) before the temporaryMutexGuardonBUFFERSis released (BUFFERS→Host::submitted).Host::executeholdsHost::submittedwhile callingself.removal_data(runs)→shadow::near(va)(shadow.rs:472), which acquiresBUFFERS(Host::submitted→BUFFERS).If a title thread unregisters a buffer during a GPU hang, DRED reporting can hang permanently instead of logging the crash.
Contention against the GPU fence wait:
Because
Host::submittedis held acrossWaitForSingleObject(self.event, INFINITE), callingh.submitted.lock()incurrent_submission()stalls any worker thread releasing a texture/shadow/staging buffer or overwriting a descriptor slot (HostHeap::mirrorholdsHostHeap::madeacrosskeep/release_late) for the entire duration of the GPU submission.Suggested fix for (1)–(3): Mirror the submission counter in a separate
AtomicU64(updated when*submitted += 1and loaded incurrent_submission()without lockingHost::submitted), and drop thesubmittedguard beforeback/to_drop.A few smaller notes:
Fixes #557from the PR body so merging doesn't auto-close the issue.VICTORY_GPU_TIMINGedge case: Whentiming()is enabled (host.rs:516–528on base),*submittedincrements once per list ingroupsrather than once perexecute(), so a multi-list submission advances pastRETAIN_SUBMISSIONS = 3immediately.deferred_retirement_retains_resources_across_submissionschecks retention after 1 submission, but doesn't verify that the resource is actually drained once the 3-submission window passes.host.rs(14/17) anddescriptor/host.rs(9/10) are unrelatedrustfmtreflows—reverting those would make the diff much easier to review.Static code review only (not executed on hardware); AI-assisted.
@justr4mzi on GitHub · 2026-11-24 10:03 UTC · original
Tested PR #609 (
6d8c72bc) integrated cleanly ontomain(8e79c80) inside a 13-PR combined stack on Windows 11 with an AMD Radeon RX 6700 XT (RDNA2) and Rust 1.98.1 (x86_64-pc-windows-msvc).#688,#652,#346,#472, and#677(plus 7 shader PRs).cargo test -p victory-gpu -- --test-threads=1: 64 passed, 0 failed, 1 ignored (host::tests::deferred_retirement_retains_resources_across_submissionspasses);--features diagnostics: 67 passed, 0 failed, 1 ignored.cargo test --workspace -- --test-threads=1): 329 passed, 0 failed, 6 ignored;cargo xtask policy:155 files ok.AI-assisted verification and stack testing (reviewed locally).
@rpmaster2 on GitHub · 2026-11-24 10:06 UTC · original · edited 2026-11-24 12:31 UTC
Tested on RDNA4: Radeon RX 9070 XT 16 GB, Adrenalin 26.11.2 (32.0.32029.2010), Windows 11 26300, Ryzen 5 5600, 32 GB RAM. Diag build,
VICTORY_D3D12_DRED=1, this branch merged onmain@58fed37, 480 s runs, the same save restored before each run.A/B, identical start state:
mainBoth end in
host GPU device removed, and both are a page fault inside a freed host texture:main:page fault at 0x4721d6000; inside freed ["texture 1024x1024 f95 flags 0x0 (type 34)", "texture 1024x1024 f83 flags 0x0 (type 34)"]page fault at 0x55c25c000; inside freed ["texture 1024x1024 f98 flags 0x0 (type 34)", "texture 1024x1024 f78 flags 0x0 (type 34)"]The PR does get further: in the same window it wrote a new checkpoint save, and
mainwrote none. But the removal is unchanged, so on this host it is not the whole of #557.Context from six earlier runs (3x
main, 2x #688, 1x this PR before the A/B): all died the same way, with 1024x1024 f98/f99/f95/f83, 1024x2048 f98, 2048x2048 f98, 512x512 f29 and 256x256 f99, alwaystype 34. In two runs the stopped list was7d85c9cab3c80721, whose tables come from shaderf0c7efd2aceb2aaaand name placed SRVs. The log also reportsa title texture was released while a list not yet reset names its host copybefore the removal, which is the path this PR targets.One correction to my earlier wording in #597, in case it misled anyone: the
view heap ... past its endtext in the DRED line is only where the fault address lies relative to the heaps (a texture is outside them, so it always prints that); it is not evidence of a wrong heap handle. The meaningful part isinside freed [...].The crash is deterministic here (every run within 8 minutes, frames 1090-1290), so any probe is easy to check. If you want, I can run with extra logging you point me at, or capture the draws of the stopped list.
No game data: texture sizes, formats, shader hashes and counters only.
AI-assisted: written by DeepSeek (OpenCode harness) from my run logs and observations; the hardware, the dump and the runs are mine.
@rpmaster2 on GitHub · 2026-11-24 10:25 UTC · original · edited 2026-11-24 12:31 UTC
More data, and it does not support the window being the problem.
I built this branch locally with
RETAIN_SUBMISSIONS = 64instead of 3 (no other change) and ran it from the same restored save:The 64-window removal has the same signature again:
page fault at 0x473c99000; inside freed ["texture 1024x2048 f72 flags 0x0 (type 34)"], 30 lists.So a 64-submission window makes the removal rarer in one run and not in the next; the stale reference either outlives a much longer window than 3, or it comes from a path that does not go through
release_lateat all. Both would explain why the crash moved from 1m39s to 3m21s with this PR but never disappeared.If it is useful, I can instrument locally: print every
release_lateandHostHeap::keepwith the resource size and format, plus the slot writes for1024x1024 f95/f98/f99/f83and1024x2048 f72/f98(the formats that keep faulting here), then correlate with the stopped list7d85c9cab3c80721. Tell me which log you want and I will produce it - the crash is still reproducible within a few minutes.No game data: sizes, formats, hashes, counters only.
AI-assisted: written by DeepSeek (OpenCode harness) from my run logs and observations; the hardware, the dump and the runs are mine.
@Daniel333313131 on GitHub · 2026-11-24 20:02 UTC · original
Tested on AMD (RDNA3), where
mainfaults on freed textures in the world. With this PR the freed-resource faults remain, in all three runs.Setup: AMD Radeon RX 7900 XTX 24 GB, driver 32.0.32029.2010; Ryzen 7 9800X3D, 32 GB; Windows 11 10.0.26300. Diag build of this PR's head
6d8c72bmerged alone ontomainffe310e, compared withmainitself. Each run used its own emptyVICTORY_CACHE_DIR,VICTORY_D3D12_DRED=1, andVICTORY_KEYSset to Enter every 3 s from 8 s to 47 s. Each run was stopped after 180 s. Method andmainnumbers as in #400.maintexture 2048x2048 f98 (type 34)×2mainmaintexture 2048x1024 f98 (type 34)title buffer 0xcbb800000+0x455d80 (type 34)texture 2048x2048 f98 (type 34)texture 2048x2048 f99 (type 34)main's median.For comparison, #431 on the same machine and method had no freed-resource fault in three runs, and two of them lasted the full 180 s. Details are on that PR.
AI use: Claude Code (Claude Opus 5.5) merged and built the commits, ran the title, summarised the log lines and wrote this comment. The numbers come from the runs above.
@J-DB0 on GitHub · 2026-11-24 21:35 UTC · original
Tested this PR (head
6d8c72b) on an RX 9070 XT (RDNA 4) with an i5-14600KF, in a diag build with VICTORY_D3D12_DRED=1.It doesn't stop the world crash on this card. On main and with this PR alike, the title loads into the world, runs for a while, then the device is removed by a page fault inside freed textures while mesh shaders draw:
page fault at 0x486bfc000; inside freed ["texture 1024x1024 f99 flags 0x0 (type 34)"], a list stopped at command 2183 of 3383 (op 42), around draws of [mesh f0c7efd2aceb2aaa, pixel 7d85c9cab3c80721]page fault at 0x46356f000; inside freed ["texture 2048x2048 f71 flags 0x0 (type 34)", "texture 2048x2048 f71 flags 0x0 (type 34)", "texture 2048x1024 f99 flags 0x0 (type 34)"], a list stopped at command 788 of 856 (op 42), mostly draws of [mesh 51ff151f75cd5759, pixel 7fe75645c406cac6]Time in the world before the crash varies from about 15 s to 2.5 min across my runs; with this PR it was 83 s, so no visible change. I can run another build or turn on GBV if that would help.
@Marvisak on GitHub · 2026-11-25 00:30 UTC · original
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-gpu/src/descriptor/host.rs,crates/victory-gpu/src/host.rs,crates/victory-gpu/src/resource.rs,crates/victory-gpu/src/texture.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.