watch, draw: tell the texture pass of the title's own writes to guarded blocks (DARNER_TITLE_WRITE_NOTICE, off by default) #461

Open
Layne wants to merge 1 commit from Layne/Darner:pr/title-write-notice into Main
First-time contributor

Off by default; nothing changes while the switch is unset. It has been in play on a fork of this tree (other local changes included) since early December; on this branch only the unit tests and the gates below were run (see "How it was tested").

Contributor role (optional)

  • Fluxer ID: Layne#3304

What it changes

  • The problem on main (#311, character skin and clothes flicker). A texture picked by index (bindless, placed in title memory) is uploaded again when something tells the texture pass its memory changed: a mapping, a write of ours, a kernel or DirectStorage write (descriptor::host::remapped_ranges). When the title writes that memory itself with the CPU, nothing tells the pass. The texture is uploaded again only when one of its own looks finds the fingerprint changed (RECHECK_FRAMES: 4, 12, 40, 120, 400 frames, so 4 to 576 frames late). Until then the old copy is drawn, and the title's next writes can make old and new versions show in turn.
  • The write-guard fault handler already learns about those writes: it is what opens the guarded 64 KiB block for the title's write. With DARNER_TITLE_WRITE_NOTICE set, that handler (both paths: the locked open in on_write and open_unlocked, including the blocks opened with it by widen_after), and the store done beside a guard (titlewrite::store), keep the block number for the next texture pass (watch::title_wrote).
  • The pass over textures picked by index takes those blocks first (watch::title_writes_told, just before host.texture_slots_remapped(frame)), adds the other views of their pages (inplace::shown_elsewhere), and hands them to remapped_ranges. The placed textures there are due from the next frame, through the existing path.
  • Modes:
    • count: the blocks are only noted, with their frame. The existing warning "a texture picked by index changed after its upload with nothing to tell of it" gets a title_wrote field saying whether a write was noted since the upload (diagnostic only).
    • painted: told to the pass. A texture a look found changed with nothing told of it is remembered (at most 4096 addresses) and guarded each time it is uploaded or looked at whole from then on (title_write_watch, by writes_since(.., guarded = true, ..)). Its first change is still found late, the next ones are not.
    • 1: told, and every texture in view memory that the pass uploads whole is guarded so from its first upload.
  • Cost in the fault handler: with the switch on, one bit swap (Bits::swap_on, so a block faulting again before a pass takes it costs nothing more) and a push under a mutex that nothing else is taken under; nothing is called and no title memory is touched with it held. The list holds at most 16,384 blocks between two passes; a fault past that is counted (not_kept) and left to the looks, as today. The texture pass takes the list's lock alone, then the views' lock to read, then the ranges', one after the other, so no new lock order. TITLE_WROTE (the frame of each told block) is the existing Landed table: 256 KiB pieces allocated per 4 GiB of address space touched.
  • Unset: title_write_notice() is a OnceLock<u8> read (done once in install, so never first in a fault); every new call returns at once. No guard, no lock, no allocation, no per-frame work.
  • One info line, at the first pass and then every 4096 blocks told: faults, not kept, blocks told, guards asked.

Relation to other pull requests

  • #433 (DirectStorage writes told through an alias): complementary, a different path. #433 tells the pass of writes the runtime does on the title's behalf at another address of the same pages. This PR tells it of the title's own CPU writes, which only the guard fault sees. Neither covers the other's writes. No shared functions; at most a textual conflict near remapped_ranges callers in watch.rs.
  • A local companion switch (writes of ours and the kernel's told again at every view of their pages) is not part of this PR: the write notice does not need it, and it was not used in the runs below.

How it was tested

  • Tested revision: ceedffcf0, on top of main d91d8e4d6.

  • Commands and results:

    • cargo check --release -p darner-gpu: finished, no warnings
    • cargo clippy -p darner-gpu --all-targets --locked -- -D warnings: clean
    • cargo test --release -p darner-gpu --lib watch: 106 passed, 0 failed, 1 ignored (3 of them new)
    • New unit tests: a told block is noted at every view of its page, once, with its latest frame (title_wrote_blocks); the kept list takes each block once, stays within its bound and keeps a block again once taken (TitleWrites::keep / take); Landed::after leaves out the frame asked about (a note from the upload's own frame does not count as after it).
  • Changes a default: no (off unless DARNER_TITLE_WRITE_NOTICE is set).

  • How the switch was checked: in play with DARNER_TITLE_WRITE_NOTICE=1 on a fork of this tree since our build of early December, RTX 4070 Ti 12 GB, Series X profile, 1440p. The player reports the skin and clothes flicker as "almost gone". No counted A/B (same route, off and on) has been run; the report is a player's impression, not a measurement. One log of mode 1 on that fork: about 1,400 guard faults a second from this switch once in the open world, every one kept (not_kept 0), about 3 blocks told per fault with the other views.

    A (off) B (on, 1)
    "changed with nothing to tell of it" warnings per minute not measured not measured
    frame time not measured not measured
  • Gates run on that revision: none of the three full gates. Only the narrower checks above.

  • Gameplay: fork sessions above (not this branch). Their logs were not reviewed for this PR beyond the counts quoted.

  • Hardware dependence: none expected (CPU-side, guard faults and the existing upload path).

  • Coverage gaps: the fault handler path and the texture pass call are not unit tested (they need guarded view memory and a device). The 16,384 bound and the 4096-address painted set were not tuned.

Risks

  • Mode 1 adds write faults: one for the first write to each guarded block after each upload, and a VirtualProtect per block (and per other view) at each guard. That is CPU time on the title's threads; not measured in frame time.
  • More uploads: textures the title paints every frame are uploaded every frame they are written instead of every 4 to 576 frames. That is the point, but it spends upload budget on them.
  • painted empties its address set when it reaches 4096 entries; textures still being painted are found again by the looks.
  • With the list full (16,384 blocks before a pass), further writes fall back to today's looks; nothing is lost beyond today's behaviour.

How to test

  1. Build as usual, then run with DARNER_TITLE_WRITE_NOTICE=1 (or painted for fewer guards, count to only count).
  2. In the log, look for the title's own writes to guarded blocks, noted for the textures picked by index: faults and blocks_told should grow in the open world, not_kept should stay at 0.
  3. A/B: same route with the switch unset and set. Compare the count of "a texture picked by index changed after its upload with nothing to tell of it" warnings, frame times, and character skin and clothes close up (#311).

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only). Run on a fork with this change, not on this branch; see above.
  • 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: #433 (DirectStorage writes told through an alias, complementary); #423 (a hooked store crossing a block boundary marks both blocks: same guard path, different fix, no shared change)
  • Related issues: #311 (character skin and clothes flicker)
  • Replaces or overlaps: none found

🤖 Generated with Claude Code

**Off by default; nothing changes while the switch is unset.** It has been in play on a fork of this tree (other local changes included) since early December; on this branch only the unit tests and the gates below were run (see "How it was tested"). ## Contributor role (optional) - Fluxer ID: Layne#3304 ## What it changes - The problem on main (#311, character skin and clothes flicker). A texture picked by index (bindless, placed in title memory) is uploaded again when something tells the texture pass its memory changed: a mapping, a write of ours, a kernel or DirectStorage write (`descriptor::host::remapped_ranges`). When the title writes that memory itself with the CPU, nothing tells the pass. The texture is uploaded again only when one of its own looks finds the fingerprint changed (`RECHECK_FRAMES`: 4, 12, 40, 120, 400 frames, so 4 to 576 frames late). Until then the old copy is drawn, and the title's next writes can make old and new versions show in turn. - The write-guard fault handler already learns about those writes: it is what opens the guarded 64 KiB block for the title's write. With `DARNER_TITLE_WRITE_NOTICE` set, that handler (both paths: the locked `open` in `on_write` and `open_unlocked`, including the blocks opened with it by `widen_after`), and the store done beside a guard (`titlewrite::store`), keep the block number for the next texture pass (`watch::title_wrote`). - The pass over textures picked by index takes those blocks first (`watch::title_writes_told`, just before `host.texture_slots_remapped(frame)`), adds the other views of their pages (`inplace::shown_elsewhere`), and hands them to `remapped_ranges`. The placed textures there are due from the next frame, through the existing path. - Modes: - `count`: the blocks are only noted, with their frame. The existing warning "a texture picked by index changed after its upload with nothing to tell of it" gets a `title_wrote` field saying whether a write was noted since the upload (diagnostic only). - `painted`: told to the pass. A texture a look found changed with nothing told of it is remembered (at most 4096 addresses) and guarded each time it is uploaded or looked at whole from then on (`title_write_watch`, by `writes_since(.., guarded = true, ..)`). Its first change is still found late, the next ones are not. - `1`: told, and every texture in view memory that the pass uploads whole is guarded so from its first upload. - Cost in the fault handler: with the switch on, one bit swap (`Bits::swap_on`, so a block faulting again before a pass takes it costs nothing more) and a push under a mutex that nothing else is taken under; nothing is called and no title memory is touched with it held. The list holds at most 16,384 blocks between two passes; a fault past that is counted (`not_kept`) and left to the looks, as today. The texture pass takes the list's lock alone, then the views' lock to read, then the ranges', one after the other, so no new lock order. `TITLE_WROTE` (the frame of each told block) is the existing `Landed` table: 256 KiB pieces allocated per 4 GiB of address space touched. - Unset: `title_write_notice()` is a `OnceLock<u8>` read (done once in `install`, so never first in a fault); every new call returns at once. No guard, no lock, no allocation, no per-frame work. - One info line, at the first pass and then every 4096 blocks told: faults, not kept, blocks told, guards asked. ### Relation to other pull requests - **#433** (DirectStorage writes told through an alias): complementary, a different path. #433 tells the pass of writes the runtime does on the title's behalf at another address of the same pages. This PR tells it of the title's own CPU writes, which only the guard fault sees. Neither covers the other's writes. No shared functions; at most a textual conflict near `remapped_ranges` callers in `watch.rs`. - A local companion switch (writes of ours and the kernel's told again at every view of their pages) is not part of this PR: the write notice does not need it, and it was not used in the runs below. ## How it was tested - Tested revision: ceedffcf0, on top of `main` d91d8e4d6. - Commands and results: - `cargo check --release -p darner-gpu`: finished, no warnings - `cargo clippy -p darner-gpu --all-targets --locked -- -D warnings`: clean - `cargo test --release -p darner-gpu --lib watch`: 106 passed, 0 failed, 1 ignored (3 of them new) - New unit tests: a told block is noted at every view of its page, once, with its latest frame (`title_wrote_blocks`); the kept list takes each block once, stays within its bound and keeps a block again once taken (`TitleWrites::keep` / `take`); `Landed::after` leaves out the frame asked about (a note from the upload's own frame does not count as after it). - Changes a default: no (off unless `DARNER_TITLE_WRITE_NOTICE` is set). - How the switch was checked: in play with `DARNER_TITLE_WRITE_NOTICE=1` on a fork of this tree since our build of early December, RTX 4070 Ti 12 GB, Series X profile, 1440p. The player reports the skin and clothes flicker as "almost gone". **No counted A/B** (same route, off and on) has been run; the report is a player's impression, not a measurement. One log of mode 1 on that fork: about 1,400 guard faults a second from this switch once in the open world, every one kept (`not_kept` 0), about 3 blocks told per fault with the other views. | | A (off) | B (on, `1`) | |---|---|---| | "changed with nothing to tell of it" warnings per minute | not measured | not measured | | frame time | not measured | not measured | - Gates run on that revision: none of the three full gates. Only the narrower checks above. - Gameplay: fork sessions above (not this branch). Their logs were not reviewed for this PR beyond the counts quoted. - Hardware dependence: none expected (CPU-side, guard faults and the existing upload path). - Coverage gaps: the fault handler path and the texture pass call are not unit tested (they need guarded view memory and a device). The 16,384 bound and the 4096-address `painted` set were not tuned. ### Risks - Mode `1` adds write faults: one for the first write to each guarded block after each upload, and a `VirtualProtect` per block (and per other view) at each guard. That is CPU time on the title's threads; not measured in frame time. - More uploads: textures the title paints every frame are uploaded every frame they are written instead of every 4 to 576 frames. That is the point, but it spends upload budget on them. - `painted` empties its address set when it reaches 4096 entries; textures still being painted are found again by the looks. - With the list full (16,384 blocks before a pass), further writes fall back to today's looks; nothing is lost beyond today's behaviour. ## How to test 1. Build as usual, then run with `DARNER_TITLE_WRITE_NOTICE=1` (or `painted` for fewer guards, `count` to only count). 2. In the log, look for `the title's own writes to guarded blocks, noted for the textures picked by index`: `faults` and `blocks_told` should grow in the open world, `not_kept` should stay at 0. 3. A/B: same route with the switch unset and set. Compare the count of "a texture picked by index changed after its upload with nothing to tell of it" warnings, frame times, and character skin and clothes close up (#311). ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). *Run on a fork with this change, not on this branch; see above.* - [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: #433 (DirectStorage writes told through an alias, complementary); #423 (a hooked store crossing a block boundary marks both blocks: same guard path, different fix, no shared change) - Related issues: #311 (character skin and clothes flicker) - Replaces or overlaps: none found 🤖 Generated with [Claude Code](https://claude.com/claude-code)
When a write of the title's own faults on a write-guarded block of view
memory, the fault handler keeps the block (deduplicated, at most 16384
per pass) and the next pass over textures picked by index takes them,
with the other views of their pages, as remapped ranges: the placed
textures there are uploaded again from the next frame, instead of when
a look of their own finds them changed (RECHECK_FRAMES, 4 to 576 frames
late), which showed old and new versions in turn (skin and clothes
flicker, #311).

- count: noted only, and the "changed with nothing to tell of it"
  warning says whether a write was noted (title_wrote=...).
- painted: told, and textures a look found changed are guarded from
  their next upload or look on.
- 1: told, and every texture in view memory the pass uploads whole is
  guarded from its first upload.

Unset, each guard fault and texture pass looks at the mode alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor

Native guarded-write A/B on Windows 11 and an RTX 4060. I integrated ceedffcf with c8258f95 so the fixture could reuse the placed-texture readback from #433. Each mode ran in its own process with DARNER_PAGE_WRITES=0. The fixture made two views of a test-owned section, verified both were read-only under the same guard, and performed a plain CPU store through the writer alias.

Switch Recorded faults Noted blocks Slot due next frame Updated GPU pixels
0 0 0 0 0/1024
count 1 2 0 0/1024
painted 1 2 1 1024/1024
1 1 2 1 1024/1024

I also exercised a lifecycle case with 1. After the same store, the writer view was unmapped before title_writes_told while the sampled alias stayed mapped. The fault was recorded, but only one block was noted and the slot never became due in that pass. All 1,024 GPU pixels still had the previous value. The pending notice appears to lose its alias lookup when the writer's view is removed.

The test-only fixture runs with cargo test --locked --offline -p darner-gpu --lib watch::tests::guarded_cpu_write_refreshes_a_placed_texture_at_its_alias -- --exact --ignored --nocapture. Set DARNER_TEST_UNMAP_WRITER=1 for the failing case. This checks next-frame delivery after the guard is installed. A counted gameplay A/B for #311 would still test a separate effect.

Native guarded-write A/B on Windows 11 and an RTX 4060. I integrated `ceedffcf` with `c8258f95` so the fixture could reuse the placed-texture readback from #433. Each mode ran in its own process with `DARNER_PAGE_WRITES=0`. The fixture made two views of a test-owned section, verified both were read-only under the same guard, and performed a plain CPU store through the writer alias. | Switch | Recorded faults | Noted blocks | Slot due next frame | Updated GPU pixels | |---|---:|---:|---:|---:| | `0` | 0 | 0 | 0 | 0/1024 | | `count` | 1 | 2 | 0 | 0/1024 | | `painted` | 1 | 2 | 1 | 1024/1024 | | `1` | 1 | 2 | 1 | 1024/1024 | I also exercised a lifecycle case with `1`. After the same store, the writer view was unmapped before `title_writes_told` while the sampled alias stayed mapped. The fault was recorded, but only one block was noted and the slot never became due in that pass. All 1,024 GPU pixels still had the previous value. The pending notice appears to lose its alias lookup when the writer's view is removed. The [test-only fixture](https://git.gtahub.st/tyr0nsur/Darner/commit/7c8b0ed65eab64810d346759eb5b518795ae1561) runs with `cargo test --locked --offline -p darner-gpu --lib watch::tests::guarded_cpu_write_refreshes_a_placed_texture_at_its_alias -- --exact --ignored --nocapture`. Set `DARNER_TEST_UNMAP_WRITER=1` for the failing case. This checks next-frame delivery after the guard is installed. A counted gameplay A/B for #311 would still test a separate effect.
TrustNo1 changed title from [pr-fix][rendering][memory] watch, draw: tell the texture pass of the title's own writes to guarded blocks (DARNER_TITLE_WRITE_NOTICE, off by default) to watch, draw: tell the texture pass of the title's own writes to guarded blocks (DARNER_TITLE_WRITE_NOTICE, off by default) 2026-12-06 03:28:40 +00:00
Owner

Test needed — commit ceedffcf; what to check:

  1. Build as usual, then run with DARNER_TITLE_WRITE_NOTICE=1 (or painted for fewer guards, count to only count).
  2. In the log, look for the title's own writes to guarded blocks, noted for the textures picked by index: faults and blocks_told should grow in the open world, not_kept should stay at 0.
  3. A/B: same route with the switch unset and set. Compare the count of "a texture picked by index changed after its upload with nothing to tell of it" warnings, frame times, and character skin and clothes close up (#311).

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 `ceedffcf`; what to check: 1. Build as usual, then run with `DARNER_TITLE_WRITE_NOTICE=1` (or `painted` for fewer guards, `count` to only count). 2. In the log, look for `the title's own writes to guarded blocks, noted for the textures picked by index`: `faults` and `blocks_told` should grow in the open world, `not_kept` should stay at 0. 3. A/B: same route with the switch unset and set. Compare the count of "a texture picked by index changed after its upload with nothing to tell of it" warnings, frame times, and character skin and clothes close up (#311). 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 can be merged automatically.
This branch is out-of-date with the base branch
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 'pr/title-write-notice:Layne-pr/title-write-notice'
git switch 'Layne-pr/title-write-notice'

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 'Layne-pr/title-write-notice'
git switch 'Layne-pr/title-write-notice'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'Layne-pr/title-write-notice'
git switch 'Layne-pr/title-write-notice'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'Layne-pr/title-write-notice'
git switch 'Main'
git merge --squash 'Layne-pr/title-write-notice'
git switch 'Main'
git merge --ff-only 'Layne-pr/title-write-notice'
git switch 'Main'
git merge 'Layne-pr/title-write-notice'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 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!461
No description provided.