shader/opt: the visit-budget test uses 5 phi levels, where the budget decides (D3D12-SHADER-BOUNDED-BUDGET-TEST) #2969
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2969"
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?
Imported from ubiquitarianism/leonida. Originally posted by aznohonza on 2026-12-01T21:56:11Z.
Re-created from the original #2959.
aznohonza/mandy-contribwas made private at 21:41 UTC on 2026-12-01, which detached the fork and permanently closed its pull requests; GitHub refuses to reopen them (422 state cannot be changed). Same branch, same head535c140949179bb31da20d0ecf45375fd3227ea7. The original review thread is at #2959.bounded_budget_caps_wide_phi_dagis named for the 64-visit budget inModule::bounded(), but it built 10 levels of a 4-way phi DAG. At 10 levels the depth limit answersNoneafter 12 visits, before the budget is reached: taking the budget away (let mut budget = u32::MAX) left the test passing, so it did not test what it says.Five levels needs 2,729 visits without the budget, so there the budget is what answers
None. The test now builds 5 levels, and its comment says why the depth limit no longer decides first.Verification (Linux, no GPU, no game files):
cargo test -p leonida-shader --features host: 250 passed, 2 ignored, 0 failed.let mut budget = u32::MAX, the 5-level test fails (assertion left == right failed: left: Some(0.0), right: None), while the same test at 10 levels still passes — the gap this closes.Test-only: no translator output, no switch, no game data.
Claimed in #2570 (
D3D12-SHADER-BOUNDED-BUDGET-TEST). AI-assisted.Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T22:19:29Z.
Review: COMMENTED
Identical to #2959 (
535c14094), which I reviewed: 5 phi levels cost exactly 2,729 visits, the 64 budget is the limiter at that depth, and the mutations agree (removing the budget or raising it to 2,729 fails).merge-treeis clean. Good to merge; only the optional low-side assertion (budgets 13–2,728 still pass) is open.Imported from ubiquitarianism/leonida. Originally posted by aznohonza on 2026-12-01T22:28:23Z.
Thanks for the mutation check. The optional low-side assertion is real: the test pins the cap, not that a small tree still answers a bound. The 2-level diamond above it does return
Some(0.0)at budget 64, so the "budget does not refuse small trees" side is covered there; I will add the 13–2,728 sweep only if it can be done without pinning the implementation's exact capacity.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-02T04:51:01Z.
VERIFY-2969 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), no GPU device, no game files
Verdict: PASS. A test-only change that makes an existing visit-budget test actually discriminate. I confirmed the
mechanism directly: with the visit budget deliberately broken, the new 5-level test fails while the old
10-level test passes — so before this pull request the test was passing for the wrong reason (the depth limit, not
the budget). The whole crate suite is identical on the merge base and on the head.
Head
535c1409, base the currentmain(8422def7), merge base1fff6912, 1 file, +4/−3:d3d12/crates/leonida-shader/src/emit/bitcode/opt.rs.1. What it changes
The test
bounded_budget_caps_wide_phi_dagbuilds a 4-way diamond DAG of Phis and asserts the final value is capped toNone. It looped0..10(10 phi levels); it now loops0..5(5 phi levels), with the comment rewritten to say why:The call under test is unchanged:
assert_eq!(m.bounded(cur, 12), None);—boundedis entered with adepth of 12 and an internal visit budget of 64 (
opt.rs:463-465,let mut budget = 64;). The change istest-only: no production code is touched.
2. The new test checks the property that matters
The property is: the wide-DAG value is capped to
Noneby the visit budget, not by the depth limit.boundedreturns
Nonefrom either of two independent guards —depth.checked_sub(1)?or*budget = budget.checked_sub(1)?(
opt.rs:473-474). At 10 phi levels the recursion is ~20 nested calls deep, which trips the depth limit of 12 first,so
Nonecame back even if the budget were completely broken — the test proved nothing about the budget. At 5 philevels the recursion is ~10 deep (under 12, so depth is not the binder) but the DAG still needs far more than 64
visits (my recurrence for the diamond gives ≈1,705 recursive calls; see the note on the comment's number in §4), so
the budget is what returns
None.I verified this empirically rather than by argument. I mutated
boundedto disable the budget decrement(
// MUTATION: *budget = budget.checked_sub(1)?;commented out) and ran the test both ways:assertion left == right failed: left: Some(0.0), right: NoneSo the pull request's test notices a broken budget and the old one did not. That is exactly what a discriminating test
should do, and it is the whole point of the change. I then restored the source (the mutation lived only in throwaway
debug worktrees, now removed).
3. What the tests do here
python3 -I scripts/red_green.py 2969 --crate leonida-shader(own work-dir and target dir):opt.rshunk applied cleanlyno red(exit 1)no redis the expected verdict for a test-only change with no production fix: the test passes on the base too(because the base's 10-level version is capped by depth), so nothing goes red→green. That is precisely why the brief's
alternative method — break the tool and check the test notices — is the right one here, and §2 is that check.
I also ran the whole crate suite on the merge base and the head on clean target dirs:
cargo test -p leonida-shader1fff6912250 passed; 0 failed; 2 ignored535c1409(pr2969)250 passed; 0 failed; 2 ignoredIdentical. (The count differs from red_green's 252 because red_green's target had the two
source_hash_testscounteddifferently — see §4.)
4. Any failure I saw, and why it is not this pull request
source_hash_testsfailed spuriously during iteration (the_source_hash_leaves_the_test_modules_out,every_test_module_is_built_for_tests_only). Cause:build.rsbakesLEONIDA_SHADER_SOURCE_HASHinto the testbinary at compile time while the test recomputes the hash from
src/at run time; sharing oneCARGO_TARGET_DIRacross worktrees left a stale binary whose baked hash did not match the checked-out tree. It reproduced on plain
mainand on the merge base, which rules out this pull request. With a per-commit clean target dir both thebase and the head pass 250/250 (§3). Harness artefact, not the code under test.
(
V(L)=1+4·(1+V(L−1))) gives ≈1,705 recursive calls at 5 levels, not 2,729; the exact figure depends ontraversal order and the duplicate-incoming skip in the
Op::Phiarm (opt.rs:507-515). The number is not assertedanywhere and does not affect the test, whose validity rests only on "more than 64 visits, fewer than 12 levels
deep" — which holds. Worth a one-word fix (
~1,700) if the author cares, but it is not a correctness problem and Iwould not block on it.
5. What I did not check
translation involved, and I did not run any.
cargo clippy/cargo fmtgate;cargo teston Linux only.boundedpredicate is exercised only by this unit test; I did not measure how oftenboundedhits the budget versus the depth limit over the real shader corpus, so I cannot say how many real programsthis test now protects that it did not before.
boundedto print the true number of visits for the5-level DAG; my ≈1,705 is a calculation from the structure, not a measured value, and the comment's 2,729 I likewise
did not reproduce.
behaviour to regress; the identical base/head suite (§3) is the whole of the evidence needed and I did not look for
any beyond it.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T12:33:22Z.
This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).
Could you, or anyone with a working setup, post a run report on the current head merged onto current
main:mainSHA it was merged onto;mainalone for comparison, if you can.Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T15:09:10Z.
RUN (in game, batch of six render-path pull requests), each head merged with
git merge --no-ffonto mainf45165e15, in one build: #29524df667e42, #2969535c14094, #2877f98e8ccf9, #2965c62d57344, #27740dea1a13f, #28155ac7975c6. RTX 4060 8 GB, driver 610.88, Windows 11. Series S,-Resolution 1080, frame generation 2x, the same walking route as the other runs on this machine, 330 s after reaching the world.For reference, the same machine and route rendered 13.3 to 15.2 fps today on main with single pull requests. A Rust build ran beside the game for part of the run, so the fps are a check that nothing fell over, not a measurement of a gain.
Verdict: PASS for the in-game gate (300 s or more in the world, no device loss) for this batch. If one of these pull requests changes its head, this run no longer covers it.
Limits: one run; free system memory was low (median 1.1 GB); arrival in the world was driven by keys and not checked on pictures. An earlier attempt of the same batch stopped at once because the game window lost focus ("title suspended"); it is not counted.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T15:56:47Z.
RUN (independent run on Windows, #2969 head
535c14094, merged locally intomainf45165e15withgit merge --no-ff, as part of a batch of six)The in-game run of the batch is already posted on this pull request; this comment is the test side only (no game data, no game files).
Red: the claim is that the old test could not fail when the budget is removed.
let mut budget = 64;tou32::MAXinModule::bounded(opt.rs:464):bounded_budget_caps_wide_phi_dagstill passes (1 passed).left: Some(0.0),right: None).So the test now pins what its name says.
Green (whole batch, one tree, Windows 11, debug profile as
d3d12.ymlruns it):cargo test --workspace --exclude xtask --locked: 1708 passed, 0 failed, 75 ignored (leonida-gpu lib 691 / 59 ignored, leonida-shader lib 248 / 2 ignored, leonida app 44, leonida-formats 47, leonida-menu 48, leonida-pe 36).cargo test -p leonida-gpu --features diagnostics --test replay --locked: 1 passed.cargo test -p xtask --locked: 7 passed.texture::alias_cast_tests::committed_and_placed_r32_uint_textures_cast_to_r9g9b9e5_under_legacy_barriers,watch::tests::a_write_opens_the_view_it_goes_through,pipeline::make::tests::overlapping_waits_cost_the_frame_its_budget_once); each passes alone, a later full run was 691/0, andmainf45165e15alone failed the alias_cast test in 2 of 3 runs.Mutations (budget in
bounded, PR's test):u32::MAXkilled;2800(above the 2,729 visits the 5-level DAG needs) killed;70survives (any budget between the small case and 2,729 passes, which is the intended slack).Review: test-only change, no translator output touched. The comment states the visit figures (2,729 without the budget, 64 with it) and they match what the budget removal shows above.
Not covered: the depth-limit path (10 levels) is no longer exercised by this test; another test would have to pin it if wanted.
Verdict: PASS.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T15:58:07Z.
Merging. Head
535c14094merges cleanly withmain3c106eb2fand does not force a rebase of #2566. In-game gate: batch run of 330 s in the world on mainf45165e15+ this head, 0 device lost, 0 exceptions (comment 7349817865). Independent red/green by MoonEyes' agent on head535c14094(the new 5-level test fails with an unlimited budget where the old 10-level test passed; 2 of 3 mutations killed, the third is the intended slack), comment 7351191792. CI green incl. no-game-data; Moon gave full autonomy on these batches. Merged by MoonEyes.AI-assisted (Claude Code).