shader: lower v_sat_pk_u8_i16 #499
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!499
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-499"
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?
@NolanCotter on GitHub · 2026-11-24 04:11 UTC · original
NolanCotter:sat-pk-u8→main· +264 −27 · 1 files · 3 commits · openDepends on #498 (uses its
lowers_ldstest helper; rebases to one commit once it lands).Summary
v_sat_pk_u8_i16(VOP1 0x62 / VOP3 0x1E2), refused atinteger()'s fallthrough on main.v_cvt_f16_f32(LLVM models the def asVOP1Inst_t16; Mesa ACOinstr_is_16bit). Uses the existinglow_halfhelper.src()already refusesabs/neg,write_irefusesclamp/omod; a nonzeroop_selis refused.sat_pk_u8_packs_the_clamped_halves:0x0100_7fff(halves 256 and 32767) saturates to0xffffin the low 16 while0xdeadsurvives in the high half, consumed by an LDS store. Refused on main, lowers now.Test plan
cargo test -p victory-shader— 59 passedcargo clippy -p victory-shader— cleancargo fmt --check— cleanAI-assisted (Devin). Semantics from the AMD RDNA2 ISA opcode description and the LLVM/ACO 16-bit-write tables; no game files used.
Generated with Devin
Each lane reads src0 of a lane in the other row of 16 of its 32-lane half, the pick taken from nibble i of the {src2, src1} selector. The lowering mirrors the whole-wave model wave.rs already uses for the op, through the same cross_lane/read_lane machinery as v_writelane_b32, and the console_lanes detector now covers the v_permlane family so host lanes are relabeled where the op appears. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>@Lyrnc on GitHub · 2026-11-24 05:53 UTC · original
RDNA2 hardware measurement: the saturation is right, but the high half is zeroed on the hardware, not kept.
Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr) sets the destination to
0xdeadbeef, then runsv_sat_pk_u8_i16 v10, v4(VOP1) and, separately,v_sat_pk_u8_i16_e64 v11, v4(VOP3) on 72 packed inputs: every pair of the halves0x0000 0x0001 0x007f 0x0080 0x00ff 0x0100 0x7fff 0x8000 0xffff 0xff80 0x0123 0xfedcagainst the first six. RDNA2 desktop silicon, not the console's. No game data.0x00ff00010x0000ff010x0000ff010x000001000x000000ff0x000000ff0x010001000x0000ffff0x0000ffff0x00007fff0x000000ff0x000000ff0x000080000x000000000x000000000x008080000x000080000x000080000x0000ffff0x000000000x000000000x0000ff800x000000000x000000000x010001230x0000ffff0x0000ffff[0, 255], src0[15:0] into bits 7:0 and src0[31:16] into bits 15:8. This matches your lowering on all 72 rows.0x0000on all 72 rows in both encodings. The0xdeadbeefthat was there is gone. Your test expects0xdeadto survive in the high half, so on this hardware it would be the wrong value.For contrast, the same kernel shape with
v_cvt_f16_f32does keep the high half:0xdead0000stays0xdead….on 34 of 34 inputs. So thev_cvt_f16_f32partial write you modelled this on does not carry over tov_sat_pk_u8_i16on RDNA2. The fix would be to write the 16-bit result zero-extended, as a full 32-bit write, instead of throughlow_half.AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
@slint6614-dev on GitHub · 2026-11-24 10:42 UTC · original
Measured on the full retail shader pack (26,503 containers) with
victory translate --validate --pipelines(pipelines on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines. Merged locally with current mainc7a5f49(main: CS 1440 / 1417).CS 1441 / 1418 (+1 validated); VS/PS and MS unchanged.
@Marvisak on GitHub · 2026-11-25 00:21 UTC · original
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-shader/src/emit/lower.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
@andrewpozdnakov7-jpg on GitHub · 2026-11-25 11:35 UTC · original
I separated the existing
v_sat_pk_u8_i16lowering from the #498 stack and replayed it unchanged on940d32f.bd0df4cretains the original Git author.The original smoke fixture encodes
0x7e08c501, which writesv4, while the LDS store readsv2.24cbda9uses the VOP1/VOP3 encoders and reads back the instruction's actual destination. The test wasUnsupportedon940d32f. On the rebase, all ten Windows/WARP cases pass, checking both encodings, signed clamps at 0 and 255, and preservation of the upper 16 bits. All 29 VALU tests passed with Microsoft DXIL validation. Strict shader Clippy and the staged asset policy passed.If you fold the readback test into a different commit, please retain
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>. Claim@LAKSHYA-cmd-tech on GitHub · 2026-11-24 04:50 UTC · original · approved these changes
Verified on Windows 11 D3D12:
@mercuryVM on GitHub · 2026-11-24 12:23 UTC · original · approved these changes
Tested
5c211d0on Windows 11, RTX 5070, MSVC:cargo test -p victory-shader -- --test-threads=1passes as part of the #576 stack (72 passed), andcargo clippy -p victory-shader --all-targetsis clean.victory translate --validate --pipelineson the local title executable still reports 12 of 12 programs. This commit is on mercuryVM/VIctory main via #576.v_sat_pk_u8_i16matches the ISA: sat8 of the low i16 in byte 0, sat8 of the high i16 in byte 1, and the register's high half kept as a GFX10 16-bit write.op_selis refused instead of guessed.sat_pk_u8_packs_the_clamped_halvesonly checks that the program lowers. Arun_casesvalue check with -1, 0x7FFF and 0x0100 per half would pin the clamps.AI-assisted (Claude Code).
@catminou4 on GitHub · 2026-11-24 12:38 UTC · original · reviewed
Test-merge with current main (
ffe310e) conflicts — needs a rebase. Main moved recently (PR #566 waterfall loops touchedlower.rs/resource.rs/valu_tests.rs), so shader PRs opened before it need rebasing. I'll re-review once it merges cleanly.@andrewpozdnakov7-jpg on GitHub · 2026-11-26 10:28 UTC · original
I corrected the upper-half expectation from my earlier WARP handoff using Lyrnc's RDNA2 hardware report. The new replay packs the two saturated bytes and writes a full dword with bits 31:16 cleared.
Branch on current main
63bcca4.d69b7acretains the original Git author anda31a726adds the readback test. On WARP, all 81 pairs passed in both VOP1 and VOP3 with a nonzero destination prefill. All 36 VALU tests, strict shader Clippy, and the asset policy passed.Please retain the Git authors when taking the commits. If folding in the readback test, please add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>. AI-assisted with Codex.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.