resource, descriptor: fix slot-pinned dead RT refcount guard, make_again race, twin check, and unmapped guard #4737
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!4737
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-4736"
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?
@nidea1 on GitHub · 2026-12-01 04:25 UTC · original
nidea1:fix/dead-rt-slot-unmapped-guard→main· +834 −127 · 3 files · 2 commits · closed without mergingRefs #4463, #2361
What it changes
Fixes five bugs in
#2361's dead render-target reclamation (reclaim_dead_render_targets_with,evict_dead_rt_slots,HostHeap::texture_slot_evicted_raw) that caused slot-pinned dead render targets to fail reclamation or race under low bury lag / concurrent invalidation:EvictedDeadRtSlotsrefcount guard across Phase 2 (descriptor.rs,descriptor/host.rs,resource.rs): PreviouslyHostHeap::unmakemoved each reset slot's COM ref intoRETIRED, soreferences(&host.texture)stayed>= 2and== 1always failed (freeing 0 bytes and loopingtexture_madeevery 5 s); conversely relaxing to<= 1 + resetfalsely reclaimed live RTs with extra COM holders underVICTORY_BURY_LAG=0or concurrenthost::bury(). Holding the evicted slot refs inEvictedDeadRtSlotsacross Phase 2 allows an exactreferences(&host.texture) == 1 + evicted.held_refs_for(raw)check under any bury lag, then retires all held refs viahost::retire_resourceon drop after resource locks are released.make_againkey-zeroed busy guard (descriptor/host.rs):HostHeap::texture_slot_evicted_rawnow returnsDeadRtSlotEvict::Busywhenmade == 0whilekeptstill holdsexpected_raw(matchingtexture_slot_evicted), so partially invalidated multi-slot RTs abort and restore already-evicted slots instead of skipping.Twinholder check and byte accounting (resource.rs):twin_idle()now checksArc::strong_count(twin) == 1,twin.colour,twin.plane, andtwin.throughreferences (andtwin_bytes()includestwin.plane.bytes), preventing reclamation whileHostList::twin_useor a UAV plane slot still holds the twin.resource.rs): EnforcesBacking::Addressandbacking_wholly_unmapped()after droppingr.host.madebefore queueing slot eviction, and verifiestake_unmapped_hostin Phase 2 without clearingr.host.usedon concurrent remaps (restoring evicted slots viatexture_made).unmapped_idle_msPhase 1 gating (resource.rs): Evaluates bothidle_supersededandidle_unmappedbefore skipping in Phase 1 and queriesrecord_frame_ringseparately withunmapped_idle_ms(30 s) for unmapped slot-pinned candidates.How it was tested
VICTORY_BURY_LAG=0or concurrenthost::bury(), slot-pinned dead RTs either loopedtexture_madeevery 5 s without freeing memory (references == 1failed againstRETIRED) or falsely reclaimed live RTs with extra COM holders under a<= 1 + resetcheck;make_again-zeroed slots were skipped instead of aborting, and depth-stencilTwinplane/Arc holders were unchecked.cargo test -j 2 --locked -p victory-gpu --lib -- resource::tests::— 71 passed, 0 failed, 1 ignored.VICTORY_BURY_LAG=0 cargo test -j 2 --locked -p victory-gpu --lib -- resource::tests::slot_pinned resource::tests::evict_dead_rt_slots resource::tests::dead_depth_rt resource::tests::reclaim_dead_render_targets resource::tests::dead_rt_reclaimable— 9 passed, 0 failed (including new multi-slotmake_againand depth-stencilTwinholder regression tests).cargo test -j 2 --locked -p victory-gpu --lib -- descriptor::— 120 passed, 0 failed, 2 ignored.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: 0 warnings/errors in touched files (origin/main5fabb46ecurrently fails workspace Clippy on 5 pre-existing#4634errors inhost/{font,menu,panel}.rs, tracked in#4707).cargo xtask policy: 464 files ok.cargo testpassed for the crates it touches: yes (targetedresource::tests::anddescriptor::suites invictory-gpu; full--workspaceandcfg(not(windows))not run).Checked for overlap
@nidea1 on GitHub · 2026-12-01 05:33 UTC · original
Live runtime check on RTX 3060 Ti 8 GB / 32 GB RAM (Windows 11, Series S, DLSS Quality, FSR 3 FG, combined with our other open PRs on
5fabb46eaf, two runs reachingt=162sandt=268sbefore0x887A0006on a host with intermittentnvlddmkmEvent 153):0HERO LEAD,0UPLOAD OVER HOST WRITE, clean visuals at+31sand+150s(24.5–26.0 FPS,35.9–38.5 msGPU).678–696 MBduring this short opening scene, so"reclaimed dead idle render targets"did not fire (0dead-RT reclaim events triggered yet in the 2–4 min window).VICTORY_BURY_LAG=0exact refcount guard,make_againbusy abort, and depth-stencilTwinholder protection remain verified by the headless D3D12 test suite (71/71resource::tests::,9/9underVICTORY_BURY_LAG=0,120/120descriptor::); longer multi-scene live RT-churn testing (such as #4463's1.0 -> 1.78 GBsequence) is still pending.@nidea1 on GitHub · 2026-12-01 10:56 UTC · original · edited 2026-12-01 11:48 UTC
Pushed
57e3a622to fix a parallel test flake in the new unmapped dead-RT unit tests without changing production behavior:cargo test --locked -p victory-gpu --lib, unrelated tests inland,shadow, andwatchholdwatch::title_memory_remapping()(MAPPING.write()) for 50 ms+, causing non-blockingtitle_memory_reading_of_now()(try_read()) insidereclaim_dead_render_targets_inner()to returnNone(WouldBlock) and skip Phase 1 or Phase 2 cleanly.reading_ofseam toreclaim_dead_render_targets_inner(),backing_wholly_unmapped_with(),take_unmapped_host_with(), andtake_if_unmapped_with(). Production (reclaim_dead_render_targets_with/take_unmapped_host) continues using non-blockingtitle_memory_reading_of_now(); the dead-RT unit tests pass blockingtitle_memory_reading_of()(never recursively held) to wait past concurrent remap-lock tests, and explicitly verify both Phase 1 and Phase 2 contendedNoneresults (Phase 1 skips without evicting; Phase 2 aborts without detaching or clearingusedand restores the evicted slot viamake_waiting()).57e3a622:cargo test --locked -p victory-gpu --lib:resource::tests::anddescriptor::passed 13/13 full parallel runs (default +VICTORY_RANGE_LOCK=1),0dead-RT failures;--test-threads=1passed1101 passed, 0 failed, 66 ignored(note: a few parallel runs hit unrelated pre-existingorigin/mainflakes inwatch.rs,host/uav_pool.rs, andhost::refresh_tests).VICTORY_BURY_LAG=0dead-RT suite (--test-threads=1):9 passed, 0 failed.cargo clippy -p victory-gpu --all-targets --locked -- -D warningsand--all-features:0warnings/errors inresource.rs,descriptor.rs,descriptor/host.rs(only the 5 pre-existingmain#4634errors inhost/{font,menu,panel}.rs).cargo xtask policy:464 files ok(--staged:1 files ok).281054850dto57e3a6228c@Dukestar69 on GitHub · 2026-12-01 12:05 UTC · original · approved these changes
Reviewed descriptor.rs, descriptor/host.rs, and
esource.rs: holding evicted dead-RT slot COM references in EvictedDeadRtSlots across the TEXTURES /
.host.made check makes 1 + held_refs_for(raw) exact regardless of VICTORY_BURY_LAG or concurrent host::bury(), and retiring them in Drop after unlocking keeps lock ordering clean. Returning DeadRtSlotEvict::Busy when make_again cleared the key while the slot still holds expected_raw, tightening win_idle (including hrough and plane refcounts), and re-checking unmapped backing under the remap guard after slot eviction all close real UAF/refcount races. Verified on Windows (RTX 5090): cargo test -p victory-gpu --lib resource::tests -- --test-threads=1 (71 passed, 0 failed) and descriptor::host::tests (85 passed, 0 failed).
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@nidea1 on GitHub · 2026-12-01 14:39 UTC · original
Thanks @Dukestar69 for the review and RTX 5090 test verification (
resource::testsanddescriptor::host::tests) on57e3a622!@trustno1-coder on GitHub · 2026-12-01 18:34 UTC · original
Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
Pull request closed