shader: accept inline constants in packed binary16 arithmetic and min/max in direct DXIL #3230
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3230"
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-28T00:05:08Z.
Accepts inline constant sources in
DirectCompute::packed_f16_alu()(v_pk_add_f16,v_pk_mul_f16,v_pk_fma_f16) andDirectCompute::packed_minmax()(v_pk_min_f16,v_pk_max_f16,v_pk_min_{i,u}16,v_pk_max_{i,u}16) insrc/gfx1013_direct_compute.inl. This clears the"unsupported packed binary16 arithmetic source"refusal noted on#3224(Rank 3's follow-on refusal after#3220).Summary of changes
packed_f16_inline_constant()helper (src/gfx1013_direct_compute.inl):240..248:0.5,-0.5,1.0,-1.0,2.0,-2.0,4.0,-4.0,1/(2*pi)) decode to bits[15:0]with[31:16]zeroed, matchinggfx1013hardware (op_sel_hi = 1reads+0.0).128..208:0..64and-1..-16) decode to 32-bit sign-extended values (0..64,0xFFFFFFFF..0xFFFFFFF0).v_pk_min_{i,u}16/v_pk_max_{i,u}16accept128..208and continue refusing float240..248.vcc_lo/vcc_hi,m0,exec_lo/exec_hi,scc,clampon packed f16 arithmetic, reserved bits, and non-default FP16 MODE writes keep their existing refusals.tests/cmake/native_packed_f16_inline.cmake,tests/native_packed_f16_inline_check.py(24 cases covering all 9 inline float constants,op_sel_hihigh-half zeroing,neg_lo/neg_hiincl.-0.0, single-rounding FMA tie witness with inline0.5+2^-24, inline integer constants,v_pk_min_f16/v_pk_max_f16incl.193NaN selection, andv_pk_min_u16/v_pk_max_i16, plus 10 refusals), anddocs/experiments/native-packed-f16-inline.md.Local verification (
mainc7215add+ this change, Windows 10.0.26100,devpreset)cmake --build --preset dev --target compile_dxil native_compute_ir_dump native_store_replay offscreen_check: passedctest --preset dev --no-tests=error -R '^native_packed_f16_inline_' -V:native_packed_f16_inline_ir: passed (24cases +10refusals,0.68s)native_packed_f16_inline_controls: passed (24compiled +10refusals,1.47s)native_packed_f16_inline_pixel_warp: passed (12paired draws /24cases,2.18s)native_packed_f16_inline_pixel_hardware: passed (Intel(R) HD Graphics 530,12paired draws /24cases,5.20s)native_packed_f16_inline_compute_hardware: skipped (77,Intel(R) HD Graphics 53031.0.101.2111: requires SM 6.6 with wave32, so GPU compute readback is not measured)ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure: 65/65 passed (80.10s)replicate_high_half,use_f32_inline,zero_extend_neg_int,drop_minmax_float_inline): all exited1onnative_packed_f16_inline_irpython -B tests/docs_links_check.py: passed (126Markdown files,624links)Fixes #3226
Refs #2935
Refs #3224
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-28T00:22:51Z.
I ran this on RTX 4070 (32.0.16.2124) in Release at
2c964029, DXC 1.9.2602.17, Windows 11 26300.10075. The four IR, compile and Pixel tests passed. The GPU Compute case reachedguard overwritten.The Compute shader's prologue leaves all 32 lanes active and writes at
group*4096 + lane*128bytes. The reference checks two 128-dword-spaced rows and treats the other lane records as guards. The second checked row therefore happens to cover a lane of group 0. I tested the following layout for the full 2,064-word reference inhardware():With this fixture-only adjustment,
ctest --preset release --no-tests=error -R '^native_packed_f16_inline_' -Vpassed 5/5 on RTX 4070 plus WARP Pixel. I also ran the same Compute probe with--direct-warpon WARP 1.0.22. Both Compute adapters matched all 24 cases in 64 lanes (1,536 output words and 528 guards). An extra store immediately after each lane's result range tripped both at word 32, expected0x69696969, actual0xffffffff.Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-28T00:33:05Z.
@RonLogic Thank you for testing on RTX 4070 + WARP 1.0.22 and catching that! Indeed
PROLOGUEactivates all 32 lanes per group (group*4096 + lane*128bytes), so checking only the first row per group treated the other 31 lanes' outputs as0x69696969guards.Updated
hardware()intests/native_packed_f16_inline_check.pyto verify all2 x 32 x 24lane output words and528guard words (2,064dwords total) and force-pushed.Re-verified locally (
devpreset, Windows 10.0.26100):native_packed_f16_inline_ir: passed (24cases +10refusals)native_packed_f16_inline_controls: passed (24compiled +10refusals)native_packed_f16_inline_pixel_warp: passed (12paired draws /24cases)native_packed_f16_inline_pixel_hardware: passed (Intel(R) HD Graphics 530,12paired draws /24cases)native_packed_f16_inline_compute_hardware: skipped (77,Intel(R) HD Graphics 530lacks SM 6.6 wave32)AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-28T00:41:04Z.
Review: APPROVED
Independently reviewed
37e76fb26eon main350785e8(candidate treeee670c8ac9). Float literals 240–248 supply low half bits with zero upper half, and integer literals 128–208 retain their signed packed representation. Integer min/max still refuses float literals. The corrected GPU Compute fixture now compares all 1,536 result words and 528 sentinel words across 2 groups of 32 lanes. It passed both configurations on RTX 4060 Laptop. The Pixel slice passed on RTX and Microsoft WARP. This is the packed-inline slice only.Windows 11 26200.9974, RTX 4060 Laptop 32.0.16.1656, WARP 10.0.26100.9818. Debug and Release /O2 each passed all 10 selected tests, including the neighbor descriptor SCC test and existing f16 FMA controls. No skips.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T00:52:29Z.
Review: APPROVED
Independently reviewed
37e76fb2integrated overmain86beae95(treeee670c8a). The merge is clean andgit diff --cached --checkis clean. I started on2c964029; the only difference is the compute GPU check, covered below.What I traced.
packed_f16_inline_constant()maps 240..248 to the binary16 bits in[15:0]with[31:16]zero. Integer constants 128..208 become 32-bit sign-extended values, so -1 is0xffffffff. That matches LLVM's VOP3P encoding rule (isInlinableLiteralV216): a v2f16 inline constant is the 16-bit value with a zero high half, and a replicated constant is encoded withop_sel_hiclear.0x3118is 1/(2π) in binary16.packed_f16_alu()still refusesvcc,m0,exec,sccand the reserved encodings. The integerv_pk_{min,max}_{i,u}16forms take 128..208 throughoperand32()and still refuse 240..248.What I ran. I built
compile_dxil native_compute_ir_dump native_store_replay offscreen_checkindevandrelease, then ranThe
_hardwaretests ran at-j 1. All 5 pass in Debug and in Release/O2, with no skips:_irand_controls: 24 cases and 10 refusals._pixel_warpand_pixel_hardware: 12 paired draws each._compute_hardware: "24 cases matched across 2x32 lanes and guards" on the RTX 5090.The 65
^native_.*_(controls|ir)$neighbours pass indev, exceptnative_raw_buffer_view_controls, which is Not Run because its executable isn't in my build.The compute GPU check. On
2c964029,native_packed_f16_inline_compute_hardwarefailed on the RTX 5090 withguard overwritten, the same failure RonLogic reported on an RTX 4070.PROLOGUElets all 32 lanes store at8 + 1024 * group + 32 * lane + slot, but the old check modelled onlyF.BASE + group * 128. I read the whole readback independently: all 1,536 written words (2 groups × 32 lanes × 24 cases) matched the model at those offsets, and every other word was the sentinel.37e76fb2builds exactly that expected buffer and compares all 2,064 words, and it passes.Negative control and mutants. These ran on
2c964029, whose source is the same. Each mutant was rebuilt indevand run against_ir,_controls,_pixel_warpand_pixel_hardware:src/gfx1013_direct_compute.inlback tomain[31:16]_ircase 9add_inline_242_hi_zero, both pixel tests)_ircase 16fma_inline_int_193_nan, both pixel tests)0x3119_ircase 8, both pixel tests)_irand_controlsrefusal 7)vcc_lo/vcc_hi_irand_controlsrefusal 0)_ir,_controls, both pixel tests)Restored and rebuilt afterwards;
git diff --quietis clean.Non-blocking. The comment above
fma_inline_src0_242_src2_241("neg_lo/neg_hi on inline 240 and inline 129 in src2 + SGPR src0") doesn't describe that case. The case has no negation, takes inline 242 in src0, takesv1in src1 and takes 241 in src2.Verdict: approve on
37e76fb2.Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0
dxc.exe(the one CTest picked up); Python 3.12.10; wave32; D3D12 debug layer enabled in the pixel tests.CI:
Build and test on Windowspasses on37e76fb2(theprpreset doesn't include these tests).This reply was AI-assisted.