compute: accept clamp on SDWA v_cvt_f32_f16 #3205

Manually merged
github merged 1 commit from github-bot/gh-3203 into gh-pr/3203/base 2026-11-28 01:25:49 +00:00 AGit
Owner

@⁠Leyukaka on GitHub · 2026-11-27 21:35 UTC · original
Leyukaka:sdwa-cvt-clamp → main · +52 −3 · 4 files · 1 commits · merged 2026-11-28 01:22 UTC

Fixes #3184. 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.

**@⁠Leyukaka** on GitHub · 2026-11-27 21:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3203) `Leyukaka:sdwa-cvt-clamp` → `main` · +52 −3 · 4 files · 1 commits · merged 2026-11-28 01:22 UTC Fixes #3184. 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.
The SDWA decoder refused clamp on v_cvt_f32_f16 because the op is in
neither the float ALU nor the conversion list. The SDWA form now takes
clamp with the integer clamp v_ldexp uses: a set sign bit or NaN gives
+0, values above 1.0 give 1.0. The direct VOP3 form, omod and the other
SDWA modifiers stay refused.

native_sdwa_f16_hardware reads back the clamped conversion from both
halves for negative, above-one, NaN, -0.0, denormal and in-range inputs.

AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 21:37:06 +00:00
Author
Owner

@⁠pigalot on GitHub · 2026-11-27 22:15 UTC · original

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 (#3203, 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.

**@⁠pigalot** on GitHub · 2026-11-27 22:15 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3203#issuecomment-7229164523) 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` (#3203, 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.
Author
Owner

@⁠KelboLive on GitHub · 2026-11-27 23:44 UTC · original · approved these changes

Review of PR #3205 — 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

**@⁠KelboLive** on GitHub · 2026-11-27 23:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3203#pullrequestreview-6094381538) · **approved these changes** ## Review of PR #3205 — 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
github-bot force-pushed github-bot/gh-3203 from 8e594dce33 to 4bf26eda35 2026-11-28 00:26:29 +00:00 Compare
github-bot changed target branch from main to gh-pr/3203/base 2026-11-28 01:25:47 +00:00
github manually merged commit 4bf26eda35 into gh-pr/3203/base 2026-11-28 01:25:49 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-28 01:22 UTC · original · approved these changes

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)$'
**@⁠R0Y00** on GitHub · 2026-11-28 01:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3203#pullrequestreview-6094876762) · **approved these changes** 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)$' ```
This discussion has been locked. Commenting is limited to contributors.
No description provided.