GPU: release resources the CPU is done with behind the queue #575
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!575
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-575"
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?
@Len1k on GitHub · 2026-11-24 05:10 UTC · original
Len1k:gpu/release-behind-the-queue→main· +51 −4 · 3 files · 3 commits · openFollow-up to what I read in #557 and #304: a host resource whose last CPU reference goes away is released immediately, while GPU work that may still read it can be queued.
HostHeap::keep(crates/victory-gpu/src/descriptor/host.rs:279)ID3D12Resourceduring recording;make_at,make_null,mirrorandconstant_atall go through itshadow::unregister(crates/victory-gpu/src/shadow.rs:391)Arc<Shadow>and with itShadow::bufferThe comment on
unregistersaid "lists that still hold its copy keep it alive", butDeferred(crates/victory-gpu/src/host.rs) holdscopies,uploads,kept(named host objects),refreshed,textures: HashSet<usize>(texture ids),writesandbudget_zeroed— noArc<Shadow>. A list reads a copy by binding it, so a draw with no bindings has nothing to hold; anExecuteIndirecttakes its arguments from memory a shader wrote, so no list can name what it will read.The console reads stale memory where the host page-faults. On the host that is a removed device:
page fault at 0x…; inside freed ["texture 1024x1024 …"], with the stopped command anExecuteIndirectkind 10 mesh list.Change
release_late(ID3D12Resource)(host.rs) queues a resource instead of dropping it;Host::executedrains the queue once the fence's event has been waited for, which is the only point where a resource is provably past use. Both paths above now hand their resource to it. Nothing is released earlier than before — the free is only deferred — so this cannot break a read.Tested
cargo test -p victory-gpuonmainof this fork: 43 passed, 0 failed, 1 ignored.Built with the
x86_64-pc-windows-gnutarget (rustc 1.98.1, llvm-mingw fromtools/), because this machine has no MSVC toolchain. No title was run and no game files were used, so this is not evidence that #557 is fixed — it removes two frees that cannot be justified by anything the host tracks, and the page fault may still have another source (a pooled snapshot buffer, or a free I have not found).Happy to shape it differently if the maintainer would rather keep the queue on
Hostinstead of a static, or drain it per list rather than per submission.AI-assisted (OpenCode).
A host resource whose last CPU reference went away was released immediately, while GPU work that may still read it could be queued. Two paths did that: * HostHeap::keep assigned the slot's new resource over the old one, dropping the previous ID3D12Resource during recording (make_at, make_null, mirror, constant_at all go through it). * shadow::unregister dropped a released title buffer's copy. Its comment claimed "lists that still hold its copy keep it alive", but Deferred holds texture ids and named host objects, never an Arc<Shadow>: a list reads a copy by binding it, and an execute-indirect draw takes its arguments from memory a shader wrote, so no list can name what it will read. The console reads stale memory where the host page-faults, so on the host the result is a removed device: "page fault at 0x...; inside freed [...]" with the stopped command an ExecuteIndirect mesh list, as in #557 and #304. Both paths now hand the resource to a queue drained by Host::execute once the fence's event has been waited for, which is the only point where a resource is provably past use. Nothing is released earlier than before, so this cannot break a read; it only defers the free. Tested with `cargo test -p victory-gpu`: 43 passed, 0 failed, 1 ignored. No device is involved in those tests, and no title was run, so this is not evidence that #557 is fixed — it removes two frees that cannot be justified, and the fault may still have another source. AI-assisted (OpenCode).@KingKaom on GitHub · 2026-11-24 05:26 UTC · original
Tested this branch (head
69e44f5, merged locally with #336 since it is based on plain main) on the RX 9070 XT rig from #557: 24.2 s into the world, device removed, identical DRED signature —page fault inside freed ["texture 1024x1024 f98 flags 0x0 (type 34)"], stopped command an ExecuteIndirect kind-10 mesh list — with zero dynamic-slot warnings (#336 still doing its job). Same key-script, DRED on, diagnostics build.So the merge looks right on its own merits (the two free paths are real; independent DRED naming agrees), but the world-entry fault survives it here, as predicted on #557 — the only build that ever avoided the signature was the never-free cap run (451 s, fault-free, to end credits): table and discussion in #557 . Current suspect on this rig: VA recycling after
Releaserather than object lifetime. Happy to re-run whenever you push.AI-assisted (Hermes Agent).
@Len1k on GitHub · 2026-11-24 05:46 UTC · original
Thanks for running it — that result is the one that decides how this PR should be read, and it argues against my premise rather than for it.
If every submission is waited for (
Host::executesignals the fence and callsWaitForSingleObject(..., INFINITE), which the module's ownshortcutnote states), then at the moment this branch frees a resource the GPU is idle: there is no in-flight list of any kind that could still read it. So "freed while queued work may still read it" cannot be the mechanism, and the fault surviving here is consistent with that. The two paths this PR closes —HostHeap::keepoverwriting a live slot'sID3D12Resource, andshadow::unregisterdropping a copy while a shader-written argument could still name it — remain real defects on their own terms, because neither has anything to do with how long the work sits queued, but neither is the page fault you are reproducing.That also makes your VA-recycling suspect the more interesting one: if the fault address is inside a freed texture whose object lifetime is already correct, the reuse of the VA range by a later allocation is what turns a stale reference into a fault, and no retention window or drain point can prevent it — which is exactly what the fence/retention table on #557 shows. Tracking list-lifetime (or never reusing a VA) would bound it; delaying release does not.
Where that leaves this PR: reviewed as resource-lifetime hygiene, not as a fix for #557. The body already says the tests are no evidence about the title, but your run is the first measurement that contradicts the "freed while in flight" reading, so it belongs in the thread. If #609's retirement queue lands, this branch's contents are mostly subsumed by it — I would rather that be said than have both merged blind.
Nothing to retest on my side until it changes; if you push another revision, I can rebuild and run
cargo test -p victory-gpuagain, though that says nothing about the fault.AI-assisted.
@hashdev512 on GitHub · 2026-11-24 11:22 UTC · original
Test report from an RX 9070 XT (RDNA4), Ryzen 7 5700X3D, driver 32.0.32029.2010 (Adrenalin 26.11.2), Windows 11 build 26300.
diagbuild with--features diagnostics,VICTORY_D3D12_DRED=1, Series X mode, package v1.0.2.1. Every figure below is one run unless it says otherwise, so treat the times as indicative. "Time" is from process start to device removal.This PR merged locally (no conflicts, 50
victory-gputests pass):8e79c80texture 2048x2048 f718e79c800x457826000inside freed["texture 1024x1024 f99", "texture 1024x1024 f95"]; a list stopped at command 415 of 606 (op 42, mesh draws)ffe310edispatch 12x1x1 [compute eeed82b877b44b5f](command 4 of 11)ffe310e0x1f00f0000So on
8e79c80the PR gets about 1.5 min further but still ends in a freed texture. Onffe310eI can't measure a difference: plainmainno longer hit the freed-texture fault in my one run. The 12 commits between the two are all in the shader translator (per-lane descriptors, waterfall loops), none in resource lifetime, so I don't know whether they removed the trigger or the run was lucky.What I measured on
8e79c80before finding this PR, with local diagnostic switches at the same two sites you name plusDrop for Resource:HostTextureof a released title texture, for 4 more completed submissionstexture 2048x1024 f98HostTextureof every released title texture, for the whole runeeed82b877b44b5fcompute dispatchHostHeap::keepreplaced it, for the whole runshadow::unregister), for the whole runTwo things follow for this PR, as far as single runs can show:
HostHeap::keep, as you say. Delaying the texture's own drop does nothing, even by 300 submissions: the slot keeps the texture alive after the title releases it, and the free happens whenever that slot is rewritten, which can be much later.executein progress or the next one, and on the same commit it still faulted inside freed textures at 3 min 59 s. I have not found why one more submission would matter.executeis serialized, so the queue is idle when you drain. It may be run-to-run variance; I can rerun either build if that helps.Whatever is kept, every run that survives the freed-texture fault ends at the same place: a
dispatch 12x1x1of computeeeed82b877b44b5f, right afterdispatch 1x1x1 [compute 37e19ccb4f889f63], with a page fault outside every allocation. That is a separate bug this PR does not touch (also mentioned in #743).The diagnostic switches are local only and not part of any PR. No game data here: hashes, addresses, sizes and timings from VIctory's own log.
AI-assisted (Claude Fable 5.2): runs launched and logs summarised by the model on my machine; times and DRED lines taken from the logs.
@KingKaom on GitHub · 2026-11-24 11:28 UTC · original
Three data points from my RX 9070 XT / 32 GB box that bear on your last two paragraphs — single runs each, same caveats you stated.
Plain
mainatffe310ehas NOT stopped faulting here.diagbuild,DEBUG+DRED: ~26 s in-world,page fault at 0x3990da000; inside freed ["texture 1024x1024 f98"], a list stopped at command 1177 of 1432 (op 42), device removed. So my single run onffe310eended inside the freed-texture class you stopped seeing — your 6 min 20 s may well have been luck rather than the translator merge, as you suspected.No finite delay has removed the freed family on my box (all
diag+DRED, single runs, seconds in-world before an identicalinside freedsignature):Your "replaced slot resource until 2 more submissions completed" (5 min 40 s, no freed fault) is the opposite result — two single runs can't separate luck from machine difference there. What my ladder does say: the only policy that reliably dodged the family here is never freeing at all, and my earlier free-path layering also found the slot-rewrite site the only free point whose removal doubled survival (47 s → 122 s) — both consistent with your conclusion that
HostHeap::keepis the site that matters on this card.Separately, in case it moots the delay designs: on my box #493's bounded root SRV views (stacked on #431) also removed the fault class entirely (~6.5 min, zero page faults, ending in a GPU timeout at ~1 fps instead) — posted on that PR. For completeness on the new endpoint: compute
eeed82b877b44b5fwas never dispatched in that fault-free run, so the #743 endpoint isn't yet this box's end of the road.AI-assisted Hermes Agent.
@Daniel333313131 on GitHub · 2026-11-24 20:29 UTC · original
Tested on AMD (RDNA3), where
mainfaults on freed textures in the world. With this PR the freed-texture 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
69e44f5merged alone ontomainffe310e. 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. The method and themainnumbers are in #400.maintexture 2048x2048 f98 (type 34)texture 2048x2048 f98,texture 2048x2048 f71 (type 34)texture 2048x2048 f71 (type 34)main's median of 143 s.For comparison, on the same machine and with the same method:
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.
@Marvisak on GitHub · 2026-11-25 00:27 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/shadow.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.