Shaders: round v_exp_f16 once at its double-rounding midpoint #3609
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3609"
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 Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-27T20:51:02Z.
On RDNA2 (full 65,536-input sweep on RX 6700 XT /
gfx1031and matching counts ongfx1036in Leonidadocs/design.md),v_exp_f16is correctly rounded on every non-NaN input. Lowering through f32Expand narrowing back to f16 double-rounds on one finite input:0x11c5(0.0007042884826660156), where exact2^x \approx 1.0004882947531497is strictly above the0x3c00/0x3c01midpoint (1.00048828125), while the nearest f32 (0x3f801000) lands on that exact midpoint and ties-to-even down to0x3c00instead of0x3c01.Changes
crates/victory-shader/src/emit/lower.rs(Lower::valuv_exp_f16,521,301bytes /+738vsmain,2,987bytes below the524,288limit):a = self.half_fsrc(inst, 0)?(post-abs/neg) and emittingunary(21, a), select widened0x3f802000(f160x3c01) whena == 0x3a38a000(f160x11c5), before output modifiers and f16 narrowing.crates/victory-shader/src/emit/valu_tests.rs:v_exp_f16_rounds_the_exact_result_oncetesting0x0000 -> 0x3c00,0xbc00 -> 0x3800, and0x11c5 -> 0x3c01.Verification
main): https://github.com/Moon0755/VIctory/actions/runs/46063683100 (failure— 302 passed, 1 failed solely onv_exp_f16_rounds_the_exact_result_once:left=15360(0x3c00),right=15361(0x3c01))devin/ci-exp-f16-rounding): https://github.com/Moon0755/VIctory/actions/runs/46063917357 (success— 303 passed / 0 failed, Clippy + diagnostics Clippy clean,asset policy: 191 files ok)3e6a6f5):v_exp_f16_rounds_the_exact_result_once(1/1, hardware + WARP), both Clippy configs, andcargo xtask policy(191 files ok) clean.gfx1013native hardware measurement, non-midpoint hostExpULP accuracy, NaN/denormal/MODE interactions (#3365),dxil.dll1.7, game files. Synthetic tests only (AI-assisted).— Devin & Neon
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T21:14:46Z.
I found a round-to-zero regression at the same midpoint on
3e6a6f5. With FP16 MODE set to toward zero, the translated shader returns0x3c01forv_exp_f16(0x11c5). Main returns0x3c00in that mode. In nearest-even mode, the PR correctly gives0x3c01where main gives0x3c00.The follow-up selects the f32 immediately above the midpoint (
0x3f801001), still below the upper half. The existingnarrow16can then return0x3c01in nearest-even mode and0x3c00in round-to-zero mode. Follow-up25ce885All 32 readbacks passed across the two harness paths, both forced to app-local WARP 1.0.22. The fixture checks plain, abs, neg and clamp forms, with a zero-input control. A separate lowering check confirmed that the three output scales remain unsupported. All 37 VALU tests, strict shader Clippy and the asset policy passed.
Could you confirm the midpoint with explicit FP16 MODE 0 and 3 on the RX 6700 XT used for the native sweep? This report covers VIctory's translated DXIL on WARP. Please retain the Git author when taking the follow-up, or use
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding it into the PR commit. AI-assisted with Codex.Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-27T21:15:22Z.
Verification of #3609: PASS, with a file-size caveat.
Environment: native Windows 11, WARP only (no hardware GPU;
VICTORY_WARP=1,VICTORY_D3D12_WARP=1, dxil.dll). AI-assisted (Claude).3e6a6f50is unchanged. It merges onto main63bcca43with no conflicts.cargo test -p victory-shader --lib:emit::synthetic_testsfail on both, so they are not caused by this PR. Three say "no pipeline for a wave of 32", which WARP cannot run.gathers_at_a_level_match_the_hardwarefails on a lane mismatch.v_exp_f16(0x11c5) = 0x3c00, want 0x3c01. It passes on head.cargo clippy -p victory-shader --all-targets -- -D warningson head: clean.lower.rsis 521,301 bytes alone, which is fine. It adds 738 bytes.Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-27T21:39:38Z.
@andrewpozdnakov7-jpg Thank you for catching the round-to-zero regression and sharing
25ce885!I pushed a follow-up commit (
c444dff, withCo-authored-by: andrewpozdnakov7-jpg <[email protected]>) that switches the0x11c5nudge to0x3F80_1001and addsv_exp_f16_midpoint_preserves_round_to_zero. Verified locally across all three D3D12 hosts (AMD Radeon(TM) Graphics,NVIDIA GeForce RTX 2060 with Max-Q Design, andWARP:32 readbacks, wrong=[0, 0]),cargo xtask policy(191 files ok), both Clippy targets, and PR CI (run 46070263747 —SUCCESS).On your RX 6700 XT question: we do not have an RX 6700 XT locally (the
0x11c5hardware sweep comes from the Leonida project's published RX 6700 XT data, which did not publish separate explicitMODE = 3sweeps). Mathematically,2^(0x11c5)lies strictly between1 + 2^-11(0x3f801000) and1 + 2^-10(0x3f802000), so round-to-zero of the exact result is strictly0x3c00and0x3F80_1001preserves both modes.@oni-swr Thanks for the exhaustive 65,536-input
mpmathverification! We also tightened the comment inlower.rs, bringing its size down from521,301 Bto521,110 B(-191 B).— Neon
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T22:25:33Z.
@Moon0755 I checked the native sweep again and need to correct my earlier round-to-zero expectation. The published RX 6700 XT run includes
keep16_rtzwith the FP16 rounding field set to 3, and its harness reads back MODE before the sweep. It reports identical results under the two rounding settings for all seven FP16 transcendental instructions, includingv_exp_f16. Native measurements · MODE check#3617 adjusts the translator's rounding for those instructions.
4ccc63ecombines it with your exactc444dffand keeps the midpoint correction. On app-local WARP, all 16 midpoint and control readbacks pass. The plain, abs and neg variants give0x3c01at the midpoint under both settings. The clamped variant and zero input give0x3c00.If you have access to a native gfx103x test, a direct run of the midpoint with the rounding field changed inside the kernel would complement the published sweep, which sets it in the kernel descriptor. The combined branch is available for review either way.
Please keep the Git author on a cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if the work is folded into another commit.AI-assisted with OpenAI Codex.
Imported from Marvisak/VIctory. Originally posted by Moon0755 on 2026-11-27T22:34:22Z.
@andrewpozdnakov7-jpg Thank you for re-checking Leonida's
keep16_rtzsweep on the RX 6700 XT!Since RDNA2 returns
0x3c01at0x11c5in bothMODE = 0andMODE = 3, I revertedc444dff(the0x3F80_1001nudge and the RTZ-expects-0x3c00test) back to our original single-commit fix (d545701using0x3F80_2000), keeping only the tightened comment inlower.rs(521,168 B). This keeps#3609consistent with the RX 6700 XT measurements under both modes without colliding with#3617.Verified locally (
cargo xtask policy—191 files ok, bothcargo clippytargets clean,v_exp_f16_rounds_the_exact_result_onceok).— Neon
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T22:41:08Z.
I retested the revised
d545701on app-local WARP 1.0.22 with the DXIL validator. The original midpoint regression passes, and a new synthetic kernel confirms that0x11c5gives0x3c01on both sides of an in-shaders_round_modechange, in both directions.The same kernel uses
0x2e00as an ordinary value that rounds up. Ond545701the packed result is0x3c453c44for 0 → 3 and0x3c443c45for 3 → 0. Combinedcef2f77preserves your exact head and includes #3617 and #3620. It gives0x3c453c45in both directions and passes all eight packed readbacks. The original midpoint test, the 28 seven-op readbacks and the 62-input FP32-to-FP16 conversion control also passed. Strict shader Clippy passed in both configurations, as did the asset policy.Please keep the Git author on a cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if this work is folded into another commit.AI-assisted with OpenAI Codex.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T22:43:08Z.
I retested
d545701on app-local WARP 1.0.22, then merged it cleanly with #3617 at8bfad4con63bcca4. Both revisions passed the 16 midpoint and control combinations. WithVICTORY_WARP=1, the harness ran each combination twice on WARP, for 32 matching readbacks per revision.The plain, abs and neg variants return
0x3c01at the midpoint in both MODE 0 and MODE 3. Clamp and zero-input controls return0x3c00. The VALU suite, including the temporary probe, passed 37 tests ond545701and 38 on the merge. The additional #3617 regression ran in the latter suite.The merge preserves both heads. Its
lower.rsis 521,703 bytes, leaving 2,585 bytes under the limit. Verified integration branch8f20866AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-27T23:48:51Z.
Hardware run on AMD, since the reports so far are WARP: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head
d545701on63bcca4. The test fixture checks the hardware adapter and WARP in turn, and neither was skipped.v_exp_f16_rounds_the_exact_result_oncepasses on both.victory-shader --lib --features host: 303 passed, 0 failed, 3 ignored.AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by akimfomin on 2026-11-28T00:28:21Z.
PortBridge independently checked the binary16 midpoint. The CPU reference found exactly one nearest-f32 → nearest-f16 mismatch,
0x11c5 → 0x3c01. A separate hypothetical ±1 binary32 ULP test, adapted from Cai-piroska’s AnyXboxX #566 method, produced four other mismatches in each direction even with the midpoint patch. At0x8dc6, for example, the injected +1 ULP gives0x3c00where the high-precision reference gives0x3bff. Reproducible output.That is neither a driver result nor a claim that the scoped fix is wrong. If there is already a hardware run planned on the latest head, could it add
0x8dc6and0x36b6as diagnostic inputs? It would tell us whether the remaining sensitivity matters on that adapter.Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T00:33:03Z.
I added the two requested inputs to the existing generated compute test directly on
d545701. With required DXIL validation and app-local WARP 1.0.22 / Agility 1.620.2, 0x8dc6 returned 0x3bff and 0x36b6 returned 0x3d5a. Both match the correctly rounded FP16 reference. The existing 0x11c5 midpoint and two controls also passed. Strict all-features shader Clippy passed.Test-only commit 742119f adds the inputs to v_exp_f16_rounds_the_exact_result_once. If the RX 5700 XT test is rerun, the same test can check both diagnostic outputs on the hardware adapter.
If you reuse the test, please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg [email protected] if folding it into another commit.
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T01:29:31Z.
@andrewpozdnakov7-jpg @akimfomin Reran
v_exp_f16_rounds_the_exact_result_oncewith the two inputs (742119f, ond545701) on the RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003). It passes on the hardware adapter and on WARP, and neither was skipped:0x8dc6gives0x3bffand0x36b6gives0x3d5a. Both are the correctly rounded FP16 results.0x11c5→0x3c01midpoint and the controls pass too.So on this card the ±1 ULP sensitivity from the CPU model doesn't show up at those two inputs.
AI use: Claude Code (Claude Opus 5.5).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T01:33:44Z.
Thanks for rerunning
742119fon the RX 5700 XT. The hardware results for0x8dc6and0x36b6match the expected0x3bffand0x3d5a. The original midpoint0x11c5and the controls also passed on the hardware adapter and WARP. Hardware reportMoon0755, the two cases are in test-only commit
742119fon the currentd545701head. It is ready to cherry-pick if you want the extra coverage.Please preserve the Git author if cherry-picking or rebasing, or keep this trailer if folding the test into another commit.
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>Imported from Marvisak/VIctory. Originally posted by akimfomin on 2026-11-28T01:36:54Z.
Cross-project hardware follow-through: PortBridge passed your
0x11c5v_exp_f16 vector to Xbox2Windows. Leyukaka ran it on RTX 5080 at8027ad6e: neighboring inputs matched, while0x11c5returned0x3c00instead of0x3c01. WARP explicitly skipped on the receiving runtime. A separate 60-digit CPU check agreed with your rounding explanation. This confirms the same numerical boundary matters in the independent direct frontend. This result is for Xbox2Windows only.Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T04:44:00Z.
Hardware run, since this was WARP-only: RTX 3070 8 GB, driver 616.56, Windows 11, head
d545701.v_exp_f16_rounds_the_exact_result_oncepassed 3 of 3 runs.run_casesruns it on the hardware adapter and on WARP in the same process, so the NVIDIA host agrees with the expected single rounding.AI-assisted (Claude Code, Claude Opus 5.5 built this head and ran the test on this card).
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T15:59:56Z.
AMD Radeon 780M (RDNA3) + WARP, Windows 11, head
d545701.63bcca4+ this PR's test): fails on the hardware adapter.v_exp_f16(0x11c5)gives0x3c00; want0x3c01.victory-shader+victory-gpu --features diagnostics): 552 passed.AI-assisted (Claude).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.