GPU: serialize PresentX texture state reads and barriers under Host::submitted #3202
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3204"
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 fuzeofficlal on 2026-11-26T12:30:58Z.
Problem
All regular GPU submissions read and update
HostTexture::stateunderHost::submittedinsideHostList::prelude.queue::presentandHost::presentviolated that invariant:queue::presentcalledresource::host_transition(resource, COPY_SOURCE)before enteringHost::presentand without holdingHost::submitted, publishing a phantomCOPY_SOURCE(0x800) state while the host resource was still in its prior GPU state (e.g.RENDER_TARGET = 0x4). Any concurrentHost::executeon another queue observed that phantom state inHostList::preludeand emitted a mismatchedStateBeforetransition barrier.Host::present_with_compositorrecordedp.copy's before/after transition barriers using that pre-call state snapshot beforeHost::executeacquiredHost::submitted. If a concurrent submission transitioned the texture beforep.copyran,p.copyexecuted with a staleStateBeforebarrier.Host::presentreturned (having already releasedHost::submittedbeforeIDXGISwapChain::PresentandMeter::frame),queue::presentunconditionally calledresource::host_transition(resource, state)outsideHost::submitted, overwriting any state change made by an intervening submission and permanently desynchronizingHostTexture::statefrom the GPU.Fix
PresentPlane::Tracked(&HostTexture)andHost::present_planessoqueue::presentpasses liveArc<HostTexture>handles directly instead of mutatingHostTexture::statebefore and after presentation.Host::submittedinsideHost::present_planes_with_compositor(preserving the existingpresenter -> submittedlock order) before reading each plane's liveHostTexture::state, recordingp.copy's barriers, and executingp.copyviaHost::execute_locked. Becausep.copytransitions each plane back to its observed state beforeHost::submittedis released,HostTexture::statestays in lockstep with the GPU without unsynchronized mutations.resource::host_transitionto#[cfg(all(windows, test))], asqueue::presentwas its only non-test caller.Tests
queue::tests::present_does_not_expose_copy_source_or_clobber_concurrent_state: fails onmain(exposes phantomCOPY_SOURCE = 2048instead ofRENDER_TARGET = 4, causes barrier replay mismatches on concurrent/present submissions, and clobbersHostTexture::stateafterward); passes with this fix.host::present_state_sync_tests::present_planes_reads_live_state_under_submission_lock: deterministically runs an interveningHost::executeduring compositor preparation and verifies viahost::tests::replaythat both single-plane fallback and multi-plane composite paths read the live GPU state underHost::submittedand emit matching transition barriers.rustfmt --edition 2024, RTX 5090 + WARP withVICTORY_D3D12_DEBUG=1, full WARPvictory-gpusuite (248 passed, 0 failed, 1 ignored),cargo clippy --workspace --all-targets --locked -- -D warnings(default and--all-features), andxtaskpolicy check.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T12:48:32Z.
Review: APPROVED
Verified on RTX 5090 against
origin/main(63bcca4):cargo test -p victory-gpu --lib queue:: -- --test-threads=1: 6/6 passed (includingpresent_does_not_expose_copy_source_or_clobber_concurrent_state).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly serializes
PresentXtexture state reads and barriers underHost::submitted.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T14:05:03Z.
WARP test report: head
f76d3f47(parent and control base: main63bcca43)VICTORY_WARP=1,VICTORY_D3D12_WARP=1,cargo test -j 4 -p victory-gpu --features diagnostics --lib, rustc 1.98.1, Windows 11,dxil.dllfrom the Windows SDK 10.0.26100.0.host::present_state_sync_tests::present_planes_reads_live_state_under_submission_lockandqueue::tests::present_does_not_expose_copy_source_or_clobber_concurrent_stateboth pass. The wholevictory-gpulib suite passes: 249 passed (248 plus the probe), 0 failed, 1 ignored.queue.rscode with this PR's test module (and this PR'shost.rs).present_does_not_expose_copy_source_or_clobber_concurrent_statefails:present must not mutate tracked state before acquiring the submission lock(left 2048, right 4).present_planes_with_compositor, which main doesn't have, so it can't be built on main. I used a mutation of this head instead: the tracked states are read at the start ofpresent_planes_with_compositor, before the compositor callback and beforeHost::submittedis locked. With that mutation, both tests fail:present_planes_reads_live_state_under_submission_lock(left 4, right 2048) andpresent_does_not_expose_copy_source_or_clobber_concurrent_state(present copy barriers:before 0x4, but the resource is in 0x80). Moving only the lock, with the state read still after the callback, did not fail the host test, so that test doesn't check lock order on its own.AI-assisted: verification by Claude Code (Claude Sonnet 5.5).
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.