shader: lower s_bfe_u64, s_bfe_i64 and s_brev_b64 in the direct compute path #3089

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/3089 into main 2026-11-27 15:26:07 +00:00
legacy-code-archaeologist commented 2026-11-27 14:51:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T14:51:22Z.


Fixes #3086 (part of #2935).
Base: main at ca659396; commit 720abcb5.

Summary

Verification

  • cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump: built cleanly.
  • ctest --preset dev --no-tests=error -R '^(native_salu_bfe64_brev64_|native_salu_shift64_|native_salu64_)' -V: native_salu_bfe64_brev64_controls passed (1.30s; pure 32-bit DXIL s_brev_b64, 21 cases compiled, _u64 descriptor-clobber refusal, 9 negative refusal checks, 6 oracle mutants caught); native_salu_shift64_controls and native_salu64_controls passed.
  • ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' -j 4 --output-on-failure: 27/27 passed (18.72s).
  • tests/docs_links_check.py: passed (79 Markdown files, 586 links).
  • native_salu_bfe64_brev64_hardware: skipped with exit code 77 (requires shader model 6.6 with wave32) on local Quadro M1000M (SM 6.1); GPU readback is unmeasured locally.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5528612852 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3089). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-27T14:51:22Z. --- Fixes #3086 (part of #2935). Base: `main` at `ca659396`; commit `720abcb5`. ## Summary - Lower `s_brev_b64`, `s_bfe_u64`, and `s_bfe_i64` in [src/gfx1013_direct_compute.inl](src/gfx1013_direct_compute.inl), reading all sources before writing the destination pair so overlapping registers stay intact. - `s_brev_b64` uses pure 32-bit DXIL `@dx.op.unary.i32(i32 30, ...)` (`reversebits`) without setting `Int64Ops`, swapping and bit-reversing both halves while leaving `SCC` unchanged. - `s_bfe_u64` and `s_bfe_i64` extract width = S1[22:16] bits at offset = S1[5:0] (clamping at 64, sign-extending negative literals for `s_bfe_i64` only, and writing `SCC = (D != 0)`). - Update `transfer()` in [src/gfx1013_compute_native.cpp](src/gfx1013_compute_native.cpp) to also clear `s[dst + 1]` for `_u64` SOP1/SOP2 instructions, and update `uses_scc_after()` for `s_bfe_u64`/`s_bfe_i64` (overwrite `SCC`) and `s_brev_b64` (preserve `SCC`). - Add [tests/cmake/native_salu_bfe64_brev64.cmake](tests/cmake/native_salu_bfe64_brev64.cmake), [tests/native_salu_bfe64_brev64_check.py](tests/native_salu_bfe64_brev64_check.py), and [docs/experiments/native-direct-salu-bfe64-brev64.md](docs/experiments/native-direct-salu-bfe64-brev64.md). ## Verification - `cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump`: built cleanly. - `ctest --preset dev --no-tests=error -R '^(native_salu_bfe64_brev64_|native_salu_shift64_|native_salu64_)' -V`: `native_salu_bfe64_brev64_controls` passed (1.30s; pure 32-bit DXIL `s_brev_b64`, 21 cases compiled, `_u64` descriptor-clobber refusal, 9 negative refusal checks, 6 oracle mutants caught); `native_salu_shift64_controls` and `native_salu64_controls` passed. - `ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' -j 4 --output-on-failure`: 27/27 passed (18.72s). - `tests/docs_links_check.py`: passed (79 Markdown files, 586 links). - `native_salu_bfe64_brev64_hardware`: skipped with exit code 77 (`requires shader model 6.6 with wave32`) on local Quadro M1000M (SM 6.1); GPU readback is **unmeasured** locally. AI-assisted.
thepatrickworld commented 2026-11-27 15:20:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-27T15:20:54Z.


Independent AMD Radeon RX 9070 XT result on 720abcb5. Not a code change; measurements only.

The body records native_salu_bfe64_brev64_hardware as skipped (77: the entry needs shader model 6.6 with wave32, the author's Quadro M1000M reports 6.1), so the GPU readback is unmeasured. This is that run, plus a mutant matrix on the C++ lowering of the three instructions.

Environment

  • Windows 11 25H2, 10.0.26200.9974; MSVC 19.44.35230, toolset 14.44.35207; DXC 1.9.2602.17
  • driver 32.0.32029.2010, preset dev
  • D3D12 debug layer not installed: Get-WindowsCapability -Online -Name Tools.Graphics.DirectX~~~~0.0.1.0 reports State: NotPresent, so no validation output exists in any run below
  • worktree on 720abcb544bf6aa5fd8aec346b148674c9825403, git status --porcelain --untracked-files=no empty, Total Tests: 2625

Commands

git fetch origin pull/3089/head:refs/panam/3089
git worktree add x2w-3089 refs/panam/3089
call "...\VC\Auxiliary\Build\vcvars64.bat" >nul
cmake --preset dev "-DINTAKE_PYTHON=C:/.../out/pe-env/Scripts/python.exe"
cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump
ctest --preset dev --no-tests=error -R '^native_salu_bfe64_brev64_' -V
ctest --preset dev --no-tests=error -R '^native_salu' -j 4

Observed

The hardware entry passed twice, 4.47 s and 3.88 s, all 21 cases matching words, SCC and guard words:

2511: brev pair scc=0: result words, SCC and guards matched
2511: brev pair scc=1: result words, SCC and guards matched
2511: brev bit0 -> bit63: result words, SCC and guards matched
2511: brev -1: result words, SCC and guards matched
2511: brev literal 0x80000001: result words, SCC and guards matched
2511: brev null: result words, SCC and guards matched
2511: bfe_u64 width=0: result words, SCC and guards matched
2511: bfe_i64 width=0: result words, SCC and guards matched
2511: bfe_u64 full 64: result words, SCC and guards matched
2511: bfe_i64 width=127 clamp: result words, SCC and guards matched
2511: bfe_u64 cross-word off=28 wd=8: result words, SCC and guards matched
2511: bfe_i64 cross-word neg off=28 wd=8: result words, SCC and guards matched
2511: bfe_i64 past-MSB neg off=40 wd=32: result words, SCC and guards matched
2511: bfe_i64 past-MSB pos off=40 wd=32: result words, SCC and guards matched
2511: bfe_u64 hi-only nonzero scc: result words, SCC and guards matched
2511: bfe_u64 zero extract clears scc: result words, SCC and guards matched
2511: bfe_i64 -1 off=32 wd=8: result words, SCC and guards matched
2511: bfe_u64 lit off=32 wd=8 (zext=0): result words, SCC and guards matched
2511: bfe_i64 lit off=32 wd=8 (sext=-1): result words, SCC and guards matched
2511: bfe_u64 null: result words, SCC and guards matched
2511: bfe_u64 overlapping dst/s0/s1: result words, SCC and guards matched
100% tests passed out of 1

controls passed in 1.43 s: 21 cases compiled, 9 operand and destination refusals plus the symbolic descriptor-clobber refusal (unproven resource descriptor s32), and the six oracle mutants caught on 4/4/3/1/1/4 cases. Neighbouring family ^native_salu with -j 4: 6/6 passed (native_salu64 controls and hardware, native_salu_bfe64_brev64 controls and hardware, native_salu_shift64 controls and hardware).

native_store_replay creates its device with D3D12CreateDevice(nullptr, …) and logs no adapter line, so the identity comes from a separate probe making the same call and matching GetAdapterLuid() against the DXGI enumeration:

enum 0: AMD Radeon RX 9070 XT | vendor=1002 device=7550 | flags=0000 | luid=00000000:0001fc9b
enum 1: AMD Radeon RX 9070 XT | vendor=1002 device=7550 | flags=0000 | luid=00000000:000129fe
enum 2: Microsoft Basic Render Driver | vendor=1414 device=008c | flags=0002 | luid=00000000:0001447e
create(nullptr) matches enum 0: AMD Radeon RX 9070 XT vendor=1002 device=7550 flags=0000
shader_model=0066 waveops=1 waves=32..64

What the hardware entry pins

One edit per mutant, rebuild, this entry, then git checkout -- with the file sha256 back to f55c3768… and git status --porcelain --untracked-files=no empty. Restored tree re-run: 21/21 green.

  • s_brev_b64 halves not swapped (src/gfx1013_direct_compute.inl:1873-1874, rev_lo built from hi) → fails case 1 brev pair scc=0: ('brev pair scc=0', (3869426816, 4155757969), 0).
  • width mask & 127 → & 63 (:1881) → fails case 9 bfe_u64 full 64, expected (2309737967, 19088743) scc 1; 8 cases passed before.
  • SCC from the low word only (:1896, or out_lo, out_hi → out_lo) → fails case 15 bfe_u64 hi-only nonzero scc, expected (0, 16) scc 1; 14 before.
  • literal sign extension without the sign guard (:1870) → fails case 5 brev literal 0x80000001, expected (0, 2147483649) scc 1; 4 before. What this pins is the negative half — s_brev_b64 must not extend the literal — and no s_bfe_i64 case can separate the sign conjunct, since sign is true for all of them by construction.
  • width >= 64 select replaced by the narrowed result (:1889) → fails case 10 bfe_i64 width=127 clamp, expected (305419896, 2147483649) scc 1; 9 before. Note what case 10 pins: the clamp value 127, not the >= 64 branch as a property. At width = 64 the pad is (64 - 64) & 63 = 0, so the narrowed result already equals the shifted one and case 9 is a no-op for this edit.

The controls entry does not see this class: on the width-mask tree it still reports Passed 1.02 sec while the hardware entry fails. It asserts on emitted-op presence and on refusal messages, so the constants above are pinned by the hardware entry only.

What it does not pin, measured

  • offset = ctrl & 63 → & 127 (:1880) passes 21/21 on a rebuilt binary, and a probe does not separate the two forms either. With ctrl = 0x0008005c (ISA offset 28, width 8, bit 6 set) the mutated tree shifts by 92; the readback is the same on both trees (lo=0x00000078 scc=1), where the leaked mask would give lo=0x00000000 scc=0. So on this target the wider constant is absorbed before it is observable: the mutant is dead, not merely uncaught, and a case carrying bit 6 would not separate them either. Which layer absorbs it — DXC legalising a shift by 92, or the ISA masking the shift count to 6 bits — was not isolated; there is no DXIL or SASS dump of the mutated shader. The & 63 on :1880 is justified by the field definition (S1[5:0]), not by any execution here.
  • the two liveness edits are not pinned by anything: reverting n == "s_bfe_u64" || n == "s_bfe_i64" from the overwrites list (:1457) keeps both entries green (controls 1.17 s, hardware 5.63 s), and reverting the n != "s_brev_b64" exclusion from uncertain_scalar (:1463) does the same (0.98 s, 3.52 s). Scope: the two entries of this PR; the wider suite was not run on those trees.
  • the runner stops at the first failure, so each mutant above reports one case only.

CI

Neither entry runs on a pull_request: the test preset pr lists no native_salu* name. After merge, .github/workflows/windows.yml:496 runs the push sweep with -E '_hardware$', so _controls runs on main and the hardware half is never built.

Limits

One machine, one driver, and no debug layer (above). The adapter identity is established for a separate process making the same D3D12CreateDevice(nullptr) call; the runner's own device LUID is not logged, and two 1002:7550 adapters are enumerated on this host, so the match with enum 0 is the best available evidence rather than a reading of the runner. The green says the 21 cases produce the expected words, SCC and guard words on this adapter, and nothing about the inputs the fixture does not build.

AI-assisted; runs executed on the machine above.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7221944527 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3089#issuecomment-7221944527). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-27T15:20:54Z. --- **Independent AMD Radeon RX 9070 XT result on `720abcb5`.** Not a code change; measurements only. The body records `native_salu_bfe64_brev64_hardware` as skipped (`77`: the entry needs shader model 6.6 with wave32, the author's Quadro M1000M reports 6.1), so the GPU readback is unmeasured. This is that run, plus a mutant matrix on the C++ lowering of the three instructions. ### Environment - Windows 11 25H2, 10.0.26200.9974; MSVC 19.44.35230, toolset 14.44.35207; DXC 1.9.2602.17 - driver 32.0.32029.2010, preset `dev` - D3D12 debug layer not installed: `Get-WindowsCapability -Online -Name Tools.Graphics.DirectX~~~~0.0.1.0` reports `State: NotPresent`, so no validation output exists in any run below - worktree on `720abcb544bf6aa5fd8aec346b148674c9825403`, `git status --porcelain --untracked-files=no` empty, `Total Tests: 2625` ### Commands ``` git fetch origin pull/3089/head:refs/panam/3089 git worktree add x2w-3089 refs/panam/3089 call "...\VC\Auxiliary\Build\vcvars64.bat" >nul cmake --preset dev "-DINTAKE_PYTHON=C:/.../out/pe-env/Scripts/python.exe" cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump ctest --preset dev --no-tests=error -R '^native_salu_bfe64_brev64_' -V ctest --preset dev --no-tests=error -R '^native_salu' -j 4 ``` ### Observed The hardware entry passed twice, 4.47 s and 3.88 s, all 21 cases matching words, SCC and guard words: ``` 2511: brev pair scc=0: result words, SCC and guards matched 2511: brev pair scc=1: result words, SCC and guards matched 2511: brev bit0 -> bit63: result words, SCC and guards matched 2511: brev -1: result words, SCC and guards matched 2511: brev literal 0x80000001: result words, SCC and guards matched 2511: brev null: result words, SCC and guards matched 2511: bfe_u64 width=0: result words, SCC and guards matched 2511: bfe_i64 width=0: result words, SCC and guards matched 2511: bfe_u64 full 64: result words, SCC and guards matched 2511: bfe_i64 width=127 clamp: result words, SCC and guards matched 2511: bfe_u64 cross-word off=28 wd=8: result words, SCC and guards matched 2511: bfe_i64 cross-word neg off=28 wd=8: result words, SCC and guards matched 2511: bfe_i64 past-MSB neg off=40 wd=32: result words, SCC and guards matched 2511: bfe_i64 past-MSB pos off=40 wd=32: result words, SCC and guards matched 2511: bfe_u64 hi-only nonzero scc: result words, SCC and guards matched 2511: bfe_u64 zero extract clears scc: result words, SCC and guards matched 2511: bfe_i64 -1 off=32 wd=8: result words, SCC and guards matched 2511: bfe_u64 lit off=32 wd=8 (zext=0): result words, SCC and guards matched 2511: bfe_i64 lit off=32 wd=8 (sext=-1): result words, SCC and guards matched 2511: bfe_u64 null: result words, SCC and guards matched 2511: bfe_u64 overlapping dst/s0/s1: result words, SCC and guards matched 100% tests passed out of 1 ``` `controls` passed in 1.43 s: 21 cases compiled, 9 operand and destination refusals plus the symbolic descriptor-clobber refusal (`unproven resource descriptor s32`), and the six oracle mutants caught on 4/4/3/1/1/4 cases. Neighbouring family `^native_salu` with `-j 4`: 6/6 passed (`native_salu64` controls and hardware, `native_salu_bfe64_brev64` controls and hardware, `native_salu_shift64` controls and hardware). `native_store_replay` creates its device with `D3D12CreateDevice(nullptr, …)` and logs no adapter line, so the identity comes from a separate probe making the same call and matching `GetAdapterLuid()` against the DXGI enumeration: ``` enum 0: AMD Radeon RX 9070 XT | vendor=1002 device=7550 | flags=0000 | luid=00000000:0001fc9b enum 1: AMD Radeon RX 9070 XT | vendor=1002 device=7550 | flags=0000 | luid=00000000:000129fe enum 2: Microsoft Basic Render Driver | vendor=1414 device=008c | flags=0002 | luid=00000000:0001447e create(nullptr) matches enum 0: AMD Radeon RX 9070 XT vendor=1002 device=7550 flags=0000 shader_model=0066 waveops=1 waves=32..64 ``` ### What the hardware entry pins One edit per mutant, rebuild, this entry, then `git checkout --` with the file sha256 back to `f55c3768…` and `git status --porcelain --untracked-files=no` empty. Restored tree re-run: 21/21 green. - `s_brev_b64` halves not swapped (`src/gfx1013_direct_compute.inl:1873-1874`, `rev_lo` built from `hi`) → fails **case 1** `brev pair scc=0`: `('brev pair scc=0', (3869426816, 4155757969), 0)`. - width mask `& 127` → `& 63` (`:1881`) → fails **case 9** `bfe_u64 full 64`, expected `(2309737967, 19088743)` scc 1; 8 cases passed before. - SCC from the low word only (`:1896`, `or out_lo, out_hi` → `out_lo`) → fails **case 15** `bfe_u64 hi-only nonzero scc`, expected `(0, 16)` scc 1; 14 before. - literal sign extension without the `sign` guard (`:1870`) → fails **case 5** `brev literal 0x80000001`, expected `(0, 2147483649)` scc 1; 4 before. What this pins is the negative half — `s_brev_b64` must not extend the literal — and no `s_bfe_i64` case can separate the `sign` conjunct, since `sign` is true for all of them by construction. - `width >= 64` select replaced by the narrowed result (`:1889`) → fails **case 10** `bfe_i64 width=127 clamp`, expected `(305419896, 2147483649)` scc 1; 9 before. Note what case 10 pins: the clamp value 127, not the `>= 64` branch as a property. At `width = 64` the pad is `(64 - 64) & 63 = 0`, so the narrowed result already equals the shifted one and case 9 is a no-op for this edit. The `controls` entry does not see this class: on the width-mask tree it still reports `Passed 1.02 sec` while the hardware entry fails. It asserts on emitted-op presence and on refusal messages, so the constants above are pinned by the hardware entry only. ### What it does not pin, measured - `offset = ctrl & 63` → `& 127` (`:1880`) **passes 21/21** on a rebuilt binary, and a probe does not separate the two forms either. With `ctrl = 0x0008005c` (ISA offset 28, width 8, bit 6 set) the mutated tree shifts by 92; the readback is the same on both trees (`lo=0x00000078 scc=1`), where the leaked mask would give `lo=0x00000000 scc=0`. So on this target the wider constant is absorbed before it is observable: the mutant is dead, not merely uncaught, and a case carrying bit 6 would not separate them either. Which layer absorbs it — DXC legalising a shift by 92, or the ISA masking the shift count to 6 bits — was not isolated; there is no DXIL or SASS dump of the mutated shader. The `& 63` on `:1880` is justified by the field definition (`S1[5:0]`), not by any execution here. - the two liveness edits are not pinned by anything: reverting `n == "s_bfe_u64" || n == "s_bfe_i64"` from the `overwrites` list (`:1457`) keeps both entries green (`controls 1.17 s`, `hardware 5.63 s`), and reverting the `n != "s_brev_b64"` exclusion from `uncertain_scalar` (`:1463`) does the same (`0.98 s`, `3.52 s`). Scope: the two entries of this PR; the wider suite was not run on those trees. - the runner stops at the first failure, so each mutant above reports one case only. ### CI Neither entry runs on a `pull_request`: the test preset `pr` lists no `native_salu*` name. After merge, `.github/workflows/windows.yml:496` runs the push sweep with `-E '_hardware$'`, so `_controls` runs on `main` and the hardware half is never built. ### Limits One machine, one driver, and no debug layer (above). The adapter identity is established for a separate process making the same `D3D12CreateDevice(nullptr)` call; the runner's own device LUID is not logged, and two `1002:7550` adapters are enumerated on this host, so the match with enum 0 is the best available evidence rather than a reading of the runner. The green says the 21 cases produce the expected words, SCC and guard words on this adapter, and nothing about the inputs the fixture does not build. _AI-assisted; runs executed on the machine above._
R0Y00 commented 2026-11-27 15:25:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T15:25:56Z.

Review: APPROVED


Independent integration of 720abcb5 with main 5df098da (tree f6f9c27b002eee8e3f3b5dafc38e2744fc15baac). The bitfield code keeps all evaluated shift amounts valid, handles widths 0 and 64+, and sets SCC from both output words. Bit reverse swaps the reversed words and preserves SCC. The _u64 symbolic clobber control refuses an unproven descriptor.

Built compile_dxil native_store_replay and ran ctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(salu_bfe64_brev64|salu_shift64|salu64)_(controls|hardware)$'. Debug and Release /O2 each passed 6/6 with no skips. All 21 BFE/reverse cases matched the result words, SCC and guards on the RTX 4060 Laptop (driver 32.0.16.1656, Windows 11 26200.9974, SDK DXC 10.0.26100, replay debug layer off). The negative references and invalid encodings differed as expected. These wave32 replay cases have no local WARP coverage.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6090331522 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3089#pullrequestreview-6090331522). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T15:25:56Z. **Review:** APPROVED --- Independent integration of `720abcb5` with `main` `5df098da` (tree `f6f9c27b002eee8e3f3b5dafc38e2744fc15baac`). The bitfield code keeps all evaluated shift amounts valid, handles widths 0 and 64+, and sets SCC from both output words. Bit reverse swaps the reversed words and preserves SCC. The `_u64` symbolic clobber control refuses an unproven descriptor. Built `compile_dxil native_store_replay` and ran `ctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(salu_bfe64_brev64|salu_shift64|salu64)_(controls|hardware)$'`. Debug and Release `/O2` each passed 6/6 with no skips. All 21 BFE/reverse cases matched the result words, SCC and guards on the RTX 4060 Laptop (driver 32.0.16.1656, Windows 11 26200.9974, SDK DXC 10.0.26100, replay debug layer off). The negative references and invalid encodings differed as expected. These wave32 replay 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!3089
No description provided.