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

Open
github-bot wants to merge 3 commits from github-bot/gh-3827 into main AGit
Owner

@⁠timbot103 on GitHub · 2026-12-02 07:04 UTC · original
timbot103:shader/mesh-small-alu-and-pack-f16 → main · +603 −23 · 6 files · 3 commits · open

Part of #3705. Refs #3418, #2413.

Clears two self-contained #3705 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.

**@⁠timbot103** on GitHub · 2026-12-02 07:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3827) `timbot103:shader/mesh-small-alu-and-pack-f16` → `main` · +603 −23 · 6 files · 3 commits · open Part of #3705. Refs #3418, #2413. Clears two self-contained #3705 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.
Part of #3703. Refs #3416, #2413.

v_pack_b32_f16 (shared direct ALU): a constant source is now a binary16
operand. An inline float (240-248) reads its binary16 encoding, an inline
integer (128-208) its value truncated to 16 bits and a literal its low 16
bits. abs clears bit 15, then neg toggles it. A high-half op_sel on a
constant, the non-constant special operands (209-239, 249-254), clamp,
omod, destination/src2 op_sel, src2 abs/neg, SDWA and DPP stay refused.
In mesh, a v_pack_b32_f16 result from two uniform sources is now uniform.

Mesh dispatch now routes to the shared lowering:
- v_cmpx_<p>_f32 for the 14 fcmp predicates (ordered ones drop a NaN
  lane, unordered ones keep it); f, tru, class and modifiers refused.
- s_cmpk_{eq,lg,gt,ge,lt,le}_{i32,u32}: SIMM16 sign-extended for i32 and
  zero-extended for u32; a special compared register is refused.
- s_bcnt0/1_i32_b32 with SCC = (D != 0); VCC/EXEC/M0 sources refused.
- v_min_f32 (FMin) and v_bfi_b32; DPP, SDWA, op_sel, clamp and omod
  refused (v_bfi_b32 abs/neg by the shared ALU).

tests/native_mesh_small_alu_pack_check.py adds IR checks, bit-exact
evaluations, uniformity cases and 48 refusals. native_pack_b32_f16_ir's
refusal list asserted the inline float, inline integer and literal forms;
they are now positive evaluated cases, and the refusals cover a high-half
op_sel on a constant, SCC and a reserved operand instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 07:05:32 +00:00
Matches the existing `native_.*_(ir|dxil|controls)` filter in the `pr`
CTest preset so CI executes the IR-only mesh small ALU and
v_pack_b32_f16 constant checks without modifying CMakePresets.json.

Part of #3703
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-02 07:30 UTC · original · approved these changes

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.

**@⁠lukaslw-lab** on GitHub · 2026-12-02 07:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3827#pullrequestreview-6146429830) · **approved these changes** 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`.
Author
Owner

@⁠timbot103 on GitHub · 2026-12-02 07:34 UTC · original

@⁠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.

**@⁠timbot103** on GitHub · 2026-12-02 07:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3827#issuecomment-7338355261) @⁠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.
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-02 07:37 UTC · original · approved these changes

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.

**@⁠lukaslw-lab** on GitHub · 2026-12-02 07:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3827#pullrequestreview-6146505556) · **approved these changes** 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.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 10:09 UTC · original · reviewed

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** on GitHub · 2026-12-02 10:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3827#pullrequestreview-6148735776) · **reviewed** 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.
Resolve merge conflict in src/gfx1013_direct_mesh.inl against #3806
(retaining vector_exec gating and the existing v_trunc_f32/v_floor_f32
path alongside v_min_f32/v_bfi_b32 operand modifier checks and lowering,
while preserving #3841 and #3792 changes).
github-bot force-pushed github-bot/gh-3827 from d90685c232 to c1adc4ddc5 2026-12-02 12:37:44 +00:00 Compare
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 12:47 UTC · original · approved these changes

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 #3853 fixes. Please rerun required CI after that fix lands.

**@⁠R0Y00** on GitHub · 2026-12-02 12:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3827#pullrequestreview-6151004951) · **approved these changes** 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 #3853 fixes. Please rerun required CI after that fix lands.
This pull request has changes conflicting with the target branch.
  • src/gfx1013_direct_mesh.inl
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3829/head:github-bot/gh-3827'
git switch 'github-bot/gh-3827'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3827'
git switch 'github-bot/gh-3827'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3827'
git switch 'github-bot/gh-3827'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3827'
git switch 'main'
git merge --squash 'github-bot/gh-3827'
git switch 'main'
git merge --ff-only 'github-bot/gh-3827'
git switch 'main'
git merge 'github-bot/gh-3827'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.