Skip to content

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 into
Marvisak:mainfrom
n-romanovich:feat/scalar-bitcmp-sext
Closed

n-romanovich wants to merge 3 commits into
Marvisak:mainfrom
n-romanovich:feat/scalar-bitcmp-sext

Conversation

@n-romanovich

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

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

edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
…8,16}

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ghost ghost mentioned this pull request Nov 24, 2026
@Lyrnc

Lyrnc commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Author

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

@DeerSilver

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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 6638098 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

@n-romanovich

Copy link
Copy Markdown
Author

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 6638098. Verified with Clippy (-D warnings) and tests on hardware — all pass cleanly.

@alexdeliu

Copy link
Copy Markdown

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

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
@Marvisak

Copy link
Copy Markdown
Owner

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.

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.

7 participants