Skip to content

Shaders: lower s_bitset{0,1}_b64, s_brev_b64 and s_bitreplicate_b64_b32 - #166

Open
n-romanovich wants to merge 1 commit into
Marvisak:mainfrom
n-romanovich:feat/scalar-bitops-b64
Open

n-romanovich wants to merge 1 commit into
Marvisak:mainfrom
n-romanovich:feat/scalar-bitops-b64

Conversation

@n-romanovich

Copy link
Copy Markdown

Implements DXIL lowering for four 64-bit scalar bit-manipulation instructions in victory-shader using pure 32-bit DXIL operations (no INT64 capability required):

  • s_bitset0_b64, s_bitset1_b64: reads both dwords of the 64-bit destination, selects the low/high dword mask via src0 & 32, and clears or sets bit src0 & 31 without modifying SCC.
  • s_brev_b64: swaps and bit-reverses the low and high dwords via DXIL unary.i32 (30).
  • s_bitreplicate_b64_b32: interleaves the low and high 16-bit halves of src0 into duplicated bit pairs across the 64-bit destination.

Testing

  • Added emit::tests::scalar_bitops_b64_execute_on_gpu in crates/victory-shader/src/emit/mod.rs covering bit set/clear across both dwords, 64-bit bit reversal, and 32-to-64 bit replication.
  • 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.

@DaviTostes

Copy link
Copy Markdown

Tested 04acee2 on Arch Linux x86_64, rustc 1.98.1: pass.

No game data used.

AntoninMichelq pushed a commit to AntoninMichelq/VIctory that referenced this pull request Nov 24, 2026
…nd s_bitreplicate_b64_b32) into the integration

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
@Lyrnc

Lyrnc commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

RDNA2 hardware check of the four rules: all match.

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) runs each instruction on literal operands, then copies the SGPRs out. There are 24 cases: random 64-bit destinations, with src0 drawn from 0, 1, 31, 32, 33, 63, 64, 65, 0xffffffff and random values. SCC was set to 1 before s_bitset0/1_b64 and read after. RDNA2 desktop silicon, not the console's. No game data.

match
s_bitset0_b64 / s_bitset1_b64: clear / set bit src0 & 63 of the 64-bit destination (the dword picked by src0 & 32), SCC unchanged 24/24
s_brev_b64: 64-bit bit reverse (dwords swapped and each reversed) 24/24
s_bitreplicate_b64_b32: bit i of src0 to bits 2i and 2i+1 24/24

src0 = 64 and 65 behave as 0 and 1, so only bits 5:0 of src0 are read.

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.

@DeerSilver

Copy link
Copy Markdown

Tested head bd034c0 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_bitops_b64_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 (bd034c0f) no longer compiles its tests. crates/victory-shader/src/emit/mod.rs:818 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 testing and pointing this out, @alexdeliu!

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

@alexdeliu

Copy link
Copy Markdown

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

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Recommended for a maintainer's look. The verdict hasn't changed. The new head is a single commit rebased onto current main (940d32f). The lowering of s_bitset0_b64/s_bitset1_b64, s_brev_b64 (two bfrevs with the dwords swapped) and s_bitreplicate_b64_b32 in the wide scalar block of crates/victory-shader/src/emit/lower.rs hasn't changed and still matches the RDNA2 ISA and Lyrnc's gfx1036 probe. I rechecked the expected values in scalar_bitops_b64_execute_on_gpu by hand. The HostShader and Parts literals match main's fields, and resource::track gets its fourth argument.

CI: passing.

#1684 also lowers these four instructions. Whichever lands second should drop the overlap.


Generated by Claude Code

@n-romanovich
n-romanovich force-pushed the feat/scalar-bitops-b64 branch 2 times, most recently from 7e84706 to 634f6f2 Compare November 25, 2026 00:48
@n-romanovich

Copy link
Copy Markdown
Author

@Marvisak, thanks for the review.

Rebased onto main as a single commit (634f6f2) and filled in the new HostShader fields (root_uavs, memory, memory_writes, view_addresses, heap, heap_writes) in scalar_bitops_b64_execute_on_gpu (crates/victory-shader/src/emit/mod.rs).

Re-ran cargo test -p victory-shader --locked -- scalar_bitops_b64_execute_on_gpu on Windows 11 (NVIDIA GeForce RTX 5060 Ti): 1 passed, 0 failed.

@n-romanovich
n-romanovich force-pushed the feat/scalar-bitops-b64 branch from 0c84774 to 0e2e4a6 Compare November 25, 2026 01:53
@Calvix2k

Copy link
Copy Markdown
Contributor

Verification on Windows 10 19045 (RX 7800 XT), your head 0e2e4a6 plus the "skip the GPU suites a device cannot run" patch from #1991 (this host reports SM 6.5, so those probes would fail for an unrelated reason):

cargo test -p victory-shader --lib — 248 passed, 0 failed, 3 ignored. The four instructions lower and their tests run; the GPU-valued paths skip here and run in CI.

No objection from reading the diff: the 64-bit shifts and bit-replicate go through the existing bin/unary paths with the same predicates as the neighbouring arms, and s_bitset's scc comes from the compared bit as the ISA says.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants