shader: decide v_dot4_i32_i8 and v_dot8_i32_i4 saturation in 32 bits #855

Merged
romn4rch merged 1 commit from upstream-pr/861 into main 2026-11-23 14:39:15 +00:00
romn4rch commented 2026-11-23 14:27:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by romn4rch on 2026-11-23T14:27:15Z.


Change

v_dot4_i32_i8 and v_dot8_i32_i4 now add the product sum to the accumulator in 32 bits and decide signed clamp from the accumulator and the wrapped result, instead of the emulated 64-bit pair (dot_i64_add / dot_i64_sat):

uint r = c + asuint(sum);
if (sat && asint(c) >= 0x40000000 && asint(r) < 0) return 0x7fffffffu;
if (sat && asint(c) < -0x40000000 && asint(r) >= 0) return 0x80000000u;
return r;

The 4 × 8-bit product sum lies in [-65024, 65536] and the 8 × 4-bit sum in [-448, 512]. A signed overflow is therefore only possible for an accumulator of at least 2^30 or below -2^30, and there it flips the sign of the wrapped result. v_dot2_i32_i16, whose sum can reach 2^31, keeps the 64-bit pair, as do the three unsigned forms.

On an Intel UHD Graphics the pair form returned wrong v_dot4_i32_i8 results inside the full dot program, while isolated probes of the same helper were exact (#736). As requested there, DOT_SETS keeps the wrapped results, saturation endpoints and five mutation controls. It gains Set 5 and Set 6, which put v_dot2_i32_i16, v_dot4_i32_i8 and v_dot8_i32_i4 one step inside INT32_MAX and INT32_MIN without saturation. docs/experiments.md now describes the two forms and the six sets.

Fixes #736

Verification

The hardware runs used 34d03c7 with exactly this change to tools/pixel_aot.py and tests/pixel_aot_check.py, on one host. This branch is based on 58da18a. There the dot helpers, DOT_BODY and DOT_SETS are unchanged, and the translated dot shader is byte-identical to the tested one (checked offline).

With XBOX2WINDOWS_ADAPTER set to Intel or NVIDIA:

ctest --preset dev --no-tests=error -R '^pixel_aot_hardware$' -j 1 -V
ctest --preset dev --no-tests=error -R '^pixel_aot_warp$' -j 1 -V
Intel UHD Graphics NVIDIA RTX 3050 Laptop WARP
without the change Failed: check_dot_draw ['pass', 'mismatch', 'mismatch', 'mismatch'] Passed Passed
with the change Passed, 3 of 3 runs (38.66, 38.61, 39.34 s) Passed (55.96 s) Passed (19.57 s)
  • Shader drawn by check_dot_draw: HLSL SHA-256 0d9b896dd5ac5083b7c962cccd2eac0d29a3f564cb82840e25474fd387082c84 as translated, CSO SHA-256 f4a67ad94bb23d463aa0698be2b913604a8db12d49e41dbde847d96c73c4a99e (Windows SDK DXC 1.9.2602.17). Before the change: 54b6fae3… and c76adeee….
  • The 15 draw-core checks on Intel, each wrapped so the run continues: without the change only check_dot_draw fails; with it all 15 pass.
  • Full dot program with six sets: exact on all three adapters, Intel in 2 of 2 runs. All five mutation controls are detected.
  • Isolated probes of v_dot4_i32_i8 and v_dot8_i32_i4, with and without clamp, 11 inputs each: exact on all three adapters.
  • Offline, the new helper equals exact signed saturation in 5,382,600 accumulator, sum and clamp cases.
  • No capability skips in these tests.

Full tables, probe inputs and the first mismatch: https://github.com/R0Y00/Xbox2Windows/issues/736#issuecomment-7103969347

Environment: Windows 11 build 26300.10075, MSVC 19.44.35230, Windows SDK 10.0.26100, CMake 4.5.1, Python 3.14.7. Intel UHD Graphics 8086:468B, driver 32.0.101.7092; NVIDIA GeForce RTX 3050 6GB Laptop GPU 10DE:25EC, driver 32.0.16.2114; WARP 10.0.26100.10068. Debug layer unavailable on all three (Graphics Tools not installed).

Not run here: pixel_aot_check.py binary (needs LLVM with gfx1030; the dot fixture body is unchanged) and other GPU vendors.

Evidence and follow-up

Sets 5 and 6 pass with both helpers, so they add no failure of their own. A clamp that fires one step early would change channel 1 (v_dot2_i32_i16) or channel 2 (v_dot4_i32_i8) in both sets. The two sets are two more cases in the existing --check-pixel-batch launch. The cause of the Intel mismatch stays a hypothesis (#736).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6561496773 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/861). Originally posted by [romn4rch](https://github.com/romn4rch) on 2026-11-23T14:27:15Z. --- ## Change `v_dot4_i32_i8` and `v_dot8_i32_i4` now add the product sum to the accumulator in 32 bits and decide signed `clamp` from the accumulator and the wrapped result, instead of the emulated 64-bit pair (`dot_i64_add` / `dot_i64_sat`): ```hlsl uint r = c + asuint(sum); if (sat && asint(c) >= 0x40000000 && asint(r) < 0) return 0x7fffffffu; if (sat && asint(c) < -0x40000000 && asint(r) >= 0) return 0x80000000u; return r; ``` The 4 × 8-bit product sum lies in [-65024, 65536] and the 8 × 4-bit sum in [-448, 512]. A signed overflow is therefore only possible for an accumulator of at least 2^30 or below -2^30, and there it flips the sign of the wrapped result. `v_dot2_i32_i16`, whose sum can reach 2^31, keeps the 64-bit pair, as do the three unsigned forms. On an Intel UHD Graphics the pair form returned wrong `v_dot4_i32_i8` results inside the full `dot` program, while isolated probes of the same helper were exact (#736). As requested there, `DOT_SETS` keeps the wrapped results, saturation endpoints and five mutation controls. It gains Set 5 and Set 6, which put `v_dot2_i32_i16`, `v_dot4_i32_i8` and `v_dot8_i32_i4` one step inside `INT32_MAX` and `INT32_MIN` without saturation. `docs/experiments.md` now describes the two forms and the six sets. Fixes #736 ## Verification The hardware runs used `34d03c7` with exactly this change to `tools/pixel_aot.py` and `tests/pixel_aot_check.py`, on one host. This branch is based on `58da18a`. There the dot helpers, `DOT_BODY` and `DOT_SETS` are unchanged, and the translated `dot` shader is byte-identical to the tested one (checked offline). With `XBOX2WINDOWS_ADAPTER` set to `Intel` or `NVIDIA`: ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_hardware$' -j 1 -V ctest --preset dev --no-tests=error -R '^pixel_aot_warp$' -j 1 -V ``` | | Intel UHD Graphics | NVIDIA RTX 3050 Laptop | WARP | |---|---|---|---| | without the change | Failed: `check_dot_draw` `['pass', 'mismatch', 'mismatch', 'mismatch']` | Passed | Passed | | with the change | Passed, 3 of 3 runs (38.66, 38.61, 39.34 s) | Passed (55.96 s) | Passed (19.57 s) | - Shader drawn by `check_dot_draw`: HLSL SHA-256 `0d9b896dd5ac5083b7c962cccd2eac0d29a3f564cb82840e25474fd387082c84` as translated, CSO SHA-256 `f4a67ad94bb23d463aa0698be2b913604a8db12d49e41dbde847d96c73c4a99e` (Windows SDK DXC 1.9.2602.17). Before the change: `54b6fae3…` and `c76adeee…`. - The 15 `draw-core` checks on Intel, each wrapped so the run continues: without the change only `check_dot_draw` fails; with it all 15 pass. - Full `dot` program with six sets: exact on all three adapters, Intel in 2 of 2 runs. All five mutation controls are detected. - Isolated probes of `v_dot4_i32_i8` and `v_dot8_i32_i4`, with and without `clamp`, 11 inputs each: exact on all three adapters. - Offline, the new helper equals exact signed saturation in 5,382,600 accumulator, sum and `clamp` cases. - No capability skips in these tests. Full tables, probe inputs and the first mismatch: https://github.com/R0Y00/Xbox2Windows/issues/736#issuecomment-7103969347 Environment: Windows 11 build 26300.10075, MSVC 19.44.35230, Windows SDK 10.0.26100, CMake 4.5.1, Python 3.14.7. Intel UHD Graphics `8086:468B`, driver 32.0.101.7092; NVIDIA GeForce RTX 3050 6GB Laptop GPU `10DE:25EC`, driver 32.0.16.2114; WARP 10.0.26100.10068. Debug layer unavailable on all three (Graphics Tools not installed). Not run here: `pixel_aot_check.py binary` (needs LLVM with gfx1030; the `dot` fixture body is unchanged) and other GPU vendors. ## Evidence and follow-up Sets 5 and 6 pass with both helpers, so they add no failure of their own. A clamp that fires one step early would change channel 1 (`v_dot2_i32_i16`) or channel 2 (`v_dot4_i32_i8`) in both sets. The two sets are two more cases in the existing `--check-pixel-batch` launch. The cause of the Intel mismatch stays a hypothesis (#736). ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. _AI-assisted._
upstream-sync closed this pull request 2026-11-24 06:45:08 +00:00
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!855
No description provided.