shader: lower v_cvt_pknorm_i16_f32 and v_cvt_pknorm_u16_f32 in direct DXIL #3295

Merged
legacy-code-archaeologist merged 2 commits from upstream-pr/3295 into main 2026-11-28 06:43:22 +00:00
legacy-code-archaeologist commented 2026-11-28 05:50:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-28T05:50:35Z.


Fixes #3294, Refs #2935.

Summary

  • Lowers VOP3 v_cvt_pknorm_i16_f32 (0x368) and v_cvt_pknorm_u16_f32 (0x369) in DirectCompute::float_alu() (src/gfx1013_direct_compute.inl) for both direct Compute and Pixel DXIL, packing cvt_norm(S0.f32) into D[15:0] and cvt_norm(S1.f32) into D[31:16].
  • Evaluates round_rne(clamp(x, -1, 1) * 32767) (i16) and round_rne(clamp(x, 0, 1) * 65535) (u16) in exact pure-32-bit unsigned integer arithmetic (m * (2^k - 1) computed as (m << k) - m split cleanly at bit k), avoiding desktop floating-point rounding/FTZ differences and i64 types.
  • Maps NaN (|x| > 0x7f800000) and tiny magnitudes (< 2^-17, zeros and binary32 subnormals) to 0, saturates |x| >= 1.0 (±Inf included), supports VOP3 abs[1:0] / neg[1:0] and VGPR / SGPR / literal / inline sources via operand32(), and keeps clamp, omod, op_sel, third-operand abs/neg, nonzero src2, and DPP/SDWA refused.
  • Adds tests/native_cvt_pknorm_f32_check.py, tests/cmake/native_cvt_pknorm_f32.cmake, and docs/experiments/native-cvt-pknorm-f32.md (26 cases, 8 refusals across Compute IR/DXIL/lossless 16-bit Pixel readbacks + SM 6.6 wave32 Compute replay).

Verification

All checks passed on Windows 11 with SDK 10.0.26100.0 (dev and release /O2 presets):

  • python -B tests/docs_links_check.py: passed (145 Markdown files, 663 links)
  • ctest --preset dev & ctest --preset release (-R '^(native_cvt_pknorm_f32_|native_cvt_pk16_controls|native_cvt_pk_u8_controls|native_f16_alu_ir)'): 7 passed, 1 skipped in each preset:
    • native_cvt_pknorm_f32_ir (26 cases, 8 refusals) & native_cvt_pknorm_f32_controls (26 cases compiled, 8 refusals): passed
    • native_cvt_pknorm_f32_pixel_warp (Microsoft Basic Render Driver, 13 draws / 26 cases) & native_cvt_pknorm_f32_pixel_hardware (NVIDIA Quadro M1000M driver 32.0.15.7371, debug_layer=unavailable, 13 draws / 26 cases): passed
    • native_cvt_pk16_controls, native_cvt_pk_u8_controls, and native_f16_alu_ir (435 results, 39 refusals): passed
    • native_cvt_pknorm_f32_compute_hardware: skipped (77 on local Intel HD Graphics 530 31.0.101.2111 lacking SM 6.6 wave32)
  • Sensitivity mutants on dev (native_cvt_pknorm_f32_ir): dropping round_up failed on 8+ halfway/tie cases; dropping is_nan failed at slots 12–13 (i16_nans, u16_nans); dropping p_lo != 0 failed on exact carry-over tie witnesses (u16_p_lo_tie_witness 0x8000 != 0x8001, i16_p_lo_tie_witness 0xc0004000 != 0xbfff4001, and u16_sgpr_literal).

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5537213298 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3295). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-28T05:50:35Z. --- Fixes #3294, Refs #2935. ## Summary - Lowers VOP3 `v_cvt_pknorm_i16_f32` (`0x368`) and `v_cvt_pknorm_u16_f32` (`0x369`) in `DirectCompute::float_alu()` (`src/gfx1013_direct_compute.inl`) for both direct Compute and Pixel DXIL, packing `cvt_norm(S0.f32)` into `D[15:0]` and `cvt_norm(S1.f32)` into `D[31:16]`. - Evaluates `round_rne(clamp(x, -1, 1) * 32767)` (`i16`) and `round_rne(clamp(x, 0, 1) * 65535)` (`u16`) in exact pure-32-bit unsigned integer arithmetic (`m * (2^k - 1)` computed as `(m << k) - m` split cleanly at bit `k`), avoiding desktop floating-point rounding/FTZ differences and `i64` types. - Maps NaN (`|x| > 0x7f800000`) and tiny magnitudes (`< 2^-17`, zeros and binary32 subnormals) to `0`, saturates `|x| >= 1.0` (`±Inf` included), supports VOP3 `abs[1:0]` / `neg[1:0]` and VGPR / SGPR / literal / inline sources via `operand32()`, and keeps `clamp`, `omod`, `op_sel`, third-operand `abs`/`neg`, nonzero `src2`, and DPP/SDWA refused. - Adds `tests/native_cvt_pknorm_f32_check.py`, `tests/cmake/native_cvt_pknorm_f32.cmake`, and `docs/experiments/native-cvt-pknorm-f32.md` (`26` cases, `8` refusals across Compute IR/DXIL/lossless 16-bit Pixel readbacks + SM 6.6 wave32 Compute replay). ## Verification All checks passed on Windows 11 with SDK `10.0.26100.0` (`dev` and `release` `/O2` presets): - `python -B tests/docs_links_check.py`: passed (`145` Markdown files, `663` links) - `ctest --preset dev` & `ctest --preset release` (`-R '^(native_cvt_pknorm_f32_|native_cvt_pk16_controls|native_cvt_pk_u8_controls|native_f16_alu_ir)'`): `7` passed, `1` skipped in each preset: - `native_cvt_pknorm_f32_ir` (`26` cases, `8` refusals) & `native_cvt_pknorm_f32_controls` (`26` cases compiled, `8` refusals): passed - `native_cvt_pknorm_f32_pixel_warp` (Microsoft Basic Render Driver, `13` draws / `26` cases) & `native_cvt_pknorm_f32_pixel_hardware` (NVIDIA Quadro M1000M driver `32.0.15.7371`, `debug_layer=unavailable`, `13` draws / `26` cases): passed - `native_cvt_pk16_controls`, `native_cvt_pk_u8_controls`, and `native_f16_alu_ir` (`435` results, `39` refusals): passed - `native_cvt_pknorm_f32_compute_hardware`: skipped (`77` on local Intel HD Graphics 530 `31.0.101.2111` lacking SM 6.6 wave32) - Sensitivity mutants on `dev` (`native_cvt_pknorm_f32_ir`): dropping `round_up` failed on `8+` halfway/tie cases; dropping `is_nan` failed at slots `12`–`13` (`i16_nans`, `u16_nans`); dropping `p_lo != 0` failed on exact carry-over tie witnesses (`u16_p_lo_tie_witness` `0x8000 != 0x8001`, `i16_p_lo_tie_witness` `0xc0004000 != 0xbfff4001`, and `u16_sgpr_literal`). AI-assisted.
Leyukaka commented 2026-11-28 06:09:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-28T06:09:07Z.


I reviewed the diff (not run). The lowering applies one rounding to the exact product clamp(x) * 32767 or * 65535. It is consistent with the model it states, and I found nothing wrong within that model. Two notes on the model and the fixture:

  • The model is not measured. v_cvt_pk_u8_f32 has an RDNA2 hardware probe in the repository (tools/rdna_cvt_pk_u8.py, tests/data/rdna_cvt_pk_u8_measured.tsv). I found none for v_cvt_pknorm_{i16,u16}_f32. A single rounding of the exact product and a binary32 multiply followed by round-to-nearest-even differ by one on some inputs. Also, docs/experiments.md on main still says these float packs "stay unsupported: no public source found here states their rounding, their bounds or their NaN result". The PR neither updates that sentence nor cites a source.

    Inputs where the two models differ:

    Op Input Exact, one rounding binary32 multiply, then RNE
    i16 0x3F000400 16385 16386 (the product rounds to 16385.5)
    i16 0x38400180 1 2
    u16 0x3F000200 32769 32770
    u16 0x37C000C0 1 2
  • The fixture does not separate the two. Every case in all_cases() gives the same result under both, so a binary32-multiply lowering would pass. The inputs above would pin the choice. A measurement like the v_cvt_pk_u8_f32 probe would show what RDNA2 does.

A small one: the comment on i16_p_lo_tie_witness says 16384.50389, but 0x3F000201 * 32767 is about 16384.50192. The .50389 belongs to the u16 case above it. The expected 16385 is right either way.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7235112805 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3295#issuecomment-7235112805). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-28T06:09:07Z. --- I reviewed the diff (not run). The lowering applies one rounding to the exact product `clamp(x) * 32767` or `* 65535`. It is consistent with the model it states, and I found nothing wrong within that model. Two notes on the model and the fixture: - **The model is not measured.** `v_cvt_pk_u8_f32` has an RDNA2 hardware probe in the repository (`tools/rdna_cvt_pk_u8.py`, `tests/data/rdna_cvt_pk_u8_measured.tsv`). I found none for `v_cvt_pknorm_{i16,u16}_f32`. A single rounding of the exact product and a binary32 multiply followed by round-to-nearest-even differ by one on some inputs. Also, `docs/experiments.md` on `main` still says these float packs "stay unsupported: no public source found here states their rounding, their bounds or their NaN result". The PR neither updates that sentence nor cites a source. Inputs where the two models differ: | Op | Input | Exact, one rounding | binary32 multiply, then RNE | |---|---|---|---| | i16 | `0x3F000400` | 16385 | 16386 (the product rounds to 16385.5) | | i16 | `0x38400180` | 1 | 2 | | u16 | `0x3F000200` | 32769 | 32770 | | u16 | `0x37C000C0` | 1 | 2 | - **The fixture does not separate the two.** Every case in `all_cases()` gives the same result under both, so a binary32-multiply lowering would pass. The inputs above would pin the choice. A measurement like the `v_cvt_pk_u8_f32` probe would show what RDNA2 does. A small one: the comment on `i16_p_lo_tie_witness` says `16384.50389`, but `0x3F000201 * 32767` is about 16384.50192. The `.50389` belongs to the u16 case above it. The expected `16385` is right either way. AI-assisted.
legacy-code-archaeologist commented 2026-11-28 06:13:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-28T06:13:10Z.


Thanks @Leyukaka for the thorough review and the four separating inputs! Updated in commit $(git rev-parse --short HEAD):

  1. Separating fixture cases (tests/native_cvt_pknorm_f32_check.py):
    • Added i16_single_round_sep (0x3F000400, 0x38400180 -> 16385, 1 under single-rounding exact product vs 16386, 2 under binary32-multiply-then-RNE) and u16_single_round_sep (0x3F000200, 0x37C000C0 -> 32769, 1 vs 32770, 2), bringing the suite from 26 to 28 cases (14 Pixel draws).
    • Added cvt_norm_f32_half_mul_f32_oracle() + check_oracle_separation() so both ir and controls verify those four inputs separate single-rounding exact multiplication from binary32-multiply-then-RNE.
    • Fixed the i16_p_lo_tie_witness comment (16384.50192 instead of 16384.50389).
  2. Unmeasured RDNA 2 status (docs/experiments/native-cvt-pknorm-f32.md, docs/experiments.md):
    • Updated both docs to state explicitly that v_cvt_pknorm_i16_f32 and v_cvt_pknorm_u16_f32 are not yet measured on physical RDNA 2 hardware (unlike v_cvt_pk_u8_f32 / tools/rdna_cvt_pk_u8.py) and that the direct DXIL lowering implements single-rounding RNE of clamp(x) * 32767 / * 65535 with NaN -> 0.

Re-verified on dev and release: native_cvt_pknorm_f32_ir (28 cases, 8 refusals), native_cvt_pknorm_f32_controls (28 cases, 8 refusals), native_cvt_pknorm_f32_pixel_warp (14 draws / 28 cases), and native_cvt_pknorm_f32_pixel_hardware (14 draws / 28 cases on NVIDIA Quadro M1000M 32.0.15.7371, debug_layer=unavailable) all passed; native_cvt_pknorm_f32_compute_hardware skipped (77 on local Intel HD Graphics 530 31.0.101.2111 lacking SM 6.6 wave32). python -B tests/docs_links_check.py passed (145 Markdown files, 664 links).

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7235155400 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3295#issuecomment-7235155400). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-28T06:13:10Z. --- Thanks @Leyukaka for the thorough review and the four separating inputs! Updated in commit `$(git rev-parse --short HEAD)`: 1. **Separating fixture cases (`tests/native_cvt_pknorm_f32_check.py`):** - Added `i16_single_round_sep` (`0x3F000400`, `0x38400180` -> `16385`, `1` under single-rounding exact product vs `16386`, `2` under binary32-multiply-then-RNE) and `u16_single_round_sep` (`0x3F000200`, `0x37C000C0` -> `32769`, `1` vs `32770`, `2`), bringing the suite from 26 to 28 cases (14 Pixel draws). - Added `cvt_norm_f32_half_mul_f32_oracle()` + `check_oracle_separation()` so both `ir` and `controls` verify those four inputs separate single-rounding exact multiplication from binary32-multiply-then-RNE. - Fixed the `i16_p_lo_tie_witness` comment (`16384.50192` instead of `16384.50389`). 2. **Unmeasured RDNA 2 status (`docs/experiments/native-cvt-pknorm-f32.md`, `docs/experiments.md`):** - Updated both docs to state explicitly that `v_cvt_pknorm_i16_f32` and `v_cvt_pknorm_u16_f32` are not yet measured on physical RDNA 2 hardware (unlike `v_cvt_pk_u8_f32` / `tools/rdna_cvt_pk_u8.py`) and that the direct DXIL lowering implements single-rounding RNE of `clamp(x) * 32767` / `* 65535` with `NaN -> 0`. Re-verified on `dev` and `release`: `native_cvt_pknorm_f32_ir` (`28` cases, `8` refusals), `native_cvt_pknorm_f32_controls` (`28` cases, `8` refusals), `native_cvt_pknorm_f32_pixel_warp` (`14` draws / `28` cases), and `native_cvt_pknorm_f32_pixel_hardware` (`14` draws / `28` cases on NVIDIA Quadro M1000M `32.0.15.7371`, `debug_layer=unavailable`) all passed; `native_cvt_pknorm_f32_compute_hardware` skipped (`77` on local Intel HD Graphics 530 `31.0.101.2111` lacking SM 6.6 wave32). `python -B tests/docs_links_check.py` passed (`145` Markdown files, `664` links). AI-assisted.
R0Y00 commented 2026-11-28 06:43:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-28T06:43:12Z.

Review: APPROVED


Independent Release check on 8efe14fa: ctest --preset release --no-tests=error --output-on-failure -j 1 -R '^native_cvt_pknorm_f32_' passed 5/5 with zero skips. That includes the four rounding-model witnesses, refusal controls, physical wave32 Compute and WARP and physical Pixel readback. Windows 11 build 26200, DXC 10.0.26100 and RTX 4060 Laptop driver 32.0.16.1656. The split product and tie-to-even selection implement the single-rounding model specified by #3294. The new documentation correctly keeps the source-built desktop verification separate from the still-unmeasured RDNA 2 behavior.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6096319046 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3295#pullrequestreview-6096319046). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-28T06:43:12Z. **Review:** APPROVED --- Independent Release check on `8efe14fa`: `ctest --preset release --no-tests=error --output-on-failure -j 1 -R '^native_cvt_pknorm_f32_'` passed 5/5 with zero skips. That includes the four rounding-model witnesses, refusal controls, physical wave32 Compute and WARP and physical Pixel readback. Windows 11 build 26200, DXC 10.0.26100 and RTX 4060 Laptop driver 32.0.16.1656. The split product and tie-to-even selection implement the single-rounding model specified by #3294. The new documentation correctly keeps the source-built desktop verification separate from the still-unmeasured RDNA 2 behavior.
JohnConnorNPC commented 2026-11-28 06:51:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-28T06:51:25Z.


Thanks for this change. This is a post-merge review of 8efe14fa (merged as 945350ac). The arithmetic is exact for the model you stated. There are two follow-ups and three small notes; the code for all of them is unchanged on current main.

What I measured: a C transcription of the new float_alu block, compared with an independent 64-bit exact-product RNE oracle over all 2^32 inputs per op. Result: u16: lane!=exact 0, i16: lane!=exact 0. This covers my transcription, not the built IR; I did not run ctest here.

  1. The abs/neg lane index and the abs-then-neg order are unpinned. Two mutants: the modifier bit read as 1u << (1 - j), and neg applied before abs. Evaluated against all_cases()/expected(), both give (case,lane) results differing from expected over 32 lanes = 0. No case sets abs and neg on one lane, and u16_abs_neg_mix uses -0.5 in both lanes, so swapping the lanes leaves it unchanged. One added case kills both mutants: Case('i16_abs_neg_same_lane', 'i16', (257, 258), (0x3F000000, 0x3E800000), abs_=0b01, neg=0b01) expects 0x2000c000. The lane-reversed mutant gives 0xe0004000 and neg-then-abs gives 0x20004000.
  2. No source is cited for the rounding model. The docs keep the model separate from the unmeasured RDNA 2 behavior, which is good. But before this PR, main kept these packs unsupported because "no public source found here states their rounding, their bounds or their NaN result". Single rounding, -1 -> -32767 and NaN -> 0 still have no citation. Over all 2^32 inputs, a binary32 multiply followed by RNE differs from single rounding on 32640 (u16) and 32256 (i16) bit patterns. The fixture now pins single rounding. A public source, or an RDNA 2 probe like tools/rdna_cvt_pk_u8.py, would show whether that pin is right.

Small notes:

  • The PR body still reports 26 cases and 13 draws; the merged fixture has 28 cases and 14 draws.
  • The reply says "Updated in commit $(git rev-parse --short HEAD)". The substitution was not expanded, so the reply has no commit id.
  • tests/cmake/native_cvt_pknorm_f32.cmake uses $<TARGET_FILE:native_compute_ir_dump>. That target is defined in native_f16_alu.cmake, which the sorted glob includes later. This works today because your guard implies that file's guard. Adding a TARGET native_compute_ir_dump check to this fragment would silently drop all five tests.

This comment was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7235560558 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3295#issuecomment-7235560558). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-28T06:51:25Z. --- Thanks for this change. This is a post-merge review of `8efe14fa` (merged as `945350ac`). The arithmetic is exact for the model you stated. There are two follow-ups and three small notes; the code for all of them is unchanged on current main. **What I measured:** a C transcription of the new `float_alu` block, compared with an independent 64-bit exact-product RNE oracle over all 2^32 inputs per op. Result: `u16: lane!=exact 0`, `i16: lane!=exact 0`. This covers my transcription, not the built IR; I did not run ctest here. 1. **The abs/neg lane index and the abs-then-neg order are unpinned.** Two mutants: the modifier bit read as `1u << (1 - j)`, and neg applied before abs. Evaluated against `all_cases()`/`expected()`, both give `(case,lane) results differing from expected over 32 lanes = 0`. No case sets abs and neg on one lane, and `u16_abs_neg_mix` uses -0.5 in both lanes, so swapping the lanes leaves it unchanged. One added case kills both mutants: `Case('i16_abs_neg_same_lane', 'i16', (257, 258), (0x3F000000, 0x3E800000), abs_=0b01, neg=0b01)` expects `0x2000c000`. The lane-reversed mutant gives `0xe0004000` and neg-then-abs gives `0x20004000`. 2. **No source is cited for the rounding model.** The docs keep the model separate from the unmeasured RDNA 2 behavior, which is good. But before this PR, main kept these packs unsupported because "no public source found here states their rounding, their bounds or their NaN result". Single rounding, `-1 -> -32767` and `NaN -> 0` still have no citation. Over all 2^32 inputs, a binary32 multiply followed by RNE differs from single rounding on 32640 (u16) and 32256 (i16) bit patterns. The fixture now pins single rounding. A public source, or an RDNA 2 probe like `tools/rdna_cvt_pk_u8.py`, would show whether that pin is right. Small notes: - The PR body still reports `26` cases and `13` draws; the merged fixture has 28 cases and 14 draws. - The reply says "Updated in commit `$(git rev-parse --short HEAD)`". The substitution was not expanded, so the reply has no commit id. - `tests/cmake/native_cvt_pknorm_f32.cmake` uses `$<TARGET_FILE:native_compute_ir_dump>`. That target is defined in `native_f16_alu.cmake`, which the sorted glob includes later. This works today because your guard implies that file's guard. Adding a `TARGET native_compute_ir_dump` check to this fragment would silently drop all five tests. This comment was AI-assisted.
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!3295
No description provided.