Skip to content

feat(victory-shader): implement s_movrels_b32 and s_movreld_b32 lowering - #608

Closed
Amit89-beep wants to merge 2 commits into
Marvisak:mainfrom
Amit89-beep:fix/s-movrel-lowering
Closed

Amit89-beep wants to merge 2 commits into
Marvisak:mainfrom
Amit89-beep:fix/s-movrel-lowering

Conversation

@Amit89-beep

@Amit89-beep Amit89-beep commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

Implements IR lowering and DXIL emission support for GFX10 scalar relative-indexing move instructions (s_movrels_b32 and s_movreld_b32) in victory-shader, replacing the previous ShaderError::Unsupported path.

Changes

  • IR Lowering (crates/victory-shader/src/ir.rs):
    • Implemented s_movrels_b32 (sdst = sgpr[src_base + m0]) for relative scalar source reads indexed by M0.
    • Implemented s_movreld_b32 (sgpr[dst_base + m0] = ssrc) for relative scalar destination writes indexed by M0.
    • Added SGPR index bounds clamping/masking so out-of-range M0 offsets cannot produce out-of-bounds SGPR accesses or invalid DXIL IR.
  • Tests:
    • Added unit tests covering static and dynamic M0 offsets for both s_movrels_b32 and s_movreld_b32, verifying round-trip register updates and DXIL emission/validation.

Verification

  • cargo fmt --check
  • cargo clippy -p victory-shader --all-targets
  • cargo test -p victory-shader

@Lyrnc

Lyrnc commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

RDNA2 hardware check of the two rules: they match.

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) fills s20..s35 with distinct values, sets M0, runs one instruction and reads all 16 back. RDNA2 desktop silicon, not the console's. No game data.

Instruction M0 = 0 M0 = 1 M0 = 2 M0 = 3
s_movrels_b32 s22, s21 s22 = s21 s22 = s22 (no change) s22 = s23 s22 = s24
s_movreld_b32 s22, s21 s22 = s21 s23 = s21 s24 = s21 s25 = s21

So sdst = s[src + M0] and s[dst + M0] = src with the whole M0, as here. Nothing else in the window changed.

Out of range: with M0 = 0x00010000 or 0x41, s_movrels_b32 read values that are none of the window's (0x057a9400, 0x35a00002), and s_movreld_b32 changed nothing in the window. So the hardware gives no defined result there, and your clamping is a choice rather than a semantic.

In case a follow-up adds the 64-bit forms: in the same runs s_movrels_b64 / s_movreld_b64 rounded the index down to even (M0 = 1 behaves as 0, 3 as 2).

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.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Conflicts with current main (ffe310e) in lower.rs/bitcode.rs — needs a rebase.

Static review: the M0-relative lowering handles static M0 (constant-folded via the new Module::as_i32) and dynamic M0 (select chain over the reachable SGPR span), with the IR's effects extended so the span is tracked as reads/writes — the relative_sgpr_access_spans_up_to_106 test covers that. Two things I'd want before approving:

  1. Execution evidence: the tests are lowers(...) smoke tests — they prove translation, not values. A host test (like the valu suite) writing known SGPRs and checking s_movrels_b32/s_movreld_b32 results for a few M0 values (in range, out of range, negative) would make this solid, especially the out-of-range-returns-0 behavior which I can't verify from the ISA docs alone.
  2. The dynamic path builds up to 106 selects per instruction; fine for rare scalar ops, but worth a comment if it ever shows up in a hot loop.

Rebase and I'll re-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 481afd9 on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 71 passed. cargo clippy -p victory-shader --all-targets is clean. victory translate --validate --pipelines on the local title executable still reports 12 of 12 emitted, validated and built into pipelines.

  • Semantics match the GFX10 ISA for the SOP1 forms, SGPR[D] = SGPR[S0.addr + M0] and SGPR[D.addr + M0] = S0, with the full M0 as the offset (unlike the VOP1 _2 forms in #627).
  • A constant M0 picks one register directly, and a non-constant M0 becomes a select chain or scatter over the reachable SGPRs. ir.rs lists the same read and write sets, so liveness agrees with the lowering.
  • An out-of-range index reads 0 and writes nothing here. That's a safe choice, but it doesn't model the hardware, which can reach VCC and the other registers above s105. A shortcut: comment would make that explicit.

AI-assisted (Claude Code).

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…rels_b32 and s_movreld_b32 lowering

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

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The s_movrels_b32 / s_movreld_b32 lowering itself reads correctly (M0 bounds-checked against the SGPR window, static-M0 fast path, dynamic select chain, destination read-modify-write preserved for s_movreld_b32), and Module::as_i32 is a clean helper for it. Two blockers before this can land:

1. Semantic conflict with main — does not compile after merge. Main's test helper is now fn lowers(words: &[u32], rsrc2: u32) (the compute rsrc2/threads field), and this PR's five new calls still use the old one-argument form:

error[E0061]: this function takes 2 arguments but 1 argument was supplied
   --> crates/victory-shader/src/emit/lower.rs:7443:9 (and 7455, 7466, 7478, 7490)

Verified fix: pass 0 as rsrc2 (these tests don't exercise threads) — lowers(&static_rels, 0).unwrap(); etc. With that one-token change on the merge with current main (ffe310e), cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 96 passed / 0 failed / 1 ignored.

2. Two existing tests are deleted with no replacement. The diff removes packed_buffer_formats_by_number and small_floats_widen_as_halves (plus the half helper) from lower.rs's test module — coverage of the packed buffer-format table and half-float widening — and they don't reappear in any other file of this PR. Unless that coverage moved somewhere I can't see, please restore them; the s_movrel_lowering addition is no reason to drop unrelated tests.

Windows note: the M0-relative behavior on hardware is valu_tests-gated like the rest, so the Windows lane should confirm once this compiles.

@alexdeliu

Copy link
Copy Markdown

Merged onto main @ ffe310eb, this PR (cc6b6984) no longer compiles its tests. crates/victory-shader/src/emit/lower.rs:7443 (and 7455, 7466, 7478, 7490) calls the lowers(&words) test helper. Since 25b0f88 it is lowers(words, rsrc2); main's tests pass 0. Clippy also flags half_shift as an unused import at lower.rs:7031.

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

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because by our reading the change is incorrect or would break something that works today.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 25, 2026
GPU: name why an indirect execution was dropped, and what its records hold
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants