Shaders: apply v_interp_p2_f16 modifiers in f32 before narrow16 #2282
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!2282
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2282"
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?
@BlueCatsz on GitHub · 2026-11-25 09:39 UTC · original
BlueCatsz:fix/interp-p2-f16-modifiers-single-narrow→main· +175 −30 · 2 files · 1 commits · openProblem
Follow-up to #1696: in
crates/victory-shader/src/emit/lower.rs,Lower::interpnarrowed interpolated 16-bit values viaself.narrow16(f)inside itshalfclosure and then passed the already-narrowedf16intoLower::half_modifiers, which widened back viadx.op.legacyF16ToF32, appliedomodandclamp, and narrowed a second time viadx.op.legacyF32ToF16.That caused two bugs on
v_interp_p2_f16withomodorclamp:omod:f16beforeomodis applied lose finite results (e.g.,98304.0withdiv:2narrowed to0x7C00/0x7BFF -> 0x77FFinstead of49152.0/0x7A00).omoddouble-round (e.g.,(2^-15 + 2^-25) * 4.0rounded away2^-25into0x0200and produced0x0800instead of0x0801).HW_REG_MODEignored / host-dependent rounding:dx.op.legacyF32ToF16instead ofself.narrow16ignoresself.mode16(HW_REG_MODEbits 3:2) and rounds toward zero on WARP and AMD even in default RNE mode (e.g.,32768.0 * 2.0->0x7BFFinstead of0x7C00, andclamp((2^-14 + 3 * 2^-24) * 0.5)->0x0201instead of0x0202).Fix
crates/victory-shader/src/emit/lower.rs:Lower::interp'sSome(pack2)helper inf32(half_f32) and passfdirectly toLower::half_modifiersforv_interp_p2_f16(flatmode == 1packs both halves viaself.narrow16(f)as before).Lower::half_modifiersto applyomodthenclampon thef32value and convert once viaself.narrow16(f), removinglegacyF16ToF32andlegacyF32ToF16.Tests
crates/victory-shader/src/emit/mod.rs:emit::tests::v_interp_p2_f16_modifiers_translate_in_both_round_modes(cross-platform lowering + Windows DXIL validator check).emit::tests::v_interp_p2_f16_modifiers_narrow_once_in_mode16(#[cfg(windows)]synthetic VS+PSHost::drawexecuting both default RNE andHW_REG_MODERTZ cases viav_cvt_f32_u32export; assertsran > 0).emit::tests::interpolated_f16_writes_the_op_sel_half_with_modifiersto check that emitted DXIL does not containlegacyF16ToF32orlegacyF32ToF16(whendxc.exeis present).Verification
windows-latestCI run: https://github.com/BlueCatsz/VIctory/actions/runs/45586121960Clippy: passedClippy, diagnostics build: passedTests:victory-shader249 passed, 0 failed, 3 ignored (includingv_interp_p2_f16_modifiers_narrow_once_in_mode16executing on WARP);xtask6 passed, 0 failedcargo test --offline --locked -p victory-shader --lib: 145 passed, 0 failed, 2 ignoredcargo --offline xtask policy:asset policy: 182 files okDisclosure
windows-latestCI) and Linux offline unit/policy checks (no local hardware GPU draw run, no console hardware, zero game files).@Dathinel on GitHub · 2026-11-25 09:51 UTC · original
Comparison with the still-open #1338: I ran the same four-channel synthetic draw from this PR at c4c7758, its parent
940d32f, and #1338's older heade2dc6ba(test helpers transferred; production code unchanged). Hardware and WARP agreed on each revision.940d32fe2dc6baOn #1338, the overflow lane yielded 0x7bff and the subnormal tie yielded 0x0201 even in nearest-even mode (expected 0x7c00 and 0x0202). #2282 distinguished those modes on both backends. I cross-checked the expected patterns using exact rational inputs and the representable positive binary16 values. This comparison is for these four vectors on each branch's own base; it helps distinguish the two PRs' coverage.
AI-assisted, synthetic test only.
@Mericas77 on GitHub · 2026-11-25 10:13 UTC · original
NVIDIA hardware test report: RTX 4070, driver 621.01, Windows 11, Rust 1.98.1 MSVC. I ran head
c4c7758againstmain940d32f; the head branches from940d32fand only changesemit/lower.rsandemit/mod.rs.This PR:
v_interp_p2_f16_modifiers_narrow_once_in_mode16,v_interp_p2_f16_modifiers_translate_in_both_round_modesandinterpolated_f16_writes_the_op_sel_half_with_modifiersall pass, on both hardware and WARP (no "skipped" line).A/B: I ran the PR's
mod.rstests on top ofmain's production code. They fail on hardware:So on NVIDIA,
mainshows the same four symptoms the PR describes:omod(ch0)legacyF32ToF16in default RNE mode (ch1 and ch3)When I forced WARP for the "hardware" pass, it gave exactly the same values. The
legacyF32ToF16rounding is therefore not AMD- or WARP-specific: NVIDIA rounds the same way, and the PR'snarrow16path fixes it there too.cargo test -p victory-shader --lib --lockedgives 246 passed, 3 failed. The 3 failures are the onesmainalready has on this card:stride_tests×2 andgathers_at_a_level_match_the_hardware.AI-assisted. Synthetic tests only, no game data.
@sinan-cmyk on GitHub · 2026-11-25 10:25 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head c4c77581 onto
main940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-25 13:31 UTC · original · edited 2026-11-26 01:25 UTC
Automated triage for the maintainers.
Merge candidate. The head is rebased (
7fd4de1) and merges cleanly into currentmain. InLower::interp, thev_interp_p2_f16path now keeps the interpolated value in f32.Lower::half_modifiersapplies omod, then clamp, then rounds once throughLower::narrow16, which honoursmode16. Before, the value went throughlegacyF16ToF32/legacyF32ToF16: it was rounded twice and ignored the round mode.main's own comment onhalf_modifiersalready called for a single rounding in f32, so this makes the code match it.half_modifiershas no other caller, and the flatmode == 1path still narrows each half as before. Independent NVIDIA and WARP runs reproduced the four wrong values onmain, and the PR's values match. This PR covers more than the older #1338. CI (check) passes on this head.Generated by Claude Code
@DenRakEiw on GitHub · 2026-11-25 09:42 UTC · original · approved these changes
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC, withdxil.dllvalidator):cargo test -p victory-shader --lib v_interp_p2_f16_— 2 passed, 0 failed (v_interp_p2_f16_modifiers_translate_in_both_round_modesandv_interp_p2_f16_modifiers_narrow_once_in_mode16)cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean fix applying
v_interp_p2_f16modifiers in f32 before narrowing once to f16. Looks good.AI-assisted (Gemini 4 Neon).
@catminou4 on GitHub · 2026-11-25 10:19 UTC · original · approved these changes
Tested locally: merged into main
940d32f69b,cargo test -p victory-shader --lockedon macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — v_interp_p2_f16 modifiers applied in f32 before packing.@fuzeofficlal on GitHub · 2026-11-26 18:11 UTC · original · approved these changes
Looks good. Verified merged onto
main(63bcca43) on an RTX 5090, Microsoft WARP, and Windows SDKdxil.dll:f16inputs inf32(half_f32atcrates/victory-shader/src/emit/lower.rs:8134) and applyingomodthenclampbefore a singleself.narrow16(f)inhalf_modifiers(lower.rs:8305) eliminates double rounding, avoids premature f16 overflow beforediv:2, and honorsHW_REG_MODE(RNE/RTZ), while shrinkingemit/lower.rsto 520,292 B (< 524,288 B).cargo xtask policy(191 files ok) andcargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features) pass.v_interp_p2_f16_modifiers_translate_in_both_round_modes,v_interp_p2_f16_modifiers_narrow_once_in_mode16, andinterpolated_f16_writes_the_op_sel_half_with_modifiers) pass on both RTX 5090 and WARP withdxil.dllvalidation.clampon negative (-0.5 * 2 -> 0x0000), above-one (0.75 * 2 -> 0x3C00), andqNaN(-> 0x0000) inputs plusop_sel[3] = 1high-half writes preserving a0xBEEFlow-half sentinel (98304.0 * 0.5 -> 0x7A00_BEEF) in both RNE and RTZ modes on both RTX 5090 and WARP.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.