[pr-fix][rendering] Mirror descriptor records that cross a watch-page boundary #163
Loading…
Reference in a new issue
No description provided.
Delete branch "Remorce/Darner:pr-descriptor-watch-page-records"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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)
What it changes
When
sync_heapsmirrors 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_partsincrates/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
1655cc05on57dea7f2. The pull request's commitd304c07bhas the same tree; only the commit message changed.cargo clippy --workspace --all-targets --locked -- -D warnings: clean, on1655cc05.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean, on1655cc05.cargo test --workspace --locked, on1655cc05: fails with the same twodarner-shaderfailures as onmain(57dea7f2). This change does not touchdarner-shader. Cargo stops at the first failing crate, so the rest was run withcargo test --workspace --locked --no-fail-fast --exclude darner-shaderandcargo test --locked -p darner-shader --doc. The first run: 3283 passed, 2 failed (the two below), 119 ignored. The rest:darner-simd,xtaskand 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 on57dea7f2alone.emit::wave64_tests::lds_shared_atomic_add_producer_executes_wave32_on_hardware: expects wave size 32 and gets 64. It fails the same way on57dea7f2alone. The test came with the isolated LDS add lowering (merge10c532c1, former CodeFloe PR 187) and does not setDARNER_LDS_ISOLATED_ADD=1, which68cb7c85made off by default.darner-gpu'shost::refresh_tests::unchanged_ranges_are_knownfailed once, in the--no-fail-fastrun, and passed in the first full run.cargo test --locked -p darner-gpu --libthen passed 3 runs of 3 on this branch. On57dea7f2alone it failed 2 runs of 3, in the write-watch tests (watch::tests::ask_once_by_res_splits_reservations_without_refusalsboth times, plus two others once), the area #150 is about. So these write-watch tests are flaky onmaintoo.cargo test --locked -p darner-gpu --lib dirty_ -- --test-threads=1 --nocapture, on1655cc05: 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".69aab2a4(test only, ond304c07b): both clippy gates clean,cargo xtask policy"asset policy: 553 files ok",dirty_parts_cover_only_touched_records_oncepassed.140980dd(main):7a2c516b+29c34040. Both clippy gates clean,cargo xtask policy"asset policy: 555 files ok",dirty_parts_cover_only_touched_records_oncepassed.cargo test --locked -p darner-gpu --lib dirty_ -- --test-threads=1 --nocaptureon29c34040: 8 passed, 0 failed, the D3D12 test on a hardware heap.cargo test --workspacewas not rerun after the rebase.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 printsskipped: no hardware heap hereand returns, as the bare-runner rule asks.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
main.docs/asset-policy.md.Checked for overlap
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 inwatch.rs); neither covers this.I ran the extracted
sync_record_partsandchanged_slotshelpers fromd304c07bwith 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 atpage - 8,taken = [(page, page + 1)]should return only(page - 8, page + 8). This check used synthetic ranges without D3D12. Pure test · D3D12 test69aab2a4: a write of only(page, page + 1)against a heap starting atpage - 8, for 16- and 32-byte records.sync_record_partsreturns just the crossing record, once.cargo xtask policypasses, anddirty_parts_cover_only_touched_records_oncepasses on69aab2a4.69aab2a413to29c34040caReproduced the second-page-only case on an RTX 4070 Ti SUPER, using the same test fixture on the PR branch point
140980ddand head29c34040. Windows 11 Pro build 28000, NVIDIA driver 617.14.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-resettingGetWriteWatch(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.