shader: lower s_bitcmp{0,1}_b{32,64} and s_sext_i32_i{8,16} #142

Closed
github-bot wants to merge 3 commits from gh-pr/142/head into gh-pr/142/base
Owner

@⁠n-romanovich on GitHub · 2026-11-24 00:56 UTC · original
n-romanovich:feat/scalar-bitcmp-sext → main · +144 −0 · 2 files · 3 commits · closed without merging

Implements DXIL lowering for six scalar ALU instructions in victory-shader:

  • s_bitcmp0_b32, s_bitcmp1_b32: extracts bit src1 & 31 from src0 and writes SCC (== 0 / != 0).
  • s_bitcmp0_b64, s_bitcmp1_b64: selects the low or high 32-bit dword via src1 & 32 (without requiring DXIL INT64), extracts bit src1 & 31, and writes SCC.
  • s_sext_i32_i8, s_sext_i32_i16: sign-extends the low 8 or 16 bits of src0 to i32 via shl + ashr (24 / 16) without modifying SCC.

Testing

  • Added emit::tests::scalar_bitcmp_and_sext_execute_on_gpu in crates/victory-shader/src/emit/mod.rs, covering all six opcodes (bit index masking, high-dword b64 bits, inline -1 sign extension, positive/negative sext, and SCC preservation).
  • Validated generated DXIL with dxil.dll and executed the compute shader on D3D12 (NVIDIA GeForce RTX 5060 Ti).
  • cargo test -p victory-shader: 58 passed, 0 failed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: passed with 0 warnings.
  • cargo xtask policy: passed (asset policy: 150 files ok).
  • cargo test --workspace: all active tests passed (3 tests in victory-formats ignored without external reference files).
**@⁠n-romanovich** on GitHub · 2026-11-24 00:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/142) `n-romanovich:feat/scalar-bitcmp-sext` → `main` · +144 −0 · 2 files · 3 commits · closed without merging Implements DXIL lowering for six scalar ALU instructions in `victory-shader`: - `s_bitcmp0_b32`, `s_bitcmp1_b32`: extracts bit `src1 & 31` from `src0` and writes `SCC` (`== 0` / `!= 0`). - `s_bitcmp0_b64`, `s_bitcmp1_b64`: selects the low or high 32-bit dword via `src1 & 32` (without requiring DXIL `INT64`), extracts bit `src1 & 31`, and writes `SCC`. - `s_sext_i32_i8`, `s_sext_i32_i16`: sign-extends the low 8 or 16 bits of `src0` to `i32` via `shl` + `ashr` (`24` / `16`) without modifying `SCC`. ### Testing - Added `emit::tests::scalar_bitcmp_and_sext_execute_on_gpu` in `crates/victory-shader/src/emit/mod.rs`, covering all six opcodes (bit index masking, high-dword `b64` bits, inline `-1` sign extension, positive/negative `sext`, and `SCC` preservation). - Validated generated DXIL with `dxil.dll` and executed the compute shader on D3D12 (**NVIDIA GeForce RTX 5060 Ti**). - `cargo test -p victory-shader`: 58 passed, 0 failed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: passed with 0 warnings. - `cargo xtask policy`: passed (`asset policy: 150 files ok`). - `cargo test --workspace`: all active tests passed (3 tests in `victory-formats` ignored without external reference files).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:52:02 +00:00
github-bot closed this pull request 2026-11-26 03:52:03 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:05 UTC · original

Tested 4293c7d on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 57 passed, 0 failed (2 test binaries), including the test this PR adds.
  • Scope note: this covers instructions that #117 (s_bitcmp0/1_b32 and s_bitcmp0/1_b64) and #120 (s_absdiff_i32, s_sext_i32_i8/i16, s_pack_ll/lh/hh_b32) also lower, and both are open. Three PRs are touching overlapping instruction sets; worth converging on one.
  • The full workspace still needs #112 for the victory-gpu E0425.

No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).

**@⁠DaviTostes** on GitHub · 2026-11-24 01:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7118749302) Tested `4293c7d` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **57 passed, 0 failed** (2 test binaries), including the test this PR adds. - Scope note: this covers instructions that **#117** (`s_bitcmp0/1_b32` and `s_bitcmp0/1_b64`) and **#120** (`s_absdiff_i32`, `s_sext_i32_i8/i16`, `s_pack_ll/lh/hh_b32`) also lower, and both are open. Three PRs are touching overlapping instruction sets; worth converging on one. - The full workspace still needs #112 for the `victory-gpu` E0425. No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
Author
Owner

@⁠Sunkiller-qc on GitHub · 2026-11-24 01:05 UTC · original

This overlaps two open PRs by tedin7: #117 adds s_bitcmp0/1_b32/b64 (lower.rs:2306 there), and #120 adds s_sext_i32_i8/i16 (lower.rs:2647 there) together with s_absdiff and s_pack_*. Both implementations here look correct (lower.rs:2360 and :2523). Since writes_scc in ir.rs already leaves sext out, the extra entry in the no-SCC list isn't needed. If more than one of these lands, though, the later match arms become unreachable patterns.

A possible split: s_bitcmp from this PR or #117 (this one has the GPU-run test), and s_sext only from #120. Up to the maintainer which one; just flagging it so the work isn't merged twice.

Static review, not built or run.

**@⁠Sunkiller-qc** on GitHub · 2026-11-24 01:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7118749252) This overlaps two open PRs by tedin7: #117 adds `s_bitcmp0/1_b32/b64` (`lower.rs:2306` there), and #120 adds `s_sext_i32_i8/i16` (`lower.rs:2647` there) together with `s_absdiff` and `s_pack_*`. Both implementations here look correct (`lower.rs:2360` and `:2523`). Since `writes_scc` in `ir.rs` already leaves sext out, the extra entry in the no-SCC list isn't needed. If more than one of these lands, though, the later match arms become unreachable patterns. A possible split: `s_bitcmp` from this PR or #117 (this one has the GPU-run test), and `s_sext` only from #120. Up to the maintainer which one; just flagging it so the work isn't merged twice. Static review, not built or run.
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-24 06:22 UTC · original

RDNA2 hardware check of the six instructions: all match.

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. 130 cases: sources from edge values (0, 1, 0x80, 0xff, 0x8000, 0xffff, 0x80000000, 0xffffffff, …) and random, random high dwords for the 64-bit forms, bit indices 0, 1, 7, 31, 32, 33, 63, 64, 0xffffffff and random. SCC was read with s_cselect right after each instruction.

  • s_bitcmp0/1_b32: SCC = bit src1 & 31 clear / set: 130/130 each.
  • s_bitcmp0/1_b64: SCC = bit src1 & 63 of the pair (dword chosen by src1 & 32): 130/130 each.
  • s_sext_i32_i8, s_sext_i32_i16: sign extension, SCC left as it was (checked from both SCC = 1 and SCC = 0): 130/130 each.

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.

**@⁠Lyrnc** on GitHub · 2026-11-24 06:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7123870935) RDNA2 hardware check of the six instructions: **all match.** **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. 130 cases: sources from edge values (`0, 1, 0x80, 0xff, 0x8000, 0xffff, 0x80000000, 0xffffffff`, …) and random, random high dwords for the 64-bit forms, bit indices `0, 1, 7, 31, 32, 33, 63, 64, 0xffffffff` and random. SCC was read with `s_cselect` right after each instruction. - `s_bitcmp0/1_b32`: SCC = bit `src1 & 31` clear / set: 130/130 each. - `s_bitcmp0/1_b64`: SCC = bit `src1 & 63` of the pair (dword chosen by `src1 & 32`): 130/130 each. - `s_sext_i32_i8`, `s_sext_i32_i16`: sign extension, SCC left as it was (checked from both SCC = 1 and SCC = 0): 130/130 each. 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.
Author
Owner

@⁠n-romanovich on GitHub · 2026-11-24 08:46 UTC · original

Thanks for the review! Addressed the feedback and resolved the compilation issue in the latest commit. All tests pass cleanly.

**@⁠n-romanovich** on GitHub · 2026-11-24 08:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7126540918) Thanks for the review! Addressed the feedback and resolved the compilation issue in the latest commit. All tests pass cleanly.
Author
Owner

@⁠DeerSilver on GitHub · 2026-11-24 10:51 UTC · original

Tested head badfee5 merged onto main ffe310e on NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1. No game files: the test suite only.

Merged onto current main, the test build fails. 6638098 ("per-lane descriptors chosen by control flow", merged with #566 at 09:53) added a fourth argument to resource::track:

error[E0061]: this function takes 4 arguments but 3 arguments were supplied
  --> crates/victory-shader/src/emit/mod.rs (in the new test)
   |     resource::track(&p, &native.layout, native.stage)
   |     argument #4 of type `Option<&structure::Structured>` is missing

There's no text conflict, so GitHub still shows the PR as mergeable, but merging it as it is would break cargo test on main. The call this PR adds needs the fourth argument. main's own tests pass Some(&st); None keeps the old three-argument behaviour.

With , None added locally to that one call, everything passes:

  • The PR's GPU test ran on the RTX 5060 (DXGI adapter 0 on this laptop; no "no SM 6.6 device" skip) and passed:
    • scalar_bitcmp_and_sext_execute_on_gpu
  • cargo test --workspace --locked: 343 passed, 0 failed, 6 ignored, against 342 passed / 6 ignored on main.
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean.

AI-assisted (Claude Code).

**@⁠DeerSilver** on GitHub · 2026-11-24 10:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7129330029) Tested head `badfee5` merged onto `main` `ffe310e` on **NVIDIA GeForce RTX 5060 Laptop GPU** (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1. No game files: the test suite only. **Merged onto current `main`, the test build fails.** `6638098` ("per-lane descriptors chosen by control flow", merged with #566 at 09:53) added a fourth argument to `resource::track`: ``` error[E0061]: this function takes 4 arguments but 3 arguments were supplied --> crates/victory-shader/src/emit/mod.rs (in the new test) | resource::track(&p, &native.layout, native.stage) | argument #4 of type `Option<&structure::Structured>` is missing ``` There's no text conflict, so GitHub still shows the PR as mergeable, but merging it as it is would break `cargo test` on `main`. The call this PR adds needs the fourth argument. `main`'s own tests pass `Some(&st)`; `None` keeps the old three-argument behaviour. **With `, None` added locally to that one call**, everything passes: - The PR's GPU test ran on the RTX 5060 (DXGI adapter 0 on this laptop; no "no SM 6.6 device" skip) and passed: - `scalar_bitcmp_and_sext_execute_on_gpu` - `cargo test --workspace --locked`: **343 passed, 0 failed, 6 ignored**, against 342 passed / 6 ignored on `main`. - `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. AI-assisted (Claude Code).
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 17:22 UTC · original

Merged onto main @ ffe310eb, this PR (badfee5c) no longer compiles its tests. crates/victory-shader/src/emit/mod.rs:826 calls resource::track with 3 arguments. Since 6638098c it takes a 4th, lanes: Option<&Structured>; main's tests pass Some(&st) with let st = structure::structure(&p).unwrap();.

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

**@⁠alexdeliu** on GitHub · 2026-11-24 17:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7139106058) Merged onto `main` @ `ffe310eb`, this PR (`badfee5c`) no longer compiles its tests. `crates/victory-shader/src/emit/mod.rs:826` calls `resource::track` with 3 arguments. Since 6638098c it takes a 4th, `lanes: Option<&Structured>`; main's tests pass `Some(&st)` with `let st = structure::structure(&p).unwrap();`. <sub>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</sub>
Author
Owner

@⁠n-romanovich on GitHub · 2026-11-24 17:54 UTC · original

Thanks for the catch, @⁠alexdeliu!

Merged latest main, dropped the duplicate s_bitcmp matching arm (now present via #117), and updated resource::track in the test to pass Some(&st) per 6638098c. Verified with Clippy (-D warnings) and tests on hardware — all pass cleanly.

**@⁠n-romanovich** on GitHub · 2026-11-24 17:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7139876625) Thanks for the catch, @⁠alexdeliu! Merged latest main, dropped the duplicate s_bitcmp matching arm (now present via #117), and updated resource::track in the test to pass Some(&st) per 6638098c. Verified with Clippy (-D warnings) and tests on hardware — all pass cleanly.
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 17:55 UTC · original

@⁠n-romanovich rechecked 26bdec94 merged onto main @ ffe310eb on the RX 9070: both CI clippy runs are clean and cargo test --workspace passes (343 tests).

**@⁠alexdeliu** on GitHub · 2026-11-24 17:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7139909763) @⁠n-romanovich rechecked `26bdec94` merged onto `main` @ `ffe310eb` on the RX 9070: both CI clippy runs are clean and `cargo test --workspace` passes (343 tests).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:00 UTC · original

Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #120. s_bitcmp0/1_b32/_b64 are already lowered in main (lower.rs sop(), strip_prefix("s_bitcmp")); the only new lowering, s_sext_i32_i8/i16, is identical to #120's, which covers more. Its GPU test builds HostShader with the old field set and does not compile on main.

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** on GitHub · 2026-11-25 00:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7148029711) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #120. s_bitcmp0/1_b32/_b64 are already lowered in main (lower.rs sop(), strip_prefix("s_bitcmp")); the only new lowering, s_sext_i32_i8/i16, is identical to #120's, which covers more. Its GPU test builds HostShader with the old field set and does not compile on main. 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.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!142
No description provided.