shader: lower 10 scalar bitops (bcnt0/ff0/flbit64/brev64/bitset64/bitreplicate) without INT64 #1684
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1684
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1684/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@geiyiliyabumo on GitHub · 2026-11-24 20:44 UTC · original
geiyiliyabumo:fix/shader-scalar-bitops-zero-rev→main· +323 −11 · 2 files · 1 commits · closed without mergingSummary
crates/victory-shader/src/emit/lower.rsusing pure 32-bit DXIL arithmetic (noINT64capability flag set inSFI0):s_bcnt0_i32_b32(0x00d) &s_bcnt0_i32_b64(0x00e): count clear bits viacountbits(~x)and setSCC = (result != 0).s_ff0_i32_b32(0x011) &s_ff0_i32_b64(0x012): lowest clear bit viafirstbitlow(~x)(-1when all ones).s_flbit_i32_b64(0x016) &s_flbit_i32_i64(0x018): leading zeros / leading bits matching sign bit 63 (-1when all bits are equal).s_brev_b64(0x00c): 64-bit bit-reversal across the swapped dword pair.s_bitset0_b64(0x01c) &s_bitset1_b64(0x01e): clear/set bitsrc0[5:0]of the 64-bit destination pair (also handlesnulldestination cleanly).s_bitreplicate_b64_b32(0x03b): duplicates each bit ofsrc0into two adjacent bits ofsdst[0:1]via SWAR bit-spreading (addss_bitreplicate_b64_b32to thewidescalar dispatch since its destination is 64-bit despite ending in_b32).Verification
cargo test -p victory-shader --lib: 121 passed, 0 failed, 1 ignored on both AMD Radeon RX 9060 XT (D3D12 hardware) and Microsoft Basic Render Driver (WARP), includingscalar_bitops_zero_rev_and_64bit_match_rdna2_without_int64exercising all 10 instructions (includingSCCchecks, boundary bit indices0/31/32/63/69, sign-bit edge cases fors_flbit_i32_i64, andSFI0 & 0x8000 == 0on all 64-bit variants).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: pass (154 files).AI-assisted; synthetic tests only, no game files.
@adamdotpy on GitHub · 2026-11-24 22:00 UTC · original
Reviewed head
c0b3633locally (isolated worktree, fresh CARGO_TARGET_DIR, real GPU dispatch).What it does: lowers the ten RDNA2 scalar bitops without INT64 — 32-bit
s_bcnt0/s_ff0_i32_b32(via xor-with-ones then the existing count/first-set path) and 64-bits_bcnt0/s_ff0/s_flbit_i32_b64,s_flbit_i32_i64,s_brev_b64,s_bitset0/s_bitset1_b64,s_bitreplicate_b64_b32. I hand-checked the tricky ones:s_brev_b64correctly writes rev(hi) to lo and rev(lo) to hi;s_bitreplicatespreads each half 16->32 with the standard mask ladder then ORsx | x<<1;s_bitset*does a proper read-modify-write of both dst halves with the bit routed by src bit 5;s_flbit_i32_i64xors both halves with the replicated sign bit before counting, which is exactly "leading bits equal to sign".Verified locally:
cargo test -p victory-shader --lib scalar_bitops -- --nocapture— passes on hardware (6s, no skip); the sweep includes all-zero inputs for bcnt0/ff0/flbit and the test asserts SFI0 bit 0x8000 (INT64) is clear, so the lowering provably needs no 64-bit opscargo test -p victory-shader --lib --locked— 121 passed / 0 failed / 1 ignoredcargo clippy -p victory-shader --all-targets --all-features --locked— cleancargo build --release -p victory --locked— okmain@ffe310e:lower.rssame 3 pre-existing hunks;valu_tests.rshas 6 new cosmetic hunks (969, 991, 1028, 1044, 1065, 1089)Findings, ranked:
s_flbit_i32_b64(both halves zero) is in the hardware-pinned cases, so the -1/none convention matches RDNA2 as emitted; ff0/bcnt0 = ff1/bcnt1 of the complement is exact.ffe310eand will now textually conflict with upstream's newmain(70564ae, the big resource/native rewrite) inemit/lower.rs— same as our #1055/#1056/#1083; semantic overlap is unlikely since these are distinct opcodes, but expect to keep both sides inlower.rs.LGTM.
@upipibi on GitHub · 2026-11-24 22:52 UTC · original
NVIDIA run: RTX 3070 8 GB, driver 616.56, Windows 11, debug, at the PR head
c0b3633.scalar_bitops_zero_rev_and_64bit_match_rdna2_without_int64passes.It is based on
ffe310eand GitHub shows conflicts withmain70564ae, so this is the head as it stands, not a merge.AI-assisted (Claude Code). Synthetic tests only.
@Marvisak on GitHub · 2026-11-25 01:24 UTC · original
Automated triage for the maintainers. Closing because another open pull request covers the same change.
See #148. Ten scalar bit operations (bcnt0, ff0, flbit 64-bit, brev64, bitset64, bitreplicate), which the title does not use. All ten are covered by PRs that merge clean: #148 (bcnt0, ff0, flbit) and #166 (bitset_b64, brev_b64, bitreplicate).
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 01:34 UTC · original
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-shader/src/emit/lower.rs,crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
Pull request closed