shader: lower s_lshl_b64, s_lshr_b64 and s_ashr_i64 in the direct compute path #3067
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3067"
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 R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T13:35:16Z.
Change
src/gfx1013_direct_compute.inllowers the SOP2 64-bit scalar shiftss_lshl_b64,s_lshr_b64ands_ashr_i64in the direct C++ compute path, matchingtools/startup/gfx2hlsl.py(scalar_wide_op). Fixes #3062 (part of #2935).s0..s104even) orvcc(106) destination; aligned SGPR pair, inline integer (-16..64), or 32-bit literalS0(zero-extended fors_lshl_b64/s_lshr_b64, sign-extended fors_ashr_i64); general SGPR (s0..s105), inline integer, or 32-bit literalS1masked with& 63. Reads all sources before writingD[0:1]so overlapping destinations keep their original inputs. Setsir.features |= 1048576(Int64Ops) andSCC = (D != 0).src/gfx1013_compute_native.cpp(transfer()) now clearss[dst + 1]for SOP1/SOP2_i64operations as well as_b64, preventing a stale symbolic descriptor tag afters_ashr_i64.uses_scc_after()insrc/gfx1013_direct_compute.inlmarks all three shifts as overwritingSCC.tests/native_salu_shift64_check.py,tests/cmake/native_salu_shift64.cmake,docs/experiments/native-direct-salu-shift64.md.Verification
Tested on
upstream/maindb28a796, Windows 10.0.26100,devpreset:cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump: ok.ctest --preset dev --no-tests=error -R '^(native_salu_shift64_|native_salu64_|native_shift64_)' -V: 3 control tests passed (native_salu_shift64_controls1.09 s,native_salu64_controls0.76 s,native_shift64_controls0.27 s); 3 hardware tests skipped (exit77— Quadro M1000M does not support shader model 6.6 with wave32, so GPU readback is unmeasured).ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' -j 4(22/23 passed initially with stalenative_compute_ir_dump.exe; after rebuildingnative_compute_ir_dump,native_f16_alu_iralso passed: 23/23 total).python -B tests/docs_links_check.py: passed (72 Markdown files and 583 links).AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-27T14:20:54Z.
Independent AMD Radeon RX 9070 XT result on
a6bb95e1. Not a code change; measurements only.docs/experiments/native-direct-salu-shift64.mdand the PR body both record the readback asunmeasured:
native_salu_shift64_hardwareskipped with77on the author's Quadro M1000M. This runexecutes that readback on a wave32-capable adapter.
Environment
1.9.2602.17(SDK10.0.26100.0), FXC10.0.26100.94571002, device7550), driver32.0.32029.2010(2026-11-18)devpreset (Debug), sharedINTAKE_PYTHON;Total Tests: 2611NotPresentgit rev-parse HEAD=a6bb95e1bc5af55b9594f65de68103eebbbc7f8f,git status --porcelain --untracked-files=noemptyWhich adapter
native_store_replayactually usesThe tool calls
D3D12CreateDevice(nullptr, …)(tests/native_store_replay.cpp:45), so its output nevernames the adapter. A probe doing the same call on the same machine reports:
The default device is adapter 0, the XT; WARP (
flags=0002) is not selected. The77guard attests/native_store_replay.cpp:58(WaveLaneCountMin > 32 || WaveLaneCountMax < 32) cannot fire withlanes=32..64, which is why the readback runs here and not on the M1000M.Commands
Observed
All 39 cases printed
result words, SCC and guards matched, fromlshl pair,0tolshr zero clears scc. Each case is onenative_store_replayinvocation and one binding line(
0 32 7 4 1, i.e.root_parameter=0 byte_offset=32 kind=7 stride=4 write=1, printed attests/native_store_replay.cpp:175) — 39 for 39.Mutation matrix on the card
Each mutant edits
src/gfx1013_direct_compute.inl(:1735,:1742,:1732) orsrc/gfx1013_compute_native.cpp(:569), rebuildsnative_store_replay, rerunshardwareagainstthe unmutated reference, then restores with
git checkout --(source SHA-256 back to890c943c…/9c7c1e00…,git statusempty, restored run green again).arithmetic ? "ashr"→"lshr"(:1735)ashr pair,1(15 cases matched)out_loonly,out_hidropped (:1742)lshl pair,32(3 cases matched)_i64removed from the descriptor-tag clear (:569)ashr pair,0(14 matched),native compute +0x2c: unbound numeric SGPR s2563→127(:1732)The
_i64arm is therefore observable from the hardware path, not only from a dedicated control: theshared setup in
compute_programreachess25, and without the arm the shader is refused before thedraw.
controlsrefuses it with the same message.For the surviving mask mutant the rebuilt executable is provably a different binary
(
native_store_replay.exeSHA-2565d1cc9f0…againstc06b860e…before the edit), so it is a realsurvivor, not a skipped rebuild.
Regression
ctest -R '^native_salu64_': 4/4 pass, includingnative_salu64_hardware(4.26 s) — the cardexecutes the neighbouring SAL64 path too.
Conclusion
On this adapter the three shifts produce, for all 39 cases, exactly the words and SCC computed by the
fixture's reference model, with the 8 guard words and the tail untouched. Three of the four planted
changes in the lowering are caught by the hardware run; the fourth is invisible here.
Limits
eval_shiftre-implements the same rules as the lowering (:47-71against:1732-1742), so asemantic error shared by both is invisible in both modes. This run measures agreement with the
fixture's model, not with an independent ISA reference.
& 63mask is not pinned on hardware here: with it widened to127, all 39 cases stillmatch, so the out-of-range amount of the
s27(65)case is neutralised somewhere between the emittedIR and the observed word. This run does not say whether DXC or the ISA does it.
s_lshl_b64on a 32-bit literal (the literal cases only covers_lshr_b64ands_ashr_i64),S1 == 255, andS1in192..208.earliest.
controlsdoes not run insidehardware: the 7 refusal forms and the 6 reference mutants arePython-side checks and were verified in a separate invocation.
prpreset's include regex does not listnative_salu_shift64), and_hardwareis excluded by-E '_hardware$'after merge.AI-assisted; runs executed on the machine above.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T14:40:03Z.
Review: APPROVED
Reviewed
a6bb95e1withmain020c7a82(tree63e391ad73162631a97b9b6e634ee26d02fd3682). The lowering snapshots both source words and the masked shift amount before either destination write. SCC uses both result words, and symbolic transfer invalidates the high word for arithmetic right shift as well as logical shifts. The explicit Int64Ops requirement matches the emitted i64 operations.Built
compile_dxil native_store_replay native_compute_ir_dumpand ranctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(salu_shift64|salu64|shift64|ldexp)_(controls|hardware)$'. Debug and Release/O2each passed 8/8 with zero skips. Exact RTX readback covered overlapping operands, logical and arithmetic literals, high-only VCC and zero-result SCC; the wrong-extension and low-word-only SCC references differed. Windows 11 build 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, SDK DXC 10.0.26100, native replay debug layer off. The native wave32 cases have no local WARP coverage.