compute: accept clamp on SDWA v_cvt_f32_f16 #3203
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3203"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 ofv_cvt_f32_f16accepts clamp in direct compute.v_ldexpuses: a set sign bit or NaN gives +0, and values above 1.0 give 1.0.dx.opsaturate is not used, because it may keep -0 or flush a denormal depending on the float mode.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
main5b145ca9plus this commit (8e594dce).native_sdwa_f16_hardwarereads 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*andnative_direct_containerpass.native_sdwa_f16_hardware.Measured on a local capture (counts and instruction shape only) with
compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests, baselinemain6057071b. The change was measured ona5dad843; the commits in between do not touch the two native source files.v_cvt_f32_f16_sdwa ... clamp dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:WORD_1.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T22:15:17Z.
I tried to review
8e594dceovermaine582a9a4, but the trial merge conflicts intests/native_sdwa_f16_check.py. On themainside the conflicting change comes from0e6ed41e(#3201, SDWAv_cvt_pkrtz_f16_f32andv_add_co_ci_u32), which landed after this branch's base5b145ca9. The other three files merge cleanly.Could you merge or rebase onto current
mainand keep both sets of cases in the test? I'll review the new head after that. I haven't built or run anything at8e594dceyet, so this isn't a verdict on the change.This reply was AI-assisted.
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_sdwain 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) forv_cvt_f32_f16SDWA — 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.ClampCaseclass 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:
Verdict: Approve
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-28T01:22:47Z.
Review: APPROVED
Independent review of
4bf26eda35on main57e94668, tree277a4f3781. 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.