Repository navigation
D3D12-SHADER-IR-BUILD-ANALYSE-ONCE: decode instruction fields and effects once - #2835
Conversation
For a program with v_writelane_b32/v_readlane_b32, unspill has to walk every instruction to find parked scalars, decoding fields and computing effects for each, and then build walks them again doing both. unspill now returns a cache indexed by instruction (name, fields, effects), and build takes it. The cache is sound because unspill only rewrites list in place and only after it has already scanned everything; any instruction unspill rewrites has its cache entry cleared, and build recomputes effects after its own parked-scalar substitution. Programs without a lane save or restore, and any program where unspill_scan bails, get no cache and decode exactly as before. Same values, same errors, same order. DXIL-identity over the full shader archive needs game files; checked here with the leonida-shader unit tests and the hand-written translator semantic suite. AI-assisted: yes
|
Verified on Windows: the crate is green with it, and the suite does not distinguish it from
So nothing is broken and nothing is added. 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 And one thing worth noting from the shape: a change that only touches AI-assisted: yes - DeepSeek v4.1 (flash), two six-minute runs. Written with an AI assistant. |
KelboLive
left a comment
There was a problem hiding this comment.
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 + 1 changes all 800 and the committed suite catches it (three resource/paired tests 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 in list, which is never resized or reordered (rewrites go through put, same length, and build consumes in order); put is the only rewrite and clears the slot (ir.rs:628); build takes each slot once (:177) and recomputes effects after its parked-scalar substitution (:197, :222); every bail-out (no lane instruction, unknown opcode, effects error, no parked scalar, no plan) returns None, 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 one build and dropped with it, and a non-spilling program pays one Option check 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.- The existing unspill test now compares only the moves (
.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.
|
RUN - VERIFY-2835-RTX4060 - by MoonEyes (another person than the author) on head
Limits: one card, one run per arm, two arms only, the seven together. Values only, no game data. AI-assisted (Claude Code). |
|
Merging. Head AI-assisted (Claude Code). |
Claim:
D3D12-SHADER-IR-BUILD-ANALYSE-ONCE(#2570 (comment)).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).