Shaders: keep overlapping f64 source pairs distinct #198
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/Belobug--VIctory-Belobug-AMD!198
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-198"
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?
@loyodea on GitHub · 2026-11-25 21:12 UTC · original
loyodea:shader-f64-overlapping-sources→main· +75 −0 · 3 files · 2 commits · openPart of #82. On the RX 9060 XT, f64 add and multiply can return the wrong result when two operand pairs share a VGPR. Reversing the low dword twice before
makeDoublepreserves the operand bits and keeps the two values distinct on the tested driver.Changes
src_f64.Tested
c289582,cargo test --locked -p victory-shader --lib f64_arithmetic_keeps_overlapping_source_pairs_distinct -- --test-threads=1 --show-outputpassed on the RX 9060 XT and WARP, with 336 exact result-word checks on each. The regression reproduced on01aadd1with the test added and the runtime change absent.c289582,cargo test --locked -p victory-shader --lib -- --test-threads=1 --nocapturereported 278 passed, 0 failed, and 6 ignored. Four of the 278 returned early because a required console or PC compiler was unavailable.01aadd1reported 555 passed, 8 failed, and 17 ignored. All eight failures reproduced with the runtime change absent. They concerned page tracking, memory mapping, GNU loader linking, and the existing size oflower.rsunder the asset policy. Clippy in that setup also stopped on existing lints invictory-formats/src/xma.rs.Limits
The pinned MSVC toolchain, other hardware drivers, retail rendering, and frame rate remain unverified. The workaround adds two integer operations per f64 source before driver optimization.
AI use
OpenAI Codex wrote the patch and synthetic regression and ran the checks at the contributor's direction. The exact model used for the original patch was unavailable.
Review follow-up
The added regression reads one double starting at an odd root-constant dword and multiplies it by an immediate constant. Both result words passed on the RX 9060 XT and WARP with DXIL validation. Removing the two emitted bit reversals reproduced the incorrect high word on the RX 9060 XT.
@MamaLeVrai on GitHub · 2026-11-26 05:00 UTC · original
RDNA2 data point. This PR (
c289582) merged onmain4f62c2a,cargo test --release -p victory-shader --libon an RX 6950 XT (Windows 11 build 26300, Rust 1.98.1):main: 275 passed, 2 failed.The 2 failures are the same as on
main: the RDNA2 wave-size testsscalar_counted_in_a_divergent_loop_read_after_itandscalar_counted_in_nested_divergent_loops, fixed by #110 and #204. No regression here. One run ended without a result line, which this test binary does now and then on this machine, onmaintoo. Not run in the game.harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300
AI-assisted (Claude Code); no game data.
@loyodea on GitHub · 2026-11-26 18:53 UTC · original
Thanks for testing
c289582on the RX 6950 XT. The new overlapping-source regression passed on RDNA2. The two failures matched the4f62c2abaseline and are tracked in #110 and #204.@adrianmjim on GitHub · 2026-11-26 19:46 UTC · original
Tested
c289582(base4f62c2a) on Windows 11 26300 with an RX 7900 XT (RDNA3) and WARP. Same driver version as in the PR description (32.0.32029.2010). Rust 1.98.1.New test on RDNA3:
f64_arithmetic_keeps_overlapping_source_pairs_distinctpasses on the RX 7900 XT and WARP, 336 checks each.lower.rschange left out (only the test applied on4f62c2a): 336 checks each, no mismatches. On this driver the overlap bug does not reproduce on RDNA3 with these inputs, so the test cannot catch it on this GPU.victory-shaderlib suite gives the same counts on RDNA3 as in the PR description.The title's whole
shaders.rpf(translate --validate --host-lanes 32-64, release build) compared with4f62c2a:CS_TransmissionVolumetrics*family. They are the only programs in the archive with f64 instructions: 216v_add_f64and 36v_cvt_f32_f64. There is nov_mul_f64orv_fma_f64.v_add_f64has source pairs that share a VGPR. 180 use two separate VGPR pairs, and 36 use an SGPR pair and a VGPR pair.v_add_f64sequences are emitted as 36WaveActiveOpsums on double. TheirmakeDoubleinputs have a constant zero low dword, so thebfrevpair is folded away there.4f62c2aDXIL, no value is the low dword of onemakeDoubleand the high dword of another.So the #82 pattern does not occur in this archive. The PR still changes these 5 programs. It adds 72
bfrevcalls in total (8 to 24 per program), and each program gets 136 to 368 more bytes of DXIL. All 36bfrevpairs sit before themakeDoublethat feeds an f64-to-f32 conversion (fptrunc). None of them reaches an add or multiply.Not tested: RDNA4, rendering or frame time of these programs in game, and whether the driver removes the
bfrevpair itself.@upipibi on GitHub · 2026-11-26 23:20 UTC · original
A pointer to related measurements upstream, since neither this thread nor #202 links them: Marvisak/VIctory#1262 (open, head
faf20ac) ran into the same AMD bug and called it FIND-21. On an RX 6950 XT (driver 32.0.21045.29003), with reports from RDNA3 and a gfx1036 iGPU, AMD's D3D12 compiler reads a double's low dword as both halves when the double comes from dwords 1 and 2 of one uniform load (the root constants). That happens in two cases: the double alone (v[2:3]read as(v2, v2)), and two sources sharing a dword. NVIDIA and WARP give correct results. Its fix,c4da80b(lower/double.rs:43-56), XORs both dwords of every VGPR or SGPR pair source withWaveGetLaneIndex() >> 31. That value is always zero, but the compiler can't prove it. The testf64_reads_uniform_pairs_at_odd_dwordsgave 45 wrong hardware results without the fix and none with it.Comparing that with this PR, by reading, not run:
(1,2)and(2,1)cases putv[2:3](root dwords 1 and 2) next tov[1:2].v[2:3]alone, with itself or with a constant.src_f64(lower.rs:8374) does change the low dword of every source, so it may cover this case too, but nothing measures it. Only the low dword changes, and abfrevpair is the identity, so an optimizer could in principle remove it (a guess, not checked). adrianmjim found that on RDNA3 the test passes even without the fix, so the RX 9060 XT is the only reproduction so far. Adding av[2:3]-alone case to the test would check this.NaN to int, also from #1262:
v_cvt_i32_f64andv_cvt_u32_f64here are a plainfptosi/fptoui(lower.rs:8330-8341onmain), so a NaN input gives whatever the host returns. In that thread an RTX 5080 under Wine/vkd3d-proton returned0x80000000for both. A native RTX 3050 and WARP returned 0, which is what the hardware gives. This PR doesn't touch those lines; I'm noting it only because they sit in the same block.AI-assisted (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.