shader: round packed U8 conversions with integer arithmetic #3058

Manually merged
github merged 1 commit from github-bot/gh-3058 into gh-pr/3058/base 2026-11-27 13:33:06 +00:00 AGit
Owner

@⁠RonLogic on GitHub · 2026-11-27 13:04 UTC · original
RonLogic:fix/native-packed-u8-rounding → main · +99 −50 · 3 files · 1 commits · merged 2026-11-27 13:31 UTC

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.

**@⁠RonLogic** on GitHub · 2026-11-27 13:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3058) `RonLogic:fix/native-packed-u8-rounding` → `main` · +99 −50 · 3 files · 1 commits · merged 2026-11-27 13:31 UTC ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 13:12:53 +00:00
github-bot changed target branch from main to gh-pr/3058/base 2026-11-27 13:33:02 +00:00
github manually merged commit 1ff709de39 into gh-pr/3058/base 2026-11-27 13:33:06 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 13:31 UTC · original · approved these changes

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.

**@⁠R0Y00** on GitHub · 2026-11-27 13:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3058#pullrequestreview-6088923918) · **approved these changes** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.