Repository navigation
Conversation
…nd split v_mad_u64_u32 carry compare
Three correctness fixes for 64-bit integer multiply-add lowering in
crates/victory-shader/src/emit/lower.rs:
1. Sign-extend 32-bit literals in v_mad_i64_i32 src2:
src64 and src64_dwords checked inst.name().ends_with("_i64"), which
missed v_mad_i64_i32 (ending in "_i32") even though its 64-bit addend
src2 is signed i64. A negative 32-bit literal such as -100 (0xFFFF_FF9C)
was zero-extended to +4_294_967_196 instead of sign-extended to -100.
2. Reject unmodeled clamp and omod modifiers on v_mad_u64_u32 and v_mad_i64_i32:
Both opcodes bypass write_i and call self.write directly, silently dropping
v.clamp (valid on VOP3b_I64_I1_I32_I32_I64 with HasClamp = 1 in LLVM's
VOP3Instructions.td) and v.omod. Reject v.clamp || v.omod != 0 with
Err("integer output modifiers"), matching write_i.
3. Compute v_mad_u64_u32 carry-out via 32-bit unsigned dword comparisons:
Replace the last remaining 64-bit integer ordering compare in lower.rs
(icmp ult i64 r, addend) with (hi <u add_hi) || (hi == add_hi && lo <u add_lo),
avoiding AMD D3D12's swapped-dword 64-bit integer ordering bug (Marvisak#1599).
Dukestar69
left a comment
There was a problem hiding this comment.
Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + dxil.dll):
cargo test -p victory-shader v_mad_ -- --test-threads=1(RTX 5090 & WARP): 1 passed, 0 failed on both (v_mad_i64_i32_and_v_mad_u64_u32_literal_modifiers_and_carry).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
|
Independent Windows verification of #3082 at 079d8f9 against exact parent 63bcca4 (carry-out of Adapter. Only Validation. Windows SDK 10.0.26100.0 Test.
Results (WARP).
What this does and does not show. The patched lowering agrees with the integer oracle on WARP across all of these, including equal high dwords and full-width wrap, so the dword form of the comparison is correct. The oracle can fail: the mutated carry is caught. But the exact parent also passes on WARP, so this test cannot tell parent from patch; WARP does not reproduce the 64-bit Not covered: signed AI use: Claude Code (Claude Sonnet 5.5) for the work; coordinated by Codex (gpt-6.2-sol). Coordination: #1633 (comment) |
|
Automated triage for the maintainers. Needs work. This overlaps two open PRs that already carry the triage merge-candidate label:
The part only this PR has is the carry-out of Generated by Claude Code |
fuzeofficlal
left a comment
There was a problem hiding this comment.
The signed literal extension in src64_dwords (crates/victory-shader/src/emit/lower.rs:6797-6805) and the split unsigned carry comparison (hi_lt || (hi_eq && lo_lt)) look right, and local valu_tests + cargo clippy -p victory-shader --all-targets -- -D warnings pass on Windows 11 (RTX 5090 + WARP).
Two issues remain in the modified MAD lowering branch (crates/victory-shader/src/emit/lower.rs:6014-6055):
- Missing
sdstlowering forv_mad_i64_i32: Bothv_mad_i64_i32andv_mad_u64_u32decode as VOP3B with an explicit scalar lane-mask destination (gfx10/fields.rs,ir.rs,structure.rs), yetemit/lower.rs:6038-6055only populateslane_bitswhen!signed. If a shader consumes the scalar destination ofv_mad_i64_i32(for example in a subsequentv_cndmask_b32), lowering fails with a missing lane-mask value. Per LLVM's AMDGPU lowering (AMDGPURegisterBankInfo::applyMappingMAD_64_32), signedsdstis bit 64 of the 65-bit mathematical sum (sign(P) ^ sign(A) ^ (R <u A)— note this differs from both unsigned carry and signedi64overflow). Please lowersdstforv_mad_i64_i32as well and add a test that consumessdst. clampvsomodrefusal rationale:emit/lower.rs:6014-6016rejects bothclampandomodtogether. Whileomodis float-only, LLVM's GFX10/GFX1030 tables allowclampon both MAD opcodes. Please document the unsupportedclamprejection separately fromomod(or clarify expected hardware behavior forclampon bothvdstandsdst).
… output modifiers v_mad_i64_i32 (a signed 32 x 32 product plus a signed 64-bit addend) had no lowering. It is now the arm of v_mad_u64_u32 with sign-extended factors; its carry mask is not modelled (a read of it stops the program, as upstream). A 32-bit literal for a signed 64-bit operand sign-extends (AMD's ISA, literal expansion to 64 bits): v_mad_i64_i32's addend and v_ashrrev_i64's value, which src64 zero-extended. Both mads refuse clamp and omod, which they bypassed write_i's check for. (The title's programs do not use v_mad_i64_i32: no refusal of the baseline's translation names it.) From Marvisak/VIctory pull request Marvisak#3082 (RVZO6) and upstream main's arm, with a test after the PR's. Not taken: its split of the carry compare into dwords, a workaround of one AMD compiler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…kes, one barrier an exchange, the water's missing squares From another tree of the family (codec-d/cool_fox, since gone): the tracer that follows a value through a program goes by the instruction's EXEC guard as well as by the lanes that reach its block, which brings back a compute program the form without early-outs dropped on 32-lane cards; a condition code from a mask operation read as a scalar is "some lane of the wave has the bit" (such a program was refused on every host); a scalar read back from a lane set earlier in the same block. From upstream: the length of one-operand vector instructions and the `v_cmpx` forms (Marvisak/VIctory pull request Marvisak#3083), `v_mad_i64_i32` and sign-extended 64-bit literals (Marvisak#3082), early depth and stencil where the console's program asks for it (Marvisak#2085; VICTORY_EARLY_DEPTH=0 turns it off; 3,009 pixel programs), the LOD bias of samplers kept inside what the host takes (Marvisak#3043). A console wave run as two host waves that exchange a value meets at one group barrier an exchange, not two (VICTORY_EXCHANGE_PARITY): 5,824 barriers become 4,046 in 179 compute programs. Where a 64-lane compute program's wave operations are the allocation idiom, each host wave on its own is tried first (VICTORY_WAVE_LOCAL_FIRST): 23 programs, 228 barriers become 35; a first-lane read of a value that differs between lanes keeps the form that meets. The water's black squares: the two volumetrics programs of the water set two words of group shared memory from one thread and all threads then work on them with atomics, with no barrier, since the console's lanes run in step. In the paired-lanes form those accesses were ordered by a fence alone, and whole groups of 8x8 texels came out zero, others each frame. Where the group is one console wave they now take a full group barrier with the fence (36 programs, 875 places). Seen in dumped targets of the open world's opening shot: zero squares in three of three frames before, in none of four after, and the dark blocks in the picture at those places are gone. Runs of 2026-11-26 on an RTX 4070 Ti: the translation counts are unchanged (14,247 vertex and pixel, 2,681 of 2,682 compute, 8,765 mesh); first room 74.1 ms a frame after the pipelines were rebuilt (77.3 on the tree before, back to back), pictures right in the prologue and in the open world. The shader cache is new with this merge: warm it up once. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Hardware data for the carry part, from an AMD Radeon RX 7900 XT (RDNA 3, driver 32.0.32015.7029), Windows 11. Synthetic shaders only, no game files. The test checks the carry and both result dwords of
The change and the test are in fxceless/victory-fork#1507. AI use: Claude Code ran the tests and drafted this comment; posted at my request. |
|
The RX 7900 XT report above exercises a register layout that the existing test does not cover. I added six cases with It passed on Windows with app-local WARP 1.0.22, Agility 1.620.2 and the DXIL 1.9.2609 validator. The disassembled carry shader contains two unsigned 32-bit comparisons. Strict shader Clippy and the asset policy passed. The local hardware adapter could not create an SM 6.6 device, so the hardware result still comes from murillojndem's report. RVZO6 can pick up the test, then murillojndem can run it on the RX 7900 XT if available. Please retain the Git author on cherry-pick or rebase, or add AI-assisted with OpenAI Codex. |
The carry out was an i64 icmp ult of the sum with the addend. On an RX 7900 XT (driver 32.0.32015.7029) it is wrong where the addend's register pair shares a register with the second factor: 124 of 324 cases of the new test with the addend in v[2:3]. WARP, the separate pair v[3:4] and the result dwords are right. The dwords are compared instead, as in the carry part of Marvisak/VIctory#3082. The test checks the carry and both result dwords against a * b + c. Co-authored-by: RVZO6 <66844656+RVZO6@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
Three correctness issues in 64-bit integer multiply-add lowering (
crates/victory-shader/src/emit/lower.rs):v_mad_i64_i3232-bit literal insrc2is zero-extended instead of sign-extended:src64andsrc64_dwordscheckedinst.name().ends_with("_i64"), missingv_mad_i64_i32(which ends in"_i32") even though its 64-bit addendsrc2is signedi64(AMD RDNA2 ISA literal extension rules; Mesaaco_opcodes.pyv_mad_i64_i32src(U32, U32, I64)). A negative 32-bit literal such as-100(0xFFFF_FF9C) zero-extended to+4_294_967_196(hi = 0) instead of sign-extending to-100(hi = 0xFFFF_FFFF).v.clampandv.omodsilently ignored onv_mad_u64_u32andv_mad_i64_i32:Both opcodes bypass
write_iand callself.writedirectly, silently droppingv.clamp(a valid saturating modifier onVOP3b_I64_I1_I32_I32_I64:HasClamp = 1in LLVMVOP3Instructions.td) andv.omod.v_mad_u64_u32carry-out emits 64-biticmp ult i64:Line 6033 was the last remaining 64-bit integer ordering comparison in
lower.rs, which AMD's D3D12 shader compiler misorders as if low and high dwords were swapped (documented in Shaders: 64-bit integer compares on their dwords (AMD orders a shared-dword i64 compare wrong) #1599 /lower.rs:7958).Fix
inst.name() == "v_mad_i64_i32"alongsideends_with("_i64")for 32-bit literal sign-extension insrc64andsrc64_dwords.v.clamp || v.omod != 0withErr("integer output modifiers")inv_mad_u64_u32/v_mad_i64_i32, matchingwrite_i.src2viasrc64_dwords(keepingflags::INT64) and computev_mad_u64_u32carry-out via 32-bit unsigned dword comparisons:(hi <u add_hi) || (hi == add_hi && lo <u add_lo).Tests & Verification
emit::valu_tests::v_mad_i64_i32_and_v_mad_u64_u32_literal_modifiers_and_carryincrates/victory-shader/src/emit/valu_tests.rs:op 0x176 clamp=true omod=0 should be refused, got None).v_mad_i64_i32negative-literal cases (both low and high dwords), and all 6v_mad_u64_u32carry-out boundary cases pass on WARP SM 6.6 +dxil.dllvalidation (victory-shader: 304 passed, 0 failed; clippy default &--all-featuresclean;xtask policyclean).Claimed in #1633.
AI-assisted: T3 Code (Antigravity, gemini-4-neon).