shader: preserve the direct fract binary32 upper bound #3287

Manually merged
github merged 1 commit from github-bot/gh-3285 into gh-pr/3285/base 2026-11-28 05:49:07 +00:00 AGit
Owner

@⁠wish131400 on GitHub · 2026-11-28 05:17 UTC · original
wish131400:shader/direct-fract-f32-bound → main · +188 −2 · 4 files · 1 commits · merged 2026-11-28 05:42 UTC

The direct DXIL frontend emits v_fract_f32 as an uncapped DXIL Frc. For tiny negative inputs such as -2^-30 and -2^-28, the desktop result rounds to 1.0. The project's gfx1013 contract requires the greatest binary32 below 1.0; a mul:2 output modifier therefore also produces an incorrect 2.0. Fixes #3285. The Python paths already received the corresponding bound in #267 and #2010; this change covers the newer native direct frontend.

Apply an ordered upper-bound comparison before output scaling and clamp. NaNs pass through unchanged. Add a source-built request fixture for eight inputs across VOP1, source-negated VOP3, clamp and mul:2, with two wave32 groups and guard words. The modified frontend is already part of the generated cache revision.

Validation at head 309c50e0, rebased onto aeef65b2:

  • Original frontend: the new readback fixture differs on 384 of 2,064 output/guard words.
  • Fixed frontend: all 2,048 output words and 16 guards match; NaNs compare by class.
  • compile_dxil and native_store_replay rebuilt successfully after the rebase.
  • native_fract_f32_controls passed; the pre-rebase patch also passed native_f16_alu_ir, native_frexp_f32_controls and native_mad32_controls.
  • python -B tests/docs_links_check.py: 142 Markdown files / 661 links passed. git diff --check passed.

Measured readbacks: Windows 10 build 19045, RTX 4070 Ti SUPER, driver 32.0.15.7270, DXC 1.9.2609, Agility 1.620.2, D3D12 debug layer disabled. The ordinary Windows 10 fixture executable returns capability skip 77 for SM6.6; the measured run locally relinked the same fixture objects with Agility version/path exports and used the existing matching runtime. This is documented in the experiment note; no SDK runtime is added to the repository. No console hardware or full-program result is claimed.

All instruction bytes are constructed by the fixture. No game assets or SDK implementation code are included.

**@⁠wish131400** on GitHub · 2026-11-28 05:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3285) `wish131400:shader/direct-fract-f32-bound` → `main` · +188 −2 · 4 files · 1 commits · merged 2026-11-28 05:42 UTC The direct DXIL frontend emits `v_fract_f32` as an uncapped DXIL `Frc`. For tiny negative inputs such as -2^-30 and -2^-28, the desktop result rounds to 1.0. The project's gfx1013 contract requires the greatest binary32 below 1.0; a `mul:2` output modifier therefore also produces an incorrect 2.0. Fixes #3285. The Python paths already received the corresponding bound in #267 and #2010; this change covers the newer native direct frontend. Apply an ordered upper-bound comparison before output scaling and clamp. NaNs pass through unchanged. Add a source-built request fixture for eight inputs across VOP1, source-negated VOP3, clamp and `mul:2`, with two wave32 groups and guard words. The modified frontend is already part of the generated cache revision. Validation at head `309c50e0`, rebased onto `aeef65b2`: - Original frontend: the new readback fixture differs on 384 of 2,064 output/guard words. - Fixed frontend: all 2,048 output words and 16 guards match; NaNs compare by class. - `compile_dxil` and `native_store_replay` rebuilt successfully after the rebase. - `native_fract_f32_controls` passed; the pre-rebase patch also passed `native_f16_alu_ir`, `native_frexp_f32_controls` and `native_mad32_controls`. - `python -B tests/docs_links_check.py`: 142 Markdown files / 661 links passed. `git diff --check` passed. Measured readbacks: Windows 10 build 19045, RTX 4070 Ti SUPER, driver 32.0.15.7270, DXC 1.9.2609, Agility 1.620.2, D3D12 debug layer disabled. The ordinary Windows 10 fixture executable returns capability skip 77 for SM6.6; the measured run locally relinked the same fixture objects with Agility version/path exports and used the existing matching runtime. This is documented in the experiment note; no SDK runtime is added to the repository. No console hardware or full-program result is claimed. All instruction bytes are constructed by the fixture. No game assets or SDK implementation code are included.
Match the established fract32 bound from the Python translators in the newer direct DXIL lowering. Preserve NaNs and apply the cap before output modifiers. Refs #267, #2010.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 05:21:01 +00:00
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-28 05:28 UTC · original

I reviewed the diff (not run). I found nothing wrong with the cap itself. Some notes on its form and on the fixture:

  • Comparison form. The lowering caps with fcmp oge float %r, 1.0 on the Frc result. tools/startup/gfx2hlsl.py deliberately compares the bits instead (asuint(f) == 0x3f800000u), because FXC folded frac(value) >= 1.0f to false. The direct path only assembles and validates, with no optimizer pass, and the PR's control asserts that fcmp oge float is in the dumped container. I have not checked whether a driver backend can use Frc's range to fold it. A bit comparison would avoid the question.
  • The rounding boundary. -2^-25 (0xb3000000) is an exact binary32 tie: 1 - 2^-25 rounds to even, which is 1.0, and needs the cap. Its neighbour 0xb3000001 gives 0x3f7fffff without the cap. The fixture uses -2^-30 and -2^-28, which are well inside the capped range, so the edge of that range is not pinned.
  • neg and the cap. All the tiny inputs are already negative, so the neg0 form turns them into positive values that never reach the cap. A tiny positive input such as 0x33000000 with neg0 would cover it.
  • Infinities. Neither +inf nor -inf is among the inputs, and the reference fract() would raise on them: math.floor(inf) raises OverflowError before the cap.
  • Denormals. The fixture has no binary32 denormal input. With f32 denormals preserved (the repo notes that gfx1013 starts with MODE[5:4] = 3), -2^-149 is another input that needs the cap. I have not checked whether Frc keeps or flushes denormal inputs on the host adapter, which would change the result to 0.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-28 05:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3285#issuecomment-7234693738) I reviewed the diff (not run). I found nothing wrong with the cap itself. Some notes on its form and on the fixture: - **Comparison form.** The lowering caps with `fcmp oge float %r, 1.0` on the `Frc` result. `tools/startup/gfx2hlsl.py` deliberately compares the bits instead (`asuint(f) == 0x3f800000u`), because FXC folded `frac(value) >= 1.0f` to false. The direct path only assembles and validates, with no optimizer pass, and the PR's control asserts that `fcmp oge float` is in the dumped container. I have not checked whether a driver backend can use `Frc`'s range to fold it. A bit comparison would avoid the question. - **The rounding boundary.** `-2^-25` (`0xb3000000`) is an exact binary32 tie: `1 - 2^-25` rounds to even, which is 1.0, and needs the cap. Its neighbour `0xb3000001` gives `0x3f7fffff` without the cap. The fixture uses `-2^-30` and `-2^-28`, which are well inside the capped range, so the edge of that range is not pinned. - **`neg` and the cap.** All the tiny inputs are already negative, so the `neg0` form turns them into positive values that never reach the cap. A tiny positive input such as `0x33000000` with `neg0` would cover it. - **Infinities.** Neither +inf nor -inf is among the inputs, and the reference `fract()` would raise on them: `math.floor(inf)` raises `OverflowError` before the cap. - **Denormals.** The fixture has no binary32 denormal input. With f32 denormals preserved (the repo notes that gfx1013 starts with `MODE[5:4] = 3`), `-2^-149` is another input that needs the cap. I have not checked whether `Frc` keeps or flushes denormal inputs on the host adapter, which would change the result to 0. AI-assisted.
github-bot changed target branch from main to gh-pr/3285/base 2026-11-28 05:49:05 +00:00
github manually merged commit 309c50e0ec into gh-pr/3285/base 2026-11-28 05:49:07 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-28 05:42 UTC · original · approved these changes

Independent Release check on 309c50e0: ctest --preset release --no-tests=error -V -R '^native_fract_f32_' passed 2/2 without a capability skip. On Windows 11 build 26200.9974 with the standard fixture executable, SDK DXC 10.0.26100 and RTX 4060 Laptop driver 32.0.16.1656, the physical readback matched 2,048 result words and 16 guards. The ordered comparison preserves NaNs and applies the cap before scaling/clamping. The uncapped and NaN-losing reference controls differ.

**@⁠R0Y00** on GitHub · 2026-11-28 05:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3285#pullrequestreview-6096108659) · **approved these changes** Independent Release check on `309c50e0`: `ctest --preset release --no-tests=error -V -R '^native_fract_f32_'` passed 2/2 without a capability skip. On Windows 11 build 26200.9974 with the standard fixture executable, SDK DXC 10.0.26100 and RTX 4060 Laptop driver 32.0.16.1656, the physical readback matched 2,048 result words and 16 guards. The ordered comparison preserves NaNs and applies the cap before scaling/clamping. The uncapped and NaN-losing reference controls differ.
This discussion has been locked. Commenting is limited to contributors.
No description provided.