Skip to content

Shaders: lower s_absdiff_i32, s_sext_i32_i8/i16 and s_pack_ll/lh/hh_b32_b16 - #120

Open
tedin7 wants to merge 1 commit into
Marvisak:mainfrom
tedin7:vic-s-pack-2
Open

tedin7 wants to merge 1 commit into
Marvisak:mainfrom
tedin7:vic-s-pack-2

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

What

  • Lowers s_absdiff_i32 (|a - b| of the wrapped difference, SCC = result != 0), s_sext_i32_i8, s_sext_i32_i16, and s_pack_ll_b32_b16, s_pack_lh_b32_b16, s_pack_hh_b32_b16 (halves picked as in the GFX10 ISA).

Why

  • They decode and are tracked in ir.rs, but sop() rejected them, so any shader using one failed to translate with Unsupported.

Tested

  • Linux x86_64 only. Commands run:
    • cargo test -j4 -p victory-shader scalar_pack with the lowering disabled (test only): fails with Unsupported { offset: 16, what: "s_absdiff_i32" }.
    • cargo test -j4 -p victory-shader after the change: 56 passed (origin/main 237f2e8), 0 failed (the new test included).
    • cargo clippy -j4 -p victory-shader --tests: no new warnings (existing: dead_code constant_color in emit/mod.rs, a boolean-simplification note in resource.rs).
    • rustfmt --edition 2024 --check on lower.rs: clean.
  • The test uses synthetic machine code (no game data) and checks that lowering succeeds, not the emitted DXIL values.
  • NOT run: Windows runtime, GPU, or a real console shader.
  • The test reuses the existing lowers() helper in the tests module.

…32_b16

These decode and are tracked in ir.rs but the lowering had no case for them, so any shader using one failed to translate with Unsupported.
@lordon1a

Copy link
Copy Markdown
Contributor

Verified cb40cdcc2 on Windows 11 (x86_64-pc-windows-gnullvm, rustc 1.100.0, applied cleanly to main@4c0bb89): pass.

AI-assisted.

@DaviTostes

Copy link
Copy Markdown

Tested cb40cdc on Arch Linux x86_64, rustc 1.98.1: pass.

@Lyrnc

Lyrnc commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

RDNA2 hardware check of the new scalar instructions: all match, including s_absdiff_i32 on the wrapped difference.

Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. 141 operand pairs: all pairs of 0, 1, 2, 0x7fffffff, 0x80000000, 0xffffffff, 0x40000000, 0xc0000000, 0x12345678, plus 60 random. SCC was read right after each instruction.

  • s_absdiff_i32: |a - b| of the difference wrapped to 32 bits, SCC = result != 0: 141/141. For example, |1 - 0x80000000| gives 0x7fffffff (not 0x80000001), and |0 - 0x80000000| gives 0x80000000, as your lowering computes.
  • s_pack_ll_b32_b16, s_pack_lh_b32_b16, s_pack_hh_b32_b16: {lo/hi(src1), lo/hi(src0)}: 141/141 each.
  • s_sext_i32_i8 / s_sext_i32_i16, measured for shader: lower s_bitcmp{0,1}_b{32,64} and s_sext_i32_i{8,16} #142: sign extension, SCC unchanged.

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.

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested cb40cdc on Windows 11, RTX 5070, MSVC: the workspace passes (186 outside victory-shader; victory-shader --lib single-threaded: 69). victory translate <title exe> --validate --pipelines gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines.

Checked against the GFX10 ISA:

  • s_absdiff_i32: |a − b| of the wrapping difference, with SCC = result ≠ 0.
  • s_sext_i32_i8/i16: shift left, then arithmetic shift right.
  • s_pack_ll gives {b.lo, a.lo}, s_pack_lh gives {b.hi, a.lo}, and s_pack_hh gives {b.hi, a.hi}, written high:low.

SCC is only written where the decoder says the instruction writes it (inst.write(Reg::Scc)), so sext and pack correctly leave SCC alone.

No issues found.

AI-assisted (Claude Code).

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…i32_i8/i16 and s_pack_ll/lh/hh_b32_b16

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexdeliu

Copy link
Copy Markdown

Merged onto main @ ffe310eb, this PR (cb40cdcc) no longer compiles its tests. crates/victory-shader/src/emit/lower.rs:7391 calls the lowers(&words) test helper. Since 25b0f88 it is lowers(words, rsrc2); main's tests pass 0.

Checked with CI's steps (both clippy runs with -D warnings, cargo test --workspace) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants