Skip to content

shader: lower v_div_fixup_f32 in the pixel AOT path - #3657

Merged
R0Y00 merged 7 commits into
R0Y00:mainfrom
lambirou:shader/div-fixup-f32
Dec 3, 2026
Merged

R0Y00 merged 7 commits into
R0Y00:mainfrom
lambirou:shader/div-fixup-f32

Conversation

@lambirou

Copy link
Copy Markdown
Contributor

Problem

v_div_fixup_f32 (VOP3, gfx1013/gfx1030) is listed as unobserved in the
coverage tables. The direct-DXIL compute path has its own lowering and hardware
test, but the pixel pixel_aot path had no lowering and no passing fixture that
writes a coverage record. No open pull request covers the f32 form; #3594 only
covers the binary16 form and is not a dependency.

Change

  • tools/pixel_aot.py: add the integer div_fixup32(s0, s1, s2) helper and a
    plain VOP3A lowering. It follows the RDNA 2 ISA section 12.12, opcode
    351

    and the existing tests/native_div_fixup_f32_check.py::div_fixup_f32:
    Quiet(S2) before Quiet(S1), 0xffc00000 for 0/0 and Inf/Inf, signed
    infinity for S1 == 0 or abs(S2) == Inf, signed zero for abs(S1) == Inf
    or S2 == 0, signed zero for exponent(S2) - exponent(S1) < -150, and
    sign(S1) ^ sign(S2) | abs(S0) otherwise, including an S0 NaN.
  • The lowering accepts only the plain VOP3A spelling (with or without _e64),
    VGPR/SGPR sources and a VGPR destination. abs/neg, clamp, omod,
    op_sel, DPP, SDWA, literals, inline constants, a non-entry mask and a write
    overlapping a pending sample are refused.
  • tests/pixel_aot_check.py: add draw-div-fixup, 22 constant rows evaluated
    four ways each through the lossless R32G32B32A32_UINT target, and compare
    every word with native_div_fixup_f32_check.div_fixup_f32. The rows cover the
    finite default, both signed-zero defaults, both signs of S1 zero, S2
    infinity, S1 infinity and S2 zero, 0/0, Inf/Inf, quiet/signaling NaNs with
    payloads in S1 and S2, S2 priority, an S0 NaN, the -150/-151 boundary and
    mixed signs. Five one-line mutations must mismatch: inverted sign XOR,
    reversed NaN priority, non-canonical 0/0, lost signed zero and swapped S1/S2
    special cases.
  • Register pixel_aot_div_fixup_warp and pixel_aot_div_fixup_hardware with
    FORM_COVERAGE_RECORD; pin exactly ("VOP3", "v_div_fixup_f32") in
    tests/form_coverage_check.py; add scanner support and its refusal control
    in tests/rdna2_tools_check.py; document the behavior in
    docs/experiments.md.

Verification

Exact commands run from the worktree root:

.\tools\dev.ps1
cmake --preset dev -DINTAKE_PYTHON=C:/Users/rolandedi/dev/labs/xbox-recomp/Xbox2Windows/out/pe-env/Scripts/python.exe
cmake --build --preset dev --target offscreen_check
cmake --build --preset dev
python -B tests/pixel_aot_check.py
ctest --preset dev --no-tests=error -R '^pixel_aot_div_fixup_' -V
python -B tests/form_coverage_check.py
python -B tests/rdna2_tools_check.py
python -B tests/docs_links_check.py

Results:

  • Configure succeeded; offscreen_check built; the full cmake --build --preset dev
    completed with exit 0 (incremental re-run: no work beyond the build stamp).
  • python -B tests/pixel_aot_check.py: exit 0.
  • ctest --preset dev --no-tests=error -R '^pixel_aot_div_fixup_' -V: 2/2
    passed, 0 failed, no skips. pixel_aot_div_fixup_hardware 6.88 s;
    pixel_aot_div_fixup_warp 5.80 s. Both printed the five mutations as
    mismatch.
  • WARP: Microsoft Basic Render Driver 10.0.26100.10068.
  • Hardware: AMD Radeon RX 9060 XT (1002:7590, driver
    32.0.32029.2010), Windows 11 build 26300.0, DXC 1.8.2502.11;
    the D3D12 debug layer was unavailable in this environment.
  • The WARP and hardware coverage records contain v_div_fixup_f32 and no
    _e64, f16 or f64 form. gfx_forms maps the record to one
    ("VOP3", "v_div_fixup_f32") row in both gfx1013.tsv and rdna2.tsv.
    Expected delta: +1 gfx1013 and +1 gfx1030.
  • python -B tests/form_coverage_check.py: form coverage checks passed.
  • python -B tests/rdna2_tools_check.py: 161 tests, OK (skipped=19);
    the 19 skips are the LLVM-library-dependent cases, reported separately.
  • python -B tests/docs_links_check.py: self-test passed; 192 Markdown files
    and 745 links checked.

Limits

No console measurement is claimed. The draws show the translated HLSL on WARP
and on one physical RDNA 4 adapter, not native RDNA 2 behavior. The ISA
Quiet() rule is applied to every signaling NaN; a guest MODE that leaves
signaling NaNs unquieted is not modelled. The lowering covers plain VOP3A
register sources only; DPP, SDWA, literals, inline constants and modifiers stay
out of scope. No native RDNA 2 readback is claimed for the underflow or NaN
payload rows.

AI-assisted: yes (deepseek-v4.1-flash).

Add the plain VOP3A v_div_fixup_f32 finalization on raw 32-bit words, with the ISA NaN priority, canonical invalid NaN, signed zero/infinity cases, -150 underflow boundary and sign(S1)^sign(S2)|abs(S0) default. Add the draw-div-fixup fixture, five detecting mutations, form-coverage pin, scanner support and experiment note.

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed fb934b05 by reading the diff; not built or run.

Verdict: comment. The lowering is correct and I would approve it. The one SHOULD is a one-line docs fix that is better made before merge than after. No MUST.

  • SHOULD The new docs/experiments.md block sets -DINTAKE_PYTHON= to an absolute path inside the author's own user folder (docs/experiments.md:14484). It is a personal path in public docs, and it won't work for anyone else. The other commands in the same block use .\out\pe-env\Scripts\python.exe, so -DINTAKE_PYTHON=out/pe-env/Scripts/python.exe (or no flag at all) fits.
  • Checked, no finding:
    • div_fixup32 (tools/pixel_aot.py:692) uses the same priority order and constants as the existing reference tests/native_div_fixup_f32_check.py:61, which the direct compute path already uses: Quiet(S2), Quiet(S1), canonical 0xffc00000 for 0/0 and Inf/Inf, signed Inf, signed zero, the < -150 exponent rule on raw exponents, then sign XOR over |S0|. The pixel and compute paths therefore agree, including an S0 NaN copied by magnitude.
    • The handler reads raw words with asuint(fp_operand(...)). It refuses modifiers, clamp/omod, literals and inline constants by matching only plain [vs]N operands, refuses a non-entry mask and an overlap with a pending sample, and range-checks the VGPR/SGPR indices. The helper is emitted only when used. The scanner pattern accepts the same spelling.

Tests: the draw-div-fixup rows (22 × 4 words, lossless R32G32B32A32_UINT) prove each rule bit for bit, including the −150/−151 boundary and NaN payloads. The five mutations show the rows catch a sign, priority, canonical-NaN, signed-zero or S1/S2 swap error. CI ran pixel_aot_check.py, form_coverage_check.py and rdna2_tools_check.py at this head. The WARP/hardware draws are outside the pr filter, so they rest on the author's WARP and RX 9060 XT runs.

@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 Windows checks passed on dcacef36: exact-head pixel translator and form coverage checks, plus draw-div-fixup on WARP and RTX 4060 Laptop. All five mutations mismatched on both adapters. This merges cleanly with current main. The one remaining documentation line is the checkout-specific interpreter path previously raised by lukaslw-lab.

Comment thread docs/experiments.md Resolved

@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.

The reproduction now uses the checkout default Python path. In the current form_coverage_check.py, however, the main block no longer invokes check_mullit_coverage. I compared the module-level calls on this head with current main: the function is still defined, but its only invocation is gone. Please keep the new div-fixup test and restore the existing MULLIT call in the active main block, then rerun python -B tests/form_coverage_check.py.

@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.

Re-reviewed 673e197. The active coverage entry point retains MULLIT and the new divide-fixup check, and the documented command uses the repository interpreter. form_coverage_check.py passed in the project Python environment. A deliberately failing MULLIT assertion also caused the entry point to fail. Windows build 26300, SDK DXC, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656: draw-div-fixup passed on both adapters, including all five failure mutations, with no skips. This resolves my previous change request.

@R0Y00
R0Y00 merged commit 52c4b97 into R0Y00:main Dec 3, 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.

3 participants