Repository navigation
shader/opt: extend Module::bounded() to zero-identity Add/Sub and budgeted acyclic Phi (D3D12-SHADER-BOUNDED-EXTENSIONS) - #2861
Conversation
…geted acyclic Phi
|
Verified on Windows 11, and the control bites: the two new tests fail on today's
So both rules are exercised by the change and not by the tests alone: the zero-identity PLACEHOLDER_SUITE The whole crate with this pull request merged into The four failures are the tests that run the DXIL validator ( So this pull request adds two tests and changes no other result. One note on the in-game gate: it is the right kind of evidence for this change, since a wider bound only ever removes a guard, and the gate shows the frame times and the stability are unchanged. What a CPU-only check cannot do is count the guards that are no longer emitted over the title's own shaders, so the "improves the guard elision" half of the claim stays unmeasured here - the unit tests show the bound is now known where it was not, not how often the title's shaders reach it. |
KelboLive
left a comment
There was a problem hiding this comment.
Sound direction, and the zero case is the right fix for RDNA's -0.0 - x — it only fires when the non-zero side already has a bound, so nothing new is asserted finite, and the old +1 was over-conservative. The tests are genuinely red on the old arm (neg_sat and the two-level phi diamond both fail), so the extension is pinned.
Worth stating in the commit: this is magnitude-identity, not bit-identity. +0.0 + -0.0 and -0.0 - -0.0 flip the zero's sign and 0.0 + sNaN quiets it — fine for |v| <= 2^b, but exactly the distinction simplify() calls out. No counterexample exists where the arm returns Some for a non-finite value: float_k only accepts float constants or a 32-bit int bitcast, the IR has no vector type, and saturate is a dx.op.unary that is already exact under 0 ± x.
One thing I would change before merge: the budget. let mut budget = 64 is per bounded() query and shared across sibling branches, so it restricts acceptance: I built a 1023-node acyclic balanced Add tree over bounded constants and it returns Some(10.0) on the PR's parent and None here — a missed v_mul_legacy_f32 elision (falls back to compare+select, not a miscompile), which partially cancels this PR's own goal. 1 << depth or memoising (v, depth) per query would cap the phi blow-up without dropping those proofs. The 300 s gate cannot see this because it has no elision count.
Minor: rustfmt --check flags the newly joined over-width arms (:479, :495, :525); the base file already fails elsewhere and the workspace fmt job is launcher-only, so it is cosmetic.
VERIFY-2861 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), no GPU device, no game filesVerdict: PASS. The repository's own red/green verifier says red then green, the two rules the pull request adds are sound for the quantity Head 1. What it changes
2. The repository's own red/green verifier says red then greenBoth new tests fail on the base and pass on the head, and nothing else moves. 3. The zero identity is sound for a magnitude bound
The The important direction is the one that could have been unsound: an unbounded operand still gives It also removes a false 4. The Phi rule is sound
The budget also matches an idiom already in the same file: 5. The new tests do not discriminate the visit budgetThis is the one thing I would change in the pull request. I took the budget away — The reason is the depth limit, which is older than this pull request: I measured the visits (I counted them with a temporary counter, and reverted it afterwards):
So the budget is real and useful — it is what stops the 5-level DAG at 64 visits instead of 2,729, and it is what turns a 64-arm phi from Two more numbers worth having: the budget allows exactly 64 instruction visits per query (constants are free — they are answered before the budget is touched), so a tree of 64 instruction nodes answers 6. What the budget costs against
|
Claimed in the coordination issue as:
D3D12-SHADER-BOUNDED-EXTENSIONS(claim comment)What and why
Extend
Module::bounded()(d3d12/crates/leonida-shader/src/emit/bitcode/opt.rs) to soundly propagatef32finite-magnitude bounds through two additional exact forms, directly improving both AMDrdna::LEGACYand095af0c96'sLEONIDA_LEGACY_PLAINv_mul_legacy_f32guard elision with zero behavioral change:Op::Bin(Bin::Add | Bin::Sub, a, b): When either operand is±0.0(self.float_k(...) == Some(0.0)),0.0 ± xandx ± 0.0preservebounded(x)directly instead of adding+ 1.0. In particular, RDNA2 float negation lowers to-0.0 - x, so this avoids doubling the magnitude bound or losing the proof at the2^125overflow cutoff (unbounded inputs still returnNone).Op::Phi(inc): For non-empty phis (!inc.is_empty() && inc.len() <= 64), deduplicates repeated incoming values and returnsSome(max_k bounded(val_k)?)when every incoming edge is bounded within the recursion depth. A shared visit budget (budget = 64instruction visits inbounded_inner) guaranteesO(1)worst-case time perbounded()query even on deep multi-way acyclic phi DAGs, while empty phis, phis with any unbounded edge, and cyclic loop phis (which exhaustdepthorbudget) conservatively returnNone.095af0c96(LEONIDA_LEGACY_PLAIN): Upstream095af0c96addedLEONIDA_LEGACY_PLAIN(opt-in, off by default) callingself.s.m.bounded(a, 12)/bounded(b, 12)alongside the existing RDNArdna::LEGACYpath. This PR touches onlyModule::bounded()inbitcode/opt.rsand introduces no new switches or semantic changes.d3d12/crates/leonida-shader/src/emit/bitcode/opt.rs:455–545andlower.rs:5674–5720) +scripts/red_green.pyverified red→green unit tests covering±0.0Add/Sub, near-2^125negation, acyclicPhi, emptyPhi, unbounded-edgePhi, incrementing/self-referential loopPhi, and wide 10-level 4-wayPhiDAG visit-budget termination + MEASURED 300 s in-game gate on exact PR headce91bce59.Tested
python3 -I scripts/check_no_game_data.py d3d12/crates/leonida-shader/src/emit/bitcode/opt.rs→ exit 0.python3 -I scripts/red_green.py pr/shader-bounded-extensions --base origin/main --no-fetch --no-python(native Linux):cargo test --locked -p leonida-shaderon PR headce91bce59(rebased ontocd73ddab7):244 passed; 0 failed; 2 ignored(includingsource_hash_tests).docs/game_gate.md) on exact PR headce91bce59(leonida.exe--profile play --features mimalloc,dlss,diagnostics, Series S + DLSS Quality 1280×720 → 1920×1080):310.89 s(world_at_s = 82.27 s,>= 300 srequired)world + 60 sto stop):3,458presented frames (3,533total world presents),15.28median FPS,103.93 msp95 frame time (15.42end-window median FPS,4,373.5median draws/frame)3.144 s(<= 10.0 srequired)6,709 MiB(<= 7,400 MiBguard)0device losses,0crashes/faults,0panics,0kernelNVRM: XiderrorsGPUs tested: NVIDIA GeForce RTX 3070 Ti 8 GB, driver 620.73.04, Arch Linux (Wine 11.22 + VKD3D-Proton 3.2.0).
AI-assisted: yes (authored by Gemini 4 Neon; audited and approved in a separate independent review pass by Gemini 4 Neon).
Checklist
main(cd73ddab7) and merges cleanly.check_no_game_data.pyclean).docs/design.md(n/a — soundModule::bounded()analysis extension, no new ISA rule).ce91bce59).