Shaders: lower s_bfe_u64, s_bfe_i64 and s_bfm_b64 #1395

Open
github-bot wants to merge 2 commits from github-bot/gh-1395 into main AGit
Owner

@⁠AnoHunted on GitHub · 2026-11-24 17:42 UTC · original
AnoHunted:shaders-scalar-bitfield-64 → main · +208 −0 · 2 files · 2 commits · open

What

The scalar 64-bit lowering path refused s_bfe_u64, s_bfe_i64 and s_bfm_b64. They now lower:

  • s_bfe_u64 / s_bfe_i64: the field is (src0 >> src1[5:0]) & ((1 << src1[22:16]) - 1); the signed form sign-extends from the field's top bit (width 0 gives 0). SCC is set to whether the result is nonzero.
  • s_bfm_b64: ((1 << src0[5:0]) - 1) << src1[5:0]. It does not write SCC, so SCC keeps its earlier value.

A width of 64 or more (and a field running past bit 63) is not defined by the ISA; it takes every bit, with shift amounts masked, so the lowering cannot go out of range. No test depends on that case. The 32-bit s_bfm_b32 is left as it is.

Why

A shader using any of these three failed to translate. They are the 64-bit counterparts of s_bfe_u32/s_bfe_i32/s_bfm_b32, which already lower.

Related PRs: #163 and #231 contained these ops but are not on main. #447 (64-bit literal sign extension) touches the same function but not these arms; this change is made on current main and does not depend on it. #166 covers different 64-bit bit ops.

Tested

Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1 (hardware and WARP):

  • cargo test -p victory-shader --features host -- --test-threads=1: main 120 passed, 0 failed, 1 ignored; branch 123 passed, 0 failed, 1 ignored (3 new tests).
  • s_bfe_64_extracts_and_sets_scc: runs both ops on the GPU for low dword, high dword and SCC (e.g. 0xFEDCBA9876543210, offset 32, width 16 gives 0xBA98 unsigned and 0xFFFFFFFFFFFFBA98 signed; zero field gives 0 and SCC 0).
  • s_bfm_b64_builds_a_mask_and_keeps_scc: masks such as width 40 / offset 8 give 0x0000FFFFFFFFFF00, and SCC set by an s_cmp before the instruction is read back unchanged afterwards (both 0 and 1, including a nonzero mask).
  • scalar_64_bit_field_ops_lower: hand-assembled encodings lower.

AMD hardware: not tested.

Not tested

  • Widths of 64 and above, and fields past bit 63 (undefined by the ISA).
  • Real AMD hardware.

No game files were used.

**@⁠AnoHunted** on GitHub · 2026-11-24 17:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/1395) `AnoHunted:shaders-scalar-bitfield-64` → `main` · +208 −0 · 2 files · 2 commits · open ## What The scalar 64-bit lowering path refused `s_bfe_u64`, `s_bfe_i64` and `s_bfm_b64`. They now lower: - `s_bfe_u64` / `s_bfe_i64`: the field is `(src0 >> src1[5:0]) & ((1 << src1[22:16]) - 1)`; the signed form sign-extends from the field's top bit (width 0 gives 0). SCC is set to whether the result is nonzero. - `s_bfm_b64`: `((1 << src0[5:0]) - 1) << src1[5:0]`. It does not write SCC, so SCC keeps its earlier value. A width of 64 or more (and a field running past bit 63) is not defined by the ISA; it takes every bit, with shift amounts masked, so the lowering cannot go out of range. No test depends on that case. The 32-bit `s_bfm_b32` is left as it is. ## Why A shader using any of these three failed to translate. They are the 64-bit counterparts of `s_bfe_u32`/`s_bfe_i32`/`s_bfm_b32`, which already lower. Related PRs: #163 and #231 contained these ops but are not on main. #447 (64-bit literal sign extension) touches the same function but not these arms; this change is made on current main and does not depend on it. #166 covers different 64-bit bit ops. ## Tested Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1 (hardware and WARP): - `cargo test -p victory-shader --features host -- --test-threads=1`: main 120 passed, 0 failed, 1 ignored; branch 123 passed, 0 failed, 1 ignored (3 new tests). - `s_bfe_64_extracts_and_sets_scc`: runs both ops on the GPU for low dword, high dword and SCC (e.g. `0xFEDCBA9876543210`, offset 32, width 16 gives `0xBA98` unsigned and `0xFFFFFFFFFFFFBA98` signed; zero field gives 0 and SCC 0). - `s_bfm_b64_builds_a_mask_and_keeps_scc`: masks such as width 40 / offset 8 give `0x0000FFFFFFFFFF00`, and SCC set by an `s_cmp` before the instruction is read back unchanged afterwards (both 0 and 1, including a nonzero mask). - `scalar_64_bit_field_ops_lower`: hand-assembled encodings lower. AMD hardware: not tested. ## Not tested - Widths of 64 and above, and fields past bit 63 (undefined by the ISA). - Real AMD hardware. No game files were used.
The scalar 64-bit path refused all three. s_bfe_u64 and s_bfe_i64 take the
field at src1[5:0] with width src1[22:16] and set SCC to whether the result is
nonzero; the signed form sign-extends from the field's top bit. s_bfm_b64 builds
((1 << src0[5:0]) - 1) << src1[5:0] and does not write SCC. Widths of 64 and up
are not defined by the ISA; they take every bit here so the lowering stays in
range.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:30:20 +00:00
Author
Owner

@⁠dcastell1 on GitHub · 2026-11-24 17:51 UTC · original

Verified on native Windows (no Wine): NVIDIA GeForce RTX 5090 (driver 621.24), Windows 11 10.0.26300, Rust 1.98.1, MSVC 14.44.35207, debug build. main@ffe310e baseline on this box: 342 passed, 0 failed, 6 ignored.

cargo test --workspace
345 passed; 0 failed; 6 ignored   (exit 0)

Three more than the baseline; s_bfe_u64, s_bfe_i64 and s_bfm_b64 lowering ships its cases and they run green.

Tree restored afterwards (full diff against a clean checkout); no game data, the tests are synthetic. AI-assisted (opencode): applied the patch to a built tree, ran cargo test --workspace, reverted it.

**@⁠dcastell1** on GitHub · 2026-11-24 17:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/1395#issuecomment-7139800626) Verified on native Windows (no Wine): NVIDIA GeForce RTX 5090 (driver 621.24), Windows 11 10.0.26300, Rust 1.98.1, MSVC 14.44.35207, debug build. `main@ffe310e` baseline on this box: **342 passed, 0 failed, 6 ignored**. ``` cargo test --workspace 345 passed; 0 failed; 6 ignored (exit 0) ``` Three more than the baseline; `s_bfe_u64`, `s_bfe_i64` and `s_bfm_b64` lowering ships its cases and they run green. Tree restored afterwards (full diff against a clean checkout); no game data, the tests are synthetic. AI-assisted (opencode): applied the patch to a built tree, ran `cargo test --workspace`, reverted it.
Author
Owner

@⁠matheusfermiano-source on GitHub · 2026-11-24 18:08 UTC · original

An AMD run, since the PR says AMD hardware was not tested; under Proton on Linux: scalar_64_bit_field_ops_lower, s_bfe_64_extracts_and_sets_scc, s_bfm_b64_builds_a_mask_and_keeps_scc pass on both GPUs.

  • Head a91e9ad. Built on Linux with llvm-mingw for x86_64-pc-windows-gnullvm (Rust 1.98.1) and run under Proton Experimental (11.0-20261027b) with its vkd3d-proton 3.1.0, one GPU at a time; dxil.dll from DXC 1.9.2609 was loaded, so the test modules were validated.
  • Radeon 660M (RDNA2, RADV Mesa 26.3.1, waves 32..64): whole victory-shader suite 122 passed, 1 failed, 1 ignored. Nothing fails that passes on main (ffe310e). The one failure, emit::tests::stub_pipeline_is_created, fails on main here too: vkd3d-proton accepts the zeroed DXIL hash that the Windows runtime refuses (one of the Wine failures listed in #1218).
  • RTX 3050 Laptop (NVIDIA 620.73.04, waves 32..32), whole suite: 122 passed, 1 failed (same failure as on main).

This is RADV, not AMD's Windows driver, so it adds to a Windows run rather than replacing it. Synthetic tests only, no game files. AI-assisted (Claude Code, Opus 5.5); every run was on this machine.

**@⁠matheusfermiano-source** on GitHub · 2026-11-24 18:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/1395#issuecomment-7140225096) An AMD run, since the PR says AMD hardware was not tested; under Proton on Linux: **`scalar_64_bit_field_ops_lower`, `s_bfe_64_extracts_and_sets_scc`, `s_bfm_b64_builds_a_mask_and_keeps_scc` pass** on both GPUs. - Head `a91e9ad`. Built on Linux with llvm-mingw for `x86_64-pc-windows-gnullvm` (Rust 1.98.1) and run under Proton Experimental (11.0-20261027b) with its vkd3d-proton 3.1.0, one GPU at a time; `dxil.dll` from DXC 1.9.2609 was loaded, so the test modules were validated. - **Radeon 660M** (RDNA2, RADV Mesa 26.3.1, waves 32..64): whole `victory-shader` suite 122 passed, 1 failed, 1 ignored. Nothing fails that passes on `main` (`ffe310e`). The one failure, `emit::tests::stub_pipeline_is_created`, fails on `main` here too: vkd3d-proton accepts the zeroed DXIL hash that the Windows runtime refuses (one of the Wine failures listed in #1218). - **RTX 3050 Laptop** (NVIDIA 620.73.04, waves 32..32), whole suite: 122 passed, 1 failed (same failure as on main). This is RADV, not AMD's Windows driver, so it adds to a Windows run rather than replacing it. Synthetic tests only, no game files. AI-assisted (Claude Code, Opus 5.5); every run was on this machine.
Author
Owner

@⁠wwwwwwww3333333 on GitHub · 2026-11-24 19:14 UTC · original

Native Windows run on AMD RDNA2: RX 6750 XT (RDNA2, gfx1031), AMD driver 32.0.21045.29003, i5-13400F, Windows 11, Rust 1.98.1 MSVC. Head a91e9ad on main ffe310e (clean merge).

cargo test -p victory-shader --lib -- --test-threads=1: 123 passed, 0 failed, 1 ignored (main alone: 120 passed). s_bfe_64_extracts_and_sets_scc, s_bfm_b64_builds_a_mask_and_keeps_scc ran on the hardware adapter and then on WARP, and passed on both. scalar_64_bit_field_ops_lower passes too. The earlier AMD run here was under Proton; this one is AMD's own D3D12 driver.

Synthetic tests only, no game files. AI-assisted (Claude picked the PRs and wrote the batch script; I ran it on my machine).

**@⁠wwwwwwww3333333** on GitHub · 2026-11-24 19:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/1395#issuecomment-7141817465) Native Windows run on AMD RDNA2: RX 6750 XT (RDNA2, gfx1031), AMD driver 32.0.21045.29003, i5-13400F, Windows 11, Rust 1.98.1 MSVC. Head a91e9ad on main ffe310e (clean merge). `cargo test -p victory-shader --lib -- --test-threads=1`: **123 passed, 0 failed**, 1 ignored (main alone: 120 passed). `s_bfe_64_extracts_and_sets_scc`, `s_bfm_b64_builds_a_mask_and_keeps_scc` ran on the hardware adapter and then on WARP, and passed on both. `scalar_64_bit_field_ops_lower` passes too. The earlier AMD run here was under Proton; this one is AMD's own D3D12 driver. Synthetic tests only, no game files. AI-assisted (Claude picked the PRs and wrote the batch script; I ran it on my machine).
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 20:44 UTC · original

Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head a91e9ad onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 123, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

**@⁠sinan-cmyk** on GitHub · 2026-11-24 20:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/1395#issuecomment-7143988285) ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head a91e9ad onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 123, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 02:38 UTC · original

Automated triage for the maintainers. Recommended for a maintainer's look: this lowers s_bfe_u64, s_bfe_i64 and s_bfm_b64 (SOP2 0x29, 0x2a, 0x25) in the scalar 64-bit arm of lower.rs, which main refuses today. I checked the arms against the RDNA2 ISA (offset in bits 5:0, width in bits 22:16, SCC = result nonzero for s_bfe, SCC untouched by s_bfm), the hand-assembled encodings in scalar_64_bit_field_ops_lower, and the expected values in the GPU tests; contributors report the tests passing on NVIDIA and AMD (native and vkd3d-proton). CI fails only on synthetic_tests::gathers_at_a_level_match_the_hardware and permutes_read_the_lane_named_and_zero_from_lanes_left_out, which this PR does not touch and which fail the same way on other PRs against current main. Small nit: there is a doubled blank line after s_bfm_b64_builds_a_mask_and_keeps_scc in valu_tests.rs.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 02:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/1395#issuecomment-7150976987) <!-- victory-triage v1 head=a8299456fc126459f075b5ba2b5f2131544c165a verdict=merge-candidate at=2026-11-25T02:20:29Z --> Automated triage for the maintainers. Recommended for a maintainer's look: this lowers s_bfe_u64, s_bfe_i64 and s_bfm_b64 (SOP2 0x29, 0x2a, 0x25) in the scalar 64-bit arm of `lower.rs`, which main refuses today. I checked the arms against the RDNA2 ISA (offset in bits 5:0, width in bits 22:16, SCC = result nonzero for s_bfe, SCC untouched by s_bfm), the hand-assembled encodings in `scalar_64_bit_field_ops_lower`, and the expected values in the GPU tests; contributors report the tests passing on NVIDIA and AMD (native and vkd3d-proton). CI fails only on `synthetic_tests::gathers_at_a_level_match_the_hardware` and `permutes_read_the_lane_named_and_zero_from_lanes_left_out`, which this PR does not touch and which fail the same way on other PRs against current main. Small nit: there is a doubled blank line after `s_bfm_b64_builds_a_mask_and_keeps_scc` in `valu_tests.rs`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:08 UTC · original

Code review and RTX 5090 + WARP + DXIL verification at head a8299456fc12 merged onto main (63bcca43c6a0):

  • 512 KiB file-size policy blocker (xtask):
    • Code merges cleanly, but crates/victory-shader/src/emit/lower.rs reaches 526,300 bytes (+2,012 B over the 524,288-byte limit), causing cargo xtask policy to fail (rc=1). Moving these 64-bit bitfield helpers into a submodule under emit/lower/ will clear the policy check with headroom.
  • Lowering & edge-case audit (lower.rs:3816-3922):
    • s_bfe_u64/s_bfe_i64 mask off = n & 63, w = (n >> 16) & 127, handle full = w >= 64 and w == 0 cleanly (skipping sign-extension on full | (w == 0) while using AShr/LShr and (64 - w) & 63 shifts in-range), and set SCC via 64-bit nonzero(rl, rh).
    • s_bfm_b64 masks both src0[5:0] and src1[5:0] and leaves SCC untouched.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, dxil.dll 10.0.26100.0, Rust 1.98.1):
    • cargo xtask policy: FAIL (lower.rs: 526300 bytes exceeds the 524288-byte limit)
    • cargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warnings
    • scalar_64_bit_field_ops_lower s_bfe_64 s_bfm_b64: 3/3 passed across RTX 5090 (hardware) and WARP (warp + explicit VICTORY_WARP=1 2/2).

Lowering and hardware tests are solid — just needs extracting out of lower.rs to pass xtask policy.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/1395#issuecomment-7179471319) Code review and RTX 5090 + WARP + DXIL verification at head `a8299456fc12` merged onto `main` (`63bcca43c6a0`): - **512 KiB file-size policy blocker (`xtask`)**: - Code merges cleanly, but `crates/victory-shader/src/emit/lower.rs` reaches **`526,300` bytes** (`+2,012` B over the `524,288`-byte limit), causing `cargo xtask policy` to fail (`rc=1`). Moving these 64-bit bitfield helpers into a submodule under `emit/lower/` will clear the policy check with headroom. - **Lowering & edge-case audit (`lower.rs:3816-3922`)**: - `s_bfe_u64`/`s_bfe_i64` mask `off = n & 63`, `w = (n >> 16) & 127`, handle `full = w >= 64` and `w == 0` cleanly (skipping sign-extension on `full | (w == 0)` while using `AShr`/`LShr` and `(64 - w) & 63` shifts in-range), and set `SCC` via 64-bit `nonzero(rl, rh)`. - `s_bfm_b64` masks both `src0[5:0]` and `src1[5:0]` and leaves `SCC` untouched. - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `dxil.dll` 10.0.26100.0, Rust 1.98.1)**: - `cargo xtask policy`: **FAIL** (`lower.rs: 526300 bytes exceeds the 524288-byte limit`) - `cargo clippy --locked -p victory-shader --tests -- -D warnings`: 0 warnings - `scalar_64_bit_field_ops_lower s_bfe_64 s_bfm_b64`: **3/3 passed** across RTX 5090 (`hardware`) and WARP (`warp` + explicit `VICTORY_WARP=1` 2/2). Lowering and hardware tests are solid — just needs extracting out of `lower.rs` to pass `xtask policy`.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1395/head:github-bot/gh-1395'
git switch 'github-bot/gh-1395'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1395'
git switch 'github-bot/gh-1395'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1395'
git switch 'github-bot/gh-1395'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1395'
git switch 'main'
git merge --squash 'github-bot/gh-1395'
git switch 'main'
git merge --ff-only 'github-bot/gh-1395'
git switch 'main'
git merge 'github-bot/gh-1395'
git push origin 'main'
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!1395
No description provided.