Shader: the packed dot over an inline constant is taken by hand from … #1896
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1896
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1896/head"
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?
@kais7654 on GitHub · 2026-11-25 00:17 UTC · original
kais7654:shader/dot-packed-const→main· +46 −11 · 2 files · 1 commits · closed without mergingProblem
fspx_programs_run_with_the_hardwares_dot_productsfails on NVIDIA (RTX 5070):one
v_dot4_i32_i8case returnsacc - 128instead ofacc - 320when one ofthe dot sources is an inline constant.
The emitted DXIL is semantically correct. Disassembling the dumped shader with
dxc -dumpbinshows the faulting call:b = 16384is the f16 pattern in the low half alone, which is exactly thewanted value. But the driver feeds the low half into BOTH halves of its native
dot instruction (broadcast), so the hardware result drifts. WARP passes the
same test with the fold in place.
Fix
In the
v_dot4_i32_i8lowering (crates/victory-shader/src/emit/lower.rs):f16 pattern in the low half through
f16_operand()and mark theinstruction as
folded.folded, compute the dot by hand — 4 signed-byte products viaselect_bits()accumulated with Mul/Add — instead of emitting thedot4AddPacked.i32intrinsic, which sidesteps the driver bug entirely.Testing
fspx_programs_run_with_the_hardwares_dot_productsPASSES on RTX 5070(laptop) and on WARP.
cargo test -p victory-shader --lib -- --test-threads=1:203 passed, 6 failed — the 6 failures are pre-existing on main (
70564ae);the packed-dot failure is gone (7 → 6).
cargo clippyclean.lower.rs(32 insertions, 8 deletions).
fspx_programs_run_with_the_hardwares_dot_productsfails on RDNA1, where the driver folds a constantDot4AddI8Packedoperand as unsigned #1782@oni-swr on GitHub · 2026-11-25 01:06 UTC · original
AMD RDNA3 (RX 7800 XT) test report for #1896 at head
51f3cb87merged withmain42363ab6(clean merge).Tested
origin/main42363ab6:cargo test -p victory-shader --lib fspx_programs_run_with_the_hardwares_dot_products -- --test-threads=1 --nocapture: 1 passed, 0 failed (0.40s; AMD did not hit the NVIDIA inline-constant dot4 broadcast bug).51f3cb87merged with42363ab6):cargo test -p victory-shader --lib fspx_programs_run_with_the_hardwares_dot_products -- --test-threads=1 --nocapture: 1 passed, 0 failed (0.40s).cargo test -p victory-shader --lib -- --test-threads=1 --nocapture: 246 passed, 0 failed, 3 ignored (33.19s; 6no console [or PC] compiler; skippedand 1warp: no pipeline for a wave of 32; skipped).cargo clippy -p victory-shader --all-targets: clean.Not tested
victory-shader, or a game run.AI use
@CaravelaLabs on GitHub · 2026-11-25 01:07 UTC · original · edited 2026-11-25 03:53 UTC
@kais7654 thanks for catching that RTX 5070 miss. For this encoding the dump is the right dword:
16384issel_hi_lo(2.0), and acc−320 is the signed dot of those bytes. A driver that copies that low half into both halves is a host bug. The by-hand path matches that dword only for this one constant.An inline float in
v_dot4_i32_i8is the 32-bit value.inlinereturns1.0as0x3F800000(and2.0as0x40000000), andop_sel/op_sel_hipick the halves. That is what main does, and what the other packed integer ops do.f16_operandis the packed-float table (1.0→0x3C00). Those two agree only for ±2.0 withsel_hi_lo.That is the only inline constant in
fspx_programs_run_with_the_hardwares_dot_products(code244,op_sel0b010,op_sel_hi0b101, expected0x4000). The test passing cannot see the rest. @oni-swr's RX 7800 XT run of that same test passing is this case, on main42363aband on this head. Thank you for that data point.On
51f3cb87the new arm sends codes 240–248 throughf16_operandand skipsop_sel. With the test'sa = 0x0302FB02and accumulator0x7FFFFFF0, identity1.0(llvm-mc gfx1030v_dot4_i32_i8 v0, v1, 1.0, v2, encoding[0x00,0x40,0x16,0xcc,0x01,0xe5,0x09,0x1c],op_sel=0,op_sel_hi=7) should be0x7FFFFFAD. This path produces0x7FFFFEC4.sel_hi_lo(4.0)should be0x7FFFFDB0, not0x7FFFFE9C. The2.0case you fixed stays0x7FFFFEB0either way. Those are the project's owndot4_refvalues; a GPU run is below. The lowering on main42363abis unchanged from4118f33.Separate from #1782 (an RDNA1 driver folding that intrinsic's constant as unsigned). No game data. I did not re-run the RTX 5070.
Update, now on AMD hardware (Radeon 8060S, RDNA3.5, so not RDNA2 itself). I ran the same VOP3P opcode (
0x16;v_dot4_i32_iu8with both operands signed on this generation) with each inline float 240-248 and fourop_sel/op_sel_hisettings, and read the results back. All 36 match the 32-bit float pattern withop_selpicking the halves. The f16 pattern withop_selignored matches 2 of the 36: ±2.0 withsel_hi_lo. Same output on every repeat.src1op_sel/op_sel_hi51f3cb87(computed)1.00x7FFFFFAD0x7FFFFEC44.0sel_hi_lo0x7FFFFDB00x7FFFFE9C2.0sel_hi_lo0x7FFFFEB00x7FFFFEB0@mercuryVM, you read RDNA2 as ignoring
op_selfor these. I can't run RDNA2 here, so if you have a reference or an RDNA2 card that shows it, I'd gladly be corrected. Your point that the by-hand sum avoids the NVIDIA fold still stands; only the constant's value is in question.AI-assisted check, run on this machine.
@Marvisak on GitHub · 2026-11-25 08:22 UTC · original · edited 2026-11-25 14:51 UTC
Automated triage for the maintainers.
Merge candidate. Re-reviewed at
9b0824a. In thev_dot4_i32_i8lowering (crates/victory-shader/src/emit/lower.rs), inline constants 240-248 now go through the ordinary operand path again:s(self, k)gives the 32-bit float pattern, andop_sel/op_sel_hipick the halves, exactly as onmain. Only when a multiplicand is such a constant is the dot taken by hand: four signed byte products fromselect_bits(.., true), added to the accumulator with wrapping i32 arithmetic. That is the same math asdot4AddPacked.i32, so the console semantics do not change; it only avoids the RTX 5070 driver reading the constant's low half in both halves. The two new cases infspx_programs_run_with_the_hardwares_dot_products(1.0at default selection,4.0withsel_hi_lo) take their expected values fromdot4_ref, and they match the AMD hardware readbacks @CaravelaLabs posted above (0x7FFFFFAD,0x7FFFFDB0).Reply to @kais7654: thanks, both requested changes are in, so the verdict moves from needs-work. A small optional follow-up:
foldedonly looks at float inline constants (240-248). If the same driver also folds integer inline constants (128-208) or a literal operand, those still reach the intrinsic; a case with one of them would show whether that matters.CI: passing (
check).Generated by Claude Code
@sinan-cmyk on GitHub · 2026-11-25 11:38 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head 51f3cb87 onto
main940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
fspx_programs_run_with_the_hardwares_dot_productsfails on RDNA1, where the driver folds a constantDot4AddI8Packedoperand as unsigned #1782@kais7654 on GitHub · 2026-11-25 13:34 UTC · original
Fixed at
9b0824a: the f16-operand branch is gone — an inline constantgoes the ordinary operand way again (the f32 pattern, through the
op_sel / op_sel_hi half selection), like main; only a dot over a
constant is still taken by hand from the byte products, for the driver
that reads the constant's low half in both halves. Two cases were added
to fspx_programs_run_with_the_hardwares_dot_products: 1.0 at the
default selection (0x3F800000 read whole → 0x7FFFFFAD) and 4.0 with the
halves swapped (0x4080 → 0x7FFFFDB0). All six dot4 cases pass on RTX
5070 Laptop GPU (driver 616.87) and WARP; CI is green.
AI-assisted (Mistral Vibe).
@Marvisak on GitHub · 2026-11-25 22:03 UTC · original
Automated triage for the maintainers, second look (a review against current
main, with builds and tests where they could change the verdict).Closing in favour of #2408, which takes the same by-hand sum (crediting this PR) for every multiplicand a host compiler can fold: inline floats, inline integers, literals and constants moved through a register, and also
v_dot4c_i32_i8. Integer inline constants and literals were measured to be misread too, and this PR matches only inline floats onv_dot4_i32_i8. The sum itself is right.If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
Pull request closed