[pr-fix][rendering] Mirror descriptor records that cross a watch-page boundary #163

Manually merged
TrustNo1 merged 3 commits from Remorce/Darner:pr-descriptor-watch-page-records into main 2026-12-04 04:21:17 +00:00
Contributor

Why: a descriptor record (a texture view or sampler) can straddle two watched pages. When the title rewrites only the second half of such a record, Darner never copies it to the card, and the GPU keeps using the old one. Nobody has seen this in a game yet. It would most likely show up as an occasional wrong or stale surface, which is hard to trace back to this. The fix stays inside one function, and foxhound already found and fixed the same thing in their tree.

Not run in the game. Tests only.

Contributor role (optional)

  • Fluxer ID: Remorce#4039

What it changes

When sync_heaps mirrors a placed descriptor heap, it cuts the written ranges that write-watch reports at watch pages, and each part covers the records that start inside it. A record that straddles two pages belonged to the part that holds its first byte. If the title wrote only the record's second page (a sampler copied in as bytes, say, with its first 8 bytes unchanged), that part did not exist, and the record was never mirrored to the host heap.

The parts are now whole records (sync_record_parts in crates/darner-gpu/src/descriptor.rs): runs of records within one page, a record that crosses a page boundary in a part of its own, overlapping written ranges deduplicated, and each record in exactly one part. Nothing else in the sync changes.

This is a port of foxhound pull request 504 ("Mirror byte-written descriptors that cross a watch-page boundary") from readmet3xt-lab/foxhound, which is GPL-3.0 like this project. Credit for finding and fixing it there goes to that project.

It was found by reading code and porting, not from a game: nobody has seen it as a visible bug in a run. It is covered by tests only.

How it was tested

  • Tested revision: 1655cc05 on 57dea7f2. The pull request's commit d304c07b has the same tree; only the commit message changed.
  • Commands and results:
    • cargo clippy --workspace --all-targets --locked -- -D warnings: clean, on 1655cc05.
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean, on 1655cc05.
    • cargo test --workspace --locked, on 1655cc05: fails with the same two darner-shader failures as on main (57dea7f2). This change does not touch darner-shader. Cargo stops at the first failing crate, so the rest was run with cargo test --workspace --locked --no-fail-fast --exclude darner-shader and cargo test --locked -p darner-shader --doc. The first run: 3283 passed, 2 failed (the two below), 119 ignored. The rest: darner-simd, xtask and the doc-tests passed.
      • emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders: "DXIL validation failed: Not all elements of output SV_Depth were written". It fails the same way on 57dea7f2 alone.
      • emit::wave64_tests::lds_shared_atomic_add_producer_executes_wave32_on_hardware: expects wave size 32 and gets 64. It fails the same way on 57dea7f2 alone. The test came with the isolated LDS add lowering (merge 10c532c1, former CodeFloe PR 187) and does not set DARNER_LDS_ISOLATED_ADD=1, which 68cb7c85 made off by default.
      • darner-gpu's host::refresh_tests::unchanged_ranges_are_known failed once, in the --no-fail-fast run, and passed in the first full run. cargo test --locked -p darner-gpu --lib then passed 3 runs of 3 on this branch. On 57dea7f2 alone it failed 2 runs of 3, in the write-watch tests (watch::tests::ask_once_by_res_splits_reservations_without_refusals both times, plus two others once), the area #150 is about. So these write-watch tests are flaky on main too.
    • cargo test --locked -p darner-gpu --lib dirty_ -- --test-threads=1 --nocapture, on 1655cc05: 8 passed, both new tests included. The sampler test printed no skip line, so it ran against a hardware heap.
    • cargo xtask policy: "asset policy: 553 files ok".
    • Review follow-up 69aab2a4 (test only, on d304c07b): both clippy gates clean, cargo xtask policy "asset policy: 553 files ok", dirty_parts_cover_only_touched_records_once passed.
    • Rebased onto 140980dd (main): 7a2c516b + 29c34040. Both clippy gates clean, cargo xtask policy "asset policy: 555 files ok", dirty_parts_cover_only_touched_records_once passed. cargo test --locked -p darner-gpu --lib dirty_ -- --test-threads=1 --nocapture on 29c34040: 8 passed, 0 failed, the D3D12 test on a hardware heap. cargo test --workspace was not rerun after the rebase.
  • New tests:
    • dirty_parts_cover_only_touched_records_once: no GPU needed. For 16- and 32-byte records and heaps starting 0, 1, 8 or one record short of a page, written ranges (overlapping, across a page, and one running past the heap's end) become parts of whole records. Every touched record appears exactly once, and no part crosses a page unless it is a single record. It also checks a write of only the first byte of the second page, with the heap starting 8 bytes before it: just the crossing record comes back, once (suggested in review).
    • dirty_sampler_across_two_watch_pages_is_mirrored: a sampler written as bytes across a watch-page boundary, 8 bytes on each side, is made at the next sync, and its neighbour is not. It needs a host GPU. Without one it prints skipped: no hardware heap here and returns, as the bare-runner rule asks.
  • Gameplay: not tested. No game run was made with this change.
  • Coverage gaps: no game run, and no picture comparison. With DARNER_HEAP_TWIN=1 (experimental, off), the watched range of a heap ends where the graphics-heap twin begins. A record straddling that end is mirrored when its first part is written; writes to the twin part are left to the twin, as before. That case has no test of its own.

Checklist

  • 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. No open pull request changes crates/darner-gpu/src/descriptor.rs. Open and closed issues and pull requests were searched for "descriptor", "watch page", "cross page", "straddle", "sync_record_parts", "sync_heaps", "descriptor.rs" and "foxhound 504". The nearest are #57 (descriptor writes wait for residency, different files and problem) and #150 (write-watch test in watch.rs); neither covers this.
**Why:** a descriptor record (a texture view or sampler) can straddle two watched pages. When the title rewrites only the second half of such a record, Darner never copies it to the card, and the GPU keeps using the old one. Nobody has seen this in a game yet. It would most likely show up as an occasional wrong or stale surface, which is hard to trace back to this. The fix stays inside one function, and foxhound already found and fixed the same thing in their tree. **Not run in the game.** Tests only. ## Contributor role (optional) - Fluxer ID: Remorce#4039 ## What it changes When `sync_heaps` mirrors a placed descriptor heap, it cuts the written ranges that write-watch reports at watch pages, and each part covers the records that start inside it. A record that straddles two pages belonged to the part that holds its first byte. If the title wrote only the record's second page (a sampler copied in as bytes, say, with its first 8 bytes unchanged), that part did not exist, and the record was never mirrored to the host heap. The parts are now whole records (`sync_record_parts` in `crates/darner-gpu/src/descriptor.rs`): runs of records within one page, a record that crosses a page boundary in a part of its own, overlapping written ranges deduplicated, and each record in exactly one part. Nothing else in the sync changes. This is a port of foxhound pull request 504 ("Mirror byte-written descriptors that cross a watch-page boundary") from readmet3xt-lab/foxhound, which is GPL-3.0 like this project. Credit for finding and fixing it there goes to that project. It was found by reading code and porting, not from a game: nobody has seen it as a visible bug in a run. It is covered by tests only. ## How it was tested - Tested revision: `1655cc05` on `57dea7f2`. The pull request's commit `d304c07b` has the same tree; only the commit message changed. - Commands and results: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean, on `1655cc05`. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: clean, on `1655cc05`. - `cargo test --workspace --locked`, on `1655cc05`: fails with the same two `darner-shader` failures as on `main` (`57dea7f2`). This change does not touch `darner-shader`. Cargo stops at the first failing crate, so the rest was run with `cargo test --workspace --locked --no-fail-fast --exclude darner-shader` and `cargo test --locked -p darner-shader --doc`. The first run: 3283 passed, 2 failed (the two below), 119 ignored. The rest: `darner-simd`, `xtask` and the doc-tests passed. - `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders`: "DXIL validation failed: Not all elements of output SV_Depth were written". It fails the same way on `57dea7f2` alone. - `emit::wave64_tests::lds_shared_atomic_add_producer_executes_wave32_on_hardware`: expects wave size 32 and gets 64. It fails the same way on `57dea7f2` alone. The test came with the isolated LDS add lowering (merge `10c532c1`, former CodeFloe PR 187) and does not set `DARNER_LDS_ISOLATED_ADD=1`, which `68cb7c85` made off by default. - `darner-gpu`'s `host::refresh_tests::unchanged_ranges_are_known` failed once, in the `--no-fail-fast` run, and passed in the first full run. `cargo test --locked -p darner-gpu --lib` then passed 3 runs of 3 on this branch. On `57dea7f2` alone it failed 2 runs of 3, in the write-watch tests (`watch::tests::ask_once_by_res_splits_reservations_without_refusals` both times, plus two others once), the area #150 is about. So these write-watch tests are flaky on `main` too. - `cargo test --locked -p darner-gpu --lib dirty_ -- --test-threads=1 --nocapture`, on `1655cc05`: 8 passed, both new tests included. The sampler test printed no skip line, so it ran against a hardware heap. - `cargo xtask policy`: "asset policy: 553 files ok". - Review follow-up `69aab2a4` (test only, on `d304c07b`): both clippy gates clean, `cargo xtask policy` "asset policy: 553 files ok", `dirty_parts_cover_only_touched_records_once` passed. - Rebased onto `140980dd` (`main`): `7a2c516b` + `29c34040`. Both clippy gates clean, `cargo xtask policy` "asset policy: 555 files ok", `dirty_parts_cover_only_touched_records_once` passed. `cargo test --locked -p darner-gpu --lib dirty_ -- --test-threads=1 --nocapture` on `29c34040`: 8 passed, 0 failed, the D3D12 test on a hardware heap. `cargo test --workspace` was not rerun after the rebase. - New tests: - `dirty_parts_cover_only_touched_records_once`: no GPU needed. For 16- and 32-byte records and heaps starting 0, 1, 8 or one record short of a page, written ranges (overlapping, across a page, and one running past the heap's end) become parts of whole records. Every touched record appears exactly once, and no part crosses a page unless it is a single record. It also checks a write of only the first byte of the second page, with the heap starting 8 bytes before it: just the crossing record comes back, once (suggested in review). - `dirty_sampler_across_two_watch_pages_is_mirrored`: a sampler written as bytes across a watch-page boundary, 8 bytes on each side, is made at the next sync, and its neighbour is not. It needs a host GPU. Without one it prints `skipped: no hardware heap here` and returns, as the bare-runner rule asks. - Gameplay: not tested. No game run was made with this change. - Coverage gaps: no game run, and no picture comparison. With `DARNER_HEAP_TWIN=1` (experimental, off), the watched range of a heap ends where the graphics-heap twin begins. A record straddling that end is mirrored when its first part is written; writes to the twin part are left to the twin, as before. That case has no test of its own. ## Checklist - [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. No open pull request changes `crates/darner-gpu/src/descriptor.rs`. Open and closed issues and pull requests were searched for "descriptor", "watch page", "cross page", "straddle", "sync_record_parts", "sync_heaps", "descriptor.rs" and "foxhound 504". The nearest are #57 (descriptor writes wait for residency, different files and problem) and #150 (write-watch test in `watch.rs`); neither covers this.
Port of foxhound pull request 504 (readmet3xt-lab/foxhound, "Mirror byte-written
descriptors that cross a watch-page boundary", GPL-3.0).

The written ranges were cut at watch pages, and a record that straddled a
part's start was left to the part holding its first byte. When only the
second page was written, that part did not exist and the record was never
mirrored. The parts are now whole records (`sync_record_parts`): runs within
one page, a record across a page boundary in a part of its own, overlapping
written ranges deduplicated, each record in exactly one part.

Tests: `dirty_parts_cover_only_touched_records_once` (no GPU), and
`dirty_sampler_across_two_watch_pages_is_mirrored`, which needs a hardware
heap and otherwise prints "skipped: no hardware heap here" and returns.
Contributor

I ran the extracted sync_record_parts and changed_slots helpers from d304c07b with Rust 1.98.1. A write limited to the first byte of page two returned the one crossing record, exactly once, for both 16- and 32-byte strides. I would add that case to the pure test. The D3D12 test copies the entire record across the boundary and dirties both pages. For a 16-byte record starting at page - 8, taken = [(page, page + 1)] should return only (page - 8, page + 8). This check used synthetic ranges without D3D12. Pure test · D3D12 test

I ran the extracted `sync_record_parts` and `changed_slots` helpers from `d304c07b` with Rust 1.98.1. A write limited to the first byte of page two returned the one crossing record, exactly once, for both 16- and 32-byte strides. I would add that case to the pure test. The D3D12 test copies the entire record across the boundary and dirties both pages. For a 16-byte record starting at `page - 8`, `taken = [(page, page + 1)]` should return only `(page - 8, page + 8)`. This check used synthetic ranges without D3D12. [Pure test](https://git.gtahub.st/Remorce/Darner/src/commit/d304c07b5556d64ad48a7fe89c84fc2d877d9e19/crates/darner-gpu/src/descriptor.rs#L3682-L3702) · [D3D12 test](https://git.gtahub.st/Remorce/Darner/src/commit/d304c07b5556d64ad48a7fe89c84fc2d877d9e19/crates/darner-gpu/src/descriptor.rs#L3806-L3820)
A record that crosses into the page is the only part, once, for 16- and
32-byte records (review on #163).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor
  • Added that case in 69aab2a4: a write of only (page, page + 1) against a heap starting at page - 8, for 16- and 32-byte records. sync_record_parts returns just the crossing record, once.
  • Same file, test only. Both clippy gates are clean, cargo xtask policy passes, and dirty_parts_cover_only_touched_records_once passes on 69aab2a4.
- Added that case in `69aab2a4`: a write of only `(page, page + 1)` against a heap starting at `page - 8`, for 16- and 32-byte records. `sync_record_parts` returns just the crossing record, once. - Same file, test only. Both clippy gates are clean, `cargo xtask policy` passes, and `dirty_parts_cover_only_touched_records_once` passes on `69aab2a4`.
Remorce force-pushed pr-descriptor-watch-page-records from 69aab2a413 to 29c34040ca 2026-12-04 02:52:54 +00:00 Compare
First-time contributor

Reproduced the second-page-only case on an RTX 4070 Ti SUPER, using the same test fixture on the PR branch point 140980dd and head 29c34040. Windows 11 Pro build 28000, NVIDIA driver 617.14.

16-byte sampler placement and writes Dirty Windows pages Branch point PR head
Starts 8 bytes before the 64 KiB boundary. Write upper 8 bytes only. 16 Missed 2/2 Mirrored 2/2
Same placement. Also rewrite the lower 8 bytes with their existing value. 15, 16 Missed 2/2 Mirrored 2/2
Shift the sampler 16 bytes forward, fully inside page 16. Write upper 8 bytes only. 16 Mirrored 2/2 Mirrored 2/2

Each observation used a fresh process and a real shader-visible D3D12 sampler heap with two slots. Slot 0 began with a valid tag and index but an invalid generation. After an initial sync I checked that both slots were unmade, cleared Windows write-watch, verified an empty page list, then restored the correct generation and called the production sync_heaps(). A non-resetting GetWriteWatch(0) immediately before that call verified the page indices (zero-based, 4 KiB each). The neighbouring slot stayed unmade in all 12 processes. A missing hardware device fails the fixture.

I also reran the two unmodified PR tests after the rebase: the range test passed, and the hardware sampler test passed in two separate processes without taking the no-hardware skip. The observed result is Darner’s host.made(0) on a real host heap. I did not measure game frames or FPS in this test.

Reproduced the second-page-only case on an RTX 4070 Ti SUPER, using the same test fixture on the PR branch point `140980dd` and head `29c34040`. Windows 11 Pro build 28000, NVIDIA driver 617.14. | 16-byte sampler placement and writes | Dirty Windows pages | Branch point | PR head | | --- | --- | --- | --- | | Starts 8 bytes before the 64 KiB boundary. Write upper 8 bytes only. | 16 | Missed 2/2 | Mirrored 2/2 | | Same placement. Also rewrite the lower 8 bytes with their existing value. | 15, 16 | Missed 2/2 | Mirrored 2/2 | | Shift the sampler 16 bytes forward, fully inside page 16. Write upper 8 bytes only. | 16 | Mirrored 2/2 | Mirrored 2/2 | Each observation used a fresh process and a real shader-visible D3D12 sampler heap with two slots. Slot 0 began with a valid tag and index but an invalid generation. After an initial sync I checked that both slots were unmade, cleared Windows write-watch, verified an empty page list, then restored the correct generation and called the production `sync_heaps()`. A non-resetting `GetWriteWatch(0)` immediately before that call verified the page indices (zero-based, 4 KiB each). The neighbouring slot stayed unmade in all 12 processes. A missing hardware device fails the fixture. I also reran the two unmodified PR tests after the rebase: the range test passed, and the hardware sampler test passed in two separate processes without taking the no-hardware skip. The observed result is Darner’s `host.made(0)` on a real host heap. I did not measure game frames or FPS in this test.
TrustNo1 manually merged commit bc1e3fd834 into main 2026-12-04 04:21:16 +00:00
Sign in to join this conversation.
No reviewers
No labels
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!163
No description provided.