Shaders: lower v_{min3,max3,med3}_{i16,u16} and v_mad_{u32_u16,i32_i16} #1300
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!1300
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1300"
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?
@ESAT586 on GitHub · 2026-11-24 17:16 UTC · original
ESAT586:shader/valu16-min3-max3-med3-mad32→main· +300 −0 · 3 files · 1 commits · openSummary
Lowers 8 missing 16-bit integer VALU instructions in
victory-shader:valu16/valu16_op):v_min3_i16(0x352),v_min3_u16(0x353)v_max3_i16(0x355),v_max3_u16(0x356)v_med3_i16(0x358),v_med3_u16(0x359)op_sel[0..2]on all three 16-bit sources andop_sel[3]on the destination, preserving the untouched half ofvdst.valu_op):v_mad_u32_u16(0x373)v_mad_i32_i16(0x375)op_sel[0..1]for the 16-bit multiplicands, reads full 32-bitsrc2, and supports both wrapping and exact 32-bit signed/unsigned saturatingclampusing pure 32-bit DXIL (noINT64required).Verification
Tested locally on Windows 11 with NVIDIA GeForce RTX 3060 Ti (
Driver 32.0.16.1656) + Microsoft WARP +dxil.dllvalidator, Rust1.98.1MSVC:cargo clippy --workspace --all-targets --locked -- -D warnings— 0 warningscargo clippy --workspace --all-targets --all-features --locked -- -D warnings— 0 warningscargo test -p victory-shader --locked— 121 passed, 0 failed, 1 ignored (includingvalu16_min3_max3_med3_and_mad32_16_match_rdna2verifying all 8 opcodes, high-halfop_sel, untouched-half preservation, wrapping, and saturatingclampon RTX 3060 Ti and WARP)cargo xtask policy— 154 files ok4726c19952to1879aace7b@adamdotpy on GitHub · 2026-11-24 17:22 UTC · original
Reviewed at head
79a7a60(worktree on the PR head, isolated target dir, Windows 11 / Rust 1.98.1). Findings, ranked:1. The lowering is semantically correct — model-checked exhaustively, then hardware-tested. Opcodes check out against the GFX10 table (
gfx10/opcodes.rs:0x352v_min3_i16 …0x359v_med3_u16,0x373v_mad_u32_u16,0x375v_mad_i32_i16). The 16-bit min3/max3/med3 arm sign-extends all three sources for_i16(soSGT/SLTon the extended values is exactly 16-bit signed compare; zero-extendedIUGT/IULTis exactly unsigned), and the med3 chainmax(min(a,b), min(max(a,b), c))is the ISA median — I checked the chain against a direct median over all sign/boundary combos (0x0000/0x0001/0x5/0x7FFF/0x8000/0xFFFE/0xFFFF triples, both signednesses): 0 mismatches. No -0-style subtlety exists for integers, so the f32/f16 med3 fix from #1259 does not interact here.2.
v_mad_u32_u16/v_mad_i32_i16clamp logic verified. I modeled the emitted ops against the wrapping-arithmetic-plus-saturation reference over 306,480 combinations (all boundary 16-bit values × boundary accumulators, near-exhaustive small grid, 300k random with random clamp): 0 mismatches. Unsigned overflow detectionsum <u accis exact because the product of two u16 is non-negative and fits in u32; the signed path's(prod^acc >= 0) & (prod^sum < 0)with saturation to the sign ofprodis the standard correct test — includingprod == 0(no false overflow).omod/abs/negare refused,clamphandled, opsel half-selection goes through the existinghalf_src/dst-half machinery.3. Hardware evidence on this machine.
cargo test -p victory-shader --lib valu16runsvalu16_min3_max3_med3_and_mad32_16_match_rdna2on the GPU: 1 passed / 0 failed. The test pins both signednesses of min3/max3/med3, a hi-dst opsel case with a0xCAFE_BEEF-seeded destination (half preservation), and mad u32/i32 in wrapping + clamped + opsel forms, including all three overflow directions (u32 wrap →u32::MAX, i32 positive overflow →i32::MAX, negative overflow →i32::MIN). Fullcargo test -p victory-shader --lib: 121 passed / 0 failed / 1 ignored.4. Checks:
cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warningsclean;cargo build --release -p victorybuilds.5. One nit, not blocking (CI has no fmt job): the PR adds 4 new rustfmt diffs of its own —
lower.rs:3951(the(imin, imax)tuple fits on one line per rustfmt) and three in the new test code invalu_tests.rs(main's copy of that file is fmt-clean). The other 3lower.rshunks are pre-existing onmain(7099/7118/7137, shifted by the additions). Worth arustfmtpass on the touched lines before merge.Nothing else found; the new opcodes previously fell through to a refusal, so this strictly widens what translates.
@geiyiliyabumo on GitHub · 2026-11-24 17:24 UTC · original
Independent verification of \79a7a60\ on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, \gfx1200) / Rust 1.98.1 MSVC:
Code audit looks solid: \_mad_u32_u16\ / \_mad_i32_i16\ products never overflow 32 bits (\65535^2 <= u32::MAX\ and
-32768)^2 = 2^30 <= i32::MAX, so checking overflow on \prod + acc\ alone is exact for both unsigned and signed clamp paths; \{min3,max3,med3}{i16,u16}\ properly uses \half_src(inst, 2)\ with sign extension for _i16. (Minor merge note: #1295 changes \half_src\ arity if both land.)AI-assisted; synthetic tests only, no game files.
@fuzeofficlal on GitHub · 2026-11-24 17:54 UTC · original
Reviewed
3c01f0eand verifiedv_mad_u32_u16/v_mad_i32_i16on NVIDIA GeForce RTX 5090, AMD Radeon(TM) Graphics, D3D12 WARP, anddxil.dll. Two bugs worth fixing:240..=248) on 16-bit integer ops use 32-bitf32bit patterns on GFX10, notf16(emit/lower.rs:3932, 4708):v_mad_{u32_u16,i32_i16}andv_{min3,max3,med3}_{i16,u16}haveOPERAND_REG_INLINE_C_INT16operands in AMDGPU's decoder (AMDGPUDisassembler.cpp: onlyFP16/BF16operands decode242as0x3C00;INT16operands decode242(1.0) as0x3F80_0000, selecting0x0000forop_sel=0and0x3F80forop_sel=1).self.half_src(inst, k)routes throughf16_operand, turning1.0withop_sel=0into0x3C00(15360) instead of0x0000(andop_sel=1into0x0000instead of0x3F80). Usingself.packed_src(inst, k, false, false)?(which readsself.operandbefore selecting the halfword) matches hardware.emit/lower.rs:3926):v.abs != 0 || v.neg != 0should return"integer operand modifiers"rather than"integer output modifiers"to match the rest oflower.rs.Verified reference tests (including inline float constants
242/243acrossop_seland signed/unsignedclampsaturation):fuzeofficlal/VIctory@dec3499.@ESAT586 on GitHub · 2026-11-24 18:44 UTC · original
Great catch, @fuzeofficlal — thank you for checking the
OPERAND_REG_INLINE_C_INT16decoding against hardware!Fixed both items on this branch:
v_mad_{u32_u16,i32_i16}andv_{min3,max3,med3}_{i16,u16}to read their 16-bit integer operands throughself.packed_src(inst, k, false, false)?so inline float constants (240..=248) decode as 32-bitf32bit patterns beforeop_selhalf selection.v_mad_{u32_u16,i32_i16}modifier checks sov.abs != 0 || v.neg != 0returns"integer operand modifiers"andv.omod != 0returns"integer output modifiers".valu16_min3_max3_med3_and_mad32_16_match_rdna2for inline float constant242(1.0f = 0x3F80_0000) withop_sel=0(0x0000) andop_sel=1(0x3F80) on bothv_mad_u32_u16andv_max3_u16.Re-verified on NVIDIA GeForce RTX 3060 Ti, WARP, and
dxil.dll(clippy -D warnings,--all-features,xtask policyall green).(Authored and verified by Gemini 4 Neon — High Mode; synthetic tests only, zero game data.)
@adamdotpy on GitHub · 2026-11-24 19:04 UTC · original
Verified the new head
7383f54here (worktree on the PR head, isolated target dir, Windows 11 / Rust 1.98.1). The two follow-ups both land: (1) the new 16-bit int ops now read inline float constants as f32 bit patterns viapacked_src(..., false, false)+ opsel half-select — consistent with the rule in #1295/#1285 (note: those PRs route the same decode throughhalf_int_src; the behaviors agree, but the second PR to merge will conflict on these arms); (2) the rustfmt pass cleared the hunks I flagged. Theabs/negrefusal is now split into a separate "integer operand modifiers" message, fine. Ran here:valu16GPU test passes, fullcargo test -p victory-shader --lib121 passed / 0 failed / 1 ignored, clippy clean, release build ok. One cosmetic leftover:rustfmt --checkstill wants to split the one-line(imin, imax)tuple atlower.rs:3959(it exceeds the width) — one hunk, CI has no fmt job.@Marvisak on GitHub · 2026-11-25 01:21 UTC · original · edited 2026-11-26 05:42 UTC
Automated triage for the maintainers.
Verdict: merge candidate. This is now rebased and merges cleanly. It lowers
v_{min3,max3,med3}_{i16,u16}andv_mad_{u32_u16,i32_i16}in a newemit/lower/valu16.rs. Before this, those opcodes (gfx10/opcodes.rs0x352-0x359, 0x373, 0x375) had no lowering onmain, so shaders using them were refused. I checked the following:_i16sign-extends before signed compares.sum <u acc) and signed (sign-flip) paths. A 16x16 product always fits in 32 bits, so the check only has to cover the add.packed_src(.., false, false), so inline float constants decode as 32-bit patterns before the op_sel half is selected. That follows the review above.The GPU test
valu16_min3_max3_med3_and_mad32_16_match_rdna2covers both signednesses, opsel, the three overflow directions and inline constants.To note: #1295/#1285 route the same operand decode through
half_int_src, so whichever lands second will need a small conflict fix on these arms.CI: passing (
check). Recommending a look, not approving.Generated by Claude Code
@ESAT586 on GitHub · 2026-11-25 11:18 UTC · original
Rebased onto \main\ (\
940d32f) at $sha. Verified on RTX 3060 Ti + WARP: \alu16_min3_max3_med3_and_mad32_16_match_rdna2\ passed, strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.