GPU: pin textures with pending host_writes against eviction #2601
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!2601
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2601"
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?
@fuzeofficlal on GitHub · 2026-11-25 16:35 UTC · original
fuzeofficlal:fix/gpu-evict-pending-host-writes→main· +380 −22 · 3 files · 1 commits · openSummary
texture::host_writesdefers settingHostTexture::host_written = trueuntilHostList::run_deferredruns at submission time. InHost::execute,resource::evict_unused()runs beforelist.run_deferred(&mut batch)(and eviction can also run between recording a copy/resolve list and submitting it on another queue).During that window,
resource::evictable()seeshost_written == falseand can evict the destinationHostTextureeven though a recorded command list is about to write to it viaCopyResource,CopyTextureRegion, orResolveSubresource. When the list subsequently executes, the copy lands in the orphaned host texture, and later readers re-create the texture from stale title memory.Changes
crates/victory-gpu/src/resource.rs:HostTexture::pending_host_writes: AtomicUsize(initialized to0).evictable()to checkpending_host_writes.load(Acquire) == 0before!host_written.load(Acquire).crates/victory-gpu/src/texture.rs:host_writes(), incrementpending_host_writesand move aDropRAII guard (PendingHostWrite) into thelist.defer_host(...)closure that storeshost_written = true(Release). BecauseHostList::run_deferredborrows closures untilHostList::reset()/Drop, the pin stays active through execution and is released without leaking VRAM if an unexecuted list is reset or dropped.Acquireordering inis_host_written().pending_host_write_pins_texture_until_executed_and_unpins_on_reset, verifying: (1) an unexecuted list withCopyResourcepinsdstagainstgive_up_nowand unpins onReset, (2) a recordedCopyResourceblocks eviction before execution, and (3) after executing and resetting the list,dstremains un-evictable and reads back the copied[0xAA; 4]texels rather than stale0x40title memory.Verification
pending_host_write_pins_texture_until_executed_and_unpins_on_resetfails atpending CopyResource must pin dst against eviction.VICTORY_D3D12_WARP=0) and WARP (VICTORY_D3D12_WARP=1):cargo test -p victory-gpu --lib texture::tests -- --test-threads=1— 3/3 pass on both backends.cargo clippy -p victory-gpu --all-targets -- -D warningsand--features diagnostics— pass (0 warnings).cargo xtask policy— pass (184 files ok).@oni-swr on GitHub · 2026-11-25 16:49 UTC · original
Verification of
5e7cbb4Environment: Windows 11, D3D12 on the WARP software adapter only (
VICTORY_D3D12_WARP=1,cargo ... --features diagnostics, which is what compiles that switch in;VICTORY_DXILset to the Windows SDKdxil.dll). No physical GPU device was created. Not run on real GPU hardware.git merge-treeagainstorigin/main(67e8ae1) is clean.cargo test -p victory-gpu --features diagnostics --lib pending_host_write_pins_texture_until_executed_and_unpins_on_reset: 1 passed. I confirmed it runs on a real WARP device and is not skipped.pending_host_writes == 0condition removed fromevictable()and the test kept, it fails.cargo test -p victory-gpu --features diagnostics --lib: 199 passed, 0 failed, 1 ignored in two of three runs. One run had 1 failure,frame::tests::waits_end_on_ticks_and_count_frames. That test is unrelated to this diff. It also failed onorigin/mainin 1 of 3 runs there (along withdescriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_waitonce), so it looks flaky under parallel tests.cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.Independent verification by Claude Code (Claude Sonnet 5.5), an AI assistant, run for oni-swr. No game files, dumps, or shader names were used.
@fuzeofficlal on GitHub · 2026-11-25 16:54 UTC · original
Thanks @DrDarkDK — both concurrency windows are real and fixed in
883db7ad:texture::PendingHostWriteandtexture::prepare_host_write(resource), which acquiresHostTextureand incrementspending_host_writesviafetch_updaterejectingEVICTEDcopies (detaching any claimed copy viaresource::detach_if_sameand filteringEVICTEDentries out ofshared_texture'sMEMORYweak-reference cache before retrying). Updatedcopy_resource,copy_texture_region,resolve, andtexture::alias_copyto obtain their targetID3D12Resourcedirectly from the pinnedPendingHostWriteand commit it viarecord(list)(dropping early on validation failure releases the pin without settinghost_written).resource::give_up, each candidate fromcandidates()is now claimed atomically viapending_host_writes.compare_exchange(0, EVICTED, AcqRel, Acquire)beforedescriptor::evictor clearingresource.host.PendingHostWrite::recordalso sets a stickyHOST_WRITTENbit on submission sopending_host_writesnever returns to zero once committed. Any texture pinned aftercandidates()ran fails the CAS and is skipped untouched.stale_eviction_snapshot_skips_texture_pinned_after_candidates(Window 2) andprepare_host_write_detaches_claimed_evicted_copy_and_pins_replacement(Window 1) alongside the original copy/reset/readback test.Re-verified on RTX 5090 (
texture::tests5/5,resource::tests17/17,draw::testshost-write & eviction tests) and WARP--features diagnostics(fullvictory-gpu --lib: 201 passed, 0 failed), plusclippy -D warnings(default & diagnostics) andcargo xtask policy.@Machad3x on GitHub · 2026-11-25 18:26 UTC · original
Setup: RTX 3080 Ti (driver 621.24), Windows 11, a local stack of open PRs merged with main
67e8ae1.Applied cleanly on that stack, together with #2598, #2576, #2611, #2626. One 10-minute game run reached gameplay with no device removal. These five PRs were not tested one by one, so nothing in that run is attributed to this PR alone.
Written with Claude Code; tested locally.
@Marvisak on GitHub · 2026-11-25 23:18 UTC · original
Automated triage for the maintainers.
This pins a destination host texture against eviction from the moment a copy, copy-region, resolve or alias copy is recorded until the list's deferred host step runs or the list is reset. It adds
texture::prepare_host_write/PendingHostWriteand apending_host_writescounter onHostTexture.resource::give_upnow claims each candidate with a CAS to anEVICTEDbit, andshared_textureignores claimed copies, which closes the race whereevict_unusedruns beforerun_deferredsetshost_written. I checked that every non-test caller oftexture::host_writesinlist.rsandtexture::alias_copynow uses the pin.host_copyandhost_resourceresolve the sameresource.host(), so behaviour stays the same for buffers and missing copies, and early returns drop the guard and unpin.host_writesitself is now only used by thedraw.rstest. This adds a new lock-free protocol (pin count plusEVICTED/HOST_WRITTENbits), so it deserves a careful maintainer read. The three new tests cover pin/unpin on reset, a candidate snapshot taken before a pin, and a copy already claimed. It merges cleanly with currentmain. CI: passing (check). This is a recommendation for a maintainer to look, not an approval.Generated by 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.