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

Open
github-bot wants to merge 1 commit from github-bot/gh-2063 into main AGit
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-25 04:19 UTC · original
geiyiliyabumo:feat/shader-s-ff0 → main · +95 −8 · 2 files · 1 commits · open

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).
**@⁠geiyiliyabumo** on GitHub · 2026-11-25 04:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2063) `geiyiliyabumo:feat/shader-s-ff0` → `main` · +95 −8 · 2 files · 1 commits · open ## 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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:53:39 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-25 04:28 UTC · original

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.

**@⁠jeremygold02** on GitHub · 2026-11-25 04:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2063#issuecomment-7152867513) **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://git.gtahub.st/github/Marvisak--VIctory/pulls/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.
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 04:41 UTC · original

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

**@⁠upipibi** on GitHub · 2026-11-25 04:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2063#issuecomment-7153078132) 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).
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 09:24 UTC · original

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

**@⁠sinan-cmyk** on GitHub · 2026-11-25 09:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2063#issuecomment-7158293672) ### 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).
Author
Owner

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

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

**@⁠Marvisak** on GitHub · 2026-11-25 09:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2063#issuecomment-7158313055) <!-- 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)_
Author
Owner

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

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2063#issuecomment-7180047321) 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 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/2063/head:github-bot/gh-2063'
git switch 'github-bot/gh-2063'

Merge

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