shader: clamp v_fract_f32 below 1.0 in the pixel translator #263
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/267"
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 Spaghetih on 2026-11-21T19:47:40Z.
Change
Independent problem:
tools/pixel_aot.pyloweredv_fract_f32to a bare HLSLfrac. On the target,v_fract_f32returns x - floor(x) clamped to0x3f7fffff, so the result never reaches 1.0. The AMD ISA entry says "result clamped to 0x3f7fffff", and LLVM's AMDGPU backend foldsminnum(x - floor(x), 0x3f7fffff)plus a NaN check into a singlev_fract_f32, as itsfract-match.lltest shows. D3Dfrchas no such clamp, and the two desktop backends I tried disagree.Measured with the repository renderer (
offscreen_check --check-pixel-case), drawingv_fract_f32on constant -2^-30 through the translator frommain:1.00.999512(mismatch)0.9995120.999512The lowering now calls a
fract32helper in the preamble. It returnsfrac(x)unless that is ≥ 1.0, in which case it returnsasfloat(0x3f7fffffu). NaN fails the comparison and propagates. ±inf gives NaN throughfrac, asS0 - floor(S0)does on the target.Shared interface:
tools/pixel_aot.pyandtests/pixel_aot_check.py. #169 and #232 edit both files. I placed the helper beforeexport16, changed only the existingfractentry inALU, and put the new draw and control at positions neither PR touches.main+ #169 + this PR andmain+ #232 + this PR both merge cleanly, andcheck_controlspasses on each combination. (#169 and #232 conflict with each other independently of this change.)Verification
Commit
294bf7con7233cec. Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100 DXC, Python 3.14.6. Debug layer enabled on both backends.pixel_aot_hardware(RTX 4070 Ti) andpixel_aot_warppassed.tools/pixel_aot.pyfrom7233cec: both failed. They stop at the new source-level control, becausefractlowers to a barefrac. With that control removed, the new draw failed on hardware (pixel_mismatch x=0 y=0 channel=0 expected=0.999512 actual=1) and passed on WARP, matching the table above.ctest --preset dev --no-tests=error: 118 passed, 0 failed, 3 capability skips (bvh_wave64_hardware,bvh_wave64_warp,wave_shuffle_warp).form_coverage_check.pypassed.Evidence and follow-up
The new draw
check_fract_drawuses synthetic constants only, with inputs -2^-30, -0.25, 2.75 and -2^-23. The Python reference computesmin(single(x - floor(x)), 0x3f7fffff)and asserts that the first input is the case where the unclamped value is exactly 1.0. A second reference that expects 1.0 for that channel must report a mismatch, so the check cannot pass if the renderer stops distinguishing the clamp.check_controlsalso asserts thatshaping()lowers throughfract32(and never a barefrac(. That check runs in bothdrawandbinarymode, so the Linux job covers it too.docs/experiments.mdgains one paragraph in the pixel-shader section.Not measured: the value on AMD hardware itself. The clamp comes from the ISA text and LLVM's codegen, not from a draw on an RDNA GPU.
Checklist
AI-assisted (Claude Code). Every result above was run locally on the configuration listed.