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

Closed
n-romanovich wants to merge 3 commits from upstream-pr/142 into main
n-romanovich commented 2026-11-24 00:56:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by n-romanovich on 2026-11-24T00:56:46Z.


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).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6572129543 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/142). Originally posted by [n-romanovich](https://github.com/n-romanovich) on 2026-11-24T00:56:46Z. --- 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).
Sunkiller-qc commented 2026-11-24 06:54:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sunkiller-qc on 2026-11-24T01:05:44Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118749252 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7118749252). Originally posted by [Sunkiller-qc](https://github.com/Sunkiller-qc) on 2026-11-24T01:05:44Z. --- 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.
DaviTostes commented 2026-11-24 06:54:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:05:44Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118749302 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7118749302). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:05:44Z. --- 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).
Lyrnc commented 2026-11-24 06:56:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-24T06:22:43Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123870935 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7123870935). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-24T06:22:43Z. --- 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.
n-romanovich commented 2026-11-24 09:06:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by n-romanovich on 2026-11-24T08:46:13Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7126540918 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7126540918). Originally posted by [n-romanovich](https://github.com/n-romanovich) on 2026-11-24T08:46:13Z. --- Thanks for the review! Addressed the feedback and resolved the compilation issue in the latest commit. All tests pass cleanly.
DeerSilver commented 2026-11-24 11:04:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DeerSilver on 2026-11-24T10:51:09Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129330029 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7129330029). Originally posted by [DeerSilver](https://github.com/DeerSilver) on 2026-11-24T10:51:09Z. --- 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).
alexdeliu commented 2026-11-24 18:05:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T17:22:49Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139106058 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7139106058). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-24T17:22:49Z. --- 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>
n-romanovich commented 2026-11-24 18:06:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by n-romanovich on 2026-11-24T17:54:27Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139876625 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7139876625). Originally posted by [n-romanovich](https://github.com/n-romanovich) on 2026-11-24T17:54:27Z. --- 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.
alexdeliu commented 2026-11-24 18:06:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T17:55:51Z.


@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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139909763 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7139909763). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-24T17:55:51Z. --- @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).
upstream-sync closed this pull request 2026-11-25 00:05:17 +00:00
Marvisak commented 2026-11-25 00:06:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:00:15Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148029711 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/142#issuecomment-7148029711). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:00:15Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!142
No description provided.