Shaders: round v_exp_f16 once at its double-rounding midpoint #3609
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3609
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Moon0755 on GitHub · 2026-11-27 20:51 UTC · original
Moon0755:fix/exp-f16-midpoint→main· +36 −0 · 2 files · 1 commits · openOn 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
@andrewpozdnakov7-jpg on GitHub · 2026-11-27 21:14 UTC · original
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.@oni-swr on GitHub · 2026-11-27 21:15 UTC · original
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.@Moon0755 on GitHub · 2026-11-27 21:39 UTC · original
@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
@andrewpozdnakov7-jpg on GitHub · 2026-11-27 22:25 UTC · original
@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.
c444dffd11tod54570166a@Moon0755 on GitHub · 2026-11-27 22:34 UTC · original
@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
@andrewpozdnakov7-jpg on GitHub · 2026-11-27 22:41 UTC · original
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.
@andrewpozdnakov7-jpg on GitHub · 2026-11-27 22:43 UTC · original
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.
@ColorMeBoom on GitHub · 2026-11-27 23:48 UTC · original
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).
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.