[pr-fix][memory] DARNER_TAKE_BLOCKS no longer compares copies that keep no mirror (DARNER_NO_MIRROR) #214

Open
infamous20x wants to merge 1 commit from infamous20x/Darner:no-mirror-take-blocks into main
First-time contributor

Contributor role (optional)

  • Fluxer ID: 1574838609712783360

What it changes

  • The problem on main: found by reading the code. The new unit test fails on main (see below). In VIctory, the same two switches crashed the game (details below).

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) refuses changes_only, send_changed and keep_left copies.

DARNER_TAKE_BLOCKS (#340) came later. For every copy that held a page before, take() (:10232) now sends the page to take_landed(.., all = true), mirrorless copies included. take_landed compares title memory with self.data 4 KiB at a time and sends only the blocks that differ. For a mirrorless copy, self.data is the mirror that was let go (release_mirror, :10529, then CardCpu::discard, :326):

  • A file's view (DARNER_CARD_CPU_FILE, on in darner.exe) keeps the bytes it held when it was let go.
  • Private pages (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:

  • If the title writes a 4 KiB block back to the bytes the mirror still holds, the block is not sent. The card's copy keeps what an earlier send put there.
  • Every block that differs is written into the mirror that was let go. That brings its pages back into memory, which is the opposite of what DARNER_NO_MIRROR is for.

This PR:

  • take(): the block compare and the landing compare only run for a copy that keeps its mirror. A mirrorless copy goes to copy(), which notes the range for the send, as the no_mirror doc describes.
  • take_landed(): a mirrorless copy goes back to copy() at the top.
  • New unit test: 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, because mirrorless() 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 with DARNER_TAKE_BLOCKS=0.

How it was tested

  • Tested revision: this commit on main f3840d73. Windows 10 (19045), RTX 4090, Rust 1.98.1 from rust-toolchain.toml.
  • Commands and results:
    • 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:
      • on 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.
      • with this change: passes (1 passed).
    • cargo test -p darner-gpu --lib --locked -- --test-threads=1 shadow::landing_tests::: passes (4 passed: the new test and the 3 existing landing_tests).
    • cargo xtask policy: passes (asset policy: 555 files ok).
  • Changes a default: no. DARNER_NO_MIRROR is off by default, and nothing changes without it.
  • A/B result: none. This changes no default and makes no speed claim. It was checked with the unit test above, and with the VIctory runs below.
  • Gates run on that revision:
    • 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.
  • Gameplay: none on Darner. In VIctory, with the same code under VICTORY_* names: RTX 4090, Series X profile, 1440p, DLSS Quality, frame generation off, hardware ray tracing on, 32 GB RAM, Windows 10 (19045).
    • In VIctory, VICTORY_NO_MIRROR also lets go of the shared mirrors and leaves the pointer null. With VICTORY_TAKE_BLOCKS on, the compare wrote title bytes at address 0 plus the offset, into memory that belonged to something else.
    • Three runs on the same save crashed the game the same way, 18 to 44 s into the world: an access violation at the same instruction, reading an address that was reserved but never committed.
    • With VICTORY_TAKE_BLOCKS=0, the game got past that point (50-70 s in the world).
    • With this guard and TAKE_BLOCKS on, the next two runs on the same save did not crash (4.6 min and about 1.5 min in the world). Both ended in a device loss with hardware ray tracing. That loss also happens without this change.
    • In Darner the mirror that was let go keeps its address. So the compare reads old bytes rather than wild memory. The expected symptom is a stale block on the card, not a crash, and we have not seen it in a game.
  • Shader wave sizes tested: not relevant (no shader change).
  • Hardware dependence: likely general. It is CPU-side bookkeeping.
  • Coverage gaps:
    • No run on Darner, with or without DARNER_NO_MIRROR=1.
    • No game result shows a stale block on Darner. It comes from reading the code, and the unit test shows it.
    • How many more bytes mirrorless copies send without the block compare was not measured.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not on Darner. The same guard ran in VIctory (see "How it was tested").
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found for the same problem.
    • On 2026-12-04 we searched the titles and bodies of all 136 pull requests and 73 issues on git.gtahub.st for TAKE_BLOCKS, NO_MIRROR, mirrorless, take_landed and mirror. We also searched main's history.
    • #340 (CodeFloe, merged as 908a6416) added DARNER_TAKE_BLOCKS. 4cfb694c fixed a host test for it. Neither touches mirrorless copies.
    • Open PRs that change shadow.rs, for other problems: #37, #56 and #62. #56 changes the return self.copy(from, to) line right after the hunk in take(), so a textual conflict is possible.
  • Replaces or overlaps: none found.
## Contributor role (optional) - Fluxer ID: 1574838609712783360 ## What it changes - The problem on main: found by reading the code. The new unit test fails on main (see below). In VIctory, the same two switches crashed the game (details below). 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`) refuses `changes_only`, `send_changed` and `keep_left` copies. `DARNER_TAKE_BLOCKS` (#340) came later. For every copy that held a page before, `take()` (`:10232`) now sends the page to `take_landed(.., all = true)`, mirrorless copies included. `take_landed` compares title memory with `self.data` 4 KiB at a time and sends only the blocks that differ. For a mirrorless copy, `self.data` is the mirror that was let go (`release_mirror`, `:10529`, then `CardCpu::discard`, `:326`): - A file's view (`DARNER_CARD_CPU_FILE`, on in darner.exe) keeps the bytes it held when it was let go. - Private pages (`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: - If the title writes a 4 KiB block back to the bytes the mirror still holds, the block is not sent. The card's copy keeps what an earlier send put there. - Every block that differs is written into the mirror that was let go. That brings its pages back into memory, which is the opposite of what `DARNER_NO_MIRROR` is for. This PR: - `take()`: the block compare and the landing compare only run for a copy that keeps its mirror. A mirrorless copy goes to `copy()`, which notes the range for the send, as the `no_mirror` doc describes. - `take_landed()`: a mirrorless copy goes back to `copy()` at the top. - New unit test: `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`, because `mirrorless()` 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 with `DARNER_TAKE_BLOCKS=0`. ## How it was tested - Tested revision: this commit on `main` f3840d73. Windows 10 (19045), RTX 4090, Rust 1.98.1 from `rust-toolchain.toml`. - Commands and results: - `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`: - on `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. - with this change: passes (1 passed). - `cargo test -p darner-gpu --lib --locked -- --test-threads=1 shadow::landing_tests::`: passes (4 passed: the new test and the 3 existing `landing_tests`). - `cargo xtask policy`: passes (`asset policy: 555 files ok`). - Changes a default: no. `DARNER_NO_MIRROR` is off by default, and nothing changes without it. - A/B result: none. This changes no default and makes no speed claim. It was checked with the unit test above, and with the VIctory runs below. - Gates run on that revision: - `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. - Gameplay: none on Darner. In VIctory, with the same code under `VICTORY_*` names: RTX 4090, Series X profile, 1440p, DLSS Quality, frame generation off, hardware ray tracing on, 32 GB RAM, Windows 10 (19045). - In VIctory, `VICTORY_NO_MIRROR` also lets go of the shared mirrors and leaves the pointer null. With `VICTORY_TAKE_BLOCKS` on, the compare wrote title bytes at address 0 plus the offset, into memory that belonged to something else. - Three runs on the same save crashed the game the same way, 18 to 44 s into the world: an access violation at the same instruction, reading an address that was reserved but never committed. - With `VICTORY_TAKE_BLOCKS=0`, the game got past that point (50-70 s in the world). - With this guard and TAKE_BLOCKS on, the next two runs on the same save did not crash (4.6 min and about 1.5 min in the world). Both ended in a device loss with hardware ray tracing. That loss also happens without this change. - In Darner the mirror that was let go keeps its address. So the compare reads old bytes rather than wild memory. The expected symptom is a stale block on the card, not a crash, and we have not seen it in a game. - Shader wave sizes tested: not relevant (no shader change). - Hardware dependence: likely general. It is CPU-side bookkeeping. - Coverage gaps: - No run on Darner, with or without `DARNER_NO_MIRROR=1`. - No game result shows a stale block on Darner. It comes from reading the code, and the unit test shows it. - How many more bytes mirrorless copies send without the block compare was not measured. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). - Not on Darner. The same guard ran in VIctory (see "How it was tested"). - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found for the same problem. - On 2026-12-04 we searched the titles and bodies of all 136 pull requests and 73 issues on git.gtahub.st for `TAKE_BLOCKS`, `NO_MIRROR`, mirrorless, `take_landed` and mirror. We also searched `main`'s history. - #340 (CodeFloe, merged as 908a6416) added `DARNER_TAKE_BLOCKS`. 4cfb694c fixed a host test for it. Neither touches mirrorless copies. - Open PRs that change `shadow.rs`, for other problems: #37, #56 and #62. #56 changes the `return self.copy(from, to)` line right after the hunk in `take()`, so a textual conflict is possible. - Replaces or overlaps: none found.
With DARNER_NO_MIRROR=1 a copy no shader writes keeps no mirror: a refresh
only notes what goes up, and the send reads title memory. A page the copy
took before and the title wrote since reaches take() with known = true,
and DARNER_TAKE_BLOCKS (on) sent it to take_landed, which compares title
memory with the mirror 4 KiB at a time and sends only the blocks that
differ. The mirror let go holds what it held when it was let go (a file's
view, DARNER_CARD_CPU_FILE, on in darner.exe) or bytes no longer known
(private pages discarded, DARNER_CARD_CPU_HEAP), not what the card's side
holds: a block the title wrote back to those bytes was not sent, and the
card's side kept what an earlier send put there. The compare also wrote
title memory into the mirror let go, bringing its pages back.

take() looks at blocks (and at landings) only for a copy with its mirror;
take_landed returns to copy() for one without. Copies with their mirror,
and every copy without DARNER_NO_MIRROR, are taken as before.

Test: a_copy_without_its_mirror_is_not_compared_block_by_block.
First-time contributor

Independent Windows build, red/green test, and code-read review of 04a41e3ab (based on main f3840d73d). Not run in-game.

Environment

  • Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (x86_64-pc-windows-msvc), MSVC 19.44.35230.

Measured results

  • Red on 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)]).
  • Green on PR #214 (04a41e3ab) with default env:
    • Gate 1 (cargo clippy --workspace --all-targets --locked -- -D warnings): PASS
    • Gate 2 (cargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASS
    • cargo xtask policy: PASS (asset policy: 555 files ok)
    • cargo test --locked -p darner-gpu --lib shadow::landing_tests -- --nocapture: PASS (4 passed; 0 failed).
  • Failed on PR #214 (04a41e3ab) with DARNER_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

  • Remaining mirror-compare path (changes_only / send_changed + keep_stores() race) at crates/darner-gpu/src/shadow.rs:10225-10240:
    • PR #214 gates self.mirrorless() only inside the else branch (shadow.rs:10228-10236), leaving if self.changes_only.load(Ordering::Relaxed) || send_changed() (shadow.rs:10227 -> take_into() at :10240) unguarded.
    • Aside from failing the new unit test under DARNER_SEND_CHANGED=1, this leaves a concurrent race in keep_stores() (shadow.rs:10611-10619, called from memory.rs:727): self.changes_only.store(true, Ordering::Relaxed) runs before self.revive_mirror() acquires self.copy_lock. A concurrent refresh holding copy_lock inside take() can observe changes_only == true while self.mirrorless() is still true, and call take_into() against the discarded mirror.
    • Suggested fix: Hoist the check to the top of Shadow::take alongside direct_paged:
      if self.direct_paged().is_some() || self.mirrorless() { return self.copy(from, to); } (at shadow.rs:10225, and defensively in take_quiet at :10262). That closes the keep_stores() race, makes the test pass under DARNER_SEND_CHANGED=1, and simplifies lines 10232-10236.

Verdict: Root cause is real and reproduced; recommend hoisting self.mirrorless() to shadow.rs:10225 so changes_only / send_changed cannot bypass it.

AI-assisted: yes (Gemini 4 Neon).

Independent Windows build, red/green test, and code-read review of `04a41e3ab` (based on `main` `f3840d73d`). Not run in-game. ### Environment - Windows 11 Pro 26H2 (build 26300.10075), Intel Core i9-14900K, NVIDIA RTX A2000 12GB (driver 621.47), Rust 1.98.1 (`x86_64-pc-windows-msvc`), MSVC 19.44.35230. ### Measured results - **Red on `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)]`). - **Green on PR #214 (`04a41e3ab`) with default env:** - Gate 1 (`cargo clippy --workspace --all-targets --locked -- -D warnings`): **PASS** - Gate 2 (`cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`): **PASS** - `cargo xtask policy`: **PASS** (`asset policy: 555 files ok`) - `cargo test --locked -p darner-gpu --lib shadow::landing_tests -- --nocapture`: **PASS** (`4 passed; 0 failed`). - **Failed on PR #214 (`04a41e3ab`) with `DARNER_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 - **Remaining mirror-compare path (`changes_only` / `send_changed` + `keep_stores()` race) at `crates/darner-gpu/src/shadow.rs:10225-10240`:** - PR #214 gates `self.mirrorless()` only inside the `else` branch (`shadow.rs:10228-10236`), leaving `if self.changes_only.load(Ordering::Relaxed) || send_changed()` (`shadow.rs:10227` -> `take_into()` at `:10240`) unguarded. - Aside from failing the new unit test under `DARNER_SEND_CHANGED=1`, this leaves a concurrent race in `keep_stores()` (`shadow.rs:10611-10619`, called from `memory.rs:727`): `self.changes_only.store(true, Ordering::Relaxed)` runs *before* `self.revive_mirror()` acquires `self.copy_lock`. A concurrent refresh holding `copy_lock` inside `take()` can observe `changes_only == true` while `self.mirrorless()` is still `true`, and call `take_into()` against the discarded mirror. - **Suggested fix:** Hoist the check to the top of `Shadow::take` alongside `direct_paged`: `if self.direct_paged().is_some() || self.mirrorless() { return self.copy(from, to); }` (at `shadow.rs:10225`, and defensively in `take_quiet` at `:10262`). That closes the `keep_stores()` race, makes the test pass under `DARNER_SEND_CHANGED=1`, and simplifies lines `10232-10236`. **Verdict:** Root cause is real and reproduced; recommend hoisting `self.mirrorless()` to `shadow.rs:10225` so `changes_only` / `send_changed` cannot bypass it. AI-assisted: yes (Gemini 4 Neon).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'no-mirror-take-blocks:infamous20x-no-mirror-take-blocks'
git switch 'infamous20x-no-mirror-take-blocks'

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.

git switch 'main'
git merge --no-ff 'infamous20x-no-mirror-take-blocks'
git switch 'infamous20x-no-mirror-take-blocks'
git rebase 'main'
git switch 'main'
git merge --ff-only 'infamous20x-no-mirror-take-blocks'
git switch 'infamous20x-no-mirror-take-blocks'
git rebase 'main'
git switch 'main'
git merge --no-ff 'infamous20x-no-mirror-take-blocks'
git switch 'main'
git merge --squash 'infamous20x-no-mirror-take-blocks'
git switch 'main'
git merge --ff-only 'infamous20x-no-mirror-take-blocks'
git switch 'main'
git merge 'infamous20x-no-mirror-take-blocks'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!214
No description provided.