Shaders: VICTORY_F16_NEAREST rounds every f16 narrowing, not only 16-bit ALU results #155
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!155
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-155"
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?
@DovisLe on GitHub · 2026-11-24 21:56 UTC · original
DovisLe:shader/f16-nearest-everywhere→main· +144 −30 · 2 files · 1 commits · openRefs #136, first row ("f16 math on AMD is rounded toward zero").
Problem. The fork already has an exact
f16_nearestbehindVICTORY_F16_NEAREST=1, but only the VOP1/VOP2/VOP3 16-bit float results (and the wave sum) go through it. The other f32-to-f16 narrowings still call the host'slegacyF32ToF16, which rounds toward zero on AMD, NVIDIA and WARP, so they stay one ulp low even with the switch on:v_cvt_f16_f32(its own arm)v_fma_mixlo_f16,v_fma_mixhi_f16v_pk_*_f16opsv_interp_*_f16)Change. A new
f16_narrowapplies the switch, and all seven sites call it.f16_toward_zerokeeps the raw host conversion it builds on. The default is unchanged (off), so nothing moves unlessVICTORY_F16_NEAREST=1is set.Test.
f16_nearest_switch_rounds_every_narrowingturns the switch on with the existingTEST_F16_NEARESThook. It runsv_cvt_f16_f32,v_pk_add_f16,v_pk_fma_f16andv_fma_mixlo/mixhi_f16(checking the destination's other half is kept) on the hardware adapter and WARP, against nearest even computed on the CPU. Every case is one where toward-zero and nearest differ, and thefmainputs keep the f32 intermediate exact.Results on a Radeon 860M (RDNA 3.5) and WARP:
main(4e17478)v_pk_add_f16(0xf8b6, 0x0001) = 0xf8b5;v_pk_fma_f16(0x3c01, 0x3c01, 0x3c01) = 0x4001(should be0x4002);v_fma_mixlo_f16(1 - 2^-24) = 0x3bff(should be0x3c00).cargo test -p victory-shader --lib: 211 passed, 0 failed, 2 ignored.cargo clippy -p victory-shader --all-targets [--all-features] --locked -- -D warnings: clean.This doesn't decide the default. Whether
VICTORY_F16_NEARESTshould be on by default is the maintainers' call, since it adds about a dozen instructions per narrowing. This makes the switch mean what it says, so turning it on fixes the whole of #136's first row.AI-assisted (Claude).
🤖 Generated with Claude Code
@avt0m4t48 on GitHub · 2026-11-24 22:00 UTC · original
Independent check of
158d93ee0fbc: I ran a source-built fixture for packed add and FMA, both mixed FMA destination halves, and the VOP3 form ofv_cvt_f16_f32. It covers positive and negative ties, and checks that conversion and mixed FMA preserve the other destination half. The packed tie cases read back0xbc023c02. The VOP3 conversion read back0xaabb3c02. FixtureWith the switch on, this PR emitted byte-for-byte the same five shaders as the independently WARP-tested ALU patch. All five modules from this PR passed Linux
dxv. With the switch off, all five matched the original4e17478bytes. The WARP run also confirmed that the test fails on the original lowering, where packed add ignores the switch. Windows positive and negative controlsThis check covered the five ALU forms. Interpolation, d16 loads and physical AMD hardware were outside this independent run. AI-assisted using Codex.
@bawhen on GitHub · 2026-11-24 22:18 UTC · original
Reproduced and fixed on a desktop RDNA3 card (RX 7700, driver 32.0.32029.2010).
cargo test -p victory-shader --locked --lib f16_nearest_switch_rounds_every_narrowing -- --nocapture158d93elower.rsfrommainv_pk_add_f16,v_pk_fma_f16,v_fma_mixlo_f16andv_fma_mixhi_f16, on both the RX 7700 and WARPThe one place the two devices differ is #136's example in the low lane of
v_pk_add_f16:The RX 7700 returns
0xf8b5where WARP returns0xf8b6. That fits the reading in #136 that AMD's compiler folds the chain into a native f16 add, so RDNA3 desktop behaves like the RX 9070 and gfx1036. The high lane and thefma/mixcases are wrong identically on both (the toward-zero conversion).Setup: AMD Radeon RX 7700 (RDNA3, 16 GB), driver 32.0.32029.2010, Ryzen 7 8700F, 16 GB RAM, Windows 11 (build 26300), Rust 1.98.1 from
rust-toolchain.toml. Baselinemainat4e17478:cargo test --workspace --lockedgives 496 passed, 0 failed, 7 ignored. The "without the fix" run checks outmain's version of the PR's non-test files and keeps the PR's new test. No game files used.AI use: Claude Code (Claude Opus 5.5) ran the tests and drafted this comment; posted at my request.
@DovisLe on GitHub · 2026-11-24 23:20 UTC · original
@alexdeliu, taking you up on the offer in #136: could you run this PR (
158d93e) on the RX 9070 and the gfx1036?The test turns
VICTORY_F16_NEARESTon by itself, so no environment variable is needed. So far it passes on a Radeon 860M (RDNA 3.5), on bawhen's RX 7700 (RDNA3) and on WARP. RDNA4 and RDNA2 would cover the rest of the AMD range.AI-assisted (Claude).
@alexdeliu on GitHub · 2026-11-24 23:59 UTC · original
@DovisLe
158d93epasses on both:f16_nearest_switch_rounds_every_narrowingis ok on the AMD Radeon RX 9070 (RDNA4) and on the Ryzen 7700's iGPU, gfx1036 (RDNA2), on Windows 11. I selected the iGPU with a local, uncommitted adapter-index override inHost::new, and the log confirms which device each run used. With your runs, that covers RDNA2, RDNA3, RDNA3.5 and RDNA4.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.