Repository navigation
Shaders: look up the second page of straddling title-memory writes in the page table - #2484
Conversation
|
Independent Windows 11 + NVIDIA GeForce RTX 5070 Ti verification of #2484 at
Not tested: live game workload / shader translation cache run. AI-assisted test run and summary. |
|
Independent Windows verification (software WARP only, no hardware GPU in the final runs)
Results:
Diff review: the second-page lookup is sound. It computes the last byte with a 64-bit add (carry into hi, masked to 16 bits), looks the page up through Caveats: environment notes for others running these tests on WARP: the Windows SDK 10.0.19041 Verified by Claude Code (Claude Sonnet 5.5), an AI assistant, on behalf of a maintainer. |
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: merged into main 940d32f, cargo test -p victory-shader --locked on macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — second page of straddling title-memory writes looked up (+241, the page-straddle fix).
Lower::memory previously computed the dirty bitmap bit for the last byte of a write by adding 32-bit wrapped page deltas to the first page's level-2 entry. Writes straddling a 4 GiB boundary wrapped the 32-bit addition to ~512 MiB out-of-bounds in the dirty bitmap UAV, and writes crossing a 256 MiB boundary overflowed the 12-bit page index into the wrong or out-of-bounds level-2 block. Guard the second bitmap update on non-missed 64 KiB page crossings and resolve the end address with 64-bit addition through the page table.
df829fb to
3c5fa89
Compare
|
Automated triage for the maintainers. Merge candidate. In
The PR computes the last byte with The new test CI: Generated by Claude Code |
Upstream main merged Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906 and Marvisak#1152 and took up what Marvisak#1769 (LDS bounds, Marvisak#1949) and Marvisak#1763 (typed UAV formats, Marvisak#2462) did; main's code is kept for those. - emit/lower.rs: ds_bpermute within each half (main's Marvisak#573, same as Marvisak#439's); LDS bounds as main's Marvisak#1949 (Marvisak#1769's test-only counter kept, its and_guard dropped); title-memory marks: main's straddling-write lookup (Marvisak#2484) with Marvisak#2167's current head (3cb308d, rebased on 63bcca4): guarded dirty atomics, raw_dword2, memory_null, synthetic_mark_dxil in lower/mark_tests.rs; the old Marvisak#2167 head taken out first. - emit/host.rs: main's shared WARP device and lock (Marvisak#244) with Marvisak#439's adapter list and Host::on (create_device takes an optional adapter). - descriptor/host.rs: main's Marvisak#2462 format checks; Marvisak#1763's tests kept. - gpu host.rs: main's multi-plane present with Marvisak#2310's crumbed copy. - pipeline.rs: Marvisak#2118/Marvisak#2311's builder and BVH checks with main's skip hashes (Marvisak#1320); draw.rs, shadow.rs, main.rs: both sides. - Tests main added since get Marvisak#439's Parts fields and emit's Target. - README: base 63bcca4; rows of PRs merged upstream, superseded or closed taken out, with a note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Fixes two out-of-bounds / mis-indexed dirty-bitmap updates in
Lower::memory(crates/victory-shader/src/emit/lower.rs) when a multi-byte title-memory store (bytes > 1, such asglobal_store_dwordx2/x3/x4) straddles a 256 MiB or 4 GiB boundary:4 GiB boundary wraparound (
lo + (bytes - 1)in 32 bits):Lower::memorypreviously computed the last byte's page delta from the low address dword alone:A store straddling a 4 GiB boundary (for example
0x1_FFFF_FFF8 ..= 0x2_0000_0007, whichmemory::tableandlo.wrapping_sub(start)explicitly allow within a single host copy) wrappedendto7, yieldingpages = 0xFFFF_0001(-65535mod2^32) and issuing anatomicBinOp.i32on the root dirty-bitmap UAV at byte offset~+512 MiBpast the 256.5 KiB mappedbitmapbuffer.256 MiB level-1 region boundary overflow (
e.entry + 1):e.entrypacks(block << 12) | page. When a store crossed from page0xFFFof one 256 MiB region into page0x000of the next (0x1_0FFF_FFF8 ..= 0x1_1000_0007),e.entry + 1overflowed the 12-bit page index into((e.block + 1) << 12) | 0instead of looking upl1 + 1in the level-1 table (memory::tableassigns blocks in descending copy-size order, so adjacent 256 MiB regions do not occupye.block + 1):e.block == CAPACITY(512),(513 << 12) | 0(word = 262_656bytes) indexed past the(CAPACITY + 1) * 4096-bit bitmap.e.block < CAPACITY, marking(e.block + 1) << 12either dirtied an unrelated region's page 0 or hit an unallocated/unowned block entry that causedmemory::bind'sdefer_missed/defer_aftercheck to treat the entire command list as having read unmapped memory (withholding all title-memory and marked-view copy-backs for that submission), while leaving the actual second page unmarked.Changes
Lower::memory_pageandLower::memory_mark_indexout ofLower::memory_entryandLower::memory, plusLower::mark_memory_bitfor bitmap updates.marks, and only whenwrite && bytes > 1,!e.miss, and(lo >> 16) != (end_lo >> 16)(computed with 64-bitadd64(lo, hi, bytes - 1, false)and 48-bitend_himasking) look up(end_lo, end_hi)viamemory_page+memory_mark_indexinside a guarded block. This also avoids emitting a redundant secondatomicBinOp.i32on single-byte writes, missed writes, and non-straddling multi-byte writes.mark_dirty_bitswith test-before-OR and coalesced loads while keeping the 32-bitend = lo + last; next = e.entry + pagescalculation; whichever lands second is a straightforward merge inLower::memory.Verification
emit::memory_tests::straddling_writes_across_256mib_and_4gib_boundaries_mark_exact_pages(crates/victory-shader/src/emit/memory_tests.rs), lowering and DXIL-validating aglobal_store_dwordx4compute shader and executing it on both SM 6.6 hardware (RTX 5090) and D3D12 WARP across:0x1_FFFF_FFF8acrossl1 = 0x1F -> block 2intol1 = 0x20 -> block 1),e.block == 512(CAPACITY) into an unmapped next region (0x1_0FFF_FFF8-> marks512 * 4096 + 0xFFFand missed region bit0x11without overflowing past block 512), and0x1_FFFF_FF00).cargo test -p victory-shader --lib emit::memory_tests(4/4 passed on hardware + WARP)cargo clippy -p victory-shader --all-targets -- -D warningscargo xtask policy