Shaders: zero unavailable mixed-precision FMA halves #683
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!683
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/683/head"
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?
@Halfect on GitHub · 2026-11-24 06:46 UTC · original
Halfect:fix/f16-interp-high-half→main· +97 −3 · 2 files · 1 commits · closed without mergingSummary
v_fma_mixlo_f16/v_fma_mixhi_f16with the same zero fallback as the other partial-VGPR-write pathsv_interp_p1ll_f16: it writes a full 32-bitf32intermediate and does not preserve the destination's old high halfValidation
cargo test --locked -p victory-shader --lib -- --test-threads=1— 90 passed, 0 failed, 1 benchmark ignoredcargo clippy --locked -p victory-shader --lib -- -D warningscargo xtask policy— 151 files passedcargo build --locked --release -p victoryorigin/mainwithemit: the first half of an interpolationand passes with this change.origin/main8e79c80: 25,889 matched program labels; DXIL validation gained 8, lost 0. Vertex + pixel validated increased from 12,148 to 12,156; compute and mesh totals were unchanged. The only outcome transition was 8 programs changing fromemit: the first half of an interpolationto validated.Offline translation and DXIL validation only; no game or GPU execution was used.
AI-assisted (Kimi)
@iurysf on GitHub · 2026-11-24 08:27 UTC · original
Measured offline against main
c2e7254withvictory translate --list --validateover the title'sshaders.rpf+ executable (26,096 programs), dxil.dll 1.9.2602.17, comparing outcomes program by program: failures 3,734 -> 3,726 (−8). Eight "the first half of an interpolation" refusals now emit and validate, and there are no regressions.AI-assisted.
@slint6614-dev on GitHub · 2026-11-24 09:30 UTC · original
Measured on the full retail shader pack (26,503 containers) with
victory translate --validate --pipelines(pipelines on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines. Merged locally with current mainc7a5f49first (main: VS/PS 12224 / 12148).VS/PS 12232 / 12156 (+8 validated): "the first half of an interpolation" 28 → 20. CS and MS unchanged.
@banbanzhige on GitHub · 2026-11-24 09:44 UTC · original
Quick ISA note on the premise here: on RDNA 2 / GFX10,
v_interp_p1ll_f16writes a full 32-bitf32intermediate (D.f32 = P10.f16 * S0.f32 + P0.f16, later consumed asS2.f32byv_interp_p2_f16), so it overwrites all 32 bits ofvdstand does not preserve the pre-interpolation high 16 bits.In those 8 pixel shaders,
v_fma_mixlo_f16is simply reusing a dead temporary VGPR afterv_interp_p2_f16has consumedv_interp_p1ll_f16's result (subsequent instructions only read the low 16 bits). Becausefirst_halveswalks pastv_interp_p1ll_f16to the value held before it, it would actually resurrect stale pre-interpolation bits ifvdsthad held a live value earlier, and it doesn't coverv_fma_mixhi_f16or reuse of other intentionally unlowered VGPRs (such as entry barycentrics).Notice that the other partial-VGPR-write paths in
lower.rs(write_placed,place_bits,write_half, andlow_half) all handle an unlowered preserved half uniformly with:Using that same fallback in
v_fma_mixlo_f16/v_fma_mixhi_f16avoids mismodelingv_interp_p1ll_f16as high-half-preserving, stays consistent withwrite_half/low_half, handles bothmixloandmixhi, and gives the same +8 validated pixel shaders with 0 regressions (tested offline against the local shader pack).AI-assisted review.
@Halfect on GitHub · 2026-11-24 10:16 UTC · original
You're right—thanks for the ISA correction. I had incorrectly modeled
v_interp_p1ll_f16as preserving the old high half;D.f32 = P10.f16 * S0.f32 + P0.f16overwrites the full destination, so walking back to the pre-interpolation value could resurrect stale bits.Updated head
0b48633removesfirst_halves/preserved_highentirely. Bothv_fma_mixlo_f16andv_fma_mixhi_f16now use the sameSome(Ok(o)) => o, _ => i32(0)fallback as the other partial-write paths. The regression covers both result halves with a deliberately stale pre-interpolation high half, and validates the resulting DXIL. It fails on currentorigin/mainwithemit: the first half of an interpolation.I also reran the full offline A/B against
origin/main8e79c80: 8 validation gains, 0 losses across 25,889 matched labels; VS/PS validated 12,148 → 12,156, with compute and mesh unchanged. No game or GPU execution was used.@ErRusso on GitHub · 2026-11-24 11:19 UTC · original
Audit: ✅ Looks good — verified & tested
Reviewed this PR as part of an audit of mergeable PRs.
crates/victory-shader/src/emit/lower.rs+mod.rs(+97/-3). Tracksv_interp_p1ll_f16instructions in afirst_halvesmap and walks the chain in the newpreserved_high()so that a low-half f16 interpolation followed by a low-half mixed-precision FMA keeps the destination's old high half instead of treating it as unknown.main.emit::tests::mixed_precision_fmas_accept_an_unavailable_interpolation_half→ passed;cargo test -p victory-shader -- emit::tests::→ 6/6 passed. The emission test exercises the full native→IR→resource→IO→structure→emit pipeline and validates the DXIL with the DXC validator when available.preserved_high()is reused by both the mixed-precision FMA path andlow_half(), which avoids two divergent implementations. Clean.No issues found.
@Halfect on GitHub · 2026-11-24 11:29 UTC · original
Thanks for the audit, but this describes the superseded implementation, not current head
0b48633.first_halvesandpreserved_high()have been removed. The current PR no longer treatsv_interp_p1ll_f16as preserving the old high half: bothv_fma_mixlo_f16andv_fma_mixhi_f16use the sameSome(Ok(o)) => o, _ => i32(0)fallback as the other partial-write paths. The regression covers both result halves with a deliberately stale pre-interpolation high half.Please retest
0b48633; the earlier ISA correction and current implementation details are in the comment above.@CaravelaLabs on GitHub · 2026-11-24 12:06 UTC · original
Thanks @Halfect — retested current head
0b48633merged onto mainffe310e, as you asked.Git merges with no text conflicts. The merged code is the zero fallback on both
v_fma_mixlo_f16andv_fma_mixhi_f16(Some(Ok(o)) => o, _ => i32(0)).first_halves/preserved_highare gone.As written,
cargo test -p victory-shader --libstill does not compile: the new test callsresource::trackwith three arguments. Already listed for this PR in #801, and @muhammed-aksoy already hit it on this head, so not a new finding.With only that call updated to pass
None, the new test passes, and the shader library tests are 97 passed / 0 failed / 1 ignored (Linux, rustc 1.98.1). The same test against main's lowering fails withthe first half of an interpolation, so it does catch this change. Both mixlo and mixhi are in the passing run. The DXIL validator did not run here (that check is Windows-only), and the test checks that emit succeeds, not the bit pattern of the zeroed half.AI-assisted; tests run on this machine.
@Halfect on GitHub · 2026-11-24 12:22 UTC · original
Thanks @CaravelaLabs — fixed in
81fb96e. I rebased onto current mainffe310eand updated the new regression call toresource::track(&p, &native.layout, native.stage, None).Validation on Windows:
mixed_precision_fmas_accept_an_unavailable_interpolation_half: passed, including its Windows DXIL validation.cargo check --locked -p victory-shader --tests: passed.diff_tests,valu_tests,waterfall_tests, andstub_pipeline_is_created: 98 passed, 0 failed, 1 ignored.-D warningsandcargo xtask policy: passed (154 files ok).No GPU execution was used for this validation. The regression still checks successful emission rather than the exact zeroed-half bit pattern, as you noted.
@CaravelaLabs on GitHub · 2026-11-24 13:05 UTC · original
Thanks @Halfect — retested
81fb96e, already on mainffe310e.cargo test -p victory-shader --libcompiles now. 97 passed, 0 failed, 1 ignored (Linux, rustc 1.98.1).mixed_precision_fmas_accept_an_unavailable_interpolation_halfpassed in that run. The DXIL validator still did not run here.AI-assisted; tests run on this machine.
@Halfect on GitHub · 2026-11-24 13:23 UTC · original
Thanks @CaravelaLabs for confirming
81fb96ecompiles and passes the library suite on your side. Nothing further from me on this head — ready for review.@DeerSilver on GitHub · 2026-11-24 14:04 UTC · original
Re-tested head
81fb96emerged ontomainffe310e(clean merge) on NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1. No game files: the test suite only. Pass, with no local change: theresource::trackcall from #801 now builds.mixed_precision_fmas_accept_an_unavailable_interpolation_halfpasses. It doesn't use the GPU, but its DXIL check did run: the Windows SDK10.0.26100.0\x64\dxil.dllis installed here, soValidator::loadfound it.cargo test --workspace --locked, the full workspace including the VALU and waterfall GPU groups (which ran on the RTX 5060): 343 passed, 0 failed, 6 ignored, against 342 / 6 onmain.cargo clippy --workspace --all-targets --locked -- -D warnings: clean.AI-assisted (Claude Code).
@Halfect on GitHub · 2026-11-24 14:22 UTC · original
Thanks @DeerSilver for re-testing
81fb96ewith the full workspace suite on the RTX 5060 — 343 passed with the VALU/waterfall groups included is a good cross-check of the CPU-only runs. Nothing further from my side on this head; ready for review.@pablogonz12 on GitHub · 2026-11-24 16:20 UTC · original
Measured on Linux (RX 9070 XT, RADV/Mesa 26.3.1, GE-Proton11-14, vkd3d-proton master), head
81fb96emerged onto our tree:cargo test -p victory-shader --lib114 pass, only the known failure.One thing for your branch: after
emit()gained atarget: Targetargument on main, the new test callsemit(..., &res)with six arguments and does not compile against current main; I passedTarget::ANY.Not tested: in-game on this branch; native Windows.
@Yaekai on GitHub · 2026-11-24 16:29 UTC · original
Independent verification on Windows 11 + NVIDIA RTX 3070 (Rust 1.98.1) at head
81fb96e:cargo test -p victory-shader --lib -- --skip valu_tests --skip waterfall_tests: 103 passed, 0 failed.cargo clippy -p victory-shader -- -D warnings: 0 warnings.1.0.2.1,--console series-s, 19-min world run): no regressions. Ready to merge!@Halfect on GitHub · 2026-11-24 16:50 UTC · original
Thanks @pablogonz12 for the measurement and the heads-up.
On the compile note: upstream
mainis stillffe310e, and thereemit()keeps its six-argument form (c, native, p, st, io, &res) — I just re-checkedcrates/victory-shader/src/emit/mod.rsatrefs/heads/main. Thetarget: Targetparameter you hit must come from the tree you merged onto, not from upstreammainyet. Against upstream,81fb96ecompiles as pushed: @CaravelaLabs built the library suite on Linux (97 passed) and @DeerSilver the full workspace on Windows (343 passed), both merged ontoffe310ewith no local change.If the target-aware
emit()lands first, I'll rebase and pass the appropriate target through the new test (yourTarget::ANYadaptation is the behavior-preserving choice for it).@pablogonz12 on GitHub · 2026-11-24 17:20 UTC · original
@Halfect You're right, thanks for checking. The
target: Targetargument comes from another PR in the tree I merged onto, not from upstream main; againstffe310eyour81fb96ecompiles as pushed. The +8 vertex/pixel count I posted still applies.@Marvisak on GitHub · 2026-11-25 00:27 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.Zero-fills the kept half of v_fma_mixlo/hi_f16 when the old value has no host form. Main handles the same programs without inventing a value: the high half stays unknown and only low-half readers are accepted (
13091f6e, low16).If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed