Skip to content

shader: lower quad-local DPP16 and DPP8 binary16 ops in pixel_aot - #419

Open
KomaGuy wants to merge 6 commits into
R0Y00:mainfrom
KomaGuy:shader/dpp-quad-f16-ops
Open

KomaGuy wants to merge 6 commits into
R0Y00:mainfrom
KomaGuy:shader/dpp-quad-f16-ops

Conversation

@KomaGuy

@KomaGuy KomaGuy commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Change

Lower quad-local DPP16 (quad_perm) and DPP8 (dpp8) forms for all 23 binary16 VOP1/VOP2 operations in tools/pixel_aot.py, covering 23 additional DPP16 and 23 additional DPP8 forms (+46 forms on both gfx1013 and gfx1030):

  • Supported v_*_dpp instructions (23):
    • Conversion & scale (4): v_cvt_f16_f32_dpp, v_ldexp_f16_dpp, v_frexp_mant_f16_dpp, v_frexp_exp_i16_f16_dpp.
    • Arithmetic & min/max (7): v_add_f16_dpp, v_sub_f16_dpp, v_subrev_f16_dpp, v_mul_f16_dpp, v_min_f16_dpp, v_max_f16_dpp, v_fmac_f16_dpp.
    • Rounding (5): v_floor_f16_dpp, v_ceil_f16_dpp, v_trunc_f16_dpp, v_rndne_f16_dpp, v_fract_f16_dpp.
    • Transcendentals & trig (7): v_log_f16_dpp, v_exp_f16_dpp, v_rcp_f16_dpp, v_sqrt_f16_dpp, v_rsq_f16_dpp, v_sin_f16_dpp, v_cos_f16_dpp.
  • RDNA 2 16-bit semantics & deterministic packing: Swizzles src0 as uint bits via SM 6.0 quad intrinsics, preserves vdst[31:16] per gfx1013 16-bit destination semantics (rejecting uninitialized destination VGPRs), and packs binary16 results with an optional pack16_rne helper (plus min16_num/max16_num, fract16, and exact bit-level dpp_ldexp_f16/dpp_frexp_{mant,exp}_f16 helpers emitted only when used). v_sin_f16_dpp and v_cos_f16_dpp scale turn inputs by 2π.
  • Strict fail-closed controls: Rejects uninitialized destination VGPRs, cross-quad DPP8, row_*/wave_* controls, partial masks (row_mask/bank_mask != 0xf), source modifiers on DPP8 and on v_ldexp_f16_dpp's i16 exponent operand, non-VGPR operands, WQM, and vmcnt hazards.
  • Genuine 4-lane quad draw fixture: DPP_F16_BODY derives binary16 quad lane ID {0, 1, 2, 3} from uv.x/uv.y, tests all 23 forms across 2 constant sets (with junk in the high 16 bits of inputs), and checks 5 negative mutations (AcrossX vs AcrossY, cyclic dpp8 rotation, rndne tie-to-even, sin vs cos turns, and DPP16 negation).

Verification

Tested on Linux x86_64 (Python 3.13.5, LLVM 19.1.7, Clang 19.1.7) on top of 6549244:

  • python3 -B tests/pixel_aot_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM-19.so — passed (controls, negative controls, and llvm-mc -mcpu=gfx1013 assembly→DXBC/XDAT/XBCH/FSSM→disassembly→lowering parity for DPP_F16_BODY and all existing fixtures).
  • python3 -B tests/ffx_dispatch_aot_check.py llvm-mc-19 llvm-objcopy-19 libLLVM-19.so — passed.
  • python3 -B tests/script_state_check.py, tests/bcpack_check.py, tests/resource_ranges_check.py, tests/layout_chunks_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py — all passed.
  • Verified tools/form_coverage.py records 23 DPP16 and 23 DPP8 forms against both docs/coverage/gfx1013.tsv and docs/coverage/rdna2.tsv.
  • Executed the actual generated HLSL (with verbatim generated helpers) for DPP_F16_BODY and all 5 negative mutations on a 4-lane SIMT 2×2 pixel quad C++20 harness with clang++-19 -std=c++20 -O2 -Wall -Wextra -Wpedantic -Werror -fsanitize=undefined,address — bit-exact match across all 4 quad lanes on both constant sets and all 5 mutations caught; 0 sanitizer errors.
  • Windows C++, DXC (dxc -Gis -T ps_6_0), WARP (pixel_aot_warp), and hardware (pixel_aot_hardware) checks were not run locally on Linux; relying on the build-and-test Windows CI job to verify DXC compilation and D3D12 WARP quad readback.

Evidence and follow-up

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

@KomaGuy

KomaGuy commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Refreshed onto main (579f58f), reusing the shared DPP helpers from #408 and compile_shader. All 4/4 CI checks are green (9a773f3). Holding #421, #423, and #428 until this lands.

@KomaGuy

KomaGuy commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Updated check_dpp_f16_draw (96fa78f) to compile with mode="any" and assert flush_ftz(word) == word on every expected word (matching #363's curve exception and #569 for dpp, since DPP_F16_BODY also exercises log2/exp2/rcp). All 4/4 CI checks are green.

@thepatrickworld

Copy link
Copy Markdown
Contributor

@KomaGuy Independent AMD (RDNA4, native wave64) result on 96fa78f. Measurements only, no code change.

Environment

  • Windows 11 25H2, build 26200.9711
  • MSVC 19.44.35230 (toolset 14.44.35207), Windows SDK 10.0.26100.0, DXC 1.9.2602.17
  • AMD Radeon RX 9070 XT, vendor 1002, device 7550, driver 32.0.32029.2010. native_wave_width=64 logical_width=64 measured in the same worktree (bvh_waves_hardware); the pixel_aot harness does not print the wave width itself.
  • debug_layer=unavailable (Tools.Graphics.DirectX is NotPresent here)
  • Clean worktree of the PR head 96fa78f, whose last commit is tests: use mode="any" for dpp_f16 draw fixture — so this run covers the fixture after that change, not before it.

Commands

cmake --preset dev
cmake --build --preset dev --parallel 12 --target offscreen_check
set XBOX2WINDOWS_ADAPTER=AMD Radeon RX 9070 XT
ctest --preset dev --no-tests=error -V -R "^pixel_aot_(hardware|warp)$"

Observed

1/2 Test: pixel_aot_hardware ... Passed
2/2 Test: pixel_aot_warp ....... Passed
Total Test time (real) = 33.69 sec
  • 49 draw cases on hardware: 48 at pixels=4096 channels=16384 and one at pixels=64 channels=256, every one max_absolute_error=0.
  • 49 draw cases on WARP in the same build, same split, max_absolute_error=0.
  • No non-zero absolute error on either backend.

What it establishes

The binary16 quad-local ops produce bit-identical output to the CPU reference on a native wave64 adapter, with the mode="any" fixture in place. Half-precision conversions and comparisons are sensitive to flush and rounding behaviour, so a vendor difference here would surface as a small non-zero absolute error rather than a failure to compile — none appeared across 16,384 channels per draw, on both the hardware and the WARP backend.

Limit

The harness prints per-draw counters but no per-program label, so this is a whole-suite result rather than a per-form attribution. And this run is on the PR head only: the tree has no per-case dpp_f16 breakdown in its output.

AI-assisted; runs executed locally.

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

Ran the Windows gates the author could not (Linux-only environment) on Windows 11 build 26300.10075, RTX 5070 (10de:2f04) driver 32.0.16.2135, in-box WARP 10.0.26100.10068, debug layer enabled.

Results:

  • tests/pixel_aot_check.py controls: pass. tests/form_coverage_check.py: pass. LLVM 15 gfx1013 binary round-trip: pass.
  • pixel_aot_warp: pass (12.38s, debug_errors=0).
  • pixel_aot_hardware: the new check_dpp_f16_draw itself ran and passed on the RTX 5070 (it is invoked before check_dpp_draw in check_render, which is where the test aborts). DXC compiles the generated HLSL and all five mutations report pixel_mismatch as designed.

One non-code issue: the run then fails in the pre-existing f32 dpp fixture with Translated pixel pipeline failed (HRESULT 0x8007000e) on the RTX 5070. That failure is a stale-base artifact, not a defect in this change: upstream b7a0597 (#569) already fixed this exact NVIDIA PSO failure by switching the dpp fixture to mode="any", and it is not in this branch's merge base (579f58f). A fresh merge or rebase onto current main should turn the hardware run green. The PR's own mode="any" commit for dpp_f16 is incidentally the same remedy.

Semantic review of the new code:

  • DPP_F16 table is faithful: f16 ops pack via pack16_rne and merge with vdst[31:16] preserved (dpp{i}_hi | dpp{i}_lo), matching gfx1013 16-bit destination semantics.
  • v_fmac_f16_dpp correctly accumulates prev_val of the destination VGPR; v_ldexp_f16_dpp sign-extends the low-16 exponent operand; v_cvt_f16_f32_dpp reads its source as f32 rather than widen16 — all three special cases handled.
  • allow_mods = not is_dpp8 enforces the ISA rule that DPP8 forms take no source modifiers.
  • fract16, dpp_ldexp_f16, dpp_frexp_*_f16 are bit-exact helpers (zero/inf/NaN passthrough, exponent clamps, mantissa forced into [0.5,1)), consistent with the f32 frexp/ldexp approach documented in experiments.
  • Interaction with #651: the new v_*_f16_dpp mnemonics are auto-denied inside exec-masked regions by the existing _dpp pattern in REGION_DENIED — correct, since quad-local ops are not pure per-lane.

No blockers on the change itself; flagging only the stale base for the hardware gate.

AI-assisted: yes. All reported checks ran locally on the adapter and driver listed.

Copy link
Copy Markdown
Contributor

Independent RTX 3060 Ti run on 96fa78f179100803c0a535366e04165bfbdb6264. Windows 10 22H2 build 19045.6466, MSVC 19.44.35230, Windows SDK 10.0.26100.0, DXC 1.8.2502.11. D3D12 debug layer unavailable.

cmake --preset dev "-DINTAKE_PYTHON=$((Get-Command python).Source)" "-DDXC_EXECUTABLE=$dxc" -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug
cmake --build --preset dev --parallel 4 --target offscreen_check
$env:XBOX2WINDOWS_ADAPTER = 'RTX 3060 Ti'
ctest --preset dev --no-tests=error -V -R '^pixel_aot_(hardware|warp)$'
  • Hardware: RTX 3060 Ti (10de:2414), driver 621.24 (32.0.16.2124 via DXGI). The full suite passed, including the existing FP32 check_dpp_draw.
  • Software: In-box WARP (1414:008c), driver 10.0.19041.5794. The full suite passed.
  • Skipped: Zero.

I also ran check_dpp_f16_draw directly on each backend. The two expected RGBA values were (9.5, 32.5, 16.0, 3.125) and (6.25, -23.5, 27.0, -2.25). Both draws matched all 4,096 pixels on both backends with zero absolute error. All five shader mutations returned exit 1 with pixel_mismatch.

AI-assisted. All tests were run locally.

@KomaGuy

KomaGuy commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @thepatrickworld (RX 9070 XT wave64), @rwZephyr (RTX 3060 Ti), and @MarlomMedeiros (RTX 5070 + semantic review) for the independent hardware runs!

Merged latest main (b5509fe, which includes #569's dpp fix) into this branch at 64c4329 so the full RTX 50-series hardware gate is green too. CI is running now.

R0Y00 commented Nov 23, 2026

Copy link
Copy Markdown
Owner

I fast-forwarded the branch to 68603ab. The merge preserves the existing binary fixtures and puts the new DPP half-float draw in its own pixel_aot_dpp_f16_* CTest. I also reproduced a raw mismatch that the aggregate color missed: WARP returned 0x8001 for v_cos_f16(0.25) before the fix, where AMD's RDNA 2 ISA reference gives 0x0000. The updated fixture checks the exact words for quarter turns, largest finite values, signed zero and infinities, plus the wrong-word control. LLVM 15 round-trip, WARP and RTX 4060 Laptop passed locally. The destination high-half sentinel checks what the translation does. If you have a DPP-specific gfx1013 reference or native readback for that preserved upper half, please link it here for review before merging.

@KomaGuy

KomaGuy commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

I fast-forwarded the branch to 68603ab. The merge preserves the existing binary fixtures and puts the new DPP half-float draw in its own pixel_aot_dpp_f16_* CTest. I also reproduced a raw mismatch that the aggregate color missed: WARP returned 0x8001 for v_cos_f16(0.25) before the fix, where AMD's RDNA 2 ISA reference gives 0x0000. The updated fixture checks the exact words for quarter turns, largest finite values, signed zero and infinities, plus the wrong-word control. LLVM 15 round-trip, WARP and RTX 4060 Laptop passed locally. The destination high-half sentinel checks what the translation does. If you have a DPP-specific gfx1013 reference or native readback for that preserved upper half, please link it here for review before merging.

@R0Y00 Thanks for fast-forwarding and catching that v_cos_f16(0.25) mismatch! I don't have a native gfx1013 readback or a DPP-specific reference for the preserved upper half on hand. I'm away from my PC for ~8 hours, so feel free to merge as-is if the current sentinel check looks good to you, or let me know if you'd like me to dig into the ISA docs once I'm back.

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.

6 participants