D3D12-SHADER-LOWER-LOAD-USES: index what uses each descriptor load instead of scanning every descriptor #2745
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2745"
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-11-30T14:22:55Z.
Claim: D3D12-SHADER-LOWER-LOAD-USES (comment).
AI-assisted: Claude Sonnet 5.5 (Cursor agent). No game files are in this pull request: the numbers are counts and times from running the translator on the author's own copy of the archive, and the tool that hashed the output was a local patch that is not part of it.
Depends on: none (independent of #2726; the two touch different files).
What
Lower::descriptor_datahandles a scalar load of a descriptor that the code also reads as numbers (sizes from descriptor bits). To tell the view's kind it asks what uses the load as a descriptor. It answered by walking every resource descriptor of the program and callingSource::leaves()on each (aVecbuilt and dropped per descriptor), and again, for each other load of the same address (twin), once more per candidate.descriptor_dataandunused_descriptor_kindalso walked every descriptor, building leaf vectors, to see whether the load is a sampler's.Now:
Lower::load_uses(load)answers from a map built on its first call (OnceCell, likenumbersandreadersnext to it): per load, the resource descriptors that take it as a leaf of their source, in the order ofResources::descriptors, once per descriptor, with its first leaf that is the load. That is what the scan returned.Lower::is_sampler_load(load)answers from the set of loads a sampler's source is.Source::for_each_leafvisits the leaves in the orderleaveslists them, without the vector.Why
Built-in sampler (
LEONIDA_PROFILE,diagnostics) onleonida translate --jobs 1of the eleven pixel programs that take longest to lower (6,200 to 8,500 IR instructions, some 800 descriptors each, no retries): of the translating thread's 3,361 samples, 3,033 (90 %) are in the closure ofdescriptor_datathat scans the descriptors: 1,675 underSource::leavesand the rest in the allocator calls that build and drop its vectors;spill::build,structure::structureandShader::finishare about 1 % each. Those programs took 0.74 to 0.88 s each inLower::run(timers around each stage in a scratch build), where the median of the 207 pixel programs of 7,000 to 9,000 instructions is 47 ms. With a cold shader cache a program that slow delays the pipeline creation of the first draw that needs it (LEONIDA_PIPELINE_WAIT_MSbounds the wait).Result
Same machine (Ryzen 7 7800X3D, 16 threads), whole archive
leonida translate <shaders.rpf>(LEONIDA_HOST_RDNA=1, 26,084 programs, 40.6 M IR instructions),--release, old and new builds of the same source plus a local patch that appendsblake3(dxil)of each emitted program to a file, alternating:docs/README-fxceless.mdshows), old--features diagnostics,mimalloc(the game's build), old--features diagnostics,mimalloc, newThe eleven pixel programs alone (
LEONIDA_TRANSLATE_ONLY, mimalloc): 7.5 / 7.3 CPU-seconds, 0.9 / 0.8 s wall -> 1.4 / 1.2 CPU-seconds, 0.3 / 0.3 s wall. Nine of the largest compute programs (12,000 to 85,000 IR instructions) are unchanged (9.9 / 9.6 -> 9.9 / 9.8 CPU-seconds together): they do not spend their time here.Output unchanged: the DXIL of all 25,689 emitted programs (15,799 distinct; the rest are duplicate containers) hashes the same in all 14 runs I made of the two builds (old: 3 on the system heap and 5 under mimalloc; new: 3 and 3), compared as multisets of (hash, length), because the label of a duplicate container is whichever thread gets there first and differs between runs of the same build. The eleven pixel programs and the nine compute programs hash the same too. (After the last of those runs only comments of
lower.rschanged.)Tests
the_index_of_load_uses_answers_as_the_scan_did: keeps the two scans as they were and compares them withload_usesandis_sampler_loadfor every instruction site of four ofresource::tests' waterfall programs (it asserts that some loads have uses and some are samplers'), and for made-up descriptors of every kind of source: a load that two leaves of one descriptor name (the first leaf is the use), one that two descriptors name (in the descriptors' order), a sampler's load that is also a resource's (not a use), andFetched/Constant/LanePhileaves that are no load's dwords. It also states the expected answers outright. Controlled: with the one-per-descriptor check left out it fails (left: [((1, 0), 0), ((1, 1), 2), ((1, 1), 4)],right: [((1, 0), 0), ((1, 1), 2)]).each_leaf_of_a_source_is_those_leaves_lists_in_order:for_each_leafagainstleaveson a source nesting phi, select, lanes and lane phi (with edges no lane takes and a join of no edges), by pointer, and on a plain source.cargo test -p leonida-shader --release: 386 passed, 1 failed, 4 ignored. The one failure,emit::valu_tests::rdna_forms_give_what_the_spelled_out_ones_give(mad_legacy: written alike), fails the same onmainwithout this change (run with this change stashed); it is what #2624 fixes.cargo clippy -p leonida-shader --release --all-targets: 3 warnings in the library and 7 in its tests, none in a line this change touches (lower.rs:1697and:2516,opt.rs,twin_bias_tests.rs,water_tests.rs).python -I scripts/check_no_game_data.pyon both files: clean.leonida translatewithout--validateor--pipelines), so no GPU or driver to name.Not covered: the effect on a title's frame time (it is the translation, not the frame), and the remaining translator time, which is spread over
Bools::ite,spill::buildand lowering of the compute programs (about 1 s of CPU each for the largest).Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T14:27:36Z.
Verified by OreoFR on macOS 27.2.1, Apple M5, Rust (rustup, Homebrew),
mainb17b22d33, head88d0dbf9c.cargo test -p leonida-shader, debug and--release, same counts both ways:main: 228 passed, 0 failed, 2 ignored.main+ this PR (merged): 230 passed, 0 failed, 2 ignored. The 2 extra tests are the newthe_index_of_load_uses_answers_as_the_scan_didandeach_leaf_of_a_source_is_those_leaves_lists_in_order.maintoo. The description reports a mutation control (the one-per-descriptor check left out → the test fails): ASSUMED, not reproduced here.valu_tests,pack_tests,paired_tests,probe_tests,size_tests,twin_bias_testsand others are#[cfg(all(test, windows))](src/emit/mod.rs105-119), so they do not build on macOS. That includes the knownrdna_forms_give_what_the_spelled_out_ones_givefailure (#2624). Not covered here: those Windows-only tests, the DXIL output-identity check and the timing table (they need the archive and Windows).main(#2566 is already merged).AI-assisted: Claude Code
Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-11-30T15:11:25Z.
Native Windows check of
88d0dbf9con currentmain232f9e603(no conflict,03a921278). Windows 11, MSVC x64, Rust 1.98.1,cargo test -p leonida-shader --libon a hardware GPU (not WARP), so the DXIL validation and the GPU dispatch tests run too.main+ this PR, the whole crate: 387 passed, 0 failed, 4 ignored.mainlists 389 tests (385 run + 4 ignored); the merge lists 391, so the two new tests are the only difference.load_usesandis_sampler_load, which this PR adds, so they don't build againstmain(E0599). It matches OreoFR's macOS counts (+2).AI-assisted: yes
Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-30T15:11:59Z.
Independent native Windows DXIL check for
88d0dbf9con232f9e603(merge treea4b9e05c1). Rust 1.98.1 MSVC release, Windows 11, LLVM DXIL validator from Windows SDK 26100.I lowered five stock synthetic descriptor waterfall programs on both trees. They cover fetched descriptors in Wave32 and Wave64 and picked, joined, and mixed descriptors in Wave32. Each lowered twice to identical bytes on its own tree. Across trees, all five raw DXIL containers matched byte for byte (2,224–2,456 bytes each). Both sets passed DXIL validation. Each case retained one non-uniform handle.
Both published regressions passed on the merged tree: the load-use index matched the scan, and the leaf visitor matched the listed traversal order. This was a CPU translation and validation check with synthetic inputs. AI-assisted with OpenAI Codex (GPT-6.2 Sol).
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T15:16:21Z.
Independent Linux DXIL check for descriptor size queries
Rust 1.98.1 on CachyOS. I tested
88d0dbf9cmerged ontomain5399c667e(tree4c3bf6e6). I added three hand-written compute fixtures that exercise the size-query path. They complement the native Windows waterfall check.All three produced byte-identical DXIL containers and identical host metadata on both trees. The bitcode symbol tables contain
dx.op.getDimensionsin each case. A size-only buffer shape returned the same unsupported error on both trees. The five stock waterfall controls also matched byte for byte.The Linux library suite passed 229 tests on
mainand 231 with this PR, including the local fixture harness once on each side. Both runs had two ignored tests and zero failures. A second agent independently compared the artifacts and checked the bitcode symbols. CPU-only translation and inspection using synthetic inputs. AI-assisted with OpenAI Codex.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T20:11:37Z.
RUN · VERIFY-2745-RTX4060 · by MoonEyes (another person than the author) on head
88d0dbf9c, with #2745 (88d0dbf9c), #2773 (6bbaeed11), #2726 (986771506) and #2780 (6c4474cfd) merged intomain51dbc5b58. Windows 11 Pro 26300, RTX 4060 8 GB,-SeriesS -FrameGen 2, diag build.cargo test -p leonida-shader --locked: 400 passed;-p leonida-gpu: 580 passed; 0 failed.main8f41d7d01with two other pull requests: n=1 on each side and not the same tree, so no speed-up is claimed. The four pull requests were in one build.AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T20:12:10Z.
Merging. Head
88d0dbf9cmerges cleanly withmain0f86bd594and does not force a rebase of #2566. Two runs in the game (RTX 4060, about 500 s steady each, no device loss) with #2745, #2773, #2726 and #2780 together on this head; cargo test green; checked by other people. The shaders are translated again at the first start. Merged by MoonEyes.AI-assisted (Claude Code).