compute: accept clamp on SDWA v_cvt_f32_f16 #3203

Merged
Leyukaka merged 1 commit from upstream-pr/3203 into main 2026-11-28 01:22:52 +00:00
Leyukaka commented 2026-11-27 21:35:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-27T21:35:47Z.


Fixes #3182. Part of #2935. Target branch main.

Change (src/gfx1013_compute_native.cpp, src/gfx1013_direct_compute.inl): the SDWA form of v_cvt_f32_f16 accepts clamp in direct compute.

  • The converted f32 is clamped with the integer test v_ldexp uses: a set sign bit or NaN gives +0, and values above 1.0 give 1.0.
  • dx.op saturate is not used, because it may keep -0 or flush a denormal depending on the float mode.
  • The direct VOP3 form, omod and sign-extended sources stay refused. SDWA abs/neg source modifiers are accepted, as before.

Tests. The setup was Windows 11 build 26300.9974 with an NVIDIA GeForce RTX 5080 (driver 32.0.16.2101) and DXC from the Windows SDK 10.0.26100, on main 5b145ca9 plus this commit (8e594dce).

  • native_sdwa_f16_hardware reads back the clamped conversion from both halves (WORD_0 and WORD_1), against a CPU reference. The inputs are negative, above-one, NaN, -0.0, denormal and in-range values.
  • native_sdwa_f16_ir, native_f16_alu* and native_direct_container pass.
  • Mutation check, run by hand: dropping the low clamp (sign bit or NaN to +0) fails native_sdwa_f16_hardware.

Measured on a local capture (counts and instruction shape only) with compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests, baseline main 6057071b. The change was measured on a5dad843; the commits in between do not touch the two native source files.

  • 3 of 2,689 requests stopped first at "unsupported SDWA destination modifier", all v_cvt_f32_f16_sdwa ... clamp dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1.
  • All 3 now pass it. 2 stop at "numeric SCC from a symbolic descriptor field" and 1 at "unbound numeric SGPR".
  • The compiled count does not change, and no request that compiled before stops compiling.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5533380195 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3203). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-27T21:35:47Z. --- Fixes #3182. Part of #2935. Target branch `main`. **Change** (`src/gfx1013_compute_native.cpp`, `src/gfx1013_direct_compute.inl`): the SDWA form of `v_cvt_f32_f16` accepts clamp in direct compute. - The converted f32 is clamped with the integer test `v_ldexp` uses: a set sign bit or NaN gives +0, and values above 1.0 give 1.0. - `dx.op` saturate is not used, because it may keep -0 or flush a denormal depending on the float mode. - The direct VOP3 form, omod and sign-extended sources stay refused. SDWA abs/neg source modifiers are accepted, as before. **Tests.** The setup was Windows 11 build 26300.9974 with an NVIDIA GeForce RTX 5080 (driver 32.0.16.2101) and DXC from the Windows SDK 10.0.26100, on `main` `5b145ca9` plus this commit (`8e594dce`). - `native_sdwa_f16_hardware` reads back the clamped conversion from both halves (WORD_0 and WORD_1), against a CPU reference. The inputs are negative, above-one, NaN, -0.0, denormal and in-range values. - `native_sdwa_f16_ir`, `native_f16_alu*` and `native_direct_container` pass. - Mutation check, run by hand: dropping the low clamp (sign bit or NaN to +0) fails `native_sdwa_f16_hardware`. **Measured on a local capture** (counts and instruction shape only) with `compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests`, baseline `main` `6057071b`. The change was measured on `a5dad843`; the commits in between do not touch the two native source files. - 3 of 2,689 requests stopped first at "unsupported SDWA destination modifier", all `v_cvt_f32_f16_sdwa ... clamp dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1`. - All 3 now pass it. 2 stop at "numeric SCC from a symbolic descriptor field" and 1 at "unbound numeric SGPR". - The compiled count does not change, and no request that compiled before stops compiling. AI-assisted.
pigalot commented 2026-11-27 22:15:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T22:15:17Z.


I tried to review 8e594dce over main e582a9a4, but the trial merge conflicts in tests/native_sdwa_f16_check.py. On the main side the conflicting change comes from 0e6ed41e (#3201, SDWA v_cvt_pkrtz_f16_f32 and v_add_co_ci_u32), which landed after this branch's base 5b145ca9. The other three files merge cleanly.

git fetch origin main "pull/3203/head:review/3203"
git merge-tree --write-tree --name-only origin/main review/3203

Could you merge or rebase onto current main and keep both sets of cases in the test? I'll review the new head after that. I haven't built or run anything at 8e594dce yet, so this isn't a verdict on the change.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7229164523 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3203#issuecomment-7229164523). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-27T22:15:17Z. --- I tried to review `8e594dce` over `main` `e582a9a4`, but the trial merge conflicts in `tests/native_sdwa_f16_check.py`. On the `main` side the conflicting change comes from `0e6ed41e` (#3201, SDWA `v_cvt_pkrtz_f16_f32` and `v_add_co_ci_u32`), which landed after this branch's base `5b145ca9`. The other three files merge cleanly. ```powershell git fetch origin main "pull/3203/head:review/3203" git merge-tree --write-tree --name-only origin/main review/3203 ``` Could you merge or rebase onto current `main` and keep both sets of cases in the test? I'll review the new head after that. I haven't built or run anything at `8e594dce` yet, so this isn't a verdict on the change. This reply was AI-assisted.
KelboLive commented 2026-11-27 23:44:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T23:44:28Z.

Review: APPROVED


Review of PR #3203 — compute: accept clamp on SDWA v_cvt_f16_f32

Summary

This PR adds support for the clamp modifier on v_cvt_f32_f16_sdwa in the direct compute path. Clamp converts values to binary16 with saturation (NaN, negative, -0 → +0; values > 1.0 → 1.0).

Changes reviewed

  • src/gfx1013_compute_native.cpp: Allows clamp-only (not scale) for v_cvt_f32_f16 SDWA — distinguishes between the two destination modifiers.
  • src/gfx1013_direct_compute.inl: Implements integer clamp semantics using bit-level operations: NaN/negative/-0 → +0 via sign-bit-or comparison, values > 1.0 → 1.0 via magnitude comparison.
  • Tests: New ClampCase class with comprehensive test cases covering -1, 2, quiet NaN, -0, smallest positive subnormal, 0.5, and 1 for both WORD_0 and WORD_1 selectors, plus refusal tests for invalid dst_mod combinations.

Assessment

The implementation is correct:

  • The clamp logic matches RDNA2's integer clamp behavior (not floating-point saturate).
  • The bit-level operations are efficient and avoid expensive float conversions.
  • Test coverage includes edge cases that would expose incorrect implementations (NaN, -0, subnormal).

Verdict: Approve

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6094381538 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3203#pullrequestreview-6094381538). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-27T23:44:28Z. **Review:** APPROVED --- ## Review of PR #3203 — compute: accept clamp on SDWA v_cvt_f16_f32 ### Summary This PR adds support for the clamp modifier on `v_cvt_f32_f16_sdwa` in the direct compute path. Clamp converts values to binary16 with saturation (NaN, negative, -0 → +0; values > 1.0 → 1.0). ### Changes reviewed - **`src/gfx1013_compute_native.cpp`**: Allows clamp-only (not scale) for `v_cvt_f32_f16` SDWA — distinguishes between the two destination modifiers. - **`src/gfx1013_direct_compute.inl`**: Implements integer clamp semantics using bit-level operations: NaN/negative/-0 → +0 via sign-bit-or comparison, values > 1.0 → 1.0 via magnitude comparison. - **Tests**: New `ClampCase` class with comprehensive test cases covering -1, 2, quiet NaN, -0, smallest positive subnormal, 0.5, and 1 for both WORD_0 and WORD_1 selectors, plus refusal tests for invalid dst_mod combinations. ### Assessment The implementation is correct: - The clamp logic matches RDNA2's integer clamp behavior (not floating-point saturate). - The bit-level operations are efficient and avoid expensive float conversions. - Test coverage includes edge cases that would expose incorrect implementations (NaN, -0, subnormal). ### Verdict: Approve
R0Y00 commented 2026-11-28 01:22:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-28T01:22:47Z.

Review: APPROVED


Independent review of 4bf26eda35 on main 57e94668, tree 277a4f3781. The SDWA widening conversion selects the half before widening and clamping the f32 bits. The ordered clamp gives positive zero for NaN, negative values and negative zero, preserves positive subnormals, and caps values above one. The omod controls still refuse.

Debug and Release /O2 each passed all six selected checks with no skips. The source-built GPU fixture compares both half selectors against the CPU result, including 14 clamp cases. Windows 11 26200.9974, RTX 4060 Laptop driver 32.0.16.1656. This verifies the direct compute fixture only.

ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^(native_sdwa_f16_(hardware|ir)|native_f16_alu_(ir|hardware)|native_direct_container|native_fma_f16_opsel_ir)$'
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6094876762 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3203#pullrequestreview-6094876762). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-28T01:22:47Z. **Review:** APPROVED --- Independent review of 4bf26eda35910663beb7d1b160bf14115c9a13ca on main 57e94668, tree 277a4f3781eeef1b64c5d91215dcf7d00da1e078. The SDWA widening conversion selects the half before widening and clamping the f32 bits. The ordered clamp gives positive zero for NaN, negative values and negative zero, preserves positive subnormals, and caps values above one. The omod controls still refuse. Debug and Release /O2 each passed all six selected checks with no skips. The source-built GPU fixture compares both half selectors against the CPU result, including 14 clamp cases. Windows 11 26200.9974, RTX 4060 Laptop driver 32.0.16.1656. This verifies the direct compute fixture only. ```powershell ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^(native_sdwa_f16_(hardware|ir)|native_f16_alu_(ir|hardware)|native_direct_container|native_fma_f16_opsel_ir)$' ```
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!3203
No description provided.