d3d12: add opt-in branch and NaN simplifications for native compute shaders #3197
Closed
leonida/mandy
ubiquitarianism wants to merge 1 commit from
perf/native-compute-shader-forms into main
pull from: perf/native-compute-shader-forms
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
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
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!3197
Loading…
Reference in a new issue
No description provided.
Delete branch "perf/native-compute-shader-forms"
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?
Pull request closed
Please reopen this pull request to perform a merge.
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.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).
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).
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.
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).
#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.
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