Repository navigation
D3D12-SHADER-OPT-CROSS-BLOCK-LOADS: propagate LOADS across write-free dominating blocks - #2684
Conversation
|
Independent CachyOS check of The positive diamond fixture currently uses both branch-local results in READ IN CODE The new MEASURED Three interleaved release runs per arm, pinned to one CPU. These are the per-run medians in ms per synthetic module for
The second fixture retains 192 loads on |
|
Thanks for the careful review @merzleckeier! Restored the |
|
Thanks for updating both points. I retested AI-assisted with OpenAI Codex. |
…D3D12-SHADER-OPT-CROSS-BLOCK-LOADS)
Addresses the d3d12/docs/findings.md item ("reads of read-only views
repeated in blocks that follow one another").
Previously, merge() cleared the LOADS map at every basic-block boundary,
preventing reuse of Effect::Reads across sequential blocks,
single-predecessor branch targets, and write-free diamonds or loops.
Extend merge() to maintain dominator-scoped dom_reads for Effect::Reads
while keeping Effect::Lanes (wave/quad operations) strictly block-local:
- Single-predecessor blocks inherit dom_reads directly from their
immediate dominator (O(1)).
- Multi-predecessor blocks (merges and loop headers) run a reverse walk
back to the immediate dominator and preserve dom_reads only when no
block on any path (including loop back-edges) executes Effect::Writes.
- Any Effect::Writes instruction clears dom_reads for the rest of its
block and dominator subtree, restoring the pre-block map on Leave so
siblings remain unaffected.
Verified with 3 new Red -> Green unit tests (write-free diamond,
branch-write invalidation + sibling reuse, loop back-edge write vs
write-free loop), the 400-seed randomized differential interpreter suite,
and 370/370 leonida-shader --lib tests on native Windows 11 + AMD Radeon
RX 7900 XTX.
AI-assisted: Antigravity (Gemini 4 Neon)
… SSA-valid AI-assisted: Antigravity (Gemini 4 Neon)
2edb157 to
bb68c6e
Compare
|
Native Windows check of
Not covered: the effect on real shaders' DXIL and frame time. AI-assisted: yes |
Both optimizer merge resolutions testedMEASURED. Follow-up to the pairwise merge check. I tested the exact PR heads
Every run had zero failures and two ignored tests. For #2687, I kept all three cross-block load tests and the heap-handle test as complete functions. For #2750, I used I captured optimizer bitcode and DXIL containers from the synthetic suite, keyed by test and emission ordinal. Adding #2750 preserved 4,923 bitcode captures and 100 DXIL containers byte for byte without #2687, and 4,924 bitcode captures and 100 DXIL containers with #2687. Each comparison agreed across all six runs. Scope: local merge resolutions and CPU-side synthetic translation. AI-assisted: Codex (GPT-6.2 Sol). |
|
RUN · VERIFY-2684-RTX4060 · by MoonEyes (another person than the author) on head
AI-assisted (Claude Code). |
|
Merging. Head AI-assisted (Claude Code). |
… 1D wave-base (ProjectLeonida#2685), NaN-exact, by_due texture queue, unlocked pool growth (ProjectLeonida#2693), pipeline wait queue (ProjectLeonida#2622)
Claimed in #2570 as
D3D12-SHADER-OPT-CROSS-BLOCK-LOADS(#issuecomment-7266940327).What and why
Addresses the open shader-performance item in
d3d12/docs/findings.md:In
d3d12/crates/leonida-shader/src/emit/bitcode/opt.rs,merge()previously calledread.clear()at the entry of every basic block, soLOADScould never reuse anEffect::Readsload across sequential blocks, single-predecessor branch targets, or write-free diamonds/loops.This change splits
Effect::Reads(memory loads) fromEffect::Lanes(wave/quad ops, which remain strictly block-local because active lanes can change across branches) and propagatesEffect::Readsalong the dominator tree:preds[b] == [idom]): inheritdom_readsdirectly fromidomin O(1).idomwhether any block on any path (including loop back-edges) executesEffect::Writes; preservedom_readsonly if no write can occur.Effect::Writes: cleardom_readsfor the remainder of the block and its dominator subtree, restoring the pre-block map onStep::Leaveso sibling branches are unaffected.Verification (Red -> Green)
Hardware / OS: native Windows 11 Pro (
10.0.26200) + AMD Radeon RX 7900 XTX (gfx1100, driver32.0.32029.2010), pinned toolchainrustc 1.98.1.cross_block_reads_reuse_dominating_load_without_writes,cross_block_reads_invalidated_when_branch_writes,cross_block_reads_in_loop_respect_backedge_writes) failed becauseLOADScleared reads at every block boundary.main40e7fe69d):cargo test -p leonida-shader --lib bitcode::opt::tests—17 passed; 0 failed(3.20s), including all 3 new tests and the 400-seed × 6-input × 12-pass randomized differential interpreter fuzzer (every_pass_leaves_what_random_programs_store).cargo test -p leonida-shader --lib -- --skip rdna_forms_give_what_the_spelled_out_ones_give --test-threads=4—370 passed; 0 failed; 4 ignored(81.00s, live GPU execution + DXIL validation on RX 7900 XTX; the 1 skipped test is the pre-existingmainfailure fixed in D3D12-SHADER-RDNA-LEGACY-MAD: restore RDNA LEGACY lowering path in legacy_mad #2624).python -I scripts/check_no_game_data.py d3d12/crates/leonida-shader/src/emit/bitcode/opt.rs— PASS.AI-assisted: Antigravity (Gemini 4 Neon)