Shaders: the v_mad_u64_u32 carry on its dwords (AMD's compiler gets the i64 compare wrong) #90
No reviewers
Labels
No labels
accessibility
bug
crash
documentation
duplicate
enhancement
good first issue
graphics
help wanted
invalid
needs logs
performance
question
rdna2
rdna3
rdna4
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/eikkapine--victory-amd!90
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-90"
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?
@murillojndem on GitHub · 2026-12-01 10:34 UTC · original
amd/mad-u64-carry-dwords→main· +94 −2 · 3 files · 1 commits · closed without mergingWhat
The carry out of
v_mad_u64_u32isr < c(unsigned), withrthe low 64 bits ofa * b + c. The translator lowers it as one i64icmp. When the addend shares a register with the second factor (v_mad_u64_u32 v[5:6], s20, v1, v2, v[2:3]), AMD's D3D12 compiler gives the wrong carry. The 64-bit compares already avoid a single i64 compare for this compiler (upstream Marvisak/VIctory@cc7ec2a, incompare()); this is a different instruction with the same kind of fault.Change
emit/lower.rs, thev_mad_u64_u32arm: the carry is computed on the dwords ofrandc, the high dwords first. The result dwords do not change.TRANSLATOR_VERSIONgoes from 4 to 5.Tests
New test
emit::valu_tests::v_mad_u64_u32_matches_its_definition: 6 x 6 factors and 9 addends, with the addend inv[3:4]and sharingv2inv[2:3]. It checks the carry and both result dwords and counts every mismatch by device, form and output before it fails.On an RX 7900 XT (driver 32.0.32015.7029, Windows 11), main
5d91fdegets the carry wrong in 124 of the 324 runs of thev[2:3]form (144 distinct inputs, since there the addend's low dword is the factorb) and everything else right. This branch gets every case right. WARP is right on both, so CI, which has no Radeon, passes with or without the change.Also run:
victory-shader --libon WARP: 310 passed, 4 failed, 4 ignored (main: 309, 4, 4). The four failures are the same on main: three fail PSV0 validation with the SDK 10.0.22621dxil.dllon this PC, anda_lane_mask_joined_with_a_number_is_read_as_the_number_it_isis a hardware-only test thatVICTORY_WARP=1sends to WARP.victory-shader --libon the RX 7900 XT (and WARP, through the same harness): 311 passed, 3 failed, 4 ignored (main: 310, 3, 4). The three failures are the PSV0 ones.cargo clippy -p victory-shader --all-targets --locked -- -D warnings, with and without--all-features: clean.cargo test -p xtask:repository_passes_policypasses.documented_switches_are_readfails, the same way as on main (VICTORY_NAMEin README.md).Limits
victory-shaderonly. My checkout leaves outcrates/victory-formats/src/bcpack-tables.bin, so I did not build-p victoryor run the workspace clippy.The same change is open as DexNom/VIctory#205, where the same test gave the same count on the same card.
Generated with Claude Code
@alexdeliu on GitHub · 2026-12-01 18:26 UTC · original
Tested on RDNA 4 and RDNA 2, which the description doesn't cover. Same result as on the RX 7900 XT.
Windows 11, RX 9070 (RDNA 4, driver 32.0.32029.2010), Ryzen 7 7700 iGPU (RDNA 2, gfx1036, driver 32.0.21045.29003), WARP.
cargo test --locked -p victory-shader --lib -- --exact emit::valu_tests::v_mad_u64_u32_matches_its_definition. "Before" ismain5d91fdewith only this PR'svalu_tests.rs; "after" is the PR headdcc35d0. Each has its ownCARGO_TARGET_DIR.("hardware", "v[2:3]", "carry"): 124of 324So both AMD generations here get exactly the RX 7900 XT's count; the fault isn't RDNA 3 only.
Also at
dcc35d0:victory-shader --lib: RX 9070 313 passed, 0 failed (withoutsize_tests::the_record_count_of_a_structured_buffer_read_by_index, which takes the test process down on this card onmaintoo); iGPU 314 passed, 0 failed.--test-threads=1: 312 passed, 1 failed (a_lane_mask_joined_with_a_number_is_read_as_the_number_it_is, the same as onmain).cargo clippy --locked -p victory-shader --all-targets -- -D warnings: clean.Not tested: in game.
Heads-up: my #117 also takes
TRANSLATOR_VERSIONfrom 4 to 5. Whichever lands second moves to the next number. I'll rebase mine if this one goes first.Pull request closed