Shaders: look up the second page of straddling title-memory writes in the page table #2484
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2484
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2484/head"
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?
@fuzeofficlal on GitHub · 2026-11-25 14:40 UTC · original
fuzeofficlal:fix/shader-memory-straddle-dirty-mark→main· +241 −37 · 2 files · 1 commits · merged 2026-11-25 21:57 UTCSummary
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@Bj0rnis on GitHub · 2026-11-25 14:45 UTC · original
Independent Windows 11 + NVIDIA GeForce RTX 5070 Ti verification of #2484 at
d0c55787(cleangit merge-treewithorigin/main940d32f6, Rust 1.98.1 MSVC):victory-shadertests (RTX 5070 Ti):cargo test -p victory-shader --lib --locked -- --test-threads=1-> 245 passed, 3 failed, 3 ignored (89.04s). The new test passes; all 3 failures reproduce identically on cleanmain940d32f6on RTX 5070 Ti (emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros[#1835], andemit::synthetic_tests::gathers_at_a_level_match_the_hardware).cargo clippy -p victory-shader --all-targets --locked -- -D warnings-> 0 warnings.cargo xtask policy-> 182 files ok.Not tested: live game workload / shader translation cache run.
AI-assisted test run and summary.
@oni-swr on GitHub · 2026-11-25 14:55 UTC · original
Independent Windows verification (software WARP only, no hardware GPU in the final runs)
d0c55787be9521d42e986f74c19c7f5db42ab15d;origin/main:940d32f69b22265690a0b5a15d6ded572ba33baf(merge base = origin/main;git merge-treemerges clean)VICTORY_D3D12_WARP=1andVICTORY_WARP=1(the latter is what victory-shader's testHost::newactually reads; the code path isEnumWarpAdapter, i.e. Microsoft Basic Render Driver 0x1414). The tests do not print the adapter id, so 0x1414 is from the code path, not from log output.Results:
cargo test -p victory-shader --lib --locked -- --test-threads=1: 246 passed, 2 failed, 3 ignored. All 4memory_testspass, includingstraddling_writes_across_256mib_and_4gib_boundaries_mark_exact_pages(new) andwrites_through_views_mark_their_pages.synthetic_tests::gathers_at_a_level_match_the_hardwareandsynthetic_tests::permutes_read_the_lane_named_and_zero_from_lanes_left_out(WARP gather result / "no pipeline for a wave of 32"). Both fail identically onorigin/mainunder WARP, so they are not caused by this PR.cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean.cargo xtask policy:asset policy: 182 files ok.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
memory_pageinstead of offsettingentry, and only does so when the write crosses a 64 KiB boundary, is not a miss, and is active. A wrap past 4 GiB also reads as "crossed". I found no logic issues and no overlap with other open PRs.Caveats: environment notes for others running these tests on WARP: the Windows SDK 10.0.19041
dxil.dllmakes the SM 6.6 tests crash with STATUS_ACCESS_VIOLATION on WARP (also on main); a current dxil.dll avoids it. Also, victory-shader tests ignoreVICTORY_D3D12_WARPand only honorVICTORY_WARP=1, otherwise their "hardware" pass uses the real GPU. An earlier attempt of mine set onlyVICTORY_D3D12_WARP, so its "hardware" pass briefly ran on the physical adapter before crashing; all results above are from the laterVICTORY_WARP=1runs.Verified by Claude Code (Claude Sonnet 5.5), an AI assistant, on behalf of a maintainer.
@Marvisak on GitHub · 2026-11-25 16:12 UTC · original · edited 2026-11-25 16:44 UTC
Automated triage for the maintainers.
Merge candidate.
In
Lower::memory(crates/victory-shader/src/emit/lower.rs), the second dirty bit of a multi-byte write is no longere.entry + (pages crossed)computed from the low dword. Main has two real bugs here:lo + bytes - 1, giving a huge entry and an out-of-range atomic on the root UAV bitmap.entry + 1into(block + 1) << 12, which is the wrong region's block.The PR computes the last byte with
add64and looks it up again through the newmemory_pageandmemory_mark_indexhelpers. It only does so inside a guarded block when the write actually crosses a 64 KiB page, is not a miss, and is active. The marking convention is unchanged (a page entry, or the region's level-1 bit when the region has no block). Values from the second lookup are used only inside the guard.The new test
straddling_writes_across_256mib_and_4gib_boundaries_mark_exact_pageschecks the exact bits, including the capacity-block edge. It overlaps textually with #2167.CI:
checkpassing.Generated by Claude Code