shader: lower mesh small ALU forms and v_pack_b32_f16 constant sources (Part of #3703) #3827

Merged
timbot103 merged 3 commits from upstream-pr/3827 into main 2026-12-02 16:33:52 +00:00
timbot103 commented 2026-12-02 07:04:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T07:04:59Z.


Part of #3703. Refs #3416, #2413.

Clears two self-contained #3703 mesh census walls (~393 mesh programs total): unsupported v_pack_b32_f16 constant source (132 programs) and the small ALU cluster (261 programs).

Summary

  1. v_pack_b32_f16 constant sources (src/gfx1013_direct_compute.inl):
    • Inline floats (240..248) read their binary16 encoding from inline_half_words (1.0 -> 0x3c00).
    • Inline integers (128..208) read their value truncated to 16 bits (0 -> 0x0000, 1 -> 0x0001, -1 -> 0xffff), matching the existing v_cvt_norm_*_f16 lowering.
    • Literal (255) reads literal & 0xffff.
    • abs clears bit 15, then neg toggles it.
    • Strictly refuses high-half op_sel on any constant source, non-constant special operands (209..239, 249..254), clamp, omod, dst/src2 op_sel, src2 abs/neg, SDWA, and DPP.
    • In src/gfx1013_direct_mesh.inl, adds v_pack_b32_f16 to 2-source uniformity tracking so two uniform/constant inputs produce a uniform result.
  2. Mesh small ALU cluster (src/gfx1013_direct_mesh.inl):
    • v_cmpx_<p>_f32: all 14 fcmp predicates (ordered predicates eq/lt/le/gt/ge/lg/o drop NaN lanes; unordered neq/nlt/nle/ngt/nge/nlg/u keep them); f, tru, class, abs/neg, clamp, DPP, and SDWA stay refused.
    • s_cmpk_{eq,lg,gt,ge,lt,le}_{i32,u32}: sign-extends SIMM16 for i32 (0xffff -> -1), zero-extends for u32 (0x8000 -> 32768); refuses comparing special registers (>= 106).
    • s_bcnt0_i32_b32 / s_bcnt1_i32_b32: dx.op.unaryBits.i32(31) (on ~S0 for bcnt0), SCC = (D != 0); refuses special-register sources (VCC/EXEC/M0) and VCC/EXEC destinations.
    • v_min_f32: dx.op.binary.f32(36) (FMin) with abs/neg sign-bit ops; DPP, SDWA, op_sel, clamp, and omod refused.
    • v_bfi_b32: (S0 & S1) | (~S0 & S2) with 3-source uniformity tracking; DPP, SDWA, op_sel, clamp, omod, and abs/neg refused.

Verification (source-built fixtures only)

Environment: Windows 11 (26200.9974), MSVC 19.44 (C++20 /W4, zero new warnings in edited files), Ninja, Windows SDK 10.0.26100.0.

  • New tests/native_mesh_small_alu_pack_check.py + tests/cmake/native_mesh_small_alu_pack.cmake: 14 bit-exact v_pack_b32_f16 constant cases (+ neg-before-abs control), 30 v_cmpx_*_f32 cases (with 0.5 and NaN), 36 s_cmpk cases (verifying opposite extension absent), 4 s_bcnt, 3 v_min_f32, 5 v_bfi_b32, 8 uniformity cases, and 48 fail-closed refusals.
  • Updated tests/native_pack_b32_f16_check.py: moved inline float/integer and literal cases to positive bit-exact evaluated checks (269 results total) and replaced their refusal entries with high-half op_sel on constant/literal, SCC (253), and reserved 209.
  • Debug (dev) & Release (release):
    • native_direct_container: Passed (13.4 s Debug / 12.2 s Release)
    • native_direct_mesh: Passed (18.4 s Debug / 16.9 s Release)
    • native_mesh_small_alu_pack: Passed (7.0 s Debug / 6.4 s Release)
    • native_pack_b32_f16_ir: Passed (9.4 s Debug / 9.3 s Release)
  • docs_links_check.py, bidi_controls_check.py, and git diff --check origin/main..HEAD all passed.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5601586859 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3827). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T07:04:59Z. --- Part of #3703. Refs #3416, #2413. Clears two self-contained #3703 mesh census walls (~393 mesh programs total): `unsupported v_pack_b32_f16 constant source` (132 programs) and the small ALU cluster (261 programs). ### Summary 1. **`v_pack_b32_f16` constant sources (`src/gfx1013_direct_compute.inl`):** - Inline floats (`240..248`) read their binary16 encoding from `inline_half_words` (`1.0` -> `0x3c00`). - Inline integers (`128..208`) read their value truncated to 16 bits (`0` -> `0x0000`, `1` -> `0x0001`, `-1` -> `0xffff`), matching the existing `v_cvt_norm_*_f16` lowering. - Literal (`255`) reads `literal & 0xffff`. - `abs` clears bit 15, then `neg` toggles it. - Strictly refuses high-half `op_sel` on any constant source, non-constant special operands (`209..239`, `249..254`), clamp, omod, dst/src2 `op_sel`, src2 `abs`/`neg`, SDWA, and DPP. - In `src/gfx1013_direct_mesh.inl`, adds `v_pack_b32_f16` to 2-source uniformity tracking so two uniform/constant inputs produce a uniform result. 2. **Mesh small ALU cluster (`src/gfx1013_direct_mesh.inl`):** - `v_cmpx_<p>_f32`: all 14 `fcmp` predicates (ordered predicates `eq/lt/le/gt/ge/lg/o` drop NaN lanes; unordered `neq/nlt/nle/ngt/nge/nlg/u` keep them); `f`, `tru`, `class`, `abs`/`neg`, clamp, DPP, and SDWA stay refused. - `s_cmpk_{eq,lg,gt,ge,lt,le}_{i32,u32}`: sign-extends `SIMM16` for `i32` (`0xffff` -> `-1`), zero-extends for `u32` (`0x8000` -> `32768`); refuses comparing special registers (`>= 106`). - `s_bcnt0_i32_b32` / `s_bcnt1_i32_b32`: `dx.op.unaryBits.i32(31)` (on `~S0` for `bcnt0`), `SCC = (D != 0)`; refuses special-register sources (`VCC`/`EXEC`/`M0`) and `VCC`/`EXEC` destinations. - `v_min_f32`: `dx.op.binary.f32(36)` (FMin) with `abs`/`neg` sign-bit ops; DPP, SDWA, `op_sel`, clamp, and omod refused. - `v_bfi_b32`: `(S0 & S1) | (~S0 & S2)` with 3-source uniformity tracking; DPP, SDWA, `op_sel`, clamp, omod, and `abs`/`neg` refused. ### Verification (source-built fixtures only) Environment: Windows 11 (`26200.9974`), MSVC `19.44` (C++20 `/W4`, zero new warnings in edited files), Ninja, Windows SDK `10.0.26100.0`. - New `tests/native_mesh_small_alu_pack_check.py` + `tests/cmake/native_mesh_small_alu_pack.cmake`: 14 bit-exact `v_pack_b32_f16` constant cases (+ `neg`-before-`abs` control), 30 `v_cmpx_*_f32` cases (with `0.5` and NaN), 36 `s_cmpk` cases (verifying opposite extension absent), 4 `s_bcnt`, 3 `v_min_f32`, 5 `v_bfi_b32`, 8 uniformity cases, and 48 fail-closed refusals. - Updated `tests/native_pack_b32_f16_check.py`: moved inline float/integer and literal cases to positive bit-exact evaluated checks (269 results total) and replaced their refusal entries with high-half `op_sel` on constant/literal, SCC (`253`), and reserved `209`. - **Debug (`dev`) & Release (`release`):** - `native_direct_container`: Passed (13.4 s Debug / 12.2 s Release) - `native_direct_mesh`: Passed (18.4 s Debug / 16.9 s Release) - `native_mesh_small_alu_pack`: Passed (7.0 s Debug / 6.4 s Release) - `native_pack_b32_f16_ir`: Passed (9.4 s Debug / 9.3 s Release) - `docs_links_check.py`, `bidi_controls_check.py`, and `git diff --check origin/main..HEAD` all passed. AI-assisted.
lukaslw-lab commented 2026-12-02 07:30:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T07:30:01Z.

Review: APPROVED


Reviewed be88a585 by reading the diff; not built or run.

Verdict: approve. Each new form follows its RDNA2 definition, and every modifier outside it is refused. No MUST.

  • SHOULD CI did not run the new test. native_mesh_small_alu_pack is not matched by the pr preset filter. Only native_pack_b32_f16_ir and native_direct_mesh ran, so the v_cmpx, s_cmpk, s_bcnt, v_min_f32 and v_bfi_b32 checks and their refusals were run only locally. It is IR-only and needs no GPU, so adding it to the filter is cheap.
  • SHOULD The 393 figure counts first refusals, not newly translated programs. A program that stops at v_pack_b32_f16 or the small ALU group can stop at the next wall. An m86 census on f365f125 before and after would give the real gain. This can come in a follow-up.
  • Checked, no finding:
    • v_pack_b32_f16 constants (gfx1013_direct_compute.inl:2583): inline_half_words covers 240–248. The value 193 + n gives (192-r)&0xffff (-1 → 0xffff), and a literal keeps its low 16 bits. A high-half op_sel on a constant is refused, and abs before neg is unchanged from the register path.
    • float_cmpx: all 14 names map through the shared predicates table (:3730). Ordered and unordered match the ISA (neq→une, nlg→ueq, o/u). f/tru/class stay out.
    • s_cmpk_*: the shared SOPK path zero-extends _u32 and sign-extends _i32 (:4868). The mesh guard refuses S0 ≥ 106.
    • s_bcnt0/1: special-register sources are refused unless constant. VCC/EXEC destinations are refused as for the other scalar ops.
    • v_bfi_b32 abs/neg reach the shared integer refusal (:4819, "direct ALU operand modifiers"), and the fixture pins it.

Tests: native_mesh_small_alu_pack proves the IR for each form, with the opposite-extension and NaN controls and 48 refusals. native_pack_b32_f16_ir now evaluates the constant cases bit-exactly. CI ran only the latter and native_direct_mesh.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6146429830 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3827#pullrequestreview-6146429830). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T07:30:01Z. **Review:** APPROVED --- Reviewed `be88a585` by reading the diff; not built or run. **Verdict: approve.** Each new form follows its RDNA2 definition, and every modifier outside it is refused. No MUST. - **SHOULD** CI did not run the new test. `native_mesh_small_alu_pack` is not matched by the `pr` preset filter. Only `native_pack_b32_f16_ir` and `native_direct_mesh` ran, so the `v_cmpx`, `s_cmpk`, `s_bcnt`, `v_min_f32` and `v_bfi_b32` checks and their refusals were run only locally. It is IR-only and needs no GPU, so adding it to the filter is cheap. - **SHOULD** The 393 figure counts first refusals, not newly translated programs. A program that stops at `v_pack_b32_f16` or the small ALU group can stop at the next wall. An `m86` census on `f365f125` before and after would give the real gain. This can come in a follow-up. - Checked, no finding: - `v_pack_b32_f16` constants (`gfx1013_direct_compute.inl:2583`): `inline_half_words` covers 240–248. The value 193 + n gives `(192-r)&0xffff` (-1 → `0xffff`), and a literal keeps its low 16 bits. A high-half `op_sel` on a constant is refused, and `abs` before `neg` is unchanged from the register path. - `float_cmpx`: all 14 names map through the shared `predicates` table (`:3730`). Ordered and unordered match the ISA (`neq`→`une`, `nlg`→`ueq`, `o`/`u`). `f`/`tru`/`class` stay out. - `s_cmpk_*`: the shared SOPK path zero-extends `_u32` and sign-extends `_i32` (`:4868`). The mesh guard refuses S0 ≥ 106. - `s_bcnt0/1`: special-register sources are refused unless constant. VCC/EXEC destinations are refused as for the other scalar ops. - `v_bfi_b32` `abs`/`neg` reach the shared integer refusal (`:4819`, "direct ALU operand modifiers"), and the fixture pins it. Tests: `native_mesh_small_alu_pack` proves the IR for each form, with the opposite-extension and NaN controls and 48 refusals. `native_pack_b32_f16_ir` now evaluates the constant cases bit-exactly. CI ran only the latter and `native_direct_mesh`.
timbot103 commented 2026-12-02 07:34:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T07:34:51Z.


@lukaslw-lab Thanks for the review! Renamed native_mesh_small_alu_pack to native_mesh_small_alu_pack_ir in 287e321d so it matches the existing native_.*_(ir|dxil|controls) filter in CMakePresets.json's pr preset without editing CMakePresets.json. Verified ctest --preset pr --no-tests=error -R '^native_mesh_small_alu_pack_ir$' passes (6.61 s Debug, 6.03 s Release).

Re: census counts — understood, keeping this PR source-fixture-only; a follow-up census against f365f125 can measure the exact net m86 gain.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7338355261 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3827#issuecomment-7338355261). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T07:34:51Z. --- @lukaslw-lab Thanks for the review! Renamed `native_mesh_small_alu_pack` to `native_mesh_small_alu_pack_ir` in `287e321d` so it matches the existing `native_.*_(ir|dxil|controls)` filter in `CMakePresets.json`'s `pr` preset without editing `CMakePresets.json`. Verified `ctest --preset pr --no-tests=error -R '^native_mesh_small_alu_pack_ir$'` passes (6.61 s Debug, 6.03 s Release). Re: census counts — understood, keeping this PR source-fixture-only; a follow-up census against `f365f125` can measure the exact net `m86` gain.
lukaslw-lab commented 2026-12-02 07:37:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T07:37:15Z.

Review: APPROVED


Reviewed 287e321d by reading the diff; not built or run.

Verdict: approve. The new commit closes the CI-coverage SHOULD. No MUST.

  • 287e321d only renames the test to native_mesh_small_alu_pack_ir in the CMake file and the docs. The new name matches the pr preset's native_.*_(ir|…) filter, so Windows CI now runs it. I checked the filter at this head.
  • src/ and the test scripts are byte-identical to be88a585, so the findings of the previous pass stand: the constants, the 14 predicates, the s_cmpk extension and the modifier refusals.
  • The census follow-up is still open, as the author noted. It does not block.

Tests: CI for this head was still running at review time.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6146505556 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3827#pullrequestreview-6146505556). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T07:37:15Z. **Review:** APPROVED --- Reviewed `287e321d` by reading the diff; not built or run. **Verdict: approve.** The new commit closes the CI-coverage SHOULD. No MUST. - `287e321d` only renames the test to `native_mesh_small_alu_pack_ir` in the CMake file and the docs. The new name matches the `pr` preset's `native_.*_(ir|…)` filter, so Windows CI now runs it. I checked the filter at this head. - `src/` and the test scripts are byte-identical to `be88a585`, so the findings of the previous pass stand: the constants, the 14 predicates, the `s_cmpk` extension and the modifier refusals. - The census follow-up is still open, as the author noted. It does not block. Tests: CI for this head was still running at review time.
R0Y00 commented 2026-12-02 10:09:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T10:09:41Z.

Review: COMMENTED


The reviewed revision is green, but the current merge conflicts in src/gfx1013_direct_mesh.inl at the VALU dispatch. Please retain main's vector_exec gating and existing v_trunc_f32/v_floor_f32 path while adding the min/bitfield/FP16 shapes. Please run native_mesh_small_alu_pack_ir and native_direct_mesh on the rebased head, and retain the renamed CI test registration.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6148735776 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3827#pullrequestreview-6148735776). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T10:09:41Z. **Review:** COMMENTED --- The reviewed revision is green, but the current merge conflicts in `src/gfx1013_direct_mesh.inl` at the VALU dispatch. Please retain main's `vector_exec` gating and existing `v_trunc_f32`/`v_floor_f32` path while adding the min/bitfield/FP16 shapes. Please run `native_mesh_small_alu_pack_ir` and `native_direct_mesh` on the rebased head, and retain the renamed CI test registration.
R0Y00 commented 2026-12-02 12:47:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T12:47:22Z.

Review: APPROVED


I checked the rebase at c1adc4dd. It keeps main's vector_exec condition and the existing truncation, floor and literal-FMA dispatch while adding the new operands and arity. The renamed IR test is registered and ran in the hosted Windows job. The trial merge is clean.

On Windows 11 26300.9974 and SDK/DXC 10.0.26100 in Debug, I built compile_dxil and native_pixel_ir_dump, then ran ctest --preset dev --no-tests=error -j 1 -V -R '^native_(pack_b32_f16_ir|mesh_small_alu_pack_ir)$'. Both passed. The pack check matched 269 results and rejected the swapped-half and neg-before-abs variants. The small ALU check also passed its 48 refusal controls.

native_direct_mesh independently reproduced the only failing hosted Windows case, +0x34: unmapped graphics export, which #3851 fixes. Please rerun required CI after that fix lands.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6151004951 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3827#pullrequestreview-6151004951). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T12:47:22Z. **Review:** APPROVED --- I checked the rebase at `c1adc4dd`. It keeps main's `vector_exec` condition and the existing truncation, floor and literal-FMA dispatch while adding the new operands and arity. The renamed IR test is registered and ran in the hosted Windows job. The trial merge is clean. On Windows 11 26300.9974 and SDK/DXC 10.0.26100 in Debug, I built `compile_dxil` and `native_pixel_ir_dump`, then ran `ctest --preset dev --no-tests=error -j 1 -V -R '^native_(pack_b32_f16_ir|mesh_small_alu_pack_ir)$'`. Both passed. The pack check matched 269 results and rejected the swapped-half and neg-before-abs variants. The small ALU check also passed its 48 refusal controls. `native_direct_mesh` independently reproduced the only failing hosted Windows case, `+0x34: unmapped graphics export`, which #3851 fixes. Please rerun required CI after that fix lands.
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!3827
No description provided.