D3D12-SHADER-IR-BUILD-ANALYSE-ONCE: decode instruction fields and effects once #2835
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2835"
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 bobcatchris on 2026-12-01T05:03:06Z.
Claim:
D3D12-SHADER-IR-BUILD-ANALYSE-ONCE(https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7298302658).What and why
ir::buildwalks every machine instruction, decodingfields(wave64)and computingeffects(...). When a program hasv_writelane_b32/v_readlane_b32,unspill_scanhas to walk every instruction first to find parked scalars, decodingfieldsand computingeffectsfor each, and thenbuilddoes both again. A sampling profile putir::buildat 16.3% of samples underspill::build; this halves the decoding for spilling programs.unspillnow returns a cache indexed by instruction:Decoded { name, fields, effects }. The cache is sound:unspill_scanonly borrowsfields/effectsduring its scan and rewriteslistin place after scanning everything;listis never resized or reordered, and everyputrewrite clears that entry's cache slot.None); programs whereunspill_scanbails (name() == None,effectserror, no parked scalars, no pair) get no cache and decode exactly as before.buildrecomputeseffectsafter its own parked-scalar substitution (which mutatesFields::Sopscalar codes) and for rewritten instructions.Same values, same errors, same order; the emitted DXIL is unchanged. No rendering or translation-rule change.
Verification (offline, no game files)
The existing
ir::tests::unspill_looks_only_where_the_code_has_a_save_or_a_restore_of_a_lanestill comparesunspillwithunspill_scanon synthetic streams and now reads the moved return type.The DXIL-identity-over-full-archive check the claim mentions needs game shader data, which is not used here; the semantic corpus is hand-written.
AI-assisted: yes. Design direction from Gemini 4 Neon (one call, no game data).
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-01T05:18:42Z.
Verified on Windows: the crate is green with it, and the suite does not distinguish it from
main- which is the honest finding for a change that decodes an instruction once instead of twice.main10bed9ff2, cherry-picked (one commit,merge-base86c30fcea),cargo 1.98.1:So nothing is broken and nothing is added.
ir.rsgains 51 lines and loses 26, and the same 404 tests pass in both trees.What that means, and I would rather say it than dress it up: the suite proves the answers did not change, which is the property a refactor must have; it does not prove the instruction is decoded once. Only a count of decodes would, and there is no such counter in
leonida-shader. If the pull request's description has a measurement, that is what to check.And one thing worth noting from the shape: a change that only touches
ir.rsand adds no test is the kind this repository has no workflow to run at all -cargo test -p leonida-shadertakes six minutes and nothing runs it in CI. That is #2816's argument, and this pull request is the case it does not cover: a refactor with no new test is exactly what a suite catches by accident or not at all.AI-assisted: yes - DeepSeek v4.1 (flash), two six-minute runs.
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T06:09:54Z.
Review: COMMENTED
The key and the invalidation are right, and the differential is the strongest evidence: 800 random spilling builds (wave32 and wave64, all cache-hitting) with the cache on against the pre-PR path off gave identical IR, identical errors, identical panics. Keying the cache to
n + 1changes all 800 and the committed suite catches it (threeresource/pairedtests fail), so the wiring is pinned by real tests, not only by the differential.The mechanism holds: a
Vec<Option<Decoded>>indexed by the instruction's place inlist, which is never resized or reordered (rewrites go throughput, same length, andbuildconsumes in order);putis the only rewrite and clears the slot (ir.rs:628);buildtakes each slot once (:177) and recomputeseffectsafter its parked-scalar substitution (:197,:222); every bail-out (no lane instruction, unknown opcode, effects error, no parked scalar, no plan) returnsNone, so those programs decode exactly as before and reproduce the same error at the same offset. Nothing is global or per-thread — the cache is owned by onebuildand dropped with it, and a non-spilling program pays oneOptioncheck per instruction with no allocation.Two small things:
cached_effects = Noneafter the substitution is unreachable for a cached instruction — every parked index was already rewritten byput, whose slot isNone— so the line is defensive. A comment saying so (or dropping it) would keep the next reader from assuming it is load-bearing..0); the cache's contents are covered by the resource/paired value tests and by the differential, not by it. Fine, just worth knowing where the coverage lives.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T08:33:28Z.
RUN - VERIFY-2835-RTX4060 - by MoonEyes (another person than the author) on head
12ff308a8, with #2836, #2835, #2695, #2696, #2689, #2699 and #2705 merged together intomain9372a4d4f(clean).main9372a4d4fand thenmain+ the seven, one run each, same save: 0 device lost, 0 panics, 0 exceptions in both, about 490 s in the world each, alive at the time limit. Frame rate median 17.8 with the seven and 15.0 onmain, not a comparison: other work ran on the PC during themainrun.main9372a4d4f+ the seven (Windows): leonida-hle 243, leonida-gpu 602, leonida-formats 47, leonida 47, leonida-shader 403 of 405: twosource_hash_testsfailed on a stale build script of mine (a target folder shared with an older branch) and pass after a rebuild of it (3 of 3).Limits: one card, one run per arm, two arms only, the seven together. Values only, no game data.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T09:09:22Z.
Merging. Head
12ff308a8merges cleanly withmain76746d35band does not force a rebase of #2566. CI green on this head and on main. In-game run on the RTX 4060 posted above (this head, with the six others, about 490 s in the world, 0 device lost, pictures compared with main). Tests on main + the seven: leonida-hle, leonida-gpu, leonida-formats, leonida, leonida-shader, 0 failed. Verified on it by fiestorra and KelboLive (800 random builds, same IR). Merged by MoonEyes.AI-assisted (Claude Code).