shader: lower v_cvt_pknorm_i16_f32 and v_cvt_pknorm_u16_f32 in direct DXIL #3295
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3295"
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 legacy-code-archaeologist on 2026-11-28T05:50:35Z.
Fixes #3294, Refs #2935.
Summary
v_cvt_pknorm_i16_f32(0x368) andv_cvt_pknorm_u16_f32(0x369) inDirectCompute::float_alu()(src/gfx1013_direct_compute.inl) for both direct Compute and Pixel DXIL, packingcvt_norm(S0.f32)intoD[15:0]andcvt_norm(S1.f32)intoD[31:16].round_rne(clamp(x, -1, 1) * 32767)(i16) andround_rne(clamp(x, 0, 1) * 65535)(u16) in exact pure-32-bit unsigned integer arithmetic (m * (2^k - 1)computed as(m << k) - msplit cleanly at bitk), avoiding desktop floating-point rounding/FTZ differences andi64types.|x| > 0x7f800000) and tiny magnitudes (< 2^-17, zeros and binary32 subnormals) to0, saturates|x| >= 1.0(±Infincluded), supports VOP3abs[1:0]/neg[1:0]and VGPR / SGPR / literal / inline sources viaoperand32(), and keepsclamp,omod,op_sel, third-operandabs/neg, nonzerosrc2, and DPP/SDWA refused.tests/native_cvt_pknorm_f32_check.py,tests/cmake/native_cvt_pknorm_f32.cmake, anddocs/experiments/native-cvt-pknorm-f32.md(26cases,8refusals 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(devandrelease/O2presets):python -B tests/docs_links_check.py: passed (145Markdown files,663links)ctest --preset dev&ctest --preset release(-R '^(native_cvt_pknorm_f32_|native_cvt_pk16_controls|native_cvt_pk_u8_controls|native_f16_alu_ir)'):7passed,1skipped in each preset:native_cvt_pknorm_f32_ir(26cases,8refusals) &native_cvt_pknorm_f32_controls(26cases compiled,8refusals): passednative_cvt_pknorm_f32_pixel_warp(Microsoft Basic Render Driver,13draws /26cases) &native_cvt_pknorm_f32_pixel_hardware(NVIDIA Quadro M1000M driver32.0.15.7371,debug_layer=unavailable,13draws /26cases): passednative_cvt_pk16_controls,native_cvt_pk_u8_controls, andnative_f16_alu_ir(435results,39refusals): passednative_cvt_pknorm_f32_compute_hardware: skipped (77on local Intel HD Graphics 53031.0.101.2111lacking SM 6.6 wave32)dev(native_cvt_pknorm_f32_ir): droppinground_upfailed on8+halfway/tie cases; droppingis_nanfailed at slots12–13(i16_nans,u16_nans); droppingp_lo != 0failed on exact carry-over tie witnesses (u16_p_lo_tie_witness0x8000 != 0x8001,i16_p_lo_tie_witness0xc0004000 != 0xbfff4001, andu16_sgpr_literal).AI-assisted.
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) * 32767or* 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_f32has an RDNA2 hardware probe in the repository (tools/rdna_cvt_pk_u8.py,tests/data/rdna_cvt_pk_u8_measured.tsv). I found none forv_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.mdonmainstill 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:
0x3F0004000x384001800x3F0002000x37C000C0The 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 thev_cvt_pk_u8_f32probe would show what RDNA2 does.A small one: the comment on
i16_p_lo_tie_witnesssays16384.50389, but0x3F000201 * 32767is about 16384.50192. The.50389belongs to the u16 case above it. The expected16385is right either way.AI-assisted.
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):tests/native_cvt_pknorm_f32_check.py):i16_single_round_sep(0x3F000400,0x38400180->16385,1under single-rounding exact product vs16386,2under binary32-multiply-then-RNE) andu16_single_round_sep(0x3F000200,0x37C000C0->32769,1vs32770,2), bringing the suite from 26 to 28 cases (14 Pixel draws).cvt_norm_f32_half_mul_f32_oracle()+check_oracle_separation()so bothirandcontrolsverify those four inputs separate single-rounding exact multiplication from binary32-multiply-then-RNE.i16_p_lo_tie_witnesscomment (16384.50192instead of16384.50389).docs/experiments/native-cvt-pknorm-f32.md,docs/experiments.md):v_cvt_pknorm_i16_f32andv_cvt_pknorm_u16_f32are not yet measured on physical RDNA 2 hardware (unlikev_cvt_pk_u8_f32/tools/rdna_cvt_pk_u8.py) and that the direct DXIL lowering implements single-rounding RNE ofclamp(x) * 32767/* 65535withNaN -> 0.Re-verified on
devandrelease:native_cvt_pknorm_f32_ir(28cases,8refusals),native_cvt_pknorm_f32_controls(28cases,8refusals),native_cvt_pknorm_f32_pixel_warp(14draws /28cases), andnative_cvt_pknorm_f32_pixel_hardware(14draws /28cases on NVIDIA Quadro M1000M32.0.15.7371,debug_layer=unavailable) all passed;native_cvt_pknorm_f32_compute_hardwareskipped (77on local Intel HD Graphics 53031.0.101.2111lacking SM 6.6 wave32).python -B tests/docs_links_check.pypassed (145Markdown files,664links).AI-assisted.
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.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 as945350ac). 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_alublock, 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.1u << (1 - j), and neg applied before abs. Evaluated againstall_cases()/expected(), both give(case,lane) results differing from expected over 32 lanes = 0. No case sets abs and neg on one lane, andu16_abs_neg_mixuses -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)expects0x2000c000. The lane-reversed mutant gives0xe0004000and neg-then-abs gives0x20004000.-1 -> -32767andNaN -> 0still 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 liketools/rdna_cvt_pk_u8.py, would show whether that pin is right.Small notes:
26cases and13draws; the merged fixture has 28 cases and 14 draws.$(git rev-parse --short HEAD)". The substitution was not expanded, so the reply has no commit id.tests/cmake/native_cvt_pknorm_f32.cmakeuses$<TARGET_FILE:native_compute_ir_dump>. That target is defined innative_f16_alu.cmake, which the sorted glob includes later. This works today because your guard implies that file's guard. Adding aTARGET native_compute_ir_dumpcheck to this fragment would silently drop all five tests.This comment was AI-assisted.