Repository navigation
Shaders: guard memory_dirty atomics with test-before-or and coalesce page-table loads (FIND-12) - #2167
Shaders: guard memory_dirty atomics with test-before-or and coalesce page-table loads (FIND-12)#2167RVZO6 wants to merge 1 commit into
Conversation
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):
cargo test -p victory-shader --lib emit::memory_tests::— 5 passed, 0 failed on both RTX 5090 hardware andVICTORY_D3D12_WARP=1cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean test-before-or guard on memory_dirty atomics and coalesced page-table loads (FIND-12), verified end-to-end on hardware and WARP. Looks great.
AI-assisted (Gemini 4 Neon).
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.
144 passed / 0 failed / 2 ignored. memory_dirty atomics guarded with test-before-or — atomic guard correctness fix.
Offline measurement on a retail dumpResult: no count change against I merged head 6ab9c98 onto No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code). |
|
Verified head
Looks good to merge from this check. AI-assisted; synthetic tests only, no game files, dumps, or captures used. |
|
Hardware data point for the contention this PR removes. I measured main (940d32f) against main + this PR (6ab9c98) with a synthetic compute test: 64 threads per group, each doing 8 Written-pages bitmap in system memory (as
Bitmap in video memory (as in #2175), same test: 0.62 us/group on main, 0.096 us/group with #2167 (9000 groups). With #2167 the bitmap's location no longer matters for the marks (0.0965 vs 0.096). On WARP (same test, bitmap in system memory, 1000 groups) it is 10.3 us/group on main and 0.86 us/group with #2167. The marked pages are identical on both branches in every variant and every run (9 of 9, 125 of 125, 1125 of 1125 pages). With #1890 and other local changes (so not On correctness: the bitmap only goes from 0 to 1 during a submission, and the host clears it ( AI-assisted. |
…rehydration Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…his stack has them The synthetic dirty-mark program (Marvisak#2167, written against main) lacked the target, console_cf and per_lane_only fields and Lower::new's numeric_selects argument that the wave and select branches add, so the Windows test build did not compile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ak#2310 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@RVZO6 a data point from the title on an RTX 5080 (Linux, Proton, vkd3d-proton 3.2.0), on our stack with #439. At world load, the title issues one list of about 7,000 direct dispatches of Microsoft's With this PR merged (cleanly; one fix-up commit so the Windows test helper builds on #439's Thanks. This turned the world load on NVIDIA from "times out" to "goes through" for us. |
…x yet Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Merge candidate (re-checked after the rebase onto
Which pages end up marked is the same as on Performance results are mixed: one tester reports a large speedup, another sees no change in W's time on an RTX 3070 Ti. Either way, the change only removes atomics for bits that are already set. #2755 adds wave-level coalescing on top of the same pre-check, so the maintainer may want to land this first and rebase that one. Optional: CI: passing ( Generated by Claude Code |
|
Rebased onto current Verified green on Thanks to @Slay326 for the RTX 3070 timestamp benchmark (~3,200x–5,800x; 535 s -> 19–25 ms in title) and @desplmfao for confirming it resolves the RTX 5080 world-load timeout. |
6ab9c98 to
87e9805
Compare
|
In-game check against W on Windows NVIDIA (W is FIND-12's 16x16x16 dispatch,
On this card W's time does not change with this PR. With One observation I could not attribute: with both #1906 and this PR, 2 of 3 runs ended at boot with the title's own AI-assisted (Claude Code); the runs are on my machine. |
…page-table loads Coalesce 8-byte (view, start) page-table and (base, phase) view-mark loads via raw_dword2 (mask 3, alignment 8), cache memory_null once in the entry block across title-memory accesses, omit the second dirty mark statically for single-byte writes, hoist the n != bits[0] guard before bitmap word/bit loads, and guard every dirty-mark atomicBinOp OR with a test-before-atomic rawBufferLoad check without WAVE_OPS. Assisted-by: T3 Code (Antigravity, gemini-4-neon)
|
Rebased onto current |
87e9805 to
3cb308d
Compare
…, coalesce page-table loads) memory_tests.rs: main's heap-direct read-mark test and Marvisak#2167's bitcode tests both kept. Marvisak#2167's synthetic_mark_dxil gets Marvisak#439's Parts fields and Lower::new's numeric_selects argument (false). memory_tests pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
The previous renderer (old upstream base 940d32f) is the first parent and is also kept as the branch renderer-2026-11-25-oldbase; the second parent is the rebuild: fork main (upstream main 63bcca4 + our pull requests) with the renderer stack merged on it: Marvisak#439 (on main: update/439-main's resolution), Marvisak#2309, Marvisak#2167, Marvisak#2118, Marvisak#2311, Marvisak#1722, Marvisak#1751, Marvisak#688, Marvisak#1872, Marvisak#2292, Marvisak#2310, Marvisak#2112 (opt-in), Marvisak#2230 (latch on by default), Marvisak#2389, Marvisak#2088 (small windows opt-in), Marvisak#2099's new head, and tonight's Marvisak#491 journal fixes. Merged upstream since: Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906, Marvisak#1152; superseded by main: Marvisak#1769, Marvisak#1763, Marvisak#2366. The picture on this base still shows the overlay that plain upstream main shows too; that is being looked into. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A benchmark (ignored by default) and a check, in HLSL that does what translated programs do when they store to title memory: look the address up in the page table (an upload heap), set the bits of the pages written in the list's bitmap with atomics, store into the host copy. Variants: main's two unconditional atomics per store; a load first and an atomic only for a clear bit (Marvisak#2167's approach); one atomic per wave for lanes sharing a bitmap word (Marvisak#2755's); both; none. Each with the bitmap in system memory, as now, and in video memory; four ways of writing. RTX 5070 Ti, driver 621.24, ms per dispatch of 131,072 threads storing 16 dwords each (bitmap clear before the dispatch / already set): one page linear page/lane scattered main, system bitmap 79.8/76.5 75.8/75.0 1595/1583 336/337 test-first, system 1.6/0.33 11.5/0.35 21/20 13.0/6.7 wave, system 1.7/0.33 11.4/0.36 22/22 13.5/6.8 main, video bitmap 0.31/0.31 0.32/0.32 20/20 6.4/6.5 test-first, video 0.30/0.30 0.32/0.32 20/21 6.8/6.7 no marks 0.30/0.29 0.32/0.32 20/19 6.5/6.5 Atomics on a bitmap in system memory are what cost: up to 250 times the dispatch without marks. Loading first removes them once a page is marked; one atomic per wave adds nothing on this GPU. A bitmap in video memory costs nothing even with main's unconditional atomics, first marks included. What is left in "page per lane" and "scattered" is the stores into the host copy in system memory. `every_variant_marks_the_pages_main_marks` checks every variant, in both places, sets exactly main's bits. `dxc.exe` comes from the Windows SDK; without it or a GPU both tests do nothing. cargo test -p victory-gpu --release --lib marks_bench -- --ignored --nocapture
…s, per way of marking (benchmark for Marvisak#2167, Marvisak#2175, Marvisak#2465, Marvisak#2755)
…with test-before-or and coalesce page-table loads (FIND-12)
Addresses
FIND-12: shaders lowered through the title-memory page-table path currently issue an unconditionaldx.op.atomicBinOp.i32(Or) into the globalmemory_dirtybitmap on every store — twice per multi-byte store (forstartandend, even when both land on the same 64 KiB page) — causing severe L2 atomic contention when many compute lanes write the same page (~2.4 s/dispatch, 4.8–6.9 s/frame reported on RTX 5080). In addition, every title-memory access re-loadsmemory_table[4096](memory_null) and reads(view, start)as two separate 4-byterawBufferLoads, andmark_view_writereads(base, phase)as two separate 4-byterawBufferLoads and emits a second dirty mark even for single-byte stores.The change
crates/victory-shader/src/emit/shader.rs: addmemory_null: Option<V>andShader::memory_null()so the null-view index atmemory_table[4096 * 4]is loaded once in entry block 0 (emit_at_entry, safe even when first used inside a branch) and reused across all title-memory accesses.crates/victory-shader/src/emit/lower.rs:raw_dword2()(dx.op.rawBufferLoad.f32,mask = 3,align = 8) to coalesce the contiguous 8-byte(view, start)load inmemory_entry()and(base, phase)load inmark_view_write().mark_dirty_bits(bitmap, bits, guard):bytes <= 1(single-byte stores cannot cross a 64 KiB page boundary).n != bits[0]before computing the word/bit offset and loading the bitmap.dx.op.atomicBinOp.i32(Or) with a read-onlyrawBufferLoad+(old & bit) == 0branch so already-dirty pages never serialize on L2 atomics. Uses pure 32-bit ops withoutWAVE_OPS(SFI0 & 0x4000 == 0).crates/victory-shader/src/emit/memory_tests.rs: addmemory_entry_caches_null_coalesces_loads_and_guards_dirty_atomicsanddirty_mark_width_and_branch_hoistingverifying single entry-blockmemory_null, coalescedraw_dword2loads, guarded dirty-mark atomics,n != bits[0]gating before bitmap load, 1-byte 2nd-mark elision,dxil.dllvalidation, and zeroWAVE_OPS.Not a duplicate of
FIND-12is open inCLAIMS.md; no other open PR guardsmemory_dirtyatomics or coalesces page-table / view-markraw_dword2loads incrates/victory-shader/src/emit/lower.rs.Tested
windows-latestMSVC + Windows WARP SM 6.6 CI on fork integration stack (Run 45562558052):cargo clippy --workspace --all-targets --locked -- -D warnings: clean.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: clean.cargo test --workspace --locked: 712 passed, 0 failed, 10 ignored, includingvictory-shader249 passed, 0 failed, 3 ignored (all 5emit::memory_tests::*includingtitle_memory_is_read_and_written_at_computed_addresses,root_views_read_their_copy_and_zeros_past_it,writes_through_views_mark_their_pages, and both new bitcode/validator tests on Windows WARP SM 6.6) andxtask(6 passed, 0 failed,repository_passes_policy).6ab9c98:cargo clippy(default &--all-features)-D warningsclean; Wine-10.0 +dxil.dll 1.9.2609.5passed both new tests andemit::lower::/emit::bitcode::(29 passed, 0 failed).Not run: the title; any hardware GPU (CI ran on Windows WARP SM 6.6 only). The title was not used in these tests.
AI-assisted: T3 Code (Antigravity, gemini-4-neon)