d3d12: add opt-in branch and NaN simplifications for native compute shaders #3197
Closed
ubiquitarianism wants to merge 1 commit from
upstream-pr/3197 into main
pull from: upstream-pr/3197
merge into: ProjectLeonida:main
ProjectLeonida:main
ProjectLeonida:claude/loop-total
ProjectLeonida:claude/pops-collision-seed
ProjectLeonida:claude/dstorage-hold-page-reads
ProjectLeonida:claude/host-image-copy-switch
ProjectLeonida:feat/gdk-lifecycle-window-hook
ProjectLeonida:claude/d16s8-uav-nvidia-fallback
ProjectLeonida:feat/mfplat-offline-shim
ProjectLeonida:claude/gameinput-slow-reader
ProjectLeonida:fix/rt-null-barrier-clear
ProjectLeonida:claude/depth-resolve-sample-positions
ProjectLeonida:integration/palmetto-parity
ProjectLeonida:claude/valu-literal-sext
ProjectLeonida:claude/slot74-pool-handle
ProjectLeonida:claude/rgb9e5-uint-alias-view
ProjectLeonida:claude/fssm-root-layout-tables
ProjectLeonida:feat/gdk-speech-display-lifecycle
ProjectLeonida:asset-audio-skip-current
ProjectLeonida:qemmhd/old-9940-rectangle-quad-lists
ProjectLeonida:feat/ws2-offline-shim
ProjectLeonida:qemmhd/rt-d16-unorm-uav
ProjectLeonida:feat/xs-device-stops-7-9
ProjectLeonida:qemmhd/rt-depth-same-base-shapes
ProjectLeonida:qemmhd/rt-lazy-attachment-variant
ProjectLeonida:feat/acphal-xma2-decoder
ProjectLeonida:asset-audio-skip
ProjectLeonida:codex/coord-claim-check-20261124-7e48
ProjectLeonida:feat/xs-frame-pacing-presentx
ProjectLeonida:feat/xs-device-vm-options
ProjectLeonida:old-pr/9844
ProjectLeonida:old-pr/9978
ProjectLeonida:old-pr/9815
ProjectLeonida:old-pr/10057
ProjectLeonida:old-pr/9874
ProjectLeonida:old-pr/9965
ProjectLeonida:old-pr/9863
ProjectLeonida:old-pr/10068
ProjectLeonida:old-pr/10066
ProjectLeonida:old-pr/10067
ProjectLeonida:old-pr/10007
ProjectLeonida:old-pr/10061
ProjectLeonida:old-pr/10065
ProjectLeonida:old-pr/10059
ProjectLeonida:old-pr/10063
ProjectLeonida:old-pr/10055
ProjectLeonida:old-pr/10062
ProjectLeonida:old-pr/10042
ProjectLeonida:old-pr/10041
ProjectLeonida:old-pr/10049
ProjectLeonida:old-pr/10047
ProjectLeonida:old-pr/10046
ProjectLeonida:old-pr/10045
ProjectLeonida:old-pr/10056
ProjectLeonida:old-pr/10043
ProjectLeonida:old-pr/10036
ProjectLeonida:old-pr/10034
ProjectLeonida:old-pr/9984
ProjectLeonida:old-pr/10052
ProjectLeonida:old-pr/10038
ProjectLeonida:old-pr/10033
ProjectLeonida:old-pr/10028
ProjectLeonida:old-pr/10050
ProjectLeonida:old-pr/9891
ProjectLeonida:old-pr/9889
ProjectLeonida:old-pr/10051
ProjectLeonida:old-pr/10019
ProjectLeonida:old-pr/10027
ProjectLeonida:old-pr/10029
ProjectLeonida:old-pr/10031
ProjectLeonida:old-pr/10026
ProjectLeonida:old-pr/9941
ProjectLeonida:old-pr/10030
ProjectLeonida:old-pr/10040
ProjectLeonida:old-pr/9990
ProjectLeonida:old-pr/10021
ProjectLeonida:old-pr/9962
ProjectLeonida:old-pr/10022
ProjectLeonida:old-pr/10020
ProjectLeonida:old-pr/10015
ProjectLeonida:old-pr/10025
ProjectLeonida:old-pr/9886
ProjectLeonida:old-pr/10048
ProjectLeonida:old-pr/10014
ProjectLeonida:old-pr/10011
ProjectLeonida:old-pr/9861
ProjectLeonida:old-pr/10010
ProjectLeonida:old-pr/10008
ProjectLeonida:old-pr/9860
ProjectLeonida:old-pr/10006
ProjectLeonida:old-pr/9920
ProjectLeonida:old-pr/9995
ProjectLeonida:old-pr/10000
ProjectLeonida:old-pr/10016
ProjectLeonida:old-pr/10004
ProjectLeonida:old-pr/10023
ProjectLeonida:old-pr/9982
ProjectLeonida:old-pr/9981
ProjectLeonida:old-pr/9983
ProjectLeonida:old-pr/9970
ProjectLeonida:old-pr/9969
ProjectLeonida:old-pr/9968
ProjectLeonida:old-pr/9971
ProjectLeonida:old-pr/9972
ProjectLeonida:old-pr/9942
ProjectLeonida:old-pr/9963
ProjectLeonida:old-pr/9960
ProjectLeonida:old-pr/9964
ProjectLeonida:old-pr/9985
ProjectLeonida:old-pr/9973
ProjectLeonida:old-pr/9862
ProjectLeonida:old-pr/9953
ProjectLeonida:old-pr/10017
ProjectLeonida:old-pr/9952
ProjectLeonida:old-pr/9955
ProjectLeonida:old-pr/9946
ProjectLeonida:old-pr/9954
ProjectLeonida:old-pr/9938
ProjectLeonida:old-pr/9956
ProjectLeonida:old-pr/9856
ProjectLeonida:old-pr/9947
ProjectLeonida:old-pr/9924
ProjectLeonida:old-pr/9961
ProjectLeonida:old-pr/9927
ProjectLeonida:old-pr/9979
ProjectLeonida:old-pr/10032
ProjectLeonida:old-pr/9926
ProjectLeonida:old-pr/5237
ProjectLeonida:old-pr/9951
ProjectLeonida:old-pr/9931
ProjectLeonida:old-pr/9902
ProjectLeonida:old-pr/9921
ProjectLeonida:old-pr/9994
ProjectLeonida:old-pr/9775
ProjectLeonida:old-pr/9768
ProjectLeonida:old-pr/9905
ProjectLeonida:old-pr/9936
ProjectLeonida:old-pr/9901
ProjectLeonida:old-pr/9904
ProjectLeonida:old-pr/9906
ProjectLeonida:old-pr/9988
ProjectLeonida:old-pr/9908
ProjectLeonida:old-pr/9909
ProjectLeonida:old-pr/9911
ProjectLeonida:old-pr/9912
ProjectLeonida:old-pr/9913
ProjectLeonida:old-pr/9887
ProjectLeonida:old-pr/9916
ProjectLeonida:old-pr/9919
ProjectLeonida:old-pr/9925
ProjectLeonida:old-pr/9933
ProjectLeonida:old-pr/9935
ProjectLeonida:old-pr/9918
ProjectLeonida:old-pr/9879
ProjectLeonida:old-pr/9880
ProjectLeonida:old-pr/9881
ProjectLeonida:old-pr/9996
ProjectLeonida:old-pr/9876
ProjectLeonida:old-pr/9892
ProjectLeonida:old-pr/9899
ProjectLeonida:old-pr/9915
ProjectLeonida:old-pr/9914
ProjectLeonida:old-pr/9872
ProjectLeonida:old-pr/9869
ProjectLeonida:old-pr/9866
ProjectLeonida:old-pr/9819
ProjectLeonida:old-pr/10012
ProjectLeonida:old-pr/9857
ProjectLeonida:old-pr/9893
ProjectLeonida:old-pr/9897
ProjectLeonida:old-pr/9928
ProjectLeonida:old-pr/9868
ProjectLeonida:old-pr/9917
ProjectLeonida:old-pr/9940
ProjectLeonida:old-pr/9873
ProjectLeonida:old-pr/9816
ProjectLeonida:old-pr/10009
ProjectLeonida:old-pr/9900
ProjectLeonida:old-pr/9966
ProjectLeonida:old-pr/9859
ProjectLeonida:old-pr/9843
ProjectLeonida:old-pr/9991
ProjectLeonida:old-pr/10058
ProjectLeonida:old-pr/9883
ProjectLeonida:old-pr/9838
ProjectLeonida:old-pr/9835
ProjectLeonida:old-pr/9959
ProjectLeonida:old-pr/9895
ProjectLeonida:old-pr/9837
ProjectLeonida:old-pr/9858
ProjectLeonida:old-pr/9865
ProjectLeonida:old-pr/9864
ProjectLeonida:old-pr/9840
ProjectLeonida:old-pr/9820
ProjectLeonida:old-pr/4669
ProjectLeonida:old-pr/9848
ProjectLeonida:old-pr/9850
ProjectLeonida:old-pr/9810
ProjectLeonida:old-pr/9799
ProjectLeonida:old-pr/9853
ProjectLeonida:old-pr/9875
ProjectLeonida:old-pr/9831
ProjectLeonida:old-pr/9796
ProjectLeonida:old-pr/9801
ProjectLeonida:old-pr/9813
ProjectLeonida:old-pr/9794
ProjectLeonida:old-pr/7417
ProjectLeonida:old-pr/9781
ProjectLeonida:old-pr/9806
ProjectLeonida:old-pr/9958
ProjectLeonida:old-pr/9809
ProjectLeonida:old-pr/9791
ProjectLeonida:old-pr/9792
ProjectLeonida:old-pr/10053
ProjectLeonida:old-pr/9784
ProjectLeonida:old-pr/9789
ProjectLeonida:old-pr/9849
ProjectLeonida:old-pr/9846
ProjectLeonida:old-pr/9773
ProjectLeonida:old-pr/9785
ProjectLeonida:old-pr/9803
ProjectLeonida:old-pr/9826
ProjectLeonida:old-pr/9839
ProjectLeonida:old-pr/9922
ProjectLeonida:old-pr/9948
ProjectLeonida:old-pr/7189
ProjectLeonida:old-pr/9957
ProjectLeonida:old-pr/9823
ProjectLeonida:old-pr/9807
ProjectLeonida:old-pr/9851
ProjectLeonida:old-pr/9774
ProjectLeonida:old-pr/9830
ProjectLeonida:old-pr/9836
ProjectLeonida:old-pr/9822
ProjectLeonida:old-pr/9783
ProjectLeonida:old-pr/9833
ProjectLeonida:old-pr/9890
ProjectLeonida:old-pr/9770
ProjectLeonida:old-pr/9769
ProjectLeonida:old-pr/9772
ProjectLeonida:old-pr/9787
ProjectLeonida:old-pr/9852
ProjectLeonida:old-pr/9834
ProjectLeonida:old-pr/9845
ProjectLeonida:old-pr/9871
ProjectLeonida:old-pr/9771
ProjectLeonida:old-pr/9776
ProjectLeonida:old-pr/10005
ProjectLeonida:old-pr/9949
ProjectLeonida:old-pr/9923
ProjectLeonida:old-pr/9805
ProjectLeonida:old-pr/9829
ProjectLeonida:old-pr/9790
ProjectLeonida:old-pr/9827
ProjectLeonida:old-pr/9929
ProjectLeonida:old-pr/9855
ProjectLeonida:old-pr/9934
ProjectLeonida:old-pr/9907
ProjectLeonida:old-pr/9910
ProjectLeonida:old-pr/9779
ProjectLeonida:old-pr/9780
ProjectLeonida:old-pr/9885
ProjectLeonida:old-pr/9882
ProjectLeonida:old-pr/9877
ProjectLeonida:old-pr/9998
ProjectLeonida:old-pr/4251
ProjectLeonida:old-pr/9987
ProjectLeonida:old-pr/9989
ProjectLeonida:old-pr/9950
ProjectLeonida:old-pr/9777
ProjectLeonida:old-pr/10044
ProjectLeonida:old-pr/9884
ProjectLeonida:old-pr/2906
ProjectLeonida:old-pr/5076
ProjectLeonida:old-pr/9937
ProjectLeonida:old-pr/9986
ProjectLeonida:old-pr/3014
ProjectLeonida:old-pr/9943
ProjectLeonida:old-pr/9939
ProjectLeonida:old-pr/4682
ProjectLeonida:old-pr/4765
No reviewers
Labels
Clear labels
No items
No labels
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.
Reference
ProjectLeonida/mandy!3197
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from ubiquitarianism/leonida. Originally posted by ubiquitarianism on 2026-12-02T18:21:31Z.
Claimed 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.Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T19:38:32Z.
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).
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-02T20:10:06Z.
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).
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T21:17:06Z.
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.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T22:00:38Z.
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).
Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-03T10:22:41Z.
#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.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-03T18:03:10Z.
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