d3d12: add opt-in branch and NaN simplifications for native compute shaders #3197
Closed
github-bot
wants to merge 1 commit from
github-bot/gh-3197 into main
AGit
pull from: github-bot/gh-3197
merge into: github:main
github:main
github:perf/darner-title-priority-ceiling
github:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
github:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
github:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
github:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
github:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
github:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
github:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
github:fix/runtime-test-conservative-fixtures
github:ci/shard-semantic-linux
github:docs/fg-limit-fps-switch
github:fix/runtime-test-fixture-paths
github:fix/runtime-test-fixture-readers
github:fix/read-file-hard-link
github:fix/book-slot-heap-never-read
github:fix/depth-resolve-spv-path
github:fix/indirect-unused-batched
github:gh-pr/3358/base
github:fix/xmem-refusal-diagnostics
github:gh-pr/3357/base
github:ci/shorten-ci-time
github:fix/alias-later-queued-submissions
github:claude/gallant-sagan-aamatr
github:gh-pr/3342/base
github:gh-pr/3341/base
github:d3d12/agility-sdk-621
github:gh-pr/3293/base
github:gh-pr/3319/base
github:gh-pr/3318/base
github:gh-pr/3315/base
github:gh-pr/3313/base
github:gh-pr/3314/base
github:claude/fervent-curie-m19lnr
github:gh-pr/3216/base
github:gh-pr/3272/base
github:gh-pr/3276/base
github:gh-pr/3279/base
github:gh-pr/3257/base
github:gh-pr/3258/base
github:gh-pr/3271/base
github:codex/skip-no-hit-ray-passes
github:gh-pr/3230/base
github:gh-pr/3266/base
github:gh-pr/3247/base
github:gh-pr/3246/base
github:gh-pr/3244/base
github:claude/sharp-sagan-1jqnp3
github:t3/preserve-fsr-sdk-restart-path
github:t3/propagate-host-failure-hresult
github:t3/launcher-custom-parameters
github:t3/series-x-2160-startup
github:codex/d3d12-uncapped-simulation
github:ci/less-to-run
github:perf/native-compute-shader-forms
github:claude/blissful-franklin-ukp7ag
github:codex/full-precompile-default
github:gh-pr/3166/base
github:gh-pr/3148/base
github:gh-pr/3138/base
github:gh-pr/3106/base
github:gh-pr/3057/base
github:gh-pr/2756/base
github:gh-pr/2812/base
github:gh-pr/3032/base
github:gh-pr/2992/base
github:notes/card-time-and-plant-flicker
github:gh-pr/2986/base
github:gh-pr/3000/base
github:gh-pr/2966/base
github:gh-pr/2924/base
github:gh-pr/726/base
github:gh-pr/2761/base
github:gh-pr/2663/base
github:gh-pr/2861/base
github:gh-pr/2862/base
github:gh-pr/2820/base
github:gh-pr/2811/base
github:gh-pr/2803/base
github:rt-call-trace
github:gh-pr/2802/base
github:gh-pr/2766/base
github:perf/ahead-split
github:gh-pr/2589/base
github:gh-pr/2699/base
github:gh-pr/2696/base
github:docs/readme-runtime-proposal
github:gh-pr/1346/base
github:codex/coord-claim-check-20261124-7e48
No reviewers
Labels
Clear labels
accessibility
Barrier affecting people with disabilities
area: ci
.github/ workflows and settings
area: d3d12
The D3D12 runtime in d3d12/ (Rust: leonida.exe and its crates)
area: docs
Documentation
area: launcher
The launcher (launcher/)
area: runtime (legacy)
The earlier Vulkan runtime in runtime/
area: shader translator
The shader translator (leonida-shader, tools/rdna2spirv) and its tests
area: tools
tools/ and scripts/
area: viewer
The map viewer (viewer/)
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
duplicate
This issue or pull request already exists
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
invalid
This doesn't seem right
missing claim
Needs a claim in #14
needs in-game run
Changes the code a frame runs through: needs the 300 s in-game gate (docs/game_gate.md)
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
wontfix
This will not be worked on
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!3197
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3197"
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?
@ubiquitarianism on GitHub · 2026-12-02 18:21 UTC · original
ProjectLeonida:perf/native-compute-shader-forms→main· +592 −40 · 15 files · 1 commits · closed without mergingClaimed in the coordination issue as: D3D12-NATIVE-COMPUTE-EMPTY-FORWARD-BLOCKS, D3D12-SHADER-RDNA-KNOWN-NON-NAN
What and why
Add two opt-in translation passes for named native D3D12 compute shaders on AMD RDNA adapters that support wave64. The first redirects branches past empty forward blocks with one predecessor and updates the corresponding phi input. The second folds NaN classifications when the input operation guarantees a numeric result. Both shader lists default to empty. The existing
FormsForAPI, wave options and launcher defaults are preserved. Forward-block claim · NaN claimIndividual shader cache keys distinguish the requested forms. The bulk pipeline warm-up ledger also accounts for the enabled lists. Upgrading follows the normal one-time shader warm-up associated with a changed translator source fingerprint.
On the original experimental build, four matched Boat drives in off/on/on/off order averaged 0.64 more rendered FPS with the forward-block pass on three programs. Isolated GPU timings for those dispatches fell by 1.09 ms/frame while driving. The NaN pass showed no repeatable gameplay gain. The rebased build was verified offscreen.
Tested
leonidaexecutable withdiagnostics. Compared the ordinary translation of 29,195 local shader inputs against unmodifiedmainat45dc41f95. All 28,990 translations matched in DXIL and host binding metadata digests. The same 205 inputs were rejected with the same errors.GPUs tested: AMD Radeon RX 6800, driver 32.0.21030.2001, Windows 11 Pro build 26200. Microsoft WARP was used for synthetic output equivalence. Additional physical AMD and NVIDIA adapters were unavailable.
AI-assisted: Yes, GPT-6.2 Astra for the implementation, port and independent code reviews.
Checklist
mainand checked for merge conflicts.docs/design.md.@Kal0s-design on GitHub · 2026-12-02 19:38 UTC · original
Ran natively on Windows 11, head
1616b35e7merged into currentmain(f1a559851, clean merge).Since then
mainmoved tob41763227(#2888, docs only) and the PR now conflicts with it ind3d12/docs/findings.md. Both add a section at the end of the file, so it needs a rebase. No code changed on main in between.Switches.
LEONIDA_KNOWN_NON_NAN_FORandLEONIDA_EMPTY_FORWARD_FORare both empty by default, and both only take effect on an RDNA adapter with wave64 (native_rdna_wave64()). On an NVIDIA card they do nothing at runtime, so my GPU runs reach the passes only through the crate tests, which set the forms directly. The fold can't be switched on throughLEONIDA_SHADER_OPTeither.shader_opt()is masked withMODULEbefore bit 512 is added, andShader::finishis the only non-test caller ofoptimise.Switches off give the same bytes as main. I ran the same throwaway hash test in both trees.
random_programseeds 1..600 × {no passes, DEFAULT, ALL},Module::write(), 3.19 MB7e9ba333…7e9ba333…translate(), all 192 translated (8 producers × 4 compares × RDNA bits on/off × NaN-exact unset/on/off)d8b88b23…d8b88b23…These are generated inputs, not real shaders. Your 29k-shader comparison covers the real ones.
leonida-shader suite
LEONIDA_WARP=1)The difference is the PR's 6 new tests plus its ignored timing test. Under WARP the same 8 tests fail on both sides, so they aren't from this PR. 7 of them fail creating the pipeline ("The parameter is incorrect") and
a_lane_mask_joined_with_a_number_is_read_as_the_number_it_isfails its lane-mask assert.cargo test -p leonida-gpu shader_cachepasses 7/7 on the merge, the new selector and warm-key test included. Clippy--all-targetson leonida-shader and leonida-gpu gives the same 6 warnings on main and on the merge, all already invalu_tests.rs.The new tests don't compile on main since the API is new. To get a real red I turned off the fold and the bypass inside the merge.
known_non_nan_changes_only_proven_classificationsfailed, and so did 3 of the 4 forward tests. The output-word test and the backward-edge test stayed green, which is right because they only assert that nothing changes.NaN fold, CPU differential. I taught the opt.rs test interpreter
dx.op.unary.f32(Saturate, FAbs),dx.op.binary.f32(FMin, FMax and one other op) and SiToFp/UiToFp. FMin/FMax there return the non-NaN operand and Saturate(NaN) is 0, which is the D3D rule the PR relies on. So this checks that the pattern match sticks to that rule. It says nothing about what devices do. The random programs mix those producers with float phis, selects, NaN/inf/±0/denormal constants and both operand orders. They emit the exact(bits & 0x7fffffff) > 0x7f800000check (mask on either side) and near misses (IUGE, SGT, threshold0x7f7fffff, mask0xffffffff), fed mostly with special input words.KNOWN_NON_NAN,KNOWN_NON_NAN|DEAD,ALL|KNOWN_NON_NAN)0xffffffffacceptedSame on the GPU. I added a few throwaway producers to
known_non_nan_preserves_every_output_word. They cover min/max with the constant as the first operand,max(|x|,|x|)with clamp andmax(|x|,|y|). I also added 4 more input pairs (sNaN/sNaN, negative sNaN with a denormal, a negative denormal with0x7fffffff, FLT_MAX with0xffffffff). Every proven producer folded andmax(|x|,|y|)was left alone. Folded and unfolded output words matched on the card and on WARP, and the run printed both device lines, so neither one was skipped.Empty forward blocks. For
random_programseeds 1..1500 × {no passes, DEFAULT, ALL}, I applied the edgesforward_blocksreturns to a copy (branch targets throughto, phi predecessors throughfrom) and ran both in the interpreter. 27000 runs and 29165 bypassed blocks gave 0 differences. The harness catches dropping thefrom[b] = from[p]update and dropping the single-predecessor check (interpreter panics), and droppingnext[p].contains(&h)(542 mismatches). It does not catch dropping the live-phi check, because the generator never makes an empty single-predecessor block with a live phi. Only yourempty_forward_keeps_distinct_phi_inputs_and_live_phiscovers that. The harness copies the writer's layout steps (reverse postorder, latch folding), so it testsforward_blocksand not the byteswrite_with_forward_blocksemits.This PR doesn't touch
x != x, ordered vs unordered float compares, select-on-compare folding, or non-NaN facts through loads or phis.known_non_nanreturns false for phis, selects, loads and bitcasts, so nothing there could break.Conflicts with other open PRs (
git merge-treeagainst this head)pub use lower::{…}line inemit/mod.rs(both add a name), plus theswitches.mdcount linewrite()inbitcode.rs. It moves the layout and latch folding into helpers, so the bypass has to be wired into the new code, not just merged textuallyswitches.mdcount lineNot checked: RDNA hardware (none here, so the runtime gate never turned on), real game shaders, the cache warm-up ledger in a live run, DXIL validator runs on bypassed output, the ignored timing test, release builds, the rest of leonida-gpu and the other crates, the Python semantic suite beyond
test_minmax_f32_payload.py(both tests pass on the merge underunittest, and I didn't check whether the new one is red on main).GPUs tested: one NVIDIA desktop card + WARP
AI-assisted: yes (Claude Code).
@lixonik on GitHub · 2026-12-02 20:10 UTC · original
Verified PR #3197 (
1616b35e7) merged cleanly ontomain(f1a559851) on native Windows 10 x64 (Rust 1.98.1):python -I scripts/check_no_game_data.pyPASS.python -I tools/d3d12_switches.py --check d3d12/docs/switches.mdPASS.LEONIDA_DXIL=none):cargo test -p leonida-shader --lib --locked emit::bitcode::-- 31 passed, 0 failed, 1 ignored (3.02 s).mainhead pastf1a559851, so a rebase/merge onto latestmainwill be needed before merge.Verdict: PASS on bitcode unit tests (needs rebase onto latest
main;dxil.dllskipped on this Win10 19041 SDK host).AI-assisted: yes (Antigravity).
@fiestorra on GitHub · 2026-12-02 21:17 UTC · original
VERIFY-3197 — Windows nativo: el código pasa; el PR está en conflicto con
mainy su test semántico no ejercita lo que cambia1616b35e745dc41f95mergeStateStatus: DIRTY,mergeable: CONFLICTINGThe PR does not merge as it stands:
d3d12/docs/findings.mdconflicts becausemainadded 19 lines there since the merge base (git merge-treelists the three stages). It needs a rebase — the code files merge cleanly, only the doc collides.Ran (worktree at
main, the PR merged with the doc conflict resolved to the PR's side, so the code is what it claims):The one
leonida-gpufailure is this machine's, unchanged all day (views_are_made_beside_the_heap_and_copied_in, the iGPU artefact ofD3D12CreateDevice(None, ..)that #2995 addresses).What the new semantic test actually exercises — worth knowing
tests/semantic/test_minmax_f32_payload.pycallsrdna2spirv.translate(...)— the Python translator, notleonida-shader. This PR touches no Python translator file: it adds the fixture and the test, which pin the Python implementation's NaN-payload behaviour rather than exercise the Rust change. That is a useful pin (the two implementations should agree), but it is not a test of this diff, and I would say so in the body rather than let it read as one.The Rust side is covered by the crate's own tests (
forward_tests.rs,known_non_nan_tests.rs, 434 passing), which is where the change lives.The red side I could not construct, said plainly
emit/bitcode/opt.rsalone does not compile — the new code referencesKNOWN_NON_NANfrom that file, so the feature is spread across the files a revert would remove.KNOWN_NON_NAN = 0) changed nothing in the semantic test — which is the finding above: that test does not run the Rust path. So I have no working red side for this PR on this machine, only the suite passing.What I could not test
known_non_nan_testsare compile-time IR tests.Written with an AI assistant.
@MoonEyes on GitHub · 2026-12-02 22:00 UTC · original
This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).
Could you, or anyone with a working setup, post a run report on the current head merged onto current
main:mainSHA it was merged onto;mainalone for comparison, if you can.Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.
AI-assisted (Claude Code).
@fiestorra on GitHub · 2026-12-03 10:22 UTC · original
#3197rebasada y empujada:pr-3197-rebased=b5113ac83— las dos secciones defindings.mderan distintas y los dos crates pasanEl conflicto era un bloque, y las dos mitades son contenido distinto:
Y los números del rebase, con los dos crates que toca:
Y el shader sube a
435desde los429demain— seis tests nuevos, y el árbol está a 0 commits demain, así que la comparación es entre lo mismo.Lo que no verifiqué: las dos traducciones nativas de cómputo sobre una RX 6800 (eso es el hallazgo del documento, y aquí no hay AMD RDNA). Lo que sí: que su documentación se une sin perder ninguna de las dos entradas y que los dos crates que toca compilan y pasan sus tests.
@MoonEyes on GitHub · 2026-12-03 18:03 UTC · original
Thanks for the work on this. This pull request has a merge conflict with the current
mainand has had no new commit, comment or review for more than 5 hours, so I am closing it to keep the list of open pull requests manageable. This is not a judgement of the change. Whenever you like, merge the latestmaininto your branch, resolve the conflict, and reopen it (or open a new pull request that links this one). Please re-run the relevant tests on the new head; a reviewer will look at it when time allows, with no guarantee of timing or outcome.Generated by Claude Code
Pull request closed