Shaders: fuse and flush sources in legacy f32 MAD and MAC (port of upstream VIctory #1554) #1026
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!1026
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1026"
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-25 16:37 UTC · original
Moon0755:fix/legacy-mad-mac-fused-ftz→main· +75 −8 · 2 files · 1 commits · openPorts upstream Marvisak/VIctory#1554 (
Calvix2k).Problem
In
crates/victory-shader/src/emit/lower.rs,v_mad_legacy_f32andv_mac_legacy_f32were lowered as unfusedlegacy_mul(a, b) + cwithout flushing subnormal operands.On RDNA2 / Xbox Series X, the legacy multiply-add encoding decodes as fused (
v_fma_legacy_f32), flushes subnormal f32 source operands to signed zero, and keeps the legacy zero-factor rule (0 * inf/NaN = +0, so+0 + c).What changed
crates/victory-shader/src/emit/lower.rs:Lower::ftzto flush f32 subnormals ((bits & 0x7F80_0000) == 0) to signed zero while preserving the sign bit and all normal/inf/NaN values.Lower::legacy_fmadusingself.fmad(a, b, c)with the legacy zero-factor override (+0 + cwhena == 0orb == 0).v_mad_legacy_f32andv_mac_legacy_f32throughftzon all three sources followed bylegacy_fmad(leaving non-legacyv_mad_f32/v_mac_f32unfused andv_fmac_f32unchanged).crates/victory-shader/src/emit/valu_tests.rs(legacy_mad_fuses_its_product_and_flushes_its_sources):v_mad_legacy_f32test covering single-rounding fusion (on hardware adapters),subnormal * 1.0 + 0.0 == 0.0,subnormal * +inf + 1.0 == 1.0(proving source FTZ happens before the zero-factor check), and0 * +inf + 1.0 == 1.0.Verification
Verified on Windows (
windows-latest+dxil.dll+ D3D12 WARP) via a temporary scoped CI branch on the fork:cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings: passedcargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings: passedcargo test -p victory-shader -p xtask --locked -- --nocapture:victory-shader216 passed; 0 failed; 3 ignored(test emit::valu_tests::legacy_mad_fuses_its_product_and_flushes_its_sources ... ok, validated viadxil.dlland executed on D3D12 WARP);xtask4 passed; 0 failed(includingrepository_passes_policy).Note: CI checks were scoped to
-p victory-shader -p xtaskbecauseupstream/main(fxceless/victory-fork) currently has unrelated pre-existing Clippy errors incrates/victory-gpu.— Neon
@HAL9000RELOADED on GitHub · 2026-11-25 18:00 UTC · original
A hardware run of this PR's new test:
legacy_mad_fuses_its_product_and_flushes_its_sourcespasses on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with #402's Agility SDK runtime. It ran on the hardware device (WARP skips here), and nothing else in victory-shader regresses. The setup, and the same run for eight related ports, are in one table on #1030: #1030@SkillIssueXO on GitHub · 2026-11-25 23:56 UTC · original
I ran
legacy_mad_fuses_its_product_and_flushes_its_sourcesfrom66e9d884on an NVIDIA RTX 5070 Ti (driver 621.40, Windows 11 build 26300). The hardware path passed all four cases, including the single-rounding result0xa8800000and the denormal and zero-factor cases. WARP passed the three applicable cases and skipped fused rounding as expected.This was the PR applied to the
6d20eed6renderer with local capture and input changes. An in-game comparison is pending. AI-assisted testing with synthetic inputs.@SkillIssueXO on GitHub · 2026-11-26 05:39 UTC · original · edited 2026-11-26 06:19 UTC
In-game follow-up on RTX 5070 Ti (621.40). I ported the PR’s lowering to Neptune and retranslated only the final composite pixel shader. Both runs used the same runtime executable, Series X checkpoint, 4K output, and water compute shader. A hash comparison of all 2,922 warm-cache files found exactly one changed entry. The revised DXIL validated, pipeline creation succeeded, and the shader’s bindings were identical.
At the held boat view, the stock composite showed black cores in the brightest water reflections. The revised composite showed bright cores in two captures over a minute apart. The sun disk was outside the frame, so this verifies the water reflection symptom in this scene.
Over about 60 seconds each, stock and revised logged 6.47 and 6.38 DXGI-accepted presents/s respectively. Median intervals were 165.9 and 157.9 ms. This was one stationary A/B pair. AI-assisted testing and analysis.
In a later Neptune replay with the revised composite, tilting the camera up showed a bright sun center in two captures. A readback immediately before a revised composite draw captured all three 33³ RGBA16F color lookup volumes. Every sample was finite and the upper corner of each volume was bright. That gives a clean reference for comparing the stock draw’s sampled inputs.
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.