shader: round packed U8 conversions with integer arithmetic #3058
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3058"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-27T13:04:54Z.
Change
Refs #3052.
v_cvt_pk_u8_f32through the direct compute frontend read literal0.5as1on the RTX 4070. The same program read lane-derived0.5as0. The guest result is0in 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_neandfptouiout of this lowering.Verification
Tested
1ff709de3925b940da51cbc19e2c0a409249936eon Windows 11 build 26300.10075, MSVC 19.52, Windows SDK 10.0.26100 and DXC 1.9.2602.17.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.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.fca7c35bRelease, using the same two source-built dispatches: 64 literal mismatches (first at word 8,0xa5a5a501vs0xa5a5a500), 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
I used Codex to prepare the change and ran verification locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T13:31:40Z.
Review: APPROVED
Independent validation on
1ff709deintegrated withmainff04a75e(treeb08040ccc32658c6627c66a76ea4af0bd1b3fcae). 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 ranctest --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/O2each 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 keepRound_neandfptouiout 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.