Skip to content

shader: preserve the direct fract binary32 upper bound - #3285

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
wish131400:shader/direct-fract-f32-bound
Nov 28, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
wish131400:shader/direct-fract-f32-bound

Conversation

@wish131400

Copy link
Copy Markdown
Contributor

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 #3283. 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 R0Y00#267, R0Y00#2010.
@Leyukaka

Copy link
Copy Markdown
Collaborator

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.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
R0Y00 merged commit 17f112b into R0Y00:main Nov 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Direct DXIL v_fract_f32 can return 1.0 for tiny negative inputs

3 participants