shader: lower s_bfm_b64, s_cselect_b64 and s_not_b64 in the direct C++ compute path #2959

Merged
Leyukaka merged 1 commit from upstream-pr/2959 into cpp-migration 2026-11-26 23:47:07 +00:00
Leyukaka commented 2026-11-26 23:35:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-26T23:35:53Z.


Fixes #2957 (it needs closing by hand, since the base is not the default branch). Part of #2935. Target branch cpp-migration.

Change (src/gfx1013_direct_compute.inl, src/gfx1013_compute_native.cpp): three _b64 SALU ops are lowered as real 64-bit values in direct compute, ahead of the generic bitwise _b64 block.

  • s_bfm_b64 D, S0, S1:
    • D = ((1 << (S0 & 63)) - 1) << (S1 & 63), both words written, SCC unchanged;
    • S0 and S1 are single 32-bit operands (an SGPR or a constant), and D is an even SGPR pair up to s[104:105];
    • the analysis folds the result when both sources are constants.
  • s_cselect_b64 D, S0, S1: both words are selected by SCC, and SCC is unchanged.
  • In the liveness pass, s_cselect_b32/_b64 are now named as SCC readers. This changes no behaviour: they were already treated as possible readers. s_bfm_b64 is marked SCC-preserving.
  • s_not_b64 D, S0: both words are inverted, and SCC = (D != 0) over the 64-bit result.
  • For s_cselect_b64 and s_not_b64:
    • constants extend to 64 bits as pair_high already does: inline negatives are sign-extended, and inline non-negatives and literals get a zero high word;
    • sources are even SGPR pairs or constants, and vcc/exec sources are refused;
    • the destination is an even SGPR pair or vcc, with the existing VCC layout; exec is refused.
  • tools/startup/gfx2hlsl.py has the same s_bfm_b64 rule (op_s_bfm_b64). Its s_cselect_b64 and s_not_b64 follow its one-bit-per-lane mask model, which does not apply to this path.

Tests. The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, on cpp-migration e3670100 plus this commit.

  • native_salu64_hardware passed, 15 cases in two 32-lane groups with guards:
    • s_bfm_b64 with (width, offset) in (0,0), (1,0), (31,1), (32,32) from SGPRs, (33,0), (63,1) and (64,0). Each case sets SCC beforehand and checks that it is unchanged.
    • s_cselect_b64 under both SCC values, choosing between an SGPR pair and -1, and between the literal 0x80000001 and an SGPR pair, written to vcc.
    • s_not_b64 of four pairs, including all ones, whose SCC is 0.
  • native_salu64_controls passed: s_cselect_b64 exec, -1, 0 and s_not_b64 s[24:25], vcc are refused. The s_bfm_b64 destination refusal has no control.
  • native_shift64_hardware, native_lane_access_hardware, native_dpp_quad_hardware and native_compute_clear still pass.

Mutation checks, run by hand; each fails the hardware test on its own case:

  • a 32-bit s_bfm_b64 with a zero high word: bfm 32,32;
  • a zero-extended -1 in s_cselect_b64: cselect pair,-1 SCC=0;
  • an s_not_b64 SCC from the low word only: not (0xffffffff, 0).

Measured on a local capture (counts and instruction shape only) with compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests.

  • Of 2,689 compute requests, 270 compiled on e3670100 and 297 with this commit; none that compiled before stops compiling.
  • On e3670100, 177 requests stop first at one of the two "unsupported wave64 scalar ... operation" refusals; 44 still do.
    • Those 44 are mostly s_bcnt1_i32_b64 and s_ff1_i32_b64 on exec, left out as in #2957.
    • Another 12 now stop at "invalid s_not_b64 source", where s_not_b64 reads vcc or exec, which this change refuses.
  • The runtime still uses the Python translator, so I matched pipelines by request key against a 600 s start-up run. 14 of the 27 newly compiled pipelines were dispatched 5,072 times in that run.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5518615266 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2959). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-26T23:35:53Z. --- Fixes #2957 (it needs closing by hand, since the base is not the default branch). Part of #2935. Target branch `cpp-migration`. **Change** (`src/gfx1013_direct_compute.inl`, `src/gfx1013_compute_native.cpp`): three `_b64` SALU ops are lowered as real 64-bit values in direct compute, ahead of the generic bitwise `_b64` block. - `s_bfm_b64 D, S0, S1`: - `D = ((1 << (S0 & 63)) - 1) << (S1 & 63)`, both words written, SCC unchanged; - S0 and S1 are single 32-bit operands (an SGPR or a constant), and D is an even SGPR pair up to `s[104:105]`; - the analysis folds the result when both sources are constants. - `s_cselect_b64 D, S0, S1`: both words are selected by SCC, and SCC is unchanged. - In the liveness pass, `s_cselect_b32`/`_b64` are now named as SCC readers. This changes no behaviour: they were already treated as possible readers. `s_bfm_b64` is marked SCC-preserving. - `s_not_b64 D, S0`: both words are inverted, and SCC = (D != 0) over the 64-bit result. - For `s_cselect_b64` and `s_not_b64`: - constants extend to 64 bits as `pair_high` already does: inline negatives are sign-extended, and inline non-negatives and literals get a zero high word; - sources are even SGPR pairs or constants, and `vcc`/`exec` sources are refused; - the destination is an even SGPR pair or `vcc`, with the existing VCC layout; `exec` is refused. - `tools/startup/gfx2hlsl.py` has the same `s_bfm_b64` rule (`op_s_bfm_b64`). Its `s_cselect_b64` and `s_not_b64` follow its one-bit-per-lane mask model, which does not apply to this path. **Tests.** The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, on `cpp-migration` `e3670100` plus this commit. - `native_salu64_hardware` passed, 15 cases in two 32-lane groups with guards: - `s_bfm_b64` with (width, offset) in (0,0), (1,0), (31,1), (32,32) from SGPRs, (33,0), (63,1) and (64,0). Each case sets SCC beforehand and checks that it is unchanged. - `s_cselect_b64` under both SCC values, choosing between an SGPR pair and `-1`, and between the literal `0x80000001` and an SGPR pair, written to `vcc`. - `s_not_b64` of four pairs, including all ones, whose SCC is 0. - `native_salu64_controls` passed: `s_cselect_b64 exec, -1, 0` and `s_not_b64 s[24:25], vcc` are refused. The `s_bfm_b64` destination refusal has no control. - `native_shift64_hardware`, `native_lane_access_hardware`, `native_dpp_quad_hardware` and `native_compute_clear` still pass. **Mutation checks**, run by hand; each fails the hardware test on its own case: - a 32-bit `s_bfm_b64` with a zero high word: `bfm 32,32`; - a zero-extended `-1` in `s_cselect_b64`: `cselect pair,-1 SCC=0`; - an `s_not_b64` SCC from the low word only: `not (0xffffffff, 0)`. **Measured on a local capture** (counts and instruction shape only) with `compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests`. - Of 2,689 compute requests, 270 compiled on `e3670100` and 297 with this commit; none that compiled before stops compiling. - On `e3670100`, 177 requests stop first at one of the two "unsupported wave64 scalar ... operation" refusals; 44 still do. - Those 44 are mostly `s_bcnt1_i32_b64` and `s_ff1_i32_b64` on `exec`, left out as in #2957. - Another 12 now stop at "invalid s_not_b64 source", where `s_not_b64` reads `vcc` or `exec`, which this change refuses. - The runtime still uses the Python translator, so I matched pipelines by request key against a 600 s start-up run. 14 of the 27 newly compiled pipelines were dispatched 5,072 times in that run. AI-assisted.
MasterDomino commented 2026-11-26 23:47:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T23:47:05Z.

Review: APPROVED


Review of head 895decff, tested merged onto cpp-migration e3670100. It merges cleanly, and CI on the head is green. Approving and merging.

Code read against RDNA 2:

  • s_bfm_b64 is ((1 << S0[5:0]) - 1) << S1[5:0] as a 64-bit value, so a raw width of 64 gives an empty mask. It sets the Int64 shader flag, and the constant fold in transfer() agrees.
  • s_cselect_b64 selects both words by SCC and leaves SCC unchanged. It is now named as an SCC reader in liveness.
  • s_not_b64 inverts both words and sets SCC from the whole 64-bit result.
  • EXEC and VCC sources are refused for the last two.

Run on AMD: Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), release. ctest --preset release --no-tests=error -R '^native_' gives 45 tests, 44 passed and 1 skipped (77, native_comparison_pso_warp), including native_salu64_hardware and native_salu64_controls.

Mutation here: taking the s_not_b64 SCC from the low word only fails native_salu64_hardware at ('not (4294967295, 0)', (0, 4294967295), 1). With it restored, it passes.

The s_bfm_b64 destination refusal has no control, as you note. That is minor. I will close #2957 by hand.

AI-assisted; the commands above were run locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6081645317 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2959#pullrequestreview-6081645317). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-26T23:47:05Z. **Review:** APPROVED --- Review of head `895decff`, tested merged onto `cpp-migration` `e3670100`. It merges cleanly, and CI on the head is green. Approving and merging. **Code read** against RDNA 2: - `s_bfm_b64` is `((1 << S0[5:0]) - 1) << S1[5:0]` as a 64-bit value, so a raw width of 64 gives an empty mask. It sets the Int64 shader flag, and the constant fold in `transfer()` agrees. - `s_cselect_b64` selects both words by SCC and leaves SCC unchanged. It is now named as an SCC reader in liveness. - `s_not_b64` inverts both words and sets SCC from the whole 64-bit result. - EXEC and VCC sources are refused for the last two. **Run on AMD:** Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), release. `ctest --preset release --no-tests=error -R '^native_'` gives 45 tests, 44 passed and 1 skipped (77, `native_comparison_pso_warp`), including `native_salu64_hardware` and `native_salu64_controls`. **Mutation here:** taking the `s_not_b64` SCC from the low word only fails `native_salu64_hardware` at `('not (4294967295, 0)', (0, 4294967295), 1)`. With it restored, it passes. The `s_bfm_b64` destination refusal has no control, as you note. That is minor. I will close #2957 by hand. AI-assisted; the commands above were run locally.
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!2959
No description provided.