Repository navigation
D3D12-SHADER-OPT-HOIST-HEAP-HANDLES: hoist uniform createHandleFromHeap out of branches and loops - #2687
Conversation
|
Checked by OreoFR on macOS 27.2.1, Apple M5, Rust 1.98.1,
AI-assisted: Claude Code |
…d loops (D3D12-SHADER-OPT-HOIST-HEAP-HANDLES)
Addresses the d3d12/docs/findings.md item ("descriptors made again in
every branch of a program (createHandleFromHeap of an index that is a
root constant plus an offset, behind a branch on a load)").
Adds Module::hoist_handles() under REUSE: marks uniform (nonuniform =
false) dx.op.createHandleFromHeap calls, their wrapping annotateHandle
calls, and their pure, non-trapping index/clamp operands
(cbufferLoadLegacy, integer non-div/rem arithmetic, casts, extracts,
dx.op.binary.i32 clamp), and hoists each in RPO order to the deepest
dominating block defining its operands. REUSE then collapses duplicate
handles across sibling branches and loops into a single descriptor
handle.
Nonuniform handles and handles whose index depends on branch-local
memory loads remain in their original blocks.
AI-assisted: Antigravity (Gemini 4 Neon)
502b9a9 to
0f8f57b
Compare
|
Independent Windows verification of
Not covered, as in OreoFR's check: the effect on the title's real shaders and frame time. AI-assisted: yes |
|
Independent checks for hoisting boundaries. I merged
The stock |
|
Independent check on Windows (not the author), at
Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Rust 1.98.1 pinned. The hoisting is covered by the crate's emit tests; I did not independently measure the performance change on a GPU. AI-assisted: yes (opencode). |
Co-authored-by: Cursor <cursoragent@cursor.com>
|
Merged main (the cross-block loads of #2684 added a test where this one adds its own, in AI-assisted: Claude Sonnet 5.5 |
There was a problem hiding this comment.
Verified hoist_handles in d3d12/crates/leonida-shader/src/emit/bitcode/opt.rs: gating hoisting on !matches!(op, Bin::UDiv | Bin::SDiv | Bin::URem) covers all potentially trapping binary ops in enum Bin (which has no SRem variant), phi and impure calls are excluded, and entry hoisting cleanly feeds the existing CSE pass. Unit tests and independent Windows/Linux runs (394/0) confirm DXIL validity and compile/runtime wins, with all CI checks green. Merging.
(AI-assisted review.)
|
Posted after the merge: the head tested below is the one that was merged. RUN (independent run on Windows, #2687 head 40a97ef, merged locally into main e56aff1 with Commands, in
Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40, Rust 1.98.1. |
Claimed in #2570 as
D3D12-SHADER-OPT-HOIST-HEAP-HANDLES(#issuecomment-7267137318).What and why
Addresses the open shader-performance item in
d3d12/docs/findings.md:Because
REUSEind3d12/crates/leonida-shader/src/emit/bitcode/opt.rsonly deduplicates along a parent -> child dominator path, identicalcreateHandleFromHeap+annotateHandlechains emitted in sibling branches (or inside loops) were never collapsed even when their index came purely from root constants (cbufferLoadLegacy) plus a constant offset.This change adds
Module::hoist_handles()underREUSE:nonuniform = false)dx.op.createHandleFromHeapcalls, their wrappingannotateHandlecalls, and their pure, non-trapping index/clamp operands (cbufferLoadLegacy, integer non-div/rem arithmetic, casts, extracts,dx.op.binary.i32clamps).entryfor root-constant + offset), preserving topological order and SSA dominance in a single linear pass.nonuniform = truehandles and handles depending on branch-local loads in their original blocks.merge()(REUSE) immediately collapses all hoisted duplicates into one handle.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.uniform_heap_handles_hoist_out_of_branches_and_deduplicatefailed because sibling branches kept separateannotateHandleinstructions (Inst(6) != Inst(11)).main40e7fe69d):cargo test -p leonida-shader --lib bitcode::opt::tests—15 passed; 0 failed(3.17s), including the new test and the 400-seed randomized differential interpreter fuzzer.cargo test -p leonida-shader --lib -- --skip rdna_forms_give_what_the_spelled_out_ones_give --test-threads=4—368 passed; 0 failed; 4 ignored(80.20s, live GPU execution + DXIL validation on RX 7900 XTX).python -I scripts/check_no_game_data.py d3d12/crates/leonida-shader/src/emit/bitcode/opt.rs— PASS.AI-assisted: Antigravity (Gemini 4 Neon)