Shaders: lower s_bcnt0_i32_b32/b64 and s_ff0_i32_b32/b64 #165

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

@⁠n-romanovich on GitHub · 2026-11-24 01:02 UTC · original
n-romanovich:feat/scalar-bitcount-firstbit → main · +156 −9 · 2 files · 3 commits · closed without merging

Implements DXIL lowering for the zero-bit counting and find-first-zero scalar ALU instructions in victory-shader:

  • s_bcnt0_i32_b32: bitwise inverts src0 and counts set bits via DXIL unaryBits.i32 (31), updating SCC (result != 0).
  • s_ff0_i32_b32: bitwise inverts src0 and finds the lowest set bit via DXIL unaryBits.i32 (32, returning -1 when all bits are 1).
  • s_bcnt0_i32_b64, s_ff0_i32_b64: shares the 64-bit split-dword lowering paths with s_bcnt1_i32_b64 and s_ff1_i32_b64 over inverted dwords, without requiring DXIL INT64.

Testing

  • Added emit::tests::scalar_bitcount_and_first_zero_execute_on_gpu in crates/victory-shader/src/emit/mod.rs covering 32-bit and 64-bit inputs, inline -1, high-dword hits, and SCC updates.
  • Validated emitted DXIL with dxil.dll and executed on D3D12 (NVIDIA GeForce RTX 5060 Ti).
  • cargo fmt -p victory-shader -- --check: passed.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: passed (0 warnings).
  • cargo xtask policy: passed (asset policy: 151 files ok).
  • cargo test -p victory-shader: 70 passed, 0 failed.
**@⁠n-romanovich** on GitHub · 2026-11-24 01:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/165) `n-romanovich:feat/scalar-bitcount-firstbit` → `main` · +156 −9 · 2 files · 3 commits · closed without merging Implements DXIL lowering for the zero-bit counting and find-first-zero scalar ALU instructions in `victory-shader`: - `s_bcnt0_i32_b32`: bitwise inverts `src0` and counts set bits via DXIL `unaryBits.i32` (`31`), updating `SCC` (`result != 0`). - `s_ff0_i32_b32`: bitwise inverts `src0` and finds the lowest set bit via DXIL `unaryBits.i32` (`32`, returning `-1` when all bits are `1`). - `s_bcnt0_i32_b64`, `s_ff0_i32_b64`: shares the 64-bit split-dword lowering paths with `s_bcnt1_i32_b64` and `s_ff1_i32_b64` over inverted dwords, without requiring DXIL `INT64`. ### Testing - Added `emit::tests::scalar_bitcount_and_first_zero_execute_on_gpu` in `crates/victory-shader/src/emit/mod.rs` covering 32-bit and 64-bit inputs, inline `-1`, high-dword hits, and `SCC` updates. - Validated emitted DXIL with `dxil.dll` and executed on D3D12 (NVIDIA GeForce RTX 5060 Ti). - `cargo fmt -p victory-shader -- --check`: passed. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: passed (0 warnings). - `cargo xtask policy`: passed (`asset policy: 151 files ok`). - `cargo test -p victory-shader`: 70 passed, 0 failed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:52:58 +00:00
github-bot closed this pull request 2026-11-26 03:52:58 +00:00
Author
Owner

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

Tested 60e32ce on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 57 passed, 0 failed (2 test binaries), including the 1 test this PR adds.
  • The full workspace still needs #112 for the victory-gpu E0425.

No game data used.

**@⁠DaviTostes** on GitHub · 2026-11-24 01:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/165#issuecomment-7118976015) Tested `60e32ce` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **57 passed, 0 failed** (2 test binaries), including the 1 test this PR adds. - The full workspace still needs #112 for the `victory-gpu` E0425. No game data used.
Author
Owner

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

This duplicates #148 (opened earlier, which also adds s_flbit_i32_b64/_i64), and #163 covers the same opcodes too. The lowering here looks correct, and the GPU test is a plus. It might be worth agreeing with #148's author on which one goes in, e.g. #148's lowering plus this test.

Static review, not built or run.

**@⁠Sunkiller-qc** on GitHub · 2026-11-24 01:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/165#issuecomment-7119153363) This duplicates #148 (opened earlier, which also adds `s_flbit_i32_b64/_i64`), and #163 covers the same opcodes too. The lowering here looks correct, and the GPU test is a plus. It might be worth agreeing with #148's author on which one goes in, e.g. #148's lowering plus this test. Static review, not built or run.
Author
Owner

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

RDNA2 hardware check of the four 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: low dwords from edge values (including 0 and 0xffffffff) and random, high dwords 0, 0xffffffff or random. SCC was read right after each instruction.

  • s_bcnt0_i32_b32 / _b64: clear-bit count, SCC = result != 0: 130/130 each.
  • s_ff0_i32_b32 / _b64: lowest clear bit, -1 when all bits are 1, SCC unchanged: 130/130 each.

(#148 covers the same four plus s_flbit_i32_b64/_i64, also matching.)

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/165#issuecomment-7123872025) RDNA2 hardware check of the four 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: low dwords from edge values (including `0` and `0xffffffff`) and random, high dwords `0`, `0xffffffff` or random. SCC was read right after each instruction. - `s_bcnt0_i32_b32` / `_b64`: clear-bit count, SCC = result != 0: 130/130 each. - `s_ff0_i32_b32` / `_b64`: lowest clear bit, `-1` when all bits are 1, SCC unchanged: 130/130 each. (#148 covers the same four plus `s_flbit_i32_b64/_i64`, also matching.) 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

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

Tested head 50d8a98 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_bitcount_and_first_zero_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/165#issuecomment-7129329535) Tested head `50d8a98` 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_bitcount_and_first_zero_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:23 UTC · original

Merged onto main @ ffe310eb, this PR (50d8a98c) no longer compiles its tests. crates/victory-shader/src/emit/mod.rs:824 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:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/165#issuecomment-7139110631) Merged onto `main` @ `ffe310eb`, this PR (`50d8a98c`) no longer compiles its tests. `crates/victory-shader/src/emit/mod.rs:824` 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:53 UTC · original

Thanks for testing and pointing this out, @⁠alexdeliu!

Merged latest main and updated resource::track in the test to pass Some(&st) per 6638098c. Verified with cargo clippy --all-targets --locked -- -D warnings and re-ran the GPU test — both compile cleanly and pass with 0 warnings.

**@⁠n-romanovich** on GitHub · 2026-11-24 17:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/165#issuecomment-7139847300) Thanks for testing and pointing this out, @⁠alexdeliu! Merged latest main and updated resource::track in the test to pass Some(&st) per 6638098c. Verified with cargo clippy --all-targets --locked -- -D warnings and re-ran the GPU test — both compile cleanly and pass with 0 warnings.
Author
Owner

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

@⁠n-romanovich rechecked cee01b43 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/165#issuecomment-7139911763) @⁠n-romanovich rechecked `cee01b43` 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 #148. s_bcnt0/s_ff0 (b32 and b64) lowering equal in effect to #148's, which also covers s_flbit_i32_b64/_i64. 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/165#issuecomment-7148031008) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #148. s_bcnt0/s_ff0 (b32 and b64) lowering equal in effect to #148's, which also covers s_flbit_i32_b64/_i64. 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!165
No description provided.