shader: round packed U8 conversions with integer arithmetic #3058

Merged
RonLogic merged 1 commit from upstream-pr/3058 into main 2026-11-27 13:31:51 +00:00
RonLogic commented 2026-11-27 13:04:54 +00:00 (Migrated from github.com)

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


Change

Refs #3052. v_cvt_pk_u8_f32 through the direct compute frontend read literal 0.5 as 1 on the RTX 4070. The same program read lane-derived 0.5 as 0. The guest result is 0 in both cases.

Lower the measured round-to-nearest-even and U8 saturation with integer operations on the binary32 word. Bound the input before deriving its significand shift. Add a parity-dependent rounding bias, then merge the resulting byte into the selected byte of the destination. This keeps DXIL Round_ne and fptoui out of this lowering.

Verification

Tested 1ff709de3925b940da51cbc19e2c0a409249936e on 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_(cvt_pk(_u8|16)_(controls|hardware)|sdwa_f16_(ir|hardware)|dxil_llvm_ident_controls)|startup_gfx2hlsl_cvt_pk_u8_(controls|warp|hardware)|compute_store_aot_alu_cvt_pk_u8_(warp|hardware))$'
foreach ($preset in 'dev', 'release') {
    cmake --build --preset $preset --target compile_dxil native_store_replay native_compute_ir_dump offscreen_check
    ctest --preset $preset --no-tests=error -j 1 -R $tests -V
}
  • Debug: 12/12 passed. Release: 12/12 passed. No registered tests skipped.
  • Native RTX 4070 (32.0.16.2124, debug layer off, SM 6.6 / wave32): 1,024 results plus all guard and untouched words matched for each of the literal and lane-derived dispatches in each configuration. The lane-derived dispatch covers all 256 integers, each upper half tie, and both binary32 neighbors of the tie.
  • WARP (10.0.26100.10068): the related HLSL graphics and compute readbacks passed with the debug layer enabled and zero debug errors. The local WARP adapter exposes wave width 4, so the native wave32 replay is inapplicable.
  • Baseline fca7c35b Release, using the same two source-built dispatches: 64 literal mismatches (first at word 8, 0xa5a5a501 vs 0xa5a5a500), and zero lane-derived mismatches.

Evidence and follow-up

The hardware reference remains ties-to-even. The compiler controls check both DXIL modules and retain the operand-modifier refusal and incorrect-reference controls. The underlying driver behavior and native readback on AMD are still unverified. All fixture inputs are synthetic.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the test command and results.
  • I checked the pre-fix failure and kept negative controls.
  • I updated the experiment notes.
  • I checked the diff for game files, dumps, distribution links and secrets.

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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5527116565 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3058). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-27T13:04:54Z. --- ## Change Refs #3052. `v_cvt_pk_u8_f32` through the direct compute frontend read literal `0.5` as `1` on the RTX 4070. The same program read lane-derived `0.5` as `0`. The guest result is `0` in both cases. Lower the measured round-to-nearest-even and U8 saturation with integer operations on the binary32 word. Bound the input before deriving its significand shift. Add a parity-dependent rounding bias, then merge the resulting byte into the selected byte of the destination. This keeps DXIL `Round_ne` and `fptoui` out of this lowering. ## Verification Tested `1ff709de3925b940da51cbc19e2c0a409249936e` on 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_(cvt_pk(_u8|16)_(controls|hardware)|sdwa_f16_(ir|hardware)|dxil_llvm_ident_controls)|startup_gfx2hlsl_cvt_pk_u8_(controls|warp|hardware)|compute_store_aot_alu_cvt_pk_u8_(warp|hardware))$' foreach ($preset in 'dev', 'release') { cmake --build --preset $preset --target compile_dxil native_store_replay native_compute_ir_dump offscreen_check ctest --preset $preset --no-tests=error -j 1 -R $tests -V } ``` - **Debug: 12/12 passed. Release: 12/12 passed.** No registered tests skipped. - **Native RTX 4070** (`32.0.16.2124`, debug layer off, SM 6.6 / wave32): 1,024 results plus all guard and untouched words matched for each of the literal and lane-derived dispatches in each configuration. The lane-derived dispatch covers all 256 integers, each upper half tie, and both binary32 neighbors of the tie. - **WARP** (`10.0.26100.10068`): the related HLSL graphics and compute readbacks passed with the debug layer enabled and zero debug errors. The local WARP adapter exposes wave width 4, so the native wave32 replay is inapplicable. - **Baseline** `fca7c35b` Release, using the same two source-built dispatches: 64 literal mismatches (first at word 8, `0xa5a5a501` vs `0xa5a5a500`), and zero lane-derived mismatches. ## Evidence and follow-up The hardware reference remains ties-to-even. The compiler controls check both DXIL modules and retain the operand-modifier refusal and incorrect-reference controls. The underlying driver behavior and native readback on AMD are still unverified. All fixture inputs are synthetic. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the test command and results. - [x] I checked the pre-fix failure and kept negative controls. - [x] I updated the experiment notes. - [x] I checked the diff 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:31:40 +00:00 (Migrated from github.com)

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

Review: APPROVED


Independent validation on 1ff709de integrated with main ff04a75e (tree b08040ccc32658c6627c66a76ea4af0bd1b3fcae). The bounded bit pattern keeps every shift in range, the retained bit makes ties round to even, and the destination mask preserves the other three bytes. An independent Python check compared 204,295 binary32 words with a ties-to-even reference, including neighborhoods of every U8 half tie and nonfinite values, with no mismatches.

After building compile_dxil native_store_replay native_compute_ir_dump offscreen_check, I ran ctest --test-dir <build> --no-tests=error -V -R '^(native_(cvt_pk(_u8|16)_(controls|hardware)|sdwa_f16_(ir|hardware)|dxil_llvm_ident_controls)|startup_gfx2hlsl_cvt_pk_u8_(controls|warp|hardware)|compute_store_aot_alu_cvt_pk_u8_(warp|hardware))$'. Debug and Release /O2 each passed 12/12 with zero skips. RTX wave32 replay matched all 2,064 words in each of the literal and lane-derived cases, including guards. The compiler controls keep Round_ne and fptoui out of both modules and verify that incorrect references differ. WARP passed the related HLSL fixtures; it has four lanes here and cannot run this native wave32 replay. Windows 11 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, WARP 10.0.26100.9818, SDK DXC 10.0.26100. Native replay debug layer off, related HLSL fixtures debug layer on.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6088923918 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3058#pullrequestreview-6088923918). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T13:31:40Z. **Review:** APPROVED --- Independent validation on `1ff709de` integrated with `main` `ff04a75e` (tree `b08040ccc32658c6627c66a76ea4af0bd1b3fcae`). The bounded bit pattern keeps every shift in range, the retained bit makes ties round to even, and the destination mask preserves the other three bytes. An independent Python check compared 204,295 binary32 words with a ties-to-even reference, including neighborhoods of every U8 half tie and nonfinite values, with no mismatches. After building `compile_dxil native_store_replay native_compute_ir_dump offscreen_check`, I ran `ctest --test-dir <build> --no-tests=error -V -R '^(native_(cvt_pk(_u8|16)_(controls|hardware)|sdwa_f16_(ir|hardware)|dxil_llvm_ident_controls)|startup_gfx2hlsl_cvt_pk_u8_(controls|warp|hardware)|compute_store_aot_alu_cvt_pk_u8_(warp|hardware))$'`. Debug and Release `/O2` each passed 12/12 with zero skips. RTX wave32 replay matched all 2,064 words in each of the literal and lane-derived cases, including guards. The compiler controls keep `Round_ne` and `fptoui` out of both modules and verify that incorrect references differ. WARP passed the related HLSL fixtures; it has four lanes here and cannot run this native wave32 replay. Windows 11 26200.9974, RTX 4060 Laptop driver 32.0.16.1656, WARP 10.0.26100.9818, SDK DXC 10.0.26100. Native replay debug layer off, related HLSL fixtures debug layer on.
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!3058
No description provided.