Shaders: lower s_ff0_i32_b32 and s_ff0_i32_b64 in pure 32-bit DXIL #2061

Open
geiyiliyabumo wants to merge 1 commit from upstream-pr/2063 into main
geiyiliyabumo commented 2026-11-25 04:19:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-25T04:19:31Z.


Summary

  • Lowers GFX10 SOP1 instructions s_ff0_i32_b32 (opcode 0x11) and s_ff0_i32_b64 (opcode 0x12) in crates/victory-shader/src/emit/lower.rs using pure 32-bit DXIL (FirstbitLo on inverted source dword(s)), matching s_ff1_i32_b32 and s_ff1_i32_b64 without enabling Int64 / WIDE_OPS.
  • Preserves SCC across both instructions and applies the same numeric lane-mask guard in pixel/vertex shaders as s_ff1_i32_* (since a shorter host wave can change the lowest clear bit).
  • Adds synthetic IR, DXIL-validation, and GPU execution tests in crates/victory-shader/src/emit/valu_tests.rs covering all boundary inputs for 32-bit and 64-bit operands with both SCC = 0 and SCC = 1, verifying Int64 is not set.

Verification

  • cargo xtask policy: passed
  • cargo clippy -p victory-shader --tests -- -D warnings: passed
  • cargo test -p victory-shader --lib scalar_ff0 with Microsoft dxil.dll: 2/2 passed on AMD Radeon RX 9060 XT (RDNA4) and Microsoft Basic Render Driver (WARP)
  • Zero game files or game-derived data used (synthetic tests only).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6597120023 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2063). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-25T04:19:31Z. --- ## Summary - Lowers GFX10 SOP1 instructions `s_ff0_i32_b32` (opcode `0x11`) and `s_ff0_i32_b64` (opcode `0x12`) in `crates/victory-shader/src/emit/lower.rs` using pure 32-bit DXIL (`FirstbitLo` on inverted source dword(s)), matching `s_ff1_i32_b32` and `s_ff1_i32_b64` without enabling `Int64` / `WIDE_OPS`. - Preserves `SCC` across both instructions and applies the same numeric lane-mask guard in pixel/vertex shaders as `s_ff1_i32_*` (since a shorter host wave can change the lowest clear bit). - Adds synthetic IR, DXIL-validation, and GPU execution tests in `crates/victory-shader/src/emit/valu_tests.rs` covering all boundary inputs for 32-bit and 64-bit operands with both `SCC = 0` and `SCC = 1`, verifying `Int64` is not set. ## Verification - `cargo xtask policy`: passed - `cargo clippy -p victory-shader --tests -- -D warnings`: passed - `cargo test -p victory-shader --lib scalar_ff0` with Microsoft `dxil.dll`: 2/2 passed on **AMD Radeon RX 9060 XT (RDNA4)** and **Microsoft Basic Render Driver (WARP)** - Zero game files or game-derived data used (synthetic tests only).
DenRakEiw commented 2026-11-25 05:05:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:31:13Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib scalar_ff0_ — 2 passed, 0 failed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1 (scalar_ff0_reads_the_source_width_and_writes_only_one_sgpr and scalar_ff0_finds_the_lowest_clear_bit_and_preserves_scc)
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean pure-32-bit DXIL lowering of s_ff0_i32_b32 and s_ff0_i32_b64 preserving SCC, verified on hardware and WARP. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6051883385 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2063#pullrequestreview-6051883385). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T04:31:13Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with `dxil.dll` validator): - `cargo test -p victory-shader --lib scalar_ff0_` — **2 passed, 0 failed** on both RTX 5090 hardware and `VICTORY_D3D12_WARP=1` (`scalar_ff0_reads_the_source_width_and_writes_only_one_sgpr` and `scalar_ff0_finds_the_lowest_clear_bit_and_preserves_scc`) - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean pure-32-bit DXIL lowering of `s_ff0_i32_b32` and `s_ff0_i32_b64` preserving SCC, verified on hardware and WARP. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 05:05:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:33:50Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. s_ff0_i32_b32/b64 lowered in pure 32-bit DXIL — ff0 find-first-zero for 32/64-bit.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051901317 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2063#pullrequestreview-6051901317). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T04:33:50Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `cargo test -p victory-shader --locked`. 144 passed / 0 failed / 2 ignored. s_ff0_i32_b32/b64 lowered in pure 32-bit DXIL — ff0 find-first-zero for 32/64-bit.
jeremygold02 commented 2026-11-25 05:06:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T04:28:00Z.


Triage verdict — Keep the focused FF0 change and reconcile #148’s overlap (d1d33ea)

Evidence

  • @geiyiliyabumo and @Rareuncommon’s #148 both lower the 32-bit and 64-bit FF0 instructions with first-bit-low on complemented dwords. The 64-bit paths select the low-half match first, add 32 for a high-half match, and return −1 when both halves are all ones. #148 also implements four zero-count and high-bit-scan forms still absent from current main. Focused lowering · #148 patch

Checks and limits

  • Both exact-head tests passed. Hardware D3D12 and WARP ran the ordinary SGPR cases, including the half boundary, all-ones sentinel, both initial SCC states, and the absence of an Int64 requirement. The cases do not exercise host-dependent lane-mask operands or independently require the optional validator. Tests

Next step

  • If maintainers take #2063 first, remove only the repeated FF0 arms from #148 on rebase. Keep its other instructions, retain the focused readback tests and mask restriction, and preserve credit for both implementations.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152867513 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2063#issuecomment-7152867513). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T04:28:00Z. --- **Triage verdict — Keep the focused FF0 change and reconcile #148’s overlap** (`d1d33ea`) **Evidence** - @geiyiliyabumo and @Rareuncommon’s #148 both lower the 32-bit and 64-bit FF0 instructions with first-bit-low on complemented dwords. The 64-bit paths select the low-half match first, add 32 for a high-half match, and return −1 when both halves are all ones. #148 also implements four zero-count and high-bit-scan forms still absent from current `main`. [Focused lowering](https://github.com/Marvisak/VIctory/blob/d1d33eaaf0300bf04c98e272406ceb62bb10e25b/crates/victory-shader/src/emit/lower.rs#L3471-L3504) · [#148 patch](https://github.com/Marvisak/VIctory/pull/148/files) **Checks and limits** - Both exact-head tests passed. Hardware D3D12 and WARP ran the ordinary SGPR cases, including the half boundary, all-ones sentinel, both initial SCC states, and the absence of an Int64 requirement. The cases do not exercise host-dependent lane-mask operands or independently require the optional validator. [Tests](https://github.com/Marvisak/VIctory/blob/d1d33eaaf0300bf04c98e272406ceb62bb10e25b/crates/victory-shader/src/emit/valu_tests.rs#L233-L306) **Next step** - If maintainers take #2063 first, remove only the repeated FF0 arms from #148 on rebase. Keep its other instructions, retain the focused readback tests and mask restriction, and preserve credit for both implementations. This verification was AI-assisted.
upipibi commented 2026-11-25 05:06:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T04:41:37Z.


Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at d1d33ea. victory-shader: 246 passed, 3 failed, 3 ignored; the new scalar_ff0_reads_the_source_width_and_writes_only_one_sgpr and scalar_ff0_finds_the_lowest_clear_bit_and_preserves_scc pass. The 3 failures are #1744's NVIDIA failures on main. Same as main on this hardware. Not run: a title.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7153078132 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2063#issuecomment-7153078132). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T04:41:37Z. --- Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `d1d33ea`. `victory-shader`: 246 passed, 3 failed, 3 ignored; the new `scalar_ff0_reads_the_source_width_and_writes_only_one_sgpr` and `scalar_ff0_finds_the_lowest_clear_bit_and_preserves_scc` pass. The 3 failures are #1744's NVIDIA failures on `main`. Same as `main` on this hardware. Not run: a title. AI-assisted (Claude Code).
sinan-cmyk commented 2026-11-25 10:07:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T09:24:43Z.


Offline measurement on a retail dump

Result: no count change against main.

I merged head d1d33eaa onto main 940d32f (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: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158293672 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2063#issuecomment-7158293672). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T09:24:43Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head d1d33eaa onto `main` 940d32f (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: 23,918 on `main`, 23,918 with this PR. No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Marvisak commented 2026-11-25 10:07:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:25:34Z.


Automated triage for the maintainers.
Merge candidate.

This lowers s_ff0_i32_b32 and s_ff0_i32_b64 (crates/victory-shader/src/emit/lower.rs, Lower::sop arms) as first-bit-low of the complemented source dword(s). It reuses the existing s_ff1_* paths, so the result is -1 when there is no clear bit, the b64 form adds 32 for a match in the high half, and no Int64 is needed. Checked against main:

  • Decoding: gfx10/opcodes.rs already decodes 0x11 and 0x12, and gfx10/fields.rs reads the 64-bit source.
  • SCC: it is left alone, matching the RDNA2 ISA definition of S_FF0.
  • Lane masks: s_ff0 is deliberately not added to the host-mask allowlist in Lower::inst, which is right because missing high lanes would read as clear bits. The added comment sits inside that match without a matching name, which reads oddly. A rewording would help but is not a blocker.
  • Tests: cover the boundary cases for both widths, both SCC states, and the absence of the Int64 flag.

#148 and #1684 also lower s_ff0 among other instructions, but both conflict with main. This one merges cleanly. The retail-dump comparison above shows no program changes, so this adds a capability the current title does not use. Recommending a look, not approving.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158313055 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2063#issuecomment-7158313055). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T09:25:34Z. --- <!-- victory-triage v1 head=d1d33eaaf0300bf04c98e272406ceb62bb10e25b verdict=merge-candidate at=2026-11-25T09:25:20Z --> Automated triage for the maintainers. **Merge candidate.** This lowers `s_ff0_i32_b32` and `s_ff0_i32_b64` (crates/victory-shader/src/emit/lower.rs, `Lower::sop` arms) as first-bit-low of the complemented source dword(s). It reuses the existing `s_ff1_*` paths, so the result is -1 when there is no clear bit, the b64 form adds 32 for a match in the high half, and no Int64 is needed. Checked against main: - Decoding: `gfx10/opcodes.rs` already decodes 0x11 and 0x12, and `gfx10/fields.rs` reads the 64-bit source. - SCC: it is left alone, matching the RDNA2 ISA definition of S_FF0. - Lane masks: s_ff0 is deliberately not added to the host-mask allowlist in `Lower::inst`, which is right because missing high lanes would read as clear bits. The added comment sits inside that `match` without a matching name, which reads oddly. A rewording would help but is not a blocker. - Tests: cover the boundary cases for both widths, both SCC states, and the absence of the Int64 flag. #148 and #1684 also lower s_ff0 among other instructions, but both conflict with main. This one merges cleanly. The retail-dump comparison above shows no program changes, so this adds a capability the current title does not use. Recommending a look, not approving. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-26 02:07:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:42:40Z.


Code review and RTX 5090 + WARP + DXIL verification at head d1d33eaaf030 merged cleanly onto main (63bcca43c6a0; emit/lower.rs = 521,062 B, 3,226 B under the 512 KiB cap):

  • Code review (crates/victory-shader/src/emit/lower.rs:3509-3511, 3737-3760, 3930-3941):
    • s_ff0_i32_b32 inverts via Xor u32::MAX + DXIL FirstbitLo (op 32), mapping 0 -> 0 and u32::MAX -> -1 without touching SCC.
    • s_ff0_i32_b64 splits into two 32-bit FirstbitLo calls (pure 32-bit DXIL, no Int64 SFI0 flag), adding 32 when only the high word has a zero bit, and mask_ok properly excludes s_ff0_i32_* from MaskData::Host.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, dxil.dll 10.0.26100.0, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy (default + --features diagnostics): 0 warnings
    • scalar_ff0 (2/2), emit::lower::tests (33/33), and emit::semantics_tests (34/34 on both RTX 5090 and WARP, 1 ignored) all passed.

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7180047321 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2063#issuecomment-7180047321). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:42:40Z. --- Code review and RTX 5090 + WARP + DXIL verification at head `d1d33eaaf030` merged cleanly onto `main` (`63bcca43c6a0`; `emit/lower.rs` = `521,062` B, `3,226` B under the 512 KiB cap): - **Code review (`crates/victory-shader/src/emit/lower.rs:3509-3511, 3737-3760, 3930-3941`)**: - `s_ff0_i32_b32` inverts via `Xor u32::MAX` + DXIL `FirstbitLo` (op 32), mapping `0 -> 0` and `u32::MAX -> -1` without touching `SCC`. - `s_ff0_i32_b64` splits into two 32-bit `FirstbitLo` calls (pure 32-bit DXIL, no `Int64` SFI0 flag), adding `32` when only the high word has a zero bit, and `mask_ok` properly excludes `s_ff0_i32_*` from `MaskData::Host`. - **Verified (Windows 11, NVIDIA RTX 5090 + WARP, `dxil.dll` 10.0.26100.0, `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy` (default + `--features diagnostics`): 0 warnings - `scalar_ff0` (2/2), `emit::lower::tests` (33/33), and `emit::semantics_tests` (34/34 on both RTX 5090 and WARP, 1 ignored) all passed. LGTM.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2063:upstream-pr/2063'
git switch 'upstream-pr/2063'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2063'
git switch 'upstream-pr/2063'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2063'
git switch 'upstream-pr/2063'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2063'
git switch 'main'
git merge --squash 'upstream-pr/2063'
git switch 'main'
git merge --ff-only 'upstream-pr/2063'
git switch 'main'
git merge 'upstream-pr/2063'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2061
No description provided.