shader: lower packed 16-bit minimum and maximum in direct DXIL #3144
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3144"
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 RonLogic on 2026-11-27T18:18:54Z.
Change
Fixes #3069. Refs #2935 and #2022. The direct DXIL frontend refused the six canonical VOP3P
v_pk_min/max_{i16,u16,f16}forms. Both selector groups now feed one shared lowering for Pixel and Compute. It compares signed and unsigned integer halves in their own order and compares binary16 as bit patterns, preserving the existing HLSL behavior for signed zeros, subnormals and NaNs.The lowering accepts numeric registers, literal words and inline zero. It uses the ordinary vector-write predicate and refuses unsupported modifiers and binary16 denormal modes.
Verification
Tested
f2149800a8d1aabcb3e85faa56be7f837913f854based on429f11d5. Windows 11 build 26300.10075, MSVC 19.52, Windows SDK 10.0.26100 and DXC 1.9.2602.17.10.0.26100.10068and RTX 407032.0.16.2124. Compute on RTX 4070 matched 2,064 words per type. Swapping selector groups changed 640 words and sparse EXEC preserved the inactive lanes. Native Compute requires wave32, while the local WARP adapter exposes four lanes.Evidence and provenance
On the old compiler, individual synthetic probes refused each of the six opcodes. The source-built fixture calculates expected results from signed/unsigned integers and Python binary16, checks signed-zero and NaN results bit for bit and verifies both destination halves and guard words. The two-NaN payload convention follows the existing Xbox2Windows path and remains unverified on RDNA hardware.
Behavioral reference was the public shadPS4 packed FP16 PR, merged as
34b35b526e3bfbb8a6f22c11035cb051174ac6f1, observed 2026-11-27 under GPL-2.0. Instruction semantics come from the AMD RDNA 2 ISA and the LLVM 21.1.0 GFX1030 syntax, revision3623fe661ae35c6c80ac221f14d85be76aa870f1(Apache-2.0 with LLVM exception). Implementation and fixtures were written in Xbox2Windows.Checklist
I used Codex to prepare the change and ran verification locally.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T21:02:19Z.
LGTM! The packed 16-bit min/max lowering is correctly implemented:
Key features:
v_min_f16,v_max_f16,v_min_u16, andv_max_u16operations in the direct compute pathImplementation notes:
This enables games using 16-bit min/max operations for compute shaders, which is essential for modern rendering pipelines that leverage half-precision math for performance.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T21:03:16Z.
This PR now conflicts with
mainafter #3159 landed. The only conflict is thehalf_binarycondition insrc/gfx1013_direct_compute.inl: #3159 added the fourv_cvt_*16names tobinary16_alu(op.name) || ...and this PR addsv_pk_min_f16/v_pk_max_f16to the same line. Keeping both lists resolves it.Could you merge
maininto your branch (a merge commit is fine, no force push needed)? I will then run the Windows tests on the new head (including thecpp-migrationmerge check) and review it.Command:
git merge-tree --write-tree origin/main pull/3144/head.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-27T21:20:24Z.
Fixed
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T21:47:47Z.
Review: COMMENTED
Review of
3f35c1fe2b(main merged in by the author). Comment only.packed_minmaxhandlesv_pk_{min,max}_{f16,i16,u16}with each lane's OP_SEL / OP_SEL_HI selector. It refuses clamp, the NEG_LO/NEG_HI fields, a third source, the unused third OP_SEL_HI bit, lane-mask SGPRs, and every inline constant except 0 and a literal, so the f32-pattern inline-float problem cannot reach it. The f16 order key maps binary16 encodings to a monotone integer key (negative half reversed, -0 below +0). NaN handling follows the existing contract: one NaN gives the other side, and two NaNs give 0x7E00. The i16/u16 keys are an XOR of the sign bit and the plain value. The f16 forms also require a known IEEE denormal mode.native_packed_minmax_pixel_warpreads the results back on WARP through the pixel path, so the lowering is checked on our host, not only through the wave32 compute leg.src/gfx1013_direct_compute.inlis also changed oncpp-migration; this merges cleanly there, and the native sweep on that merge is in the comment below.Commands:
git diff origin/main...pull/3144/head(read),git merge-tree --write-tree origin/cpp-migration pull/3144/head, plus the Windows commands in the comment below.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T21:47:49Z.
Windows Server 2025 verification of
3f35c1fe2beef74da6e333eb581ee26330146439(D3D12 WARP, MSVC 14.44.35207):cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump;ctest --preset dev -R <native sweep>: 100% tests passed out of 150 (87 passed, 63 skipped), includingnative_packed_minmax_controls,native_packed_minmax_pixel_warpand_pixel_hardware(_compute_hardwareskips here, it needs a wave32 adapter)--preset release;ctest --preset release -R <native sweep>: 100% tests passed out of 150 (87 passed, 63 skipped)cpp-migration(a0f67731): 100% tests passed out of 150 in both presets<native sweep>= everynative_*test exceptnative_startup_request_cache_hardware, which fails on WARP-only hosts with or without this PR.AI-assisted; commands listed were executed locally.