Shaders: guard memory_dirty atomics with test-before-or and coalesce page-table loads (FIND-12) #2167
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!2167
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2167"
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?
@RVZO6 on GitHub · 2026-11-25 06:50 UTC · original
RVZO6:rvzo/find12-dirty-atomics→main· +292 −59 · 4 files · 1 commits · openAddresses
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)
@sinan-cmyk on GitHub · 2026-11-25 08:02 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head 6ab9c988 onto
main940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.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).
@nathanbzrr on GitHub · 2026-11-25 08:40 UTC · original
Verified head
6ab9c9880f5b8dbad7582f8a046473b4e3e659c6merged cleanly ontomain(940d32f69b) on Windows 11 x64 / AMD Radeon RX 7600 (driver32.0.32029.2010,rustc 1.98.1,dxil.dll 1.8.2502.11):cargo test -p victory-shader emit::memory_tests -- --nocapture: 5 passed, 0 failed (confirmsdx.op.rawBufferLoad.f32(..., mask=3, align=8)validates againstdxil.dll 1.8.2502.11and executes on RDNA3 hardware).$env:VICTORY_D3D12_DEBUG='1'; cargo test -p victory-gpu --lib memory:: -- --test-threads=1: 3 passed, 0 failed.lower.rs/shader.rs/draw.rs/memory.rs:Shader::memory_null()hoisting into block0strictly dominates all uses inbitcode.rsSSA layout, resets cleanly onStop::Retry, and every dispatched stage withstage.memory.is_some()binds a full page table (draw.rs:739-771).mark_dirty_bitsstructured CFG keepsbegin_guarded/end_guardednested with zero wave ops (SFI0 & 0x4000 == 0-> RDNA3 Wave32/64 divergence safe), non-globallycoherentL1 reads of monotonically0 -> 1bits are conservative, and all fourwrite == truecallers inlower.rsre-readself.cur.Looks good to merge from this check.
AI-assisted; synthetic tests only, no game files, dumps, or captures used.
@Slay326 on GitHub · 2026-11-25 09:45 UTC · original
Hardware data point for the contention this PR removes. I measured main (
940d32f) against main + this PR (6ab9c988) with a synthetic compute test: 64 threads per group, each doing 8global_store_dwordx4through the title-memory page table (the shape of a node writer), GPU timestamps, 3 runs of 5 dispatches each (median per run, mean of the 3 runs). RTX 3070 8 GB, driver 32.0.16.1088, Windows 11 Pro 26200.Written-pages bitmap in system memory (as
memory::bindmakes it), copy of title memory in video memory: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).
cargo test -p victory-shaderand-p victory-gpugive the same failures on main and on main + #2167 (3 hardware-comparison tests instride_tests/synthetic_tests, and 2 heap-size tests invictory-gpu; they fail identically without this PR, and all other tests pass).With #1890 and other local changes (so not
main; title 1.0.2.1): one list of the XboxBvhBuilder passes (a node writer with 12 stores per thread over ~140,000 groups) ran for more than 535 s and never finished. With the same guard in place (our equivalent of this PR) the same passes take a median of 25 ms and 19 ms of GPU time per frame and no list stalls (300 s run, 42 world intervals).On correctness: the bitmap only goes from 0 to 1 during a submission, and the host clears it (
defer_after,mem::take) only afterexecutehas waited for the lists. A stale load can therefore only see a bit as clear (an extra, harmless OR), never a cleared bit as set. Two lanes that both see a clear bit both OR it, which is idempotent. A list named twice in one submission shares the bitmap, and the union is read after both runs, so skipped atomics lose nothing. Sogloballycoherentis not needed.AI-assisted.
@desplmfao on GitHub · 2026-11-25 10:44 UTC · original
@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
XboxBvhBuilder.dllrehydration passes (Box32Rehydration28918b7150a7aad5,Box16Rehydrationcaa78b8ca62bc3d6,DecompressHeader4ddd6f9702fab2a7). Most are 1 to 11 groups, and Box32 goes up to about 1,800. Without this PR the GPU worked through about 200 of them per second (measured with the breadcrumbs from #2310), so the list ran past the driver's timeout:NVRM: Xid 109 CTX SWITCH TIMEOUT, then the title's watchdog. We had to skip those three passes.With this PR merged (cleanly; one fix-up commit so the Windows test helper builds on #439's
Parts/Lower), the whole list finishes and the run gets past it. Breadcrumbs stop pointing at these passes. The next stall is a different program, in the title's hair system, which we're looking at separately. The translated Box32 drops from 274 to 233 raw loads, and every dirty-mark atomic now sits behind the bit test.Thanks. This turned the world load on NVIDIA from "times out" to "goes through" for us.
@Marvisak on GitHub · 2026-11-25 12:37 UTC · original · edited 2026-11-26 01:21 UTC
Automated triage for the maintainers.
Merge candidate (re-checked after the rebase onto
63bcca4, head3cb308d). It merges cleanly again. Incrates/victory-shader/src/emit/lower.rs,Lower::memorynow marks both its first page and the straddling page frommain's 256 MiB / 4 GiB fix through the newmark_dirty_bit. That function loads the bitmap word first and issues theatomicOronly when the bit is clear, the same patternmark_view_writealready used onmain. Other changes:mark_view_writeskips the second mark for 1-byte writes.(view, start)and(base, phase)pairs are read with one 8-byte-alignedraw_dword2.Shader::memory_nullloads the null index once in the entry block, asmemory_handledoes.Which pages end up marked is the same as on
main, by my reading.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:
lower/mark_tests.rsand the bitcode reader inmemory_tests.rsare not rustfmt-formatted.CI: passing (
check).Generated by Claude Code
@RVZO6 on GitHub · 2026-11-25 17:20 UTC · original
Rebased onto current
main(13f91ca, head87e9805; resolved the end-of-file test-append conflict inmemory_tests.rs).Verified green on
windows-latestMSVC + WARP SM 6.6 CI (Run 45662428628) and Wine +dxil.dll 1.9.2609.5.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.
@davesousa on GitHub · 2026-11-25 20:08 UTC · original
In-game check against W on Windows NVIDIA (W is FIND-12's 16x16x16 dispatch,
[compute 00167d58cc5a78d7]in #1968): RTX 3070 Ti 8 GB, driver 621.40, Windows 11 26200.main13f91ca+ #2319, with and without this PR (87e9805, merges cleanly;memory_tests5/5 pass here, skipping the #2571 crash), shader cache rebuilt for each translator.slow host submission ms=)13f91ca+ #2319 + #190613f91ca+ #2319 + this PR13f91ca+ #2319 + #1906 + this PROn this card W's time does not change with this PR. With
VICTORY_GPU_TIMING=1(base13f91ca+ #2319), W alone is 11.4-11.6 s as one list command (4 times), so the time is in W itself, not the lists around it. W was issued in every run that got to world loading (6 of 6), in the first submission with heavy compute and then about once per world frame (FIND-15).One observation I could not attribute: with both #1906 and this PR, 2 of 3 runs ended at boot with the title's own
0xc0000005write to 0 atimage+0x258b000(before the first menu). The third reached the world. With only one of the two PRs, 3 of 3 booted. That is too few runs to blame either PR; I note it in case someone sees the same offset.AI-assisted (Claude Code); the runs are on my machine.
@RVZO6 on GitHub · 2026-11-26 00:21 UTC · original
Rebased onto current
main(63bcca4, head3cb308d). Preserved63bcca4's 256 MiB / 4 GiB straddling-write fix inLower::memory(applying test-before-ORmark_dirty_bitto both primary and straddling-page marks) and movedsynthetic_mark_dxilintocrates/victory-shader/src/emit/lower/mark_tests.rssolower.rsstays below the 512 KiB asset-policy limit. Verified green onwindows-latestMSVC + WARP SM 6.6 CI (clippy, xtask policy, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45727774760.@DenRakEiw on GitHub · 2026-11-25 07:03 UTC · original · approved these changes
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, withdxil.dllvalidator):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_dirtyatomics and coalesced page-table loads (FIND-12), verified end-to-end on hardware and WARP. Looks great.AI-assisted (Gemini 4 Neon).
@catminou4 on GitHub · 2026-11-25 07:24 UTC · original · approved these changes
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.144 passed / 0 failed / 2 ignored. memory_dirty atomics guarded with test-before-or — atomic guard correctness fix.
@fuzeofficlal on GitHub · 2026-11-26 17:01 UTC · original · approved these changes
Verified
3cb308dd76c8b7e7617590e637ab99d005b31f90merged cleanly onto63bcca43on Windows 11 with an RTX 5090, WARP,dxil.dll(Windows SDK 10.0.26100.0), andVICTORY_D3D12_DEBUG=1.Code review
Shader::memory_null()(crates/victory-shader/src/emit/shader.rs:398) emits thememory_table[4096 * 4]load once in entry block0aftermemory_handle(), strictly dominating all uses including accesses inside conditional branches.Lower::raw_dword2(crates/victory-shader/src/emit/lower.rs:4549) issues an 8-byte-alignedrawBufferLoad.f32(mask = 3, align = 8) for both(base, phase)atindex * 8(mark_view_write,lower.rs:4601) and(view, start)at(entry << 3) + 4096 * 4(memory_entry,lower.rs:4785); both offsets and backing D3D12 buffers satisfy 8-byte alignment.mark_dirty_bit(lower.rs:4559) andmark_dirty_bits(lower.rs:4581) guard every dirty-markatomicBinOp.i32(Or) with a read-only load and(old & bit) == 0branch without introducingWAVE_OPS. Since submission dirty bitmaps transition monotonically0 -> 1until host copy-back clears them after fence completion, a stale L1 load can only trigger a redundant idempotent OR and never drop a mark.Lower::memory(lower.rs:4688-4738) properly reloadslet c = self.curatlower.rs:4717before emitting the straddling-page check and guards both the primary and straddling-page marks;mark_view_writestatically omits the second mark forbytes <= 1and checksn != bits[0]before loading the bitmap for multi-byte writes.crates/victory-shader/src/emit/lower.rsstays within the 512 KiB asset-policy limit at520,860bytes (and520,942bytes when co-merged with#2229, with zero conflict).Verification
cargo xtask policy:192 files ok.cargo clippy --locked -p victory-shader -p victory-gpu --all-targets -- -D warnings(default and--all-features): clean.dxil.dll+VICTORY_D3D12_DEBUG=1:emit::memory_tests::(skipping pre-existing#2571NVIDIA crash inheap_direct_texture_reads_mark_their_heap_index): 6 passed, 0 failed (includingmemory_entry_caches_null_coalesces_loads_and_guards_dirty_atomics,dirty_mark_width_and_branch_hoistingvalidated bydxil.dll, andstraddling_writes_across_256mib_and_4gib_boundaries_mark_exact_pageson both hardware and WARP).victory-gpumemory::tests::: 7/7 passed on RTX 5090 (skipping pre-existing 1M-caplists_share_a_table_and_copies_keep_their_views) and 8/8 passed on WARP (--features diagnostics,VICTORY_D3D12_DEBUG=1).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.