shader: lower s_lshl_b64, s_lshr_b64 and s_ashr_i64 in the direct compute path #3067

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/3067 into main 2026-11-27 14:40:21 +00:00
legacy-code-archaeologist commented 2026-11-27 13:35:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T13:35:16Z.


Change

src/gfx1013_direct_compute.inl lowers the SOP2 64-bit scalar shifts s_lshl_b64, s_lshr_b64 and s_ashr_i64 in the direct C++ compute path, matching tools/startup/gfx2hlsl.py (scalar_wide_op). Fixes #3062 (part of #2935).

  • Operands & semantics: aligned SGPR pair (s0..s104 even) or vcc (106) destination; aligned SGPR pair, inline integer (-16..64), or 32-bit literal S0 (zero-extended for s_lshl_b64/s_lshr_b64, sign-extended for s_ashr_i64); general SGPR (s0..s105), inline integer, or 32-bit literal S1 masked with & 63. Reads all sources before writing D[0:1] so overlapping destinations keep their original inputs. Sets ir.features |= 1048576 (Int64Ops) and SCC = (D != 0).
  • Symbolic transfer & SCC liveness: src/gfx1013_compute_native.cpp (transfer()) now clears s[dst + 1] for SOP1/SOP2 _i64 operations as well as _b64, preventing a stale symbolic descriptor tag after s_ashr_i64. uses_scc_after() in src/gfx1013_direct_compute.inl marks all three shifts as overwriting SCC.
  • Tests & docs: tests/native_salu_shift64_check.py, tests/cmake/native_salu_shift64.cmake, docs/experiments/native-direct-salu-shift64.md.

Verification

Tested on upstream/main db28a796, Windows 10.0.26100, dev preset:

  • 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_controls 1.09 s, native_salu64_controls 0.76 s, native_shift64_controls 0.27 s); 3 hardware tests skipped (exit 77 — 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 stale native_compute_ir_dump.exe; after rebuilding native_compute_ir_dump, native_f16_alu_ir also passed: 23/23 total).
  • python -B tests/docs_links_check.py: passed (72 Markdown files and 583 links).

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5527538352 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3067). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-27T13:35:16Z. --- ## Change `src/gfx1013_direct_compute.inl` lowers the SOP2 64-bit scalar shifts `s_lshl_b64`, `s_lshr_b64` and `s_ashr_i64` in the direct C++ compute path, matching `tools/startup/gfx2hlsl.py` (`scalar_wide_op`). Fixes #3062 (part of #2935). - **Operands & semantics:** aligned SGPR pair (`s0..s104` even) or `vcc` (`106`) destination; aligned SGPR pair, inline integer (`-16..64`), or 32-bit literal `S0` (zero-extended for `s_lshl_b64`/`s_lshr_b64`, sign-extended for `s_ashr_i64`); general SGPR (`s0..s105`), inline integer, or 32-bit literal `S1` masked with `& 63`. Reads all sources before writing `D[0:1]` so overlapping destinations keep their original inputs. Sets `ir.features |= 1048576` (`Int64Ops`) and `SCC = (D != 0)`. - **Symbolic transfer & SCC liveness:** `src/gfx1013_compute_native.cpp` (`transfer()`) now clears `s[dst + 1]` for SOP1/SOP2 `_i64` operations as well as `_b64`, preventing a stale symbolic descriptor tag after `s_ashr_i64`. `uses_scc_after()` in `src/gfx1013_direct_compute.inl` marks all three shifts as overwriting `SCC`. - **Tests & docs:** `tests/native_salu_shift64_check.py`, `tests/cmake/native_salu_shift64.cmake`, `docs/experiments/native-direct-salu-shift64.md`. ## Verification Tested on `upstream/main` `db28a796`, Windows 10.0.26100, `dev` preset: - `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_controls` 1.09 s, `native_salu64_controls` 0.76 s, `native_shift64_controls` 0.27 s); 3 hardware tests skipped (exit `77` — 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 stale `native_compute_ir_dump.exe`; after rebuilding `native_compute_ir_dump`, `native_f16_alu_ir` also passed: 23/23 total). - `python -B tests/docs_links_check.py`: passed (72 Markdown files and 583 links). AI-assisted.
thepatrickworld commented 2026-11-27 14:20:54 +00:00 (Migrated from github.com)

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.md and the PR body both record the readback as
unmeasured: native_salu_shift64_hardware skipped with 77 on the author's Quadro M1000M. This run
executes that readback on a wave32-capable adapter.

Environment

  • Windows 10.0.26200.9974, MSVC 19.44.35230, toolset 14.44.35207
  • DXC 1.9.2602.17 (SDK 10.0.26100.0), FXC 10.0.26100.9457
  • AMD Radeon RX 9070 XT (vendor 1002, device 7550), driver 32.0.32029.2010 (2026-11-18)
  • dev preset (Debug), shared INTAKE_PYTHON; Total Tests: 2611
  • D3D12 debug layer: NotPresent
  • git rev-parse HEAD = a6bb95e1bc5af55b9594f65de68103eebbbc7f8f, git status --porcelain --untracked-files=no empty

Which adapter native_store_replay actually uses

The tool calls D3D12CreateDevice(nullptr, …) (tests/native_store_replay.cpp:45), so its output never
names the adapter. A probe doing the same call on the same machine reports:

adapter[0] luid=00000000:0001fc9b flags=0000 vendor=1002 device=7550 "AMD Radeon RX 9070 XT"
adapter[2] luid=00000000:0001447e flags=0002 vendor=1414 device=008c "Microsoft Basic Render Driver"
D3D12CreateDevice(nullptr) hr=0x00000000
chosen luid=00000000:0001fc9b
WaveOps=1 lanes=32..64

The default device is adapter 0, the XT; WARP (flags=0002) is not selected. The 77 guard at
tests/native_store_replay.cpp:58 (WaveLaneCountMin > 32 || WaveLaneCountMax < 32) cannot fire with
lanes=32..64, which is why the readback runs here and not on the M1000M.

Commands

cd C:/Users/walde/Downloads/x2w-pr3067
cmake --preset dev "-DINTAKE_PYTHON=C:/Users/walde/Downloads/x2w-pr641/out/pe-env/Scripts/python.exe"
cmake --build --preset dev --target native_store_replay compile_dxil
ctest --preset dev --no-tests=error -R '^native_salu_shift64_' -V
ctest --preset dev --no-tests=error -R '^native_salu64_' -V

Observed

1/2 Test #2504: native_salu_shift64_controls .....   Passed    0.91 sec
2/2 Test #2505: native_salu_shift64_hardware .....   Passed    8.17 sec
100% tests passed out of 2

All 39 cases printed result words, SCC and guards matched, from lshl pair,0 to
lshr zero clears scc. Each case is one native_store_replay invocation and one binding line
(0 32 7 4 1, i.e. root_parameter=0 byte_offset=32 kind=7 stride=4 write=1, printed at
tests/native_store_replay.cpp:175) — 39 for 39.

Mutation matrix on the card

Each mutant edits src/gfx1013_direct_compute.inl (:1735, :1742, :1732) or
src/gfx1013_compute_native.cpp (:569), rebuilds native_store_replay, reruns hardware against
the unmutated reference, then restores with git checkout -- (source SHA-256 back to 890c943c… /
9c7c1e00…, git status empty, restored run green again).

mutant hardware result
arithmetic ? "ashr" → "lshr" (:1735) fails at ashr pair,1 (15 cases matched)
SCC over out_lo only, out_hi dropped (:1742) fails at lshl pair,32 (3 cases matched)
_i64 removed from the descriptor-tag clear (:569) fails at ashr pair,0 (14 matched), native compute +0x2c: unbound numeric SGPR s25
shift mask 63 → 127 (:1732) survives, 39/39

The _i64 arm is therefore observable from the hardware path, not only from a dedicated control: the
shared setup in compute_program reaches s25, and without the arm the shader is refused before the
draw. controls refuses it with the same message.

For the surviving mask mutant the rebuilt executable is provably a different binary
(native_store_replay.exe SHA-256 5d1cc9f0… against c06b860e… before the edit), so it is a real
survivor, not a skipped rebuild.

Regression

ctest -R '^native_salu64_': 4/4 pass, including native_salu64_hardware (4.26 s) — the card
executes 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

  • One machine, one adapter, no debug layer; nothing here says anything about other vendors.
  • eval_shift re-implements the same rules as the lowering (:47-71 against :1732-1742), so a
    semantic error shared by both is invisible in both modes. This run measures agreement with the
    fixture's model, not with an independent ISA reference.
  • The & 63 mask is not pinned on hardware here: with it widened to 127, all 39 cases still
    match, so the out-of-range amount of the s27(65) case is neutralised somewhere between the emitted
    IR and the observed word. This run does not say whether DXC or the ISA does it.
  • Acceptance branches with no case: s_lshl_b64 on a 32-bit literal (the literal cases only cover
    s_lshr_b64 and s_ashr_i64), S1 == 255, and S1 in 192..208.
  • Failures stop at the first divergent case, so a mutant that breaks several cases reports only the
    earliest.
  • controls does not run inside hardware: the 7 refusal forms and the 6 reference mutants are
    Python-side checks and were verified in a separate invocation.
  • Neither entry runs in CI before merge (the pr preset's include regex does not list
    native_salu_shift64), and _hardware is excluded by -E '_hardware$' after merge.

AI-assisted; runs executed on the machine above.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7220668259 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3067#issuecomment-7220668259). Originally posted by [thepatrickworld](https://github.com/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.md` and the PR body both record the readback as unmeasured: `native_salu_shift64_hardware` skipped with `77` on the author's Quadro M1000M. This run executes that readback on a wave32-capable adapter. ### Environment - Windows 10.0.26200.9974, MSVC 19.44.35230, toolset 14.44.35207 - DXC `1.9.2602.17` (SDK `10.0.26100.0`), FXC `10.0.26100.9457` - AMD Radeon RX 9070 XT (vendor `1002`, device `7550`), driver `32.0.32029.2010` (2026-11-18) - `dev` preset (Debug), shared `INTAKE_PYTHON`; `Total Tests: 2611` - D3D12 debug layer: `NotPresent` - `git rev-parse HEAD` = `a6bb95e1bc5af55b9594f65de68103eebbbc7f8f`, `git status --porcelain --untracked-files=no` empty ### Which adapter `native_store_replay` actually uses The tool calls `D3D12CreateDevice(nullptr, …)` (`tests/native_store_replay.cpp:45`), so its output never names the adapter. A probe doing the same call on the same machine reports: ``` adapter[0] luid=00000000:0001fc9b flags=0000 vendor=1002 device=7550 "AMD Radeon RX 9070 XT" adapter[2] luid=00000000:0001447e flags=0002 vendor=1414 device=008c "Microsoft Basic Render Driver" D3D12CreateDevice(nullptr) hr=0x00000000 chosen luid=00000000:0001fc9b WaveOps=1 lanes=32..64 ``` The default device is adapter 0, the XT; WARP (`flags=0002`) is not selected. The `77` guard at `tests/native_store_replay.cpp:58` (`WaveLaneCountMin > 32 || WaveLaneCountMax < 32`) cannot fire with `lanes=32..64`, which is why the readback runs here and not on the M1000M. ### Commands ``` cd C:/Users/walde/Downloads/x2w-pr3067 cmake --preset dev "-DINTAKE_PYTHON=C:/Users/walde/Downloads/x2w-pr641/out/pe-env/Scripts/python.exe" cmake --build --preset dev --target native_store_replay compile_dxil ctest --preset dev --no-tests=error -R '^native_salu_shift64_' -V ctest --preset dev --no-tests=error -R '^native_salu64_' -V ``` ### Observed ``` 1/2 Test #2504: native_salu_shift64_controls ..... Passed 0.91 sec 2/2 Test #2505: native_salu_shift64_hardware ..... Passed 8.17 sec 100% tests passed out of 2 ``` All 39 cases printed `result words, SCC and guards matched`, from `lshl pair,0` to `lshr zero clears scc`. Each case is one `native_store_replay` invocation and one binding line (`0 32 7 4 1`, i.e. `root_parameter=0 byte_offset=32 kind=7 stride=4 write=1`, printed at `tests/native_store_replay.cpp:175`) — 39 for 39. ### Mutation matrix on the card Each mutant edits `src/gfx1013_direct_compute.inl` (`:1735`, `:1742`, `:1732`) or `src/gfx1013_compute_native.cpp` (`:569`), rebuilds `native_store_replay`, reruns `hardware` against the **unmutated** reference, then restores with `git checkout --` (source SHA-256 back to `890c943c…` / `9c7c1e00…`, `git status` empty, restored run green again). | mutant | hardware result | | --- | --- | | `arithmetic ? "ashr"` → `"lshr"` (`:1735`) | fails at `ashr pair,1` (15 cases matched) | | SCC over `out_lo` only, `out_hi` dropped (`:1742`) | fails at `lshl pair,32` (3 cases matched) | | `_i64` removed from the descriptor-tag clear (`:569`) | fails at `ashr pair,0` (14 matched), `native compute +0x2c: unbound numeric SGPR s25` | | shift mask `63` → `127` (`:1732`) | **survives**, 39/39 | The `_i64` arm is therefore observable from the hardware path, not only from a dedicated control: the shared setup in `compute_program` reaches `s25`, and without the arm the shader is refused before the draw. `controls` refuses it with the same message. For the surviving mask mutant the rebuilt executable is provably a different binary (`native_store_replay.exe` SHA-256 `5d1cc9f0…` against `c06b860e…` before the edit), so it is a real survivor, not a skipped rebuild. ### Regression `ctest -R '^native_salu64_'`: 4/4 pass, including `native_salu64_hardware` (4.26 s) — the card executes 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 - One machine, one adapter, no debug layer; nothing here says anything about other vendors. - `eval_shift` re-implements the same rules as the lowering (`:47-71` against `:1732-1742`), so a semantic error shared by both is invisible in **both** modes. This run measures agreement with the fixture's model, not with an independent ISA reference. - The `& 63` mask is **not pinned on hardware here**: with it widened to `127`, all 39 cases still match, so the out-of-range amount of the `s27(65)` case is neutralised somewhere between the emitted IR and the observed word. This run does not say whether DXC or the ISA does it. - Acceptance branches with no case: `s_lshl_b64` on a 32-bit literal (the literal cases only cover `s_lshr_b64` and `s_ashr_i64`), `S1 == 255`, and `S1` in `192..208`. - Failures stop at the first divergent case, so a mutant that breaks several cases reports only the earliest. - `controls` does not run inside `hardware`: the 7 refusal forms and the 6 reference mutants are Python-side checks and were verified in a separate invocation. - Neither entry runs in CI before merge (the `pr` preset's include regex does not list `native_salu_shift64`), and `_hardware` is excluded by `-E '_hardware$'` after merge. _AI-assisted; runs executed on the machine above._
R0Y00 commented 2026-11-27 14:40:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T14:40:03Z.

Review: APPROVED


Reviewed a6bb95e1 with main 020c7a82 (tree 63e391ad73162631a97b9b6e634ee26d02fd3682). 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_dump and ran ctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(salu_shift64|salu64|shift64|ldexp)_(controls|hardware)$'. Debug and Release /O2 each 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6089772133 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3067#pullrequestreview-6089772133). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T14:40:03Z. **Review:** APPROVED --- Reviewed `a6bb95e1` with `main` `020c7a82` (tree `63e391ad73162631a97b9b6e634ee26d02fd3682`). 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_dump` and ran `ctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(salu_shift64|salu64|shift64|ldexp)_(controls|hardware)$'`. Debug and Release `/O2` each 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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
R0Y00/Xbox2Windows!3067
No description provided.