DARNER_TAKE_BLOCKS sends pages whole for copies shaders write where nobody declared #494

Open
italianar15 wants to merge 1 commit from italianar15/Darner:fix/take-blocks-undeclared-writes into Main
First-time contributor

Not run in the game. Found by reading the code and by review in a private fork; unit-tested here. Nothing changes with no switch set: the new guard acts only when DARNER_PICKED_WRITES finds a writer or DARNER_ROOT_UAV_MB cuts a writing root UAV short.

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main (read from the code, not seen in a game run): DARNER_TAKE_BLOCKS is on by default and skips only copies with left set (Shadow::take in crates/darner-gpu/src/shadow.rs). Two kinds of shader write are never declared, so they never come back to the CPU's side:

    • a store through a view the shader picks from the heap (DARNER_PICKED_WRITES is off by default, so nothing finds these);
    • a store past the end of a writing root UAV whose declaration was clamped by DARNER_ROOT_UAV_MB.

    After either, the card holds the shader's value and the CPU's side still holds the title's last value. When the title then writes that same last value again (resetting a counter or an indirect argument each frame, for example), the 4 KiB block compares alike, nothing is sent, and the card keeps the shader's value. Before TAKE_BLOCKS the whole page went up and the title's value won. In the fork, a "send only what changed" switch of our own failed the same way: a room drew with wrong lighting and geometry because a same-value rewrite by the title no longer covered a shader's leftover on the card. A growing indirect count can also hang the card.

This change:

  • New per-copy flag unseen. Once set it is never cleared. It is set in two places:
    • picked::found sets it the first time picked finds a copy written through views picked from the heap (new Shadow::written_unseen()).
    • Shadow::root_uav_declared(address, limit, writes) replaces s.left(a).min(limit) in draw.rs root_uav. It returns the same length, and sets unseen when a writing root UAV is cut short by DARNER_ROOT_UAV_MB.
  • The guard in Shadow::take. It is now take_blocks() && !left && !unseen: a marked copy skips the block compare, and its page goes up whole, as before TAKE_BLOCKS.
  • take_blocks doc comment. It now says what the switch rests on, what this covers, and what stays open (below).

With nothing set, behaviour is unchanged (from the code):

  • picked::declare returns empty Ranges when !on(), and the ranges Host::picked_found walks come only from there, so found is never called with DARNER_PICKED_WRITES unset.
  • With DARNER_ROOT_UAV_MB unset or not a number, limit is u64::MAX, so the cut never happens and root_uav_declared returns exactly left.min(limit).

Still open, and not fixed here:

  • With DARNER_PICKED_WRITES unset (the default), nothing is found, so every buffer written through picked views stays exposed. The safe default may be to keep block taking off unless DARNER_PICKED_WRITES=2; that changes a default, so it is left to you and an A/B.
  • With picked on, a buffer is exposed until picked's turn reaches it.
  • A copy found clean that a shader starts writing later (a room change, or a shader that writes only sometimes) is exposed until picked finds it, tens of frames at the default slice. A possible fix: when take_landed finds pages of such a copy alike and sends nothing, compare those pieces ahead on the card in the same submission, or treat a copy as unchecked again after N frames.
  • The same exposure in the dword path (DARNER_SEND_CHANGED / changes_only) is untouched.
  • DARNER_UPCOPY_CHECK=1 style checking (count words a send puts over a card value the title left as the CPU's side held it) sees this case; a refresh check does not.

How it was tested

  • Tested revision: 405b191 on top of main d91d8e4.
  • Commands and results:
    • 3 new tests in shadow::landing_tests:
      • an_unmarked_copy_takes_only_the_blocks_that_changed;
      • a_copy_found_written_unseen_goes_up_whole;
      • a_copy_past_a_cut_writing_root_uav_goes_up_whole: no limit, a limit that fits, or a cut read-only view do not mark the copy; a cut writing view does, and its next take sends the whole range.
    • All three pass with defaults and with DARNER_TAKE_BLOCKS=0. With the unseen guard removed for a moment, the found test and the root-UAV test both failed; the file was then restored.
  • Changes a default: no.
  • A/B result: not applicable (no default changes; the guard acts only with DARNER_PICKED_WRITES or DARNER_ROOT_UAV_MB set). Checked by the tests above.
  • Gates run on 405b191:
    • cargo clippy --workspace --all-targets --locked -- -D warnings: exit 0.
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: exit 0.
    • cargo xtask policy: asset policy: 564 files ok.
    • cargo test --workspace --locked: not green, in tests this change does not touch:
      • apps/darner/tests/picked_folders.rs (4 tests) fails on this machine only because VICTORY_HOME is set (darner-core/src/renamed.rs copies VICTORY_* to DARNER_*; the test clears DARNER_HOME but not VICTORY_HOME). With VICTORY_HOME unset: 8 of 8 pass.
      • darner-gpu host::card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end fails here, and it also failed 6 of 6 runs on main d91d8e4 on this machine.
      • darner-gpu host::refresh_tests::chunked_nothing_new_with_matches_individual failed once, while another build was testing on the same machine; it passed in an earlier full run and 5 of 5 runs alone. Not checked on main.
      • darner-shader lib tests: stopped after a long debug run, so that result is incomplete, not a pass.
      • Everything else passed (darner-gpu lib: 1794 passed, 2 failed as above, 81 ignored).
  • Gameplay: not run.
  • Hardware dependence: none expected.
  • Coverage gaps: no game run; no run with DARNER_PICKED_WRITES on.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only). Not run in the game: the private fork that found this is paused and has no Darner build set up for game runs.
  • 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: #214 (DARNER_TAKE_BLOCKS no longer compares copies that keep no mirror) handles a different case of the same switch. Both add tests at the same place in shadow::landing_tests, so whichever lands second may need a trivial rebase.
  • Replaces or overlaps: none found.
**Not run in the game.** Found by reading the code and by review in a private fork; unit-tested here. Nothing changes with no switch set: the new guard acts only when `DARNER_PICKED_WRITES` finds a writer or `DARNER_ROOT_UAV_MB` cuts a writing root UAV short. ## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main (read from the code, not seen in a game run): `DARNER_TAKE_BLOCKS` is on by default and skips only copies with `left` set (`Shadow::take` in crates/darner-gpu/src/shadow.rs). Two kinds of shader write are never declared, so they never come back to the CPU's side: - a store through a view the shader picks from the heap (`DARNER_PICKED_WRITES` is off by default, so nothing finds these); - a store past the end of a writing root UAV whose declaration was clamped by `DARNER_ROOT_UAV_MB`. After either, the card holds the shader's value and the CPU's side still holds the title's last value. When the title then writes that same last value again (resetting a counter or an indirect argument each frame, for example), the 4 KiB block compares alike, nothing is sent, and the card keeps the shader's value. Before TAKE_BLOCKS the whole page went up and the title's value won. In the fork, a "send only what changed" switch of our own failed the same way: a room drew with wrong lighting and geometry because a same-value rewrite by the title no longer covered a shader's leftover on the card. A growing indirect count can also hang the card. This change: - **New per-copy flag `unseen`.** Once set it is never cleared. It is set in two places: - `picked::found` sets it the first time picked finds a copy written through views picked from the heap (new `Shadow::written_unseen()`). - `Shadow::root_uav_declared(address, limit, writes)` replaces `s.left(a).min(limit)` in `draw.rs` `root_uav`. It returns the same length, and sets `unseen` when a writing root UAV is cut short by `DARNER_ROOT_UAV_MB`. - **The guard in `Shadow::take`.** It is now `take_blocks() && !left && !unseen`: a marked copy skips the block compare, and its page goes up whole, as before TAKE_BLOCKS. - **`take_blocks` doc comment.** It now says what the switch rests on, what this covers, and what stays open (below). With nothing set, behaviour is unchanged (from the code): - `picked::declare` returns empty `Ranges` when `!on()`, and the ranges `Host::picked_found` walks come only from there, so `found` is never called with `DARNER_PICKED_WRITES` unset. - With `DARNER_ROOT_UAV_MB` unset or not a number, `limit` is `u64::MAX`, so the cut never happens and `root_uav_declared` returns exactly `left.min(limit)`. Still open, and not fixed here: - With `DARNER_PICKED_WRITES` unset (the default), nothing is found, so every buffer written through picked views stays exposed. The safe default may be to keep block taking off unless `DARNER_PICKED_WRITES=2`; that changes a default, so it is left to you and an A/B. - With picked on, a buffer is exposed until picked's turn reaches it. - A copy found clean that a shader starts writing later (a room change, or a shader that writes only sometimes) is exposed until picked finds it, tens of frames at the default slice. A possible fix: when `take_landed` finds pages of such a copy alike and sends nothing, compare those pieces ahead on the card in the same submission, or treat a copy as unchecked again after N frames. - The same exposure in the dword path (`DARNER_SEND_CHANGED` / `changes_only`) is untouched. - `DARNER_UPCOPY_CHECK=1` style checking (count words a send puts over a card value the title left as the CPU's side held it) sees this case; a refresh check does not. ## How it was tested - Tested revision: 405b191 on top of main d91d8e4. - Commands and results: - 3 new tests in `shadow::landing_tests`: - `an_unmarked_copy_takes_only_the_blocks_that_changed`; - `a_copy_found_written_unseen_goes_up_whole`; - `a_copy_past_a_cut_writing_root_uav_goes_up_whole`: no limit, a limit that fits, or a cut read-only view do not mark the copy; a cut writing view does, and its next take sends the whole range. - All three pass with defaults and with `DARNER_TAKE_BLOCKS=0`. With the `unseen` guard removed for a moment, the found test and the root-UAV test both failed; the file was then restored. - Changes a default: no. - A/B result: not applicable (no default changes; the guard acts only with `DARNER_PICKED_WRITES` or `DARNER_ROOT_UAV_MB` set). Checked by the tests above. - Gates run on 405b191: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: exit 0. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: exit 0. - `cargo xtask policy`: `asset policy: 564 files ok`. - `cargo test --workspace --locked`: not green, in tests this change does not touch: - `apps/darner/tests/picked_folders.rs` (4 tests) fails on this machine only because `VICTORY_HOME` is set (`darner-core/src/renamed.rs` copies `VICTORY_*` to `DARNER_*`; the test clears `DARNER_HOME` but not `VICTORY_HOME`). With `VICTORY_HOME` unset: 8 of 8 pass. - `darner-gpu` `host::card_steps::tests::shared_scratch_eliminates_flight_settle_end_to_end` fails here, and it also failed 6 of 6 runs on main d91d8e4 on this machine. - `darner-gpu` `host::refresh_tests::chunked_nothing_new_with_matches_individual` failed once, while another build was testing on the same machine; it passed in an earlier full run and 5 of 5 runs alone. Not checked on main. - `darner-shader` lib tests: stopped after a long debug run, so that result is incomplete, not a pass. - Everything else passed (`darner-gpu` lib: 1794 passed, 2 failed as above, 81 ignored). - Gameplay: not run. - Hardware dependence: none expected. - Coverage gaps: no game run; no run with `DARNER_PICKED_WRITES` on. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). Not run in the game: the private fork that found this is paused and has no Darner build set up for game runs. - [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: #214 (`DARNER_TAKE_BLOCKS` no longer compares copies that keep no mirror) handles a different case of the same switch. Both add tests at the same place in `shadow::landing_tests`, so whichever lands second may need a trivial rebase. - Replaces or overlaps: none found.
DARNER_TAKE_BLOCKS compares a copy's pages 4 KiB at a time and sends only
the blocks whose title bytes differ from the CPU's side. That rests on the
CPU's side holding what the card holds. It does not for a buffer a shader
writes through a view it picks from the heap: the card holds the shader's
bytes, and when the title writes its older bytes again the block compares
alike and is not sent, so the card keeps the shader's bytes. With the page
sent whole, the title's bytes went over them. Found by reading the code,
not seen in a game run.

- A new per-copy flag, `unseen`, set when crate::picked finds a copy written
  through picked views, and when a writing root UAV is declared shorter than
  its buffer reaches (DARNER_ROOT_UAV_MB). take treats it as it treats
  `left`: no block compare for that copy, the page goes up whole.
- The take_blocks doc says what is covered and what is still open: with
  DARNER_PICKED_WRITES unset nothing is found; with it set a buffer is
  exposed until picked's turn reaches it; a buffer found clean that a shader
  writes later is exposed until picked finds it.
- Tests: a copy found by picked goes up whole on the next take; a copy
  nothing marked still takes only the changed block; a cut writing root UAV
  marks its copy, a read-only or uncut one does not.

Nothing changes for users who set nothing: crate::picked::declare returns
no ranges when DARNER_PICKED_WRITES is unset, so found is never called, and
without DARNER_ROOT_UAV_MB the limit is u64::MAX, so no root UAV is cut.
TrustNo1 changed title from [pr-fix][memory] DARNER_TAKE_BLOCKS sends pages whole for copies shaders write where nobody declared to DARNER_TAKE_BLOCKS sends pages whole for copies shaders write where nobody declared 2026-12-06 03:27:59 +00:00
Owner

Test needed — commit 405b1915; what to check:

  • The problem on main (read from the code, not seen in a game run): DARNER_TAKE_BLOCKS is on by default and skips only copies with left set (Shadow::take in crates/darner-gpu/src/shadow.rs). Two kinds of shader write are never declared, so they never come back to the CPU's side:

    • a store through a view the shader picks from the heap (DARNER_PICKED_WRITES is off by default, so nothing finds these);
    • a store past the end of a writing root UAV whose declaration was clamped by DARNER_ROOT_UAV_MB.

    After either, the card holds the shader's value and the CPU's side still holds the title's last value. When the title then writes that same last value again (resetting a counter or an indirect argument each frame, for example), the 4 KiB block compares alike, nothing is sent, and the card keeps the shader's value. Before TAKE_BLOCKS the whole page went up and the title's value won. In the fork, a "send only what changed" switch of our own failed the same way: a room drew with wrong lighting and geometry because a same-value rewrite by the title no longer covered a shader's leftover on the card. A growing indirect count can also hang the card.

This change:

  • **New per-copy f

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `405b1915`; what to check: - The problem on main (read from the code, not seen in a game run): `DARNER_TAKE_BLOCKS` is on by default and skips only copies with `left` set (`Shadow::take` in crates/darner-gpu/src/shadow.rs). Two kinds of shader write are never declared, so they never come back to the CPU's side: - a store through a view the shader picks from the heap (`DARNER_PICKED_WRITES` is off by default, so nothing finds these); - a store past the end of a writing root UAV whose declaration was clamped by `DARNER_ROOT_UAV_MB`. After either, the card holds the shader's value and the CPU's side still holds the title's last value. When the title then writes that same last value again (resetting a counter or an indirect argument each frame, for example), the 4 KiB block compares alike, nothing is sent, and the card keeps the shader's value. Before TAKE_BLOCKS the whole page went up and the title's value won. In the fork, a "send only what changed" switch of our own failed the same way: a room drew with wrong lighting and geometry because a same-value rewrite by the title no longer covered a shader's leftover on the card. A growing indirect count can also hang the card. This change: - **New per-copy f Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This pull request has changes conflicting with the target branch.
  • crates/darner-gpu/src/shadow.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'fix/take-blocks-undeclared-writes:italianar15-fix/take-blocks-undeclared-writes'
git switch 'italianar15-fix/take-blocks-undeclared-writes'

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 'italianar15-fix/take-blocks-undeclared-writes'
git switch 'italianar15-fix/take-blocks-undeclared-writes'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'italianar15-fix/take-blocks-undeclared-writes'
git switch 'italianar15-fix/take-blocks-undeclared-writes'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'italianar15-fix/take-blocks-undeclared-writes'
git switch 'Main'
git merge --squash 'italianar15-fix/take-blocks-undeclared-writes'
git switch 'Main'
git merge --ff-only 'italianar15-fix/take-blocks-undeclared-writes'
git switch 'Main'
git merge 'italianar15-fix/take-blocks-undeclared-writes'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
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!494
No description provided.