d3d12-shader: merge after chains() and accept commuted And in canonical() #3156
Open
github-bot
wants to merge 1 commit from
github-bot/gh-3156 into main
AGit
pull from: github-bot/gh-3156
merge into: github:main
github:main
github:perf/darner-title-priority-ceiling
github:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
github:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
github:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
github:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
github:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
github:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github:fix/runtime-test-conservative-fixtures
github:ci/shard-semantic-linux
github:docs/fg-limit-fps-switch
github:fix/runtime-test-fixture-paths
github:fix/runtime-test-fixture-readers
github:fix/read-file-hard-link
github:fix/book-slot-heap-never-read
github:fix/depth-resolve-spv-path
github:fix/indirect-unused-batched
github:gh-pr/3358/base
github:fix/xmem-refusal-diagnostics
github:gh-pr/3357/base
github:ci/shorten-ci-time
github:fix/alias-later-queued-submissions
github:claude/gallant-sagan-aamatr
github:gh-pr/3342/base
github:gh-pr/3341/base
github:d3d12/agility-sdk-621
github:gh-pr/3293/base
github:gh-pr/3319/base
github:gh-pr/3318/base
github:gh-pr/3315/base
github:gh-pr/3313/base
github:gh-pr/3314/base
github:claude/fervent-curie-m19lnr
github:gh-pr/3216/base
github:gh-pr/3272/base
github:gh-pr/3276/base
github:gh-pr/3279/base
github:gh-pr/3257/base
github:gh-pr/3258/base
github:gh-pr/3271/base
github:codex/skip-no-hit-ray-passes
github:gh-pr/3230/base
github:gh-pr/3266/base
github:gh-pr/3247/base
github:gh-pr/3246/base
github:gh-pr/3244/base
github:claude/sharp-sagan-1jqnp3
github:t3/preserve-fsr-sdk-restart-path
github:t3/propagate-host-failure-hresult
github:t3/launcher-custom-parameters
github:t3/series-x-2160-startup
github:codex/d3d12-uncapped-simulation
github:ci/less-to-run
github:perf/native-compute-shader-forms
github:claude/blissful-franklin-ukp7ag
github:codex/full-precompile-default
github:gh-pr/3166/base
github:gh-pr/3148/base
github:gh-pr/3138/base
github:gh-pr/3106/base
github:gh-pr/3057/base
github:gh-pr/2756/base
github:gh-pr/2812/base
github:gh-pr/3032/base
github:gh-pr/2992/base
github:notes/card-time-and-plant-flicker
github:gh-pr/2986/base
github:gh-pr/3000/base
github:gh-pr/2966/base
github:gh-pr/2924/base
github:gh-pr/726/base
github:gh-pr/2761/base
github:gh-pr/2663/base
github:gh-pr/2861/base
github:gh-pr/2862/base
github:gh-pr/2820/base
github:gh-pr/2811/base
github:gh-pr/2803/base
github:rt-call-trace
github:gh-pr/2802/base
github:gh-pr/2766/base
github:perf/ahead-split
github:gh-pr/2589/base
github:gh-pr/2699/base
github:gh-pr/2696/base
github:docs/readme-runtime-proposal
github:gh-pr/1346/base
github:codex/coord-claim-check-20261124-7e48
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
area: ci
.github/ workflows and settings
area: d3d12
The D3D12 runtime in d3d12/ (Rust: leonida.exe and its crates)
area: docs
Documentation
area: launcher
The launcher (launcher/)
area: runtime (legacy)
The earlier Vulkan runtime in runtime/
area: shader translator
The shader translator (leonida-shader, tools/rdna2spirv) and its tests
area: tools
tools/ and scripts/
area: viewer
The map viewer (viewer/)
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs in-game run
Changes the code a frame runs through: needs the 300 s in-game gate (docs/game_gate.md)
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
wontfix
This will not be worked on
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!3156
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3156"
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?
@molodayamama on GitHub · 2026-12-02 14:38 UTC · original
molodayamama:fix/d3d12-shader-opt-chains-merge→main· +132 −1 · 1 files · 1 commits · openSummary
Fixes two bugs in
d3d12/crates/leonida-shader/src/emit/bitcode/opt.rsthat causedCHAINS(LEONIDA_SHADER_OPTbit 256) to leave duplicateand i1chains behind in large shaders instead of deduplicating shared prefixes:Bin::Andoperands inchains()'scanonical()check:Module::key()commutes integerBin::And, somerge()(REUSE) can replacea & bwith an earlier dominatingb & a. Previouslycanonical()only checkedOp::Bin(Bin::And, x, y) if y == want, causing it to returnfalseon(b & a) & c, re-emit the entire chain on every round, and ping-pong withmerge()through all 4 rounds.merge()ifchains()fired on the final round:Module::optimiseranchains()at the end offor _ in 0..4, so any chains emitted on round 4 were never seen bymerge()(REUSE). Trackingneed_mergeand running one finalself.merge(passes)whenchains()modified the module on the last iteration guarantees every canonicalized prefix is deduplicated.Verification
opt.rs):chains_accepts_commuted_and_operands— failed onmain(3 != 2Bin::Ands left behind), passes with fix (!m.chains()aftermerge(REUSE)and2Bin::Ands total).optimise_merges_chains_emitted_on_final_round— failed onmain(3 != 1Bin::Ands in dominated blockb4), passes with fix (1Bin::Andinb4).cargo test --manifest-path d3d12/Cargo.toml -p leonida-shader --lib bitcode::opt::tests: 23/23 passed (including the 400 random-program interpreter equivalence suite).dxil.dllvalidation (LEONIDA_HOST_MAX_WAVE=32, 25,687 emitted shaders):7,271shaders strictly smaller,0bigger.103,500,704 -> 103,045,759(-454,945,-0.44%;arith:49,590,221 -> 49,135,276,-0.92%; largest single-shader drop:-18,498instructions).dxil.dllvalidation counts unchanged (2,694VP,2,675CS,2,650MS validated;0regressions).106.8 s -> 104.5 s.cargo clippy --manifest-path d3d12/Cargo.toml -p leonida-shader --lib -- -D warnings: 0 warnings.python -I scripts/check_no_game_data.py: clean.python -I tools/d3d12_switches.py --check d3d12/docs/switches.md: clean.LGTM(0 blockers).AI-assisted.
@merzleckeier on GitHub · 2026-12-02 14:43 UTC · original · reviewed
Independently checked
53c3100onmainacc350745with native Linux Rust 1.98.1 and separate Cargo target directories. With the two submitted tests copied ontomain, the optimizer suite passed 21 tests and failed exactly the two new cases. The commuted prefix was rewritten, and the final-round test left threeAndinstructions inb4where it expected one. The clean PR build passed 255 shader-crate tests, with two existing ignores. This includes all 23 optimizer tests and the 400-program interpreter check.I also ran local variants of the two new fixtures with independently controlled Boolean inputs. For all 8 and 16 input combinations, their store and return traces matched before and after optimization. The structural assertions still passed in those variants. These were synthetic checks. Archive size, throughput and native D3D12 validation were outside this run. AI-assisted with OpenAI Codex.
@fiestorra on GitHub · 2026-12-02 15:41 UTC · original
Verified on this machine:
red then green, no test moved, and the whole archive translates to the same numbers asmain.And the corpus, because this is the optimiser and a unit test only says the two cases are fixed:
leonida translateover the title'sshaders.rpf, the pull request's build againstmain's build, both--jobs 16:Identical to the instruction, including all 40,597,574 IR instructions - so the change moves nothing on the 26,084 programs the archive holds, which is what a fix to two edge cases of
CHAINSshould look like from outside.What that does not say, and I am not claiming it:
CHAINSis bit 256 ofLEONIDA_SHADER_OPTand part ofMODULE, so it was on in both runs - what the runs say is that turning the fixes on does not change the corpus result, not that the pass does nothing;AI-assisted: yes - DeepSeek v4.1 (flash).
Written with an AI assistant.
@Kal0s-design on GitHub · 2026-12-02 17:54 UTC · original
Ran natively on Windows 11, head
53c3100merged into currentmain(45dc41f, clean merge). The runs below were done onmain5b1fff8, whereleonida-shaderis byte-identical to45dc41f. Rust 1.98.1,--locked.Below is what this thread does not have yet: how this PR overlaps with #2800, and a differential fuzz of
chains().Overlap with #2800 (measured)
#2800 adds the same
canonical()arm,if x == want => cur = y, character for character. Beyond that the two PRs share nothing. #3156 adds the trailingmerge(). #2800 (b6ebced) gives same-block phis distinct birth positions inchains().main+ #3156 + #2800 merges cleanly in either order. Both orders give the same tree.chains_accepts_commuted_and_operandsoptimise_merges_chains_emitted_on_final_roundand, want 1)a_chain_with_the_operands_of_its_steps_the_other_way_round_is_left_as_it_isa_chain_with_its_terms_out_of_order_is_still_rewritten(control)a_chain_of_three_phis_in_the_same_block_settles_in_one_passchains()returns true)Neither PR subsumes the other:
A residual loop this PR leaves (measured)
With this PR's code, a chain over one dominating term and two
i1phis of one block is rewritten on every call. The shape is(br & p0) & p1, withbra compare in the entry block andp0/p1phis of the join:chains()called 4 times(br & p0) & p1(p0 & p1) & t(tmade in the join)Three phis are not needed. Two tied phis are enough when they are not the first two terms, because the new arm accepts either operand order only at the lowest step. #2800's tie-break closes it.
Differential fuzz of
chains()(throwaway test, not proposed for the PR)Programs come from two generators:
and(operands in either order),or,xor,xor true,select(c, t, false),select(c, false, f),i1add/mul, andzext→add/mul→ compare.true/falseconstants, and commuted copies ofands already built.i1phis.random_program, seeds 1–10,000.Each program ran in the crate's interpreter (
run) on 12 input vectors, before and afteroptimise()with 6 pass sets:CHAINS,+REUSE,+DEAD,+FOLD,GUARDS|CHAINS|REUSE|DEAD,ALL. Each was also optimised a second time.To check that the harness can catch a miscompile, I ran it on a build where
chains()drops the last term of a 4+ term chain. That build gave 70,100 mismatches.Synthetic generator, 20,000 programs:
chains()+merge(REUSE)not settled after 12 alternationschains()still fires right afteroptimise(CHAINS)optimise(CHAINS|REUSE)twice ≠ onceoptimise(ALL)twice ≠ onceALL(ands)optimise(ALL)time, 3 passes over the setrandom_program, 10,000 seeds:optimise(ALL)twice ≠ onceALL(dominating term & phi & phi)shape above.optimise(ALL)twice ≠ once with both PRs behave the same withCHAINSturned off (ALL & !CHAINS,GUARDS|REUSE|DEAD) and onmain. They do not come from either PR.CHAINSmakesALLoutput larger thanALL & !CHAINSin every variant: 1,652,367 live and 266,546ands without it. It does this less with the PRs than onmain. Shared sub-ands get rebuilt per root. This is a property of the pass on these shapes, not of this PR.Suites (measured)
cargo test -p leonida-shader, NVIDIA cardThe 8 WARP failures are the same on
main. They are pipeline creation failing with "The parameter is incorrect", inpack_tests,valu_testsandwave64_tests. They are not related to this PR.cargo clippy -p leonida-shader --all-targets: the same 6 warnings asmainon every tree, none new.Reading, not measured
chains()fired in the last round andpasseshas one ofFOLD|REUSE|FACTS|LOADS. Nothing runs after it exceptDEAD. Aprune/guardsopportunity the extra merge opens is left for the nextoptimisecall. That matches the residual counts above, which are the same withCHAINSoff.Not checked: game shaders or archive output, any in-game run, debug-layer runs,
rustfmt, other crates. WARP was not run for this PR on its own.Suggestion: the two PRs are complementary. Merging both, or folding #2800's
bornchange into this one, gives zero unsettled programs in the fuzz above.GPUs tested: one NVIDIA desktop card + WARP
AI-assisted: yes (Claude Code).
@MoonEyes on GitHub · 2026-12-02 18:01 UTC · original
Code review, not built here (
leonida-shadertests were run by fiestorra). Ready.53c3100ce, merge base9cb1902d3, 59 behind currentmain45dc41f95. A trial merge is clean. CI on the head: all 6 checks pass.python -I scripts/red_green.py 3156(red then green on both new tests, 428 pass on both sides) and a full-corpus translate with identical counts (26,084 programs, 40,597,574 IR instructions). Nothing has changed since.Review of
d3d12/crates/leonida-shader/src/emit/bitcode/opt.rs:Op::Bin(Bin::And, x, y) if x == want => cur = yincanonical()is the right fix for the ping-pong betweenREUSE, which picksc1 & a, andCHAINS, which re-emitteda & c1.chains_accepts_commuted_and_operandspins it directly (assert!(!m.chains())aftermerge(REUSE)).need_mergeis set only bychains()in the last round that ran. A loop that ends on!changedleaves it false, so the extramergeruns only when round 4 still emitted chains. The cost is bounded at one more merge peroptimise. The guardpasses & (FOLD | REUSE | FACTS | LOADS)is narrower than the unconditionalmerge(passes)inside the loop. That is harmless:mergedoes nothing for the other passes.pruneorchainsthat is never run. This was equally true before, since the loop is capped at 4 rounds.Verdict: ready.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
@MoonEyes on GitHub · 2026-12-02 22:00 UTC · original
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).
@fiestorra on GitHub · 2026-12-02 23:36 UTC · original
VERIFY-3156 — Windows nativo:
red then greenen el optimizador de bitcode53c3100ce—emit/bitcode/opt.rs, +132/−1Ran at the head
Negative control (synthetic): I disabled the commuted case (
Op::Bin(Bin::And, x, y) if x == want→&& false), rebuilt and ran:The test bites.
What the change is, in two halves:
chains()accepts the commuted form —andis symmetric, sox & wantandwant & xare the same chain, and the recogniser only matched one order.need_mergewhenchains()changed something and runsmerge(passes)if any ofFOLD | REUSE | FACTS | LOADSis on, instead of leaving a chain emitted by the last round unmerged. That is the classic final-round bug: every pass is correct in isolation and the last one has no successor to fix it.What I could not test: a title frame whose shaders go through this path — the tests drive the optimiser's own representation.
Written with an AI assistant.
@MoonEyes on GitHub · 2026-12-03 00:02 UTC · original
RUN (in game, batch of nine pull requests), each head merged with
git merge --no-ffonto main81efe4566, in one build: #313674bd1bcd4, #315653c3100ce, #3206d024194b3, #3248efd21d867, #3256e7aad1d4c, #32623643c2879, #2851b83b0b375, #312589bf1d328, #2642164506d01. RTX 4060 8 GB, driver 610.88, Windows 11. Series S,-Resolution 1080, frame generation 2x,-PrecompileUsed, 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 17.2 fps on other batches in the last day. These 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, on the heads listed above. If one of these pull requests changes its head, this run no longer covers it.
Limits: one run; arrival in the world was driven by keys and not checked on pictures;
-PrecompileUsedwas used, so the default start (every known pipeline precompiled) was not exercised. The precompile before the world took 619 s, against 157 s for the previous batch; the shader-side changes in this batch (#3156, #3262) probably left the pipeline cache cold (not checked). Switches that are off by default (for example #2851'sLEONIDA_TITLE_MEMORY_SCALE, #3136's timeline attribution) were not turned on: this run covers their default path only. #2642 targets Wine and was run on Windows only.AI-assisted (Claude Code).
@limittox on GitHub · 2026-12-03 02:41 UTC · original
RUN (in game): this PR alone against
mainalone, 3 runs each, interleaved. No device loss or crash in any run. The fps difference is within run-to-run noise.This adds to MoonEyes's batch run above in three ways: the PR is in a build of its own, a second GPU is used, and the launcher's default start (every known pipeline precompiled) is exercised.
53c3100cemerged withgit merge --no-ffontomain81efe4566, with no conflicts;main81efe4566alone.-Dlss quality(1280x720 → 1920x1080).LEONIDA_SHADER_OPTunset: its default, 447, includesCHAINS(256), so the changed pass ran.main, PR, PR,main,main, PR.mainmainmainEvery run exited normally after its time limit.
main23.6–24.8 (median 24.4).mainin every run, by about 0.5 fps at the median. With 3 runs each, and a 1.2 fps spread betweenmain's own runs, I can't tell that apart from noise. I don't claim a gain.main: 2,712 s, then the pipeline library written in 23 s.main's, which had just filled the NVIDIA driver cache with a full set of new pipelines. That may explain the slow library write, but I haven't checked.Limits:
AI-assisted: Claude Opus 5.5 (Claude Code) built both versions, scripted the runs and wrote this report. A separate read-only reviewer agent rechecked it against the raw logs.
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.