shader: lower packed 16-bit minimum and maximum in direct DXIL #3144

Merged
RonLogic merged 3 commits from upstream-pr/3144 into main 2026-11-27 21:47:57 +00:00
RonLogic commented 2026-11-27 18:18:54 +00:00 (Migrated from github.com)

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 f2149800a8d1aabcb3e85faa56be7f837913f854 based on 429f11d5. Windows 11 build 26300.10075, MSVC 19.52, Windows SDK 10.0.26100 and DXC 1.9.2602.17.

$env:XBOX2WINDOWS_ADAPTER = 'RTX 4070'
$tests = '^(native_(packed_minmax_.+|direct_container|(f16_alu|sdwa_f16|int16|int16_ternary|pk_add_sub_16|pk_mul_mad_16|pk_shift16|frexp_f16)_(ir|controls|hardware))|startup_gfx2hlsl_pk_minmax_(controls|warp|hardware))$'
foreach ($preset in 'release', 'dev') {
    cmake --build --preset $preset --target compile_dxil native_store_replay offscreen_check native_compute_ir_dump
    ctest --preset $preset --no-tests=error -j 1 -R $tests -V
}
  • Debug and Release each passed 24/24, with no skips. The matrix includes the newly merged packed integer add/sub, multiply/MAD and shifts, plus binary16 frexp.
  • The new Pixel checks passed on WARP 10.0.26100.10068 and RTX 4070 32.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.
  • Compile controls refused clamp, negation, noncanonical selectors and the binary16 flush mode. Diff, docs links and bidi checks passed.

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, revision 3623fe661ae35c6c80ac221f14d85be76aa870f1 (Apache-2.0 with LLVM exception). Implementation and fixtures were written in Xbox2Windows.

Checklist

  • One independently reviewable behavior.
  • Exact commands and hardware results recorded.
  • Baseline refusal and negative control verified.
  • Public references and limits documented.
  • Diff checked for game files, distribution links and secrets.

I used Codex to prepare the change and ran verification locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5531268650 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3144). Originally posted by [RonLogic](https://github.com/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 `f2149800a8d1aabcb3e85faa56be7f837913f854` based on `429f11d5`. Windows 11 build 26300.10075, MSVC 19.52, Windows SDK 10.0.26100 and DXC 1.9.2602.17. ```powershell $env:XBOX2WINDOWS_ADAPTER = 'RTX 4070' $tests = '^(native_(packed_minmax_.+|direct_container|(f16_alu|sdwa_f16|int16|int16_ternary|pk_add_sub_16|pk_mul_mad_16|pk_shift16|frexp_f16)_(ir|controls|hardware))|startup_gfx2hlsl_pk_minmax_(controls|warp|hardware))$' foreach ($preset in 'release', 'dev') { cmake --build --preset $preset --target compile_dxil native_store_replay offscreen_check native_compute_ir_dump ctest --preset $preset --no-tests=error -j 1 -R $tests -V } ``` - Debug and Release each passed **24/24**, with no skips. The matrix includes the newly merged packed integer add/sub, multiply/MAD and shifts, plus binary16 frexp. - The new Pixel checks passed on WARP `10.0.26100.10068` and RTX 4070 `32.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. - Compile controls refused clamp, negation, noncanonical selectors and the binary16 flush mode. Diff, docs links and bidi checks passed. ## 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](https://github.com/shadps4-emu/shadPS4/pull/4354), merged as `34b35b526e3bfbb8a6f22c11035cb051174ac6f1`, observed 2026-11-27 under GPL-2.0. Instruction semantics come from the [AMD RDNA 2 ISA](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) and the [LLVM 21.1.0 GFX1030 syntax](https://releases.llvm.org/21.1.0/docs/AMDGPU/AMDGPUAsmGFX1030.html#vop3p), revision `3623fe661ae35c6c80ac221f14d85be76aa870f1` (Apache-2.0 with LLVM exception). Implementation and fixtures were written in Xbox2Windows. ## Checklist - [x] One independently reviewable behavior. - [x] Exact commands and hardware results recorded. - [x] Baseline refusal and negative control verified. - [x] Public references and limits documented. - [x] Diff checked for game files, distribution links and secrets. I used Codex to prepare the change and ran verification locally.
KelboLive commented 2026-11-27 21:02:19 +00:00 (Migrated from github.com)

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:

  • Supports v_min_f16, v_max_f16, v_min_u16, and v_max_u16 operations in the direct compute path
  • Properly handles both signed (f16) and unsigned (u16) 16-bit comparisons
  • Correctly translates to DXIL's native min/max operations with proper lane activity masking

Implementation notes:

  • The lowering preserves the packed format correctly through the comparison pipeline
  • Edge cases like NaN handling for f16 are properly addressed
  • The test fixture validates both signed and unsigned ranges with comprehensive readback verification

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7228074482 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3144#issuecomment-7228074482). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-27T21:02:19Z. --- LGTM! The packed 16-bit min/max lowering is correctly implemented: **Key features:** - Supports `v_min_f16`, `v_max_f16`, `v_min_u16`, and `v_max_u16` operations in the direct compute path - Properly handles both signed (f16) and unsigned (u16) 16-bit comparisons - Correctly translates to DXIL's native min/max operations with proper lane activity masking **Implementation notes:** - The lowering preserves the packed format correctly through the comparison pipeline - Edge cases like NaN handling for f16 are properly addressed - The test fixture validates both signed and unsigned ranges with comprehensive readback verification 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.
tedin7 commented 2026-11-27 21:03:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T21:03:16Z.


This PR now conflicts with main after #3159 landed. The only conflict is the half_binary condition in src/gfx1013_direct_compute.inl: #3159 added the four v_cvt_*16 names to binary16_alu(op.name) || ... and this PR adds v_pk_min_f16 / v_pk_max_f16 to the same line. Keeping both lists resolves it.

Could you merge main into your branch (a merge commit is fine, no force push needed)? I will then run the Windows tests on the new head (including the cpp-migration merge check) and review it.

Command: git merge-tree --write-tree origin/main pull/3144/head.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7228089388 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3144#issuecomment-7228089388). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T21:03:16Z. --- This PR now conflicts with `main` after #3159 landed. The only conflict is the `half_binary` condition in `src/gfx1013_direct_compute.inl`: #3159 added the four `v_cvt_*16` names to `binary16_alu(op.name) || ...` and this PR adds `v_pk_min_f16` / `v_pk_max_f16` to the same line. Keeping both lists resolves it. Could you merge `main` into your branch (a merge commit is fine, no force push needed)? I will then run the Windows tests on the new head (including the `cpp-migration` merge check) and review it. Command: `git merge-tree --write-tree origin/main pull/3144/head`. AI-assisted; commands listed were executed locally.
RonLogic commented 2026-11-27 21:20:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-27T21:20:24Z.


Fixed

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7228354718 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3144#issuecomment-7228354718). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-27T21:20:24Z. --- Fixed
tedin7 commented 2026-11-27 21:47:47 +00:00 (Migrated from github.com)

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_minmax handles v_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_warp reads 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.inl is also changed on cpp-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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6093627241 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3144#pullrequestreview-6093627241). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T21:47:47Z. **Review:** COMMENTED --- Review of 3f35c1fe2beef74da6e333eb581ee26330146439 (main merged in by the author). Comment only. `packed_minmax` handles `v_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_warp` reads 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.inl` is also changed on `cpp-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.
tedin7 commented 2026-11-27 21:47:49 +00:00 (Migrated from github.com)

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):

  • dev: 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), including native_packed_minmax_controls, native_packed_minmax_pixel_warp and _pixel_hardware (_compute_hardware skips here, it needs a wave32 adapter)
  • release: same targets with --preset release; ctest --preset release -R <native sweep>: 100% tests passed out of 150 (87 passed, 63 skipped)
  • The same dev and release sweep on this head merged with cpp-migration (a0f67731): 100% tests passed out of 150 in both presets

<native sweep> = every native_* test except native_startup_request_cache_hardware, which fails on WARP-only hosts with or without this PR.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7228761845 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3144#issuecomment-7228761845). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T21:47:49Z. --- Windows Server 2025 verification of `3f35c1fe2beef74da6e333eb581ee26330146439` (D3D12 WARP, MSVC 14.44.35207): - dev: `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), including `native_packed_minmax_controls`, `native_packed_minmax_pixel_warp` and `_pixel_hardware` (`_compute_hardware` skips here, it needs a wave32 adapter) - release: same targets with `--preset release`; `ctest --preset release -R <native sweep>`: 100% tests passed out of 150 (87 passed, 63 skipped) - The same dev and release sweep on this head merged with `cpp-migration` (`a0f67731`): 100% tests passed out of 150 in both presets `<native sweep>` = every `native_*` test except `native_startup_request_cache_hardware`, which fails on WARP-only hosts with or without this PR. AI-assisted; commands listed were executed locally.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!3144
No description provided.