Shaders: lower v_mad_u32_u16, v_mad_i32_i16, and v_lerp_u8 #1068
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#1068
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@kilvynsilveira-tech on GitHub · 2026-11-24 15:27 UTC · original
Summary
Lowers three RDNA2 integer VALU instructions in \crates/victory-shader/src/emit/lower.rs\ that previously returned \Unsupported:
a[i] + b[i] + (c[i] & 1)) >> 1Because external PR creation is currently restricted (\collaborators_only), the branch is ready on my fork for cherry-pick / review:
Changes
Verification (Windows x64 MSVC)
Synthetic tests only; no game files.
@DrDarkDK on GitHub · 2026-11-24 15:37 UTC · original
Tested
5319a34on native Windows with an RTX 4070 Ti (621.01) and WARP. Both backends returned the expected values in all eight synthetic DXIL readbacks, covering independentop_selchoices, signed and unsigned MAD wraparound, and per-bytev_lerp_u8rounding.Both MAD opcodes with
clampset still returnUnsupported: integer output modifiersduring lowering.I also scanned 26,096 decoded programs from the local 1.0.2.1 executable and shader archive. None contained these three opcodes. No gameplay test.
AI-assisted with Codex.
@Marvisak on GitHub · 2026-11-25 10:00 UTC · original
Automated triage for the maintainers.
maindecodesv_mad_u32_u16,v_mad_i32_i16andv_lerp_u8(crates/victory-shader/src/gfx10/opcodes.rs), butcrates/victory-shader/src/emit/lower.rshas no lowering for them, so a program using them is refused today. The change fits the translator's scope.Open PR #1688 has the same title, refers to this issue and appears to carry the same three lowerings, so review can happen there. Pull requests are open to everyone now, so you can also open yours from
shader/lerp-and-mad16-u32(5319a34) if it differs.From the test comment: the two MAD forms with
clampset are still refused (integer output modifiers). None of the three opcodes turned up in the 1.0.2.1 programs scanned, so this adds coverage but doesn't fix a known failure in the title.Generated by Claude Code
@Lyrnc on GitHub · 2026-11-26 18:52 UTC · original
RDNA2 hardware results for these three opcodes, from gfx1036. Two
op_selbits do something here that #1688 doesn't model, andclampsaturates.Setup.
0,1,2,0x7fff,0x8000,0x8001,0xffff,0x1234,0xabcd,0xffand random values; the addend is0,-1,0x80000000,0x7fffffffor random. 12 more rows run with a preset destination.build_valu_cs, on that Radeon and on an RTX 5080 (driver 610.88), one adapter at a time with a local switch.PC RDNA2 silicon, not the console's GPU. No game data.
What the hardware does.
v_mad_u32_u16:S0[15:0] * S1[15:0] + S2, the addend all 32 bits, wrapping.v_mad_i32_i16: the same with signed 16-bit factors. Both match that on all 76 rows.op_sel[0]/op_sel[1]: pick the high half ofsrc0/src1. 76/76 rows forop_sel1, 2 and 3, both opcodes.op_sel[2]: the addend becomesS2[31:16], zero-extended, forv_mad_i32_i16too:v_mad_u32_u16 op_sel:[0,0,1,0]of0xffffffff, 0xffffffff, 0xffffffffgives0xffff0000(0xfffe0001 + 0xffff).v_mad_i32_i16of the same gives0x00010000(1 + 0xffff, not1 - 1).v_mad_i32_i16of0x8000ffff, 0x80000001, 0x7fff8000gives0x00007ffe.op_sel[3]: the low 16 bits of the result go toD[31:16], andD[15:0]becomes 0, whatever it held before.10 * 10 + 0gives0x00640000;3 * 2 + 0x80017fffover a destination of0xa5a5a5a5gives0x80050000.clamp: saturates.v_mad_u32_u16goes to0xffffffff(0xffff * 0xffff + 0xffffffff → 0xffffffff),v_mad_i32_i16to[-2^31, 2^31 - 1]. 76/76 rows each.v_lerp_u8:(a + b + (c & 1)) >> 1per byte, 76/76 rows.op_sel[0]changes nothing.Translator, rows that differ from the hardware (of 76), the same on the Radeon and the RTX 5080:
main63bcca48c6ff38)v_mad_u32_u16/v_mad_i32_i16,op_sel0..3op_sel[2]setop_sel[3]setclampv_lerp_u8, with and withoutop_sel[0]So #1688 is right where it reads
op_sel[0..1]. It silently ignoresop_sel[2]andop_sel[3], wheremainrefuses the program. #1688 could model those two bits from the rows above, or refuse them. The saturatingclampis a pair of selects, if it is wanted. DrDarkDK found none of the three opcodes in the 1.0.2.1 programs, so this is about not getting a wrong answer later.AI use: Claude Code (Claude Opus 5.5) wrote the probe and ran it on the GPUs above; the numbers come from those runs.