d3d12/descriptor: mirror a record across two watch pages when only the second was written (D3D12-DESCRIPTOR-STRADDLE-SECOND-PAGE) #3431

Closed
leonida/mandy
OreoFR wants to merge 2 commits from oreofr/descriptor-straddle into main AGit

Pull request closed

Please reopen this pull request to perform a merge.

Member

Claimed in the coordination issue as: D3D12-DESCRIPTOR-STRADDLE-SECOND-PAGE (https://git.leonida.now/leonida/mandy/issues/3312#issuecomment-25244)

What and why

sync_heaps() (d3d12/crates/leonida-gpu/src/descriptor.rs) mirrors descriptor records the title copies into a placed shader-visible heap as plain bytes, from the pages the write watch reports. It cut the written ranges at the 64 KiB 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, so the record was never mirrored (the slot kept the old descriptor).

The parts of the write-watch path are now whole records (sync_record_parts): runs of records 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. The LEONIDA_PORT_DESCRIPTORS path (port_descriptors::plan_parts) is unchanged; its parts already begin on a record, so the read loop is unchanged too (only its comment).

On by default (no switch): it is a correctness fix of the existing default path. A part now covers the whole records the written ranges touch, so a sync reads at most a record more at each end of a written range than before, and a record shared by overlapping ranges is read once.

Ported from Darner (TrustNo1/Darner, GPL-3.0-or-later) commits 7a2c516b2 and 29c34040c, after foxhound's PR 504. Mandy's parts are 3-field tuples (with the port #2 check flag), so the change was rewritten to fit rather than applied as-is.

Nearby open PRs: #3429 (diagnostics on missed heap views) and #3309 (KEPT_SEEN epoch) touch the same file but not these lines; no dependency.

Tested

  • Red/green: with the old page-cutting logic restored, dirty_sampler_across_two_watch_pages_is_mirrored fails: left: (false, false), right: (true, false) (the sampler written only on the second page is not mirrored). With the fix both new tests pass (dirty_parts_cover_only_touched_records_once, dirty_sampler_across_two_watch_pages_is_mirrored; the latter ran with a hardware heap, not skipped).
  • cargo test --locked -p leonida-gpu: 732 passed, 0 failed, 59 ignored.
  • cargo clippy -p leonida-gpu --all-targets --locked -- -D warnings: clean.
  • cargo build --locked --profile diag -p leonida --features diagnostics,dlss,mimalloc: builds.
  • python -I scripts/check_no_game_data.py on the changed file: clean.
  • No in-game run yet.

GPUs tested: NVIDIA GeForce RTX 4070 Laptop GPU, driver 621.40, Windows 11 Pro.

AI-assisted: yes, Claude Code (Claude Opus 5.5).

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption, including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md (n/a, no translator change).

🤖 Generated with Claude Code

Claimed in the coordination issue as: `D3D12-DESCRIPTOR-STRADDLE-SECOND-PAGE` (https://git.leonida.now/leonida/mandy/issues/3312#issuecomment-25244) ### What and why `sync_heaps()` (`d3d12/crates/leonida-gpu/src/descriptor.rs`) mirrors descriptor records the title copies into a placed shader-visible heap as plain bytes, from the pages the write watch reports. It cut the written ranges at the 64 KiB 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, so the record was never mirrored (the slot kept the old descriptor). The parts of the write-watch path are now whole records (`sync_record_parts`): runs of records 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. The `LEONIDA_PORT_DESCRIPTORS` path (`port_descriptors::plan_parts`) is unchanged; its parts already begin on a record, so the read loop is unchanged too (only its comment). On by default (no switch): it is a correctness fix of the existing default path. A part now covers the whole records the written ranges touch, so a sync reads at most a record more at each end of a written range than before, and a record shared by overlapping ranges is read once. Ported from Darner (TrustNo1/Darner, GPL-3.0-or-later) commits 7a2c516b2 and 29c34040c, after foxhound's PR 504. Mandy's parts are 3-field tuples (with the port #2 check flag), so the change was rewritten to fit rather than applied as-is. Nearby open PRs: #3429 (diagnostics on missed heap views) and #3309 (KEPT_SEEN epoch) touch the same file but not these lines; no dependency. ### Tested - Red/green: with the old page-cutting logic restored, `dirty_sampler_across_two_watch_pages_is_mirrored` fails: `left: (false, false)`, `right: (true, false)` (the sampler written only on the second page is not mirrored). With the fix both new tests pass (`dirty_parts_cover_only_touched_records_once`, `dirty_sampler_across_two_watch_pages_is_mirrored`; the latter ran with a hardware heap, not skipped). - `cargo test --locked -p leonida-gpu`: 732 passed, 0 failed, 59 ignored. - `cargo clippy -p leonida-gpu --all-targets --locked -- -D warnings`: clean. - `cargo build --locked --profile diag -p leonida --features diagnostics,dlss,mimalloc`: builds. - `python -I scripts/check_no_game_data.py` on the changed file: clean. - No in-game run yet. GPUs tested: NVIDIA GeForce RTX 4070 Laptop GPU, driver 621.40, Windows 11 Pro. AI-assisted: yes, Claude Code (Claude Opus 5.5). ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption, including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md` (n/a, no translator change). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sync_heaps cut the written ranges at the watch pages and left a record that
straddled a part's start 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 of the write-watch path 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. The LEONIDA_PORT_DESCRIPTORS path (plan_parts) is
unchanged.

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

Ported from Darner (TrustNo1/Darner, GPL-3.0-or-later) commits 7a2c516b2
and 29c34040c, after foxhound's PR 504.

Item: D3D12-DESCRIPTOR-STRADDLE-SECOND-PAGE

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator

Gate run on an RTX 3090 (NVIDIA 621.40, Windows 11 Pro build 26300), head 26ef78281 merged into main 04a838fc4 (clean, no merge commit needed), diag profile with diagnostics,dlss,mimalloc, msvc target. Reference: main 04a838fc4 built the same way. Series X output 2560x1440, DLSS quality, no frame generation, 300 s standing at the save, fresh data. The newer head c9e54b082 only changes comments against the tested one (git diff 26ef78281 c9e54b082: 8 lines in descriptor.rs, all comments).

  • 0 device lost, 0 crash, 0 ERROR lines.
  • 33.7 frames/s over 150-300 s against 34.5 for main (-0.8, inside the run-to-run spread of this recipe); median frame 29.33 against 28.69 ms, p99 45.3 against 45.5 ms. Pauses as in the reference (the loading one, then a few of 1.5-2.1 s right after reaching the world), none after 150 s.
  • Captures at 150 and 300 s: the same picture as main, no fault seen.
  • Descriptor refresh line, mean over 150-300 s: the same work on both sides (about 54.5 pages, 23,300 slots and 2,900-2,950 copied a frame), but 4.07 ms a frame (max 6.84) against 3.54 ms (max 5.83) for main, so about +0.5 ms a frame for that step here. One run each, so take it as an indication, not a measured cost.

Verdict: PASS (no loss, picture fine, frame rate within tolerance). Worth a look: the refresh step's time per frame went up by about half a millisecond for the same number of descriptors.

GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40.
AI-assisted: run and report by Claude Code (Claude Opus 5.5).

Gate run on an RTX 3090 (NVIDIA 621.40, Windows 11 Pro build 26300), head `26ef78281` merged into `main` `04a838fc4` (clean, no merge commit needed), diag profile with `diagnostics,dlss,mimalloc`, msvc target. Reference: `main` `04a838fc4` built the same way. Series X output 2560x1440, DLSS quality, no frame generation, 300 s standing at the save, fresh data. The newer head `c9e54b082` only changes comments against the tested one (`git diff 26ef78281 c9e54b082`: 8 lines in descriptor.rs, all comments). - 0 device lost, 0 crash, 0 ERROR lines. - 33.7 frames/s over 150-300 s against 34.5 for `main` (-0.8, inside the run-to-run spread of this recipe); median frame 29.33 against 28.69 ms, p99 45.3 against 45.5 ms. Pauses as in the reference (the loading one, then a few of 1.5-2.1 s right after reaching the world), none after 150 s. - Captures at 150 and 300 s: the same picture as `main`, no fault seen. - Descriptor refresh line, mean over 150-300 s: the same work on both sides (about 54.5 pages, 23,300 slots and 2,900-2,950 copied a frame), but 4.07 ms a frame (max 6.84) against 3.54 ms (max 5.83) for `main`, so about +0.5 ms a frame for that step here. One run each, so take it as an indication, not a measured cost. Verdict: PASS (no loss, picture fine, frame rate within tolerance). Worth a look: the refresh step's time per frame went up by about half a millisecond for the same number of descriptors. GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40. AI-assisted: run and report by Claude Code (Claude Opus 5.5).
Author
Member

Closing as superseded by #3445 (merged as 1c3570a88). Main now has the same fix: sync_record_parts treats a record across a watch-page boundary as one whole part, and does not drop it when only the second page was written. Main also has its own test for it, record_across_a_watch_page_is_one_whole_part.

Notes for the record:

  • The 300 s gate of this PR on an RTX 3090 (enlighted, comment above) passed: -0.8 fps, within tolerance, and the same picture.
  • This PR's GPU test dirty_sampler_across_two_watch_pages_is_mirrored ran red/green on a real hardware heap. #3445's commit says its own red case was "by reasoning, not run". If someone wants that check on main, the test can be ported on its own.

Reopen if anything in this PR is still missing from main.

Closing as superseded by #3445 (merged as `1c3570a88`). Main now has the same fix: `sync_record_parts` treats a record across a watch-page boundary as one whole part, and does not drop it when only the second page was written. Main also has its own test for it, `record_across_a_watch_page_is_one_whole_part`. Notes for the record: - The 300 s gate of this PR on an RTX 3090 (enlighted, comment above) passed: -0.8 fps, within tolerance, and the same picture. - This PR's GPU test `dirty_sampler_across_two_watch_pages_is_mirrored` ran red/green on a real hardware heap. #3445's commit says its own red case was "by reasoning, not run". If someone wants that check on main, the test can be ported on its own. Reopen if anything in this PR is still missing from main.
OreoFR closed this pull request 2026-12-04 12:04:12 +00:00
Sign in to join this conversation.
No description provided.