shader: lower packed halfword dot products in direct compute #3061

Merged
RonLogic merged 1 commit from upstream-pr/3061 into main 2026-11-27 13:55:58 +00:00
RonLogic commented 2026-11-27 13:21:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-27T13:21:13Z.


Change

Refs #2935. Add v_dot2_i32_i16 and v_dot2_u32_u16 to the direct C++ compute frontend. At 801f4c3b, canonical source-built requests for both opcodes were refused at +0x38 with direct ALU operand modifiers. #3036 covers the separate HLSL frontend.

Each 16×16 product fits in a 32-bit word. The ordinary form wraps. The clamped form adds the carries from both additions and the signed extensions to track the upper word of the exact sum. Saturation happens after the accumulator is added, so an intermediate overflow can cancel. This requires only 32-bit DXIL arithmetic.

Verification

Tested edede1ff472be772c86f96e9f2831515b7aaf349 on db28a796 with Windows 11 build 26300.10075, MSVC 19.52, SDK 10.0.26100 and DXC 1.9.2602.17.

$env:XBOX2WINDOWS_ADAPTER = 'RTX 4070'
$tests = '^(native_(packed_dot2|int16_ternary|perm_lerp|dxil_llvm_ident|absdiff)_.+|compute_store_aot_dot_u_(warp|hardware)|startup_gfx2hlsl_v_dot8_(controls|warp|hardware))$'
foreach ($preset in 'release', 'dev') {
    cmake --build --preset $preset --target compile_dxil native_store_replay offscreen_check
    ctest --preset $preset --no-tests=error -j 1 -R $tests -V
}
  • Release: 16/16 passed. Debug: 16/16 passed. No registered tests skipped.
  • Native RTX 4070 (32.0.16.2124, SM 6.6 / wave32, debug layer off): both full and sparse EXEC dispatches matched 2,048 result words and 16 guards. The signed 2^30 + 2^30 - 2^31 case returned zero. The no-clamp replay matched wrapping and differed from the clamped reference at 376 words.
  • WARP (10.0.26100.10068, debug layer enabled for the adjacent HLSL checks): related readbacks passed. Native replay requires wave32 and is inapplicable to this 4-lane WARP adapter.
  • The compile checks refused five noncanonical encodings. Docs links, bidi controls and git diff --check passed.

Evidence and follow-up

The source-built fixture uses synthetic instructions and a Python integer oracle. It covers both signed overflow directions, unsigned double carry, the exact saturation bounds, and inactive lanes. The branch trial-merges cleanly with main, cpp-migration, #3058 and #3060. Native readback on AMD remains unverified.

Checklist

  • One reviewable behavior.
  • Test commands, results and capability limits recorded.
  • Baseline refusal and wrong-output control checked.
  • Experiment notes updated.
  • Diff checked for game files, dumps, distribution links and secrets.

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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5527344190 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3061). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-27T13:21:13Z. --- ## Change Refs #2935. Add `v_dot2_i32_i16` and `v_dot2_u32_u16` to the direct C++ compute frontend. At `801f4c3b`, canonical source-built requests for both opcodes were refused at `+0x38` with `direct ALU operand modifiers`. #3036 covers the separate HLSL frontend. Each 16×16 product fits in a 32-bit word. The ordinary form wraps. The clamped form adds the carries from both additions and the signed extensions to track the upper word of the exact sum. Saturation happens after the accumulator is added, so an intermediate overflow can cancel. This requires only 32-bit DXIL arithmetic. ## Verification Tested `edede1ff472be772c86f96e9f2831515b7aaf349` on `db28a796` with Windows 11 build 26300.10075, MSVC 19.52, SDK 10.0.26100 and DXC 1.9.2602.17. ```powershell $env:XBOX2WINDOWS_ADAPTER = 'RTX 4070' $tests = '^(native_(packed_dot2|int16_ternary|perm_lerp|dxil_llvm_ident|absdiff)_.+|compute_store_aot_dot_u_(warp|hardware)|startup_gfx2hlsl_v_dot8_(controls|warp|hardware))$' foreach ($preset in 'release', 'dev') { cmake --build --preset $preset --target compile_dxil native_store_replay offscreen_check ctest --preset $preset --no-tests=error -j 1 -R $tests -V } ``` - **Release: 16/16 passed. Debug: 16/16 passed.** No registered tests skipped. - **Native RTX 4070** (`32.0.16.2124`, SM 6.6 / wave32, debug layer off): both full and sparse EXEC dispatches matched 2,048 result words and 16 guards. The signed `2^30 + 2^30 - 2^31` case returned zero. The no-clamp replay matched wrapping and differed from the clamped reference at 376 words. - **WARP** (`10.0.26100.10068`, debug layer enabled for the adjacent HLSL checks): related readbacks passed. Native replay requires wave32 and is inapplicable to this 4-lane WARP adapter. - The compile checks refused five noncanonical encodings. Docs links, bidi controls and `git diff --check` passed. ## Evidence and follow-up The source-built fixture uses synthetic instructions and a Python integer oracle. It covers both signed overflow directions, unsigned double carry, the exact saturation bounds, and inactive lanes. The branch trial-merges cleanly with main, cpp-migration, #3058 and #3060. Native readback on AMD remains unverified. ## Checklist - [x] One reviewable behavior. - [x] Test commands, results and capability limits recorded. - [x] Baseline refusal and wrong-output control checked. - [x] Experiment notes updated. - [x] Diff checked for game files, dumps, distribution links and secrets. I used Codex to prepare the change and ran verification locally.
R0Y00 commented 2026-11-27 13:54:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T13:54:13Z.

Review: APPROVED


Independent review of the exact head integrated over main 36d2cbeb, #2871 and #3060 (tree 8b3f4eb5d58ccd10535336aa03034a164b0fe8bc). The two carries and sign extensions implement the exact upper word through the accumulation, before saturation. An independent CPU arithmetic check matched an unbounded integer reference for 202,662 signed and unsigned inputs, including cancellation and both saturation directions.

Built compile_dxil native_store_replay. Debug and Release /O2 each passed 12/12 with zero skips using ctest --test-dir <build> --no-tests=error -j 1 -V -R '^(native_(packed_dot[24]|int16_ternary|perm_lerp|absdiff)_.+|native_dxil_llvm_ident_controls|startup_gfx2hlsl_v_dot8_controls)$'. Both packed dot fixtures matched 2,048 result words and 16 guards for each full and sparse EXEC case. Windows 11 build 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, SDK DXC 10.0.26100, replay debug layer off. Native replay needs wave32 and has no WARP case; the PR author reports the adjacent HLSL WARP runs.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6089187934 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3061#pullrequestreview-6089187934). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T13:54:13Z. **Review:** APPROVED --- Independent review of the exact head integrated over `main` `36d2cbeb`, #2871 and #3060 (tree `8b3f4eb5d58ccd10535336aa03034a164b0fe8bc`). The two carries and sign extensions implement the exact upper word through the accumulation, before saturation. An independent CPU arithmetic check matched an unbounded integer reference for 202,662 signed and unsigned inputs, including cancellation and both saturation directions. Built `compile_dxil native_store_replay`. Debug and Release `/O2` each passed 12/12 with zero skips using `ctest --test-dir <build> --no-tests=error -j 1 -V -R '^(native_(packed_dot[24]|int16_ternary|perm_lerp|absdiff)_.+|native_dxil_llvm_ident_controls|startup_gfx2hlsl_v_dot8_controls)$'`. Both packed dot fixtures matched 2,048 result words and 16 guards for each full and sparse EXEC case. Windows 11 build 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, SDK DXC 10.0.26100, replay debug layer off. Native replay needs wave32 and has no WARP case; the PR author reports the adjacent HLSL WARP runs.
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!3061
No description provided.