[pr-fix][memory] DARNER_TAKE_BLOCKS no longer compares copies that keep no mirror (DARNER_NO_MIRROR) #214
Loading…
Reference in a new issue
No description provided.
Delete branch "infamous20x/Darner:no-mirror-take-blocks"
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?
Contributor role (optional)
What it changes
With
DARNER_NO_MIRROR=1, a copy that no shader writes keeps no mirror. A refresh only notes what goes up, and the send reads title memory (no_mirror,shadow.rs:356-381). That design keeps such copies out of every compare with the mirror:mirror_droppable(:10414) refuseschanges_only,send_changedandkeep_leftcopies.DARNER_TAKE_BLOCKS(#340) came later. For every copy that held a page before,take()(:10232) now sends the page totake_landed(.., all = true), mirrorless copies included.take_landedcompares title memory withself.data4 KiB at a time and sends only the blocks that differ. For a mirrorless copy,self.datais the mirror that was let go (release_mirror,:10529, thenCardCpu::discard,:326):DARNER_CARD_CPU_FILE, on in darner.exe) keeps the bytes it held when it was let go.DARNER_CARD_CPU_HEAP) are discarded, so their bytes are undefined.Neither matches the card's copy once mirrorless sends have gone up from title memory. So:
DARNER_NO_MIRRORis for.This PR:
take(): the block compare and the landing compare only run for a copy that keeps its mirror. A mirrorless copy goes tocopy(), which notes the range for the send, as theno_mirrordoc describes.take_landed(): a mirrorless copy goes back tocopy()at the top.shadow::landing_tests::a_copy_without_its_mirror_is_not_compared_block_by_block. It sets up a mirrorless copy whose old mirror matches title memory in all but one page, and checks that every written page goes up and the mirror stays as it was.Nothing changes without
DARNER_NO_MIRROR=1, becausemirrorless()is then always false. Copies that keep their mirror are compared as before. The cost: a mirrorless copy's written pages go up whole, as withDARNER_TAKE_BLOCKS=0.How it was tested
mainf3840d73. Windows 10 (19045), RTX 4090, Rust 1.98.1 fromrust-toolchain.toml.cargo test -p darner-gpu --lib --locked -- --test-threads=1 --exact shadow::landing_tests::a_copy_without_its_mirror_is_not_compared_block_by_block:main's code (the test added, the fix left out): fails:every page written goes up, left[(4096, 8192)], right[(0, 16384)]. Only the one page that differs from the old mirror went up.cargo test -p darner-gpu --lib --locked -- --test-threads=1 shadow::landing_tests::: passes (4 passed: the new test and the 3 existinglanding_tests).cargo xtask policy: passes (asset policy: 555 files ok).DARNER_NO_MIRRORis off by default, and nothing changes without it.cargo clippy --workspace --all-targets --locked -- -D warnings: passes, no warnings.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes, no warnings.cargo test --workspace --locked: not run. Its GPU tests make a D3D12 device, and on this Windows 10 PC they end the test process. The unit tests of the changed code are listed above.VICTORY_*names: RTX 4090, Series X profile, 1440p, DLSS Quality, frame generation off, hardware ray tracing on, 32 GB RAM, Windows 10 (19045).VICTORY_NO_MIRRORalso lets go of the shared mirrors and leaves the pointer null. WithVICTORY_TAKE_BLOCKSon, the compare wrote title bytes at address 0 plus the offset, into memory that belonged to something else.VICTORY_TAKE_BLOCKS=0, the game got past that point (50-70 s in the world).DARNER_NO_MIRROR=1.Checklist
main.docs/asset-policy.md.Checked for overlap
TAKE_BLOCKS,NO_MIRROR, mirrorless,take_landedand mirror. We also searchedmain's history.908a6416) addedDARNER_TAKE_BLOCKS.4cfb694cfixed a host test for it. Neither touches mirrorless copies.shadow.rs, for other problems: #37, #56 and #62. #56 changes thereturn self.copy(from, to)line right after the hunk intake(), so a textual conflict is possible.Independent Windows build, red/green test, and code-read review of
04a41e3ab(based onmainf3840d73d). Not run in-game.Environment
x86_64-pc-windows-msvc), MSVC 19.44.35230.Measured results
main(f3840d73d+ PR's new test only):cargo test --locked -p darner-gpu --lib shadow::landing_tests::a_copy_without_its_mirror_is_not_compared_block_by_block -- --exact --nocapture: FAILED (assertion left == right failed: every page written goes up,left: [(4096, 8192)],right: [(0, 16384)]).04a41e3ab) with default env:cargo clippy --workspace --all-targets --locked -- -D warnings): PASScargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASScargo xtask policy: PASS (asset policy: 555 files ok)cargo test --locked -p darner-gpu --lib shadow::landing_tests -- --nocapture: PASS (4 passed; 0 failed).04a41e3ab) withDARNER_SEND_CHANGED=1:DARNER_SEND_CHANGED=1 cargo test --locked -p darner-gpu --lib shadow::landing_tests::a_copy_without_its_mirror_is_not_compared_block_by_block -- --exact --nocapture: FAILED (left: [(4196, 4200)],right: [(0, 16384)]).Finding
changes_only/send_changed+keep_stores()race) atcrates/darner-gpu/src/shadow.rs:10225-10240:self.mirrorless()only inside theelsebranch (shadow.rs:10228-10236), leavingif self.changes_only.load(Ordering::Relaxed) || send_changed()(shadow.rs:10227->take_into()at:10240) unguarded.DARNER_SEND_CHANGED=1, this leaves a concurrent race inkeep_stores()(shadow.rs:10611-10619, called frommemory.rs:727):self.changes_only.store(true, Ordering::Relaxed)runs beforeself.revive_mirror()acquiresself.copy_lock. A concurrent refresh holdingcopy_lockinsidetake()can observechanges_only == truewhileself.mirrorless()is stilltrue, and calltake_into()against the discarded mirror.Shadow::takealongsidedirect_paged:if self.direct_paged().is_some() || self.mirrorless() { return self.copy(from, to); }(atshadow.rs:10225, and defensively intake_quietat:10262). That closes thekeep_stores()race, makes the test pass underDARNER_SEND_CHANGED=1, and simplifies lines10232-10236.Verdict: Root cause is real and reproduced; recommend hoisting
self.mirrorless()toshadow.rs:10225sochanges_only/send_changedcannot bypass it.AI-assisted: yes (Gemini 4 Neon).
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.