d3d12: console lanes 32..63 of a wave64 VS/PS where the code proves them (D3D12-SHADER-UPPER-LANES) #2706
Closed
spzero12 wants to merge 2 commits from
upstream-pr/2706 into main
pull from: upstream-pr/2706
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!2706
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2706"
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 spzero12 on 2026-11-30T09:10:58Z.
Claimed in the coordination issue as:
D3D12-SHADER-UPPER-LANES(https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7270183812)Depends on: none
What and why
A 32-lane host runs a wave64 vertex or pixel program as waves of 32, so a
v_readlaneof a console lane >= 32 reads no host lane: today a constant lane is refused outside compute ("a cross-lane operation outside compute") and a computed one is lowered toWaveReadLaneAt(v, lane & 31).emit/upper_lanes.rsis the port planned ind3d12/docs/wave64-upper-lanes.md: a forward pass overcrate::irthat follows what lanes 32..63 hold, and thev_readlaneis lowered from that value instead of the read.wave::section_lanes) or av_writelaneproves a lane; a plain write to the VGPR clears what the pass knew.LEONIDA_UPPER_LANES_WHY=1says how many it resolved and left).LEONIDA_UPPER_LANES=0turns it off for an A/B; the shader cache keys on it (the build script lists everyLEONIDA_*the translator reads).What the pack shows, so nobody expects a picture change from it. Before writing it we assumed the compiler's lane-spill and post-section reads were unfixed. They are not:
ir::unspillalready rewrites a VGPR whose every use is thev_writelane/v_readlanepair with a constant lane into scalar moves, before any lowering.wave::sections'Section.readsalready lowers a same-blockv_readlaneafter a whole-wave section (the reduction's broadcast read included).Over all 26,503 containers of the pack (
D:\leonida-work2\shaders\dxbc,translate_cdxil --census) the pass lowers for 353 graphics programs and resolves 0 reads, 355 left. The programs looked at (!PS_FogComposite_57ae119e,_PS_PropFoliageForwardLit_18b3d403) leave a waterfall read at a computed lane (v_readlane sX, v, s2), which no constant stands in for. No translation changed, and the pack's 202 failures are the same as without the pass (195 containers without a program, 2 no wave32 lowering, 5 a descriptor read only as data).So this adds the exact rule for the cases the pack does not contain — a spill through a lane held in an SGPR, a VGPR with other writes, and a read in another block than its section — and it costs nothing where it proves nothing (a program with no such read is byte-identical with the switch off). A whole-wave reduction over all 64 lanes stays an approximation in VS/PS: those stages have no group-shared memory or barrier to exchange the halves (the separate, larger port in the doc).
Tested
cargo test -p leonida-shader upper_lanes: 9 passed (hand-written pixel programs, no game files): a spill through an SGPR lane drawn to a target, a lower-lane spill, a plain write clearing the knowledge, a lane built in an SGPR, a section's identity and a section's uniform value, a compute program untouched, and a program without such a read byte-identical to the switch off.cargo test -p leonida-shader --lib: 393 passed, 0 failed, 4 ignored (the run started before the ninth upper-lane test was added; that one passes separately, so 394 with it).cargo clippy -p leonida-shader --all-targets: no warning from the new files (the two warnings left are the pre-existing ones inlower.rsandbitcode/opt.rs).spirv-val: this is the d3d12 Rust translator, nottools/rdna2spirv.py; the emitted modules go throughdxil.dllin the tests where it is installed.GPUs tested: NVIDIA GeForce GTX 1070 8 GB, driver 582.78, Windows 11 (hardware and WARP).
AI-assisted: yes (Claude).
Checklist
mainand merges cleanly (branchshader-upper-lanes, one commit on1bb726b30).docs/design.mdcontract table is the Python translator's (tools/rdna2spirv.py); this rule is in the d3d12 Rust translator and is written up with how it was confirmed ind3d12/docs/wave64-upper-lanes.mdandd3d12/docs/findings.md.Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T09:24:25Z.
Independent check of
0bfcb3a1onmain1bb726b30. I found a false resolution inexec_after()inemit/upper_lanes.rs. Thes_and*shortcut preservesHi::Zerofor any destination of EXEC. An ordinarys_and_b64reads two explicit operands, so it can replace EXEC without reading the old mask.This hand-written wave64 pixel fixture reproduces it (assembled with
llvm-mc -arch=amdgcn -mcpu=gfx1030):The AND sets every EXEC bit, so the
v_mov_b32overwrites lane 40 with1.0.analyse()instead resolves the read toSome(Value(Value(4))), the old2.0SGPR value. As a control,s_and_b64 exec, exec, -1really does preserve an empty upper mask and should continue to resolve the spill. A locally tested conservative rule keptHi::Zerofor the explicit AND only if one source was current EXEC (for ANDN2, the first source), and kept the implicit 64-bit AND/ANDN2 SAVEEXEC forms. The overwrite case then returnedNoneand the control still resolved. This report's overwrite evidence is from IR analysis. The separate GPU probe for that case produced neither of the reference colors.Measured under Wine 11.22 / VKD3D-Proton 3.1.0: all nine stock upper-lane tests pass on RTX 4070 SUPER (NVIDIA 620.73.04) and Radeon 610M (RADV 26.3.1). A separate draw that requires a real hardware device read back
[2.0; 4]in all 64 pixels for the ordinary lane-40 spill on both. The conservative local comparison passed 12/12 on each GPU, including both IR cases and the live draw. Native Linuxleonida-shader --libpassed 228 on both trees, 2 ignored.AI-assisted: yes (OpenAI Codex).
Imported from ubiquitarianism/leonida. Originally posted by spzero12 on 2026-11-30T09:41:54Z.
Thanks, that is a real one and a good catch. Fixed in
70b273f6aon the branch.exec_after()now keepsHi::Zeroonly where the new EXEC isold EXEC & <anything>:saveexecforms and the ANDN2wrexecforms (the old mask is implicit);s_and_b64with EXEC as either source;s_andn2_b64with EXEC as the first source (S0 & ~S1only clears by S0; yours_andn2_b64 exec, -1, execcase is not preserved).Every other
s_and*, including yours_and_b64 exec, -1, -1, isHi::Anynow. A low-word-only write also leaves the upper word unchanged for every instruction, not justs_mov_b32.Regression tests use your fixture:
s_and_b64 exec, -1, -1leaves the read unresolved;s_and_b64 exec, exec, -1,s_andn2_b64 exec, exec, -1ands_and_saveexec_b64 s[8:9], -1still resolve the spill;s_andn2_b64 exec, -1, execdoes not.cargo test -p leonida-shader upper_lanes: 13 passed (the target-draw test ran on a GTX 1070 and WARP here). The corpus measurement in the description is unchanged (0 reads resolved), so no translation moves.AI-assisted (Claude).
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T09:46:53Z.
I rebuilt
70b273f6amerged ontomain4014af7feand confirmed that the original explicit-AND reproducer is fixed. All 13 stockupper_lanestests passed under Wine 11.22 / VKD3D-Proton 3.1.0 on RTX 4070 SUPER (620.73.04) and Radeon 610M (RADV 26.3.1).Two implicit-mask forms still produce the same false resolution. AMD's RDNA 2 SOP1 tables specify
new EXEC = S0 & ~old EXECfor boths_andn2_saveexec_b64ands_andn2_wrexec_b64. They differ in the value written to the destination SGPRs. WithS0=-1, each sets the previously clear upper mask bits. Your explicits_andn2_b64 exec, -1, execcontrol has that same effect on EXEC.Using the PR's
spill_readhelper, these are the two additional cases (encodings checked withllvm-mc -arch=amdgcn -mcpu=gfx1030):Both return
Some(Value(Value(4)))at70b273f6a, substituting the stale 2.0 for the overwritten lane 40. I removed the implicit ANDN2 forms fromclears_upperin a local comparison, keeping the explicit AND/ANDN2 operand checks and the AND SAVEEXEC controls. Both new cases returnedNone, and all 15 targeted tests then passed on both machines' adapter paths. This reproduction checks the data-flow analysis. The repository's separate SPIR-Vtest_andn2_exec_b64.pyalso passes 4/4 and agrees with AMD's semantics.AI-assisted: yes (OpenAI Codex).
Pull request closed