Repository navigation
Conversation
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: merged into main 940d32f, cargo test -p victory-shader --locked on macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — constant-multiplicand dot product folded.
|
I ran the FSPX test and the seven packed-dot operand classes on an RTX 5080 (driver 621.40) and built-in Microsoft WARP. Each comparison used the same tests on the PR head and its direct parent. The device was verified by DXGI LUID and every case completed a D3D12 dispatch and readback.
That is four FSPX results plus four inputs for each of the seven operand classes. The inline |
|
WARP verification Tested: PR head
The failure on the first run was New tests Diff review ( Limits: WARP only. The AI use: Claude Code (Claude Sonnet 5.5) |
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:
- Lowering dot products over constant multiplicands by hand passes all live GPU dot-product tests on RTX 5090 and WARP.
cargo test -p victory-shader dot: 3/3 passed on RTX 5090, 3/3 passed on WARP (byte_dot_products_match_the_hardware,fspx_programs_run_with_the_hardwares_dot_products,dot4_takes_every_constant_class_whole).cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.
AI-assisted (Gemini 4 Neon).
|
Automated triage for the maintainers. Merge candidate. Both packed byte-dot lowerings in On your reply: the rebase only adds lines next to Generated by Claude Code |
|
Verified the semantics: known-side bytes extract as One note: when the other operand is runtime-valued the expansion emits up to 4 mul+add pairs instead of one op — strictly more instructions, so on non-buggy drivers this is a mild pessimisation. An env/flag gate would let a driver that handles the intrinsic correctly keep it; not a blocker. |
On an Intel UHD (Xe-LP, 8086:a78b, driver 31.0.101.5445), `fspx_programs_run_with_the_hardwares_dot_products` gives acc - 128 where RDNA 2 gives acc - 320 (Marvisak#1829). The case is `v_dot4_i32_i8 v0, v1, 2.0` with `sel_hi_lo`, a multiplicand of 0x4000. The DXIL is right: the op_sel selection is integer arithmetic on 0x40000000, and the driver folds it to `dot4AddPacked(acc, a, 0x4000)`. The device then multiplies by 0x40004000: -5 * 64 + 3 * 64 = -128. A probe over constant multiplicands on that device shows the rule. Every constant that fits in 16 bits (signed or not) is read as its low half in both halves: 1, 2, 64, -2, -16, 0x4000, 0x7F00, 0xFF80 and 0xFFFF8000 all give the replicated value. 0 and -1 are right only because their replication is themselves. Constants wider than 16 bits (the inline floats as 32-bit patterns, 0x00800000, 0x12345678) are right, and so is every run-time multiplicand. A constant moved into a VGPR or an SGPR first fails the same way, and so does `v_dot4c_i32_i8`. Marvisak#1896 reports the same symptom on an RTX 5070. Both dot lowerings now go through `dot4_i8`. When a multiplicand is something the host compiler can work out before the program runs, the lowering sums the other operand's sign-extended bytes times the constant's non-zero bytes by hand, which is V_DOT4_I32_I8 and V_DOT4C_I32_I8 in the RDNA 2 ISA (November 2020, pp. 140 and 173), so no `dot4AddPacked` sees a constant. `bitcode::Module::known_i32` decides this. It folds constants through integer arithmetic, casts and selects, which covers the op_sel half selection the lowering itself emits. Run-time multiplicands keep the intrinsic. The constant's value is unchanged: an inline float is its 32-bit pattern and op_sel picks its halves, as on `main`. `dot4_takes_every_constant_class_whole` checks against `dot4_ref`, one program per class with its dot products chained through v0: inline integers 0, 1, 2, 15, 16, 63, 64, -1, -2 and -16; the nine inline floats; 16-bit and wider literals (each constant in src1 with four op_sel choices and in src0); constants in a VGPR or an SGPR; `v_dot4c` with literal and inline sources; constant accumulators; and run-time operands with four op_sel choices. With `main`'s lowering the Intel UHD fails the first six classes and passes the last two. With this change it passes all of them, and the FSPX test passes too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2644bbc to
9ea9e00
Compare
|
Rebased onto AI use: Claude Code (Claude Opus 5.5). |
…t multiplicand is taken by hand # Conflicts: # crates/victory-shader/src/emit/valu_tests.rs
…t multiplicand is taken by hand # Conflicts: # crates/victory-shader/src/emit/valu_tests.rs
Part of #1829: this fixes the
fspxfailure on the Intel UHD from the report there. It also fixes the RTX 5070 symptom from #1896. It keepsmain's operand values and uses a by-hand sum when a multiplicand is a constant, as #1896's triage asked.Root cause
fspx_programs_run_with_the_hardwares_dot_productsfails on the Intel UHD (Xe-LP,8086:a78b, driver 31.0.101.5445) in one case:v_dot4_i32_i8 v0, v1, 2.0withsel_hi_lo. The result isacc − 128, and RDNA 2 givesacc − 320.The DXIL is right.
dxc -dumpbinof the translation onmainshows the op_sel selection as integer arithmetic on the inline constant, which goes straight into the intrinsic:The driver folds
%25to0x4000and then multiplies by0x40004000. Witha = 0x0302FB02, that gives −5·64 + 3·64 = −128.I ran a probe on that device over constant multiplicands. It uses
a = 0x0705FB82and accumulator0x7FFFFFF0, both from root constants, so only the multiplicand is known to the compiler. Every constant that fits in 16 bits, signed or unsigned, is read as its low half repeated in both halves:main0,-11,2,64,-2,-160x00010001,0x00020002,0x00400040,0xFFFEFFFE,0xFFF0FFF00x4000,0x7F00,0xFF80,0xFFFF80000x3F000000…0x3E22F983), literals0x00800000,0x12345678v_mov_b32 v2, lit) firstv_dot4c_i32_i8with a literalThe pattern fits a driver that encodes a constant source as a half-word immediate when it fits, which the packed byte dot then reads as a whole dword. #1896 saw the same thing on an RTX 5070 with
0x4000. The same values from root constants give the right result, so what goes wrong is a constant reachingdot4AddPacked.Fix
Both dot lowerings now go through
Lower::dot4_i8(acc, a, b):D = Σ S0.i8[k]·S1.i8[k] + S2(+ Dfordot4c), wrapping. So nodot4AddPackedever sees a constant operand."Can work out" is decided by the new
bitcode::Module::known_i32. The builder doesn't fold anything itself.known_i32folds constants through integer arithmetic, casts and selects, which covers the op_sel half selection the lowering itself emits (the shift/and/or chain above),v_mov/s_movliterals and chains of those.The constant's value is the same as on
main. An inline float is its 32-bit pattern, and op_sel picks its halves. That is what @CaravelaLabs measured for all nine inline floats on RDNA 3.5 in #1896 and what the triage there asked to keep. After the change, the translation of the case above has nodot4AddPacked. It hasshl/ashrbyte extraction,mul i32 %b1, 64andadd. A register operand still emitsdot4AddPacked(acc, %a, %b).The by-hand sum for constants comes from @kais7654's #1896. This PR keeps
main's operand handling, which that PR's triage asked for.Tests
emit::valu_tests::dot4_takes_every_constant_class_whole(new GPU test): it runs on the hardware and on WARP and checks againstdot4_ref. Each class is one program with its dot products chained through v0, so the test takes about 2 s on the RTX 4060 and under 1 s on the Intel UHD. The other operand and the accumulator come from root constants (four input sets), so only the constant is known to the compiler. The classes:0x4000,0x7F00,0xFF80,0xFFFF8000,0x00800000and0x12345678;v_mov_b32) or an SGPR (s_mov_b32) first;v_dot4c_i32_i8with literal and inline sources;In classes 1-3, each constant runs in src1 with four op_sel/op_sel_hi choices and in src0.
emit::bitcode::tests::known_i32_folds_constant_integer_arithmetic(new unit test): it checks the fold (the op_sel chain, a float bitcast,ashr) and that it stops at run-time values, at selects whose arms differ, and at float arithmetic.fspx_programs_run_with_the_hardwares_dot_products: unchanged. It now passes on the Intel UHD.Results
Debug build, Windows 11 26200, Rust 1.98.1 MSVC, on
main940d32f. The laptop has an RTX 4060 Laptop GPU (driver 32.0.16.1047, the default adapter) and the Intel UHD8086:a78b. For the Intel runs I used a local, uncommitted hook inemit::host::hardware_adapterthat picks the adapter by name, as in #1829. Its log shows onlyIntel(R) UHD Graphics (8086:a78b)for every hardware device. The hook is not part of this PR.main940d32fcargo test -p victory-shader --libfspxfailsfspxand both new tests pass0x7fff3c23, want0x7fff3679); 6 and 7 passcargo test --workspace --locked --no-fail-fastVICTORY_WARP=1), same--all-features(RTX)cargo clippy --workspace --all-targets --locked -- -D warnings, default and--all-featurescargo xtask policyThe 7 failures left on the Intel UHD are the ones #1829 lists for other causes:
arith, the threebvhtests,heap,permuteandatom64. All of them are onmaintoo.The RTX, WARP and all-features failures are the ones
main940d32fhas on this machine:dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views, the twostride_testsheap tests andgathers_at_a_level_match_the_hardware.victory-gputests,gathers_at_a_level_match_the_hardwareand the wave-32permutes_….The new tests and the FSPX test pass on the RTX 4060 and on WARP, both before and after the change.
Not run: AMD or NVIDIA RDNA-class hardware other than the RTX 4060, the RTX 5070 from #1896, and the title. I used no game data.
Overlap:
dot8forms. They would meet a textual conflict here, and their constant operands intodot4AddPacked(op 164 for the unsigned forms included) would need the same handling.AI use: Claude Code (Claude Opus 5.5) investigated, wrote the change and the tests, ran the hardware runs on this machine, and wrote this description.
🤖 Generated with Claude Code