Shaders: lower s_sext_i32_i8 and s_sext_i32_i16 in pure 32-bit DXIL #2075

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

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


Summary

  • Lowers GFX10 SOP1 instructions s_sext_i32_i8 (opcode 0x19) and s_sext_i32_i16 (opcode 0x1a) in crates/victory-shader/src/emit/lower.rs using pure 32-bit DXIL (shl + ashr by 24/16), without enabling Int64 / WIDE_OPS and while preserving SCC.
  • Adds synthetic IR, DXIL-validation, and GPU execution tests in crates/victory-shader/src/emit/valu_tests.rs covering 10 boundary input vectors across both instructions with both SCC = 0 and SCC = 1, verifying single-dword operand/result widths and that Int64 is not set.

Verification

  • cargo xtask policy: passed
  • cargo clippy -p victory-shader --tests -- -D warnings: passed
  • cargo test -p victory-shader --lib s_sext_i32 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:6597170322 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2077). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-25T04:24:07Z. --- ## Summary - Lowers GFX10 SOP1 instructions `s_sext_i32_i8` (opcode `0x19`) and `s_sext_i32_i16` (opcode `0x1a`) in `crates/victory-shader/src/emit/lower.rs` using pure 32-bit DXIL (`shl` + `ashr` by 24/16), without enabling `Int64` / `WIDE_OPS` and while preserving `SCC`. - Adds synthetic IR, DXIL-validation, and GPU execution tests in `crates/victory-shader/src/emit/valu_tests.rs` covering 10 boundary input vectors across both instructions with both `SCC = 0` and `SCC = 1`, verifying single-dword operand/result widths and that `Int64` is not set. ## Verification - `cargo xtask policy`: passed - `cargo clippy -p victory-shader --tests -- -D warnings`: passed - `cargo test -p victory-shader --lib s_sext_i32` 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:06:01 +00:00 (Migrated from github.com)

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

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 s_sext_i32_ — 2 passed, 0 failed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1 (including s_sext_i32_lowers_without_int64_and_preserves_scc_on_gpu)
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

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

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6051882613 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2077#pullrequestreview-6051882613). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T04:31:07Z. **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 s_sext_i32_` — **2 passed, 0 failed** on both RTX 5090 hardware and `VICTORY_D3D12_WARP=1` (including `s_sext_i32_lowers_without_int64_and_preserves_scc_on_gpu`) - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean pure-32-bit DXIL lowering of `s_sext_i32_i8` and `s_sext_i32_i16` preserving SCC, verified on hardware and WARP. Looks good. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 05:06:01 +00:00 (Migrated from github.com)

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

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. s_sext_i32_i8/s_sext_i32_i16 lowered in pure 32-bit DXIL — sign-extension ops without i64.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051907417 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2077#pullrequestreview-6051907417). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T04:34:43Z. **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. s_sext_i32_i8/s_sext_i32_i16 lowered in pure 32-bit DXIL — sign-extension ops without i64.
jeremygold02 commented 2026-11-25 05:06:21 +00:00 (Migrated from github.com)

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


Triage verdict — Keep the focused sign extension and reconcile #120’s overlap (b92ae69)

Evidence

  • @geiyiliyabumo’s patch and @tedin7’s #120 use the same 32-bit shift pairs for the two sign-extension instructions and leave SCC unchanged. #120 separately implements absolute difference and three halfword packing instructions that current main still lacks. Current patch · #120 patch

Checks and limits

  • Both exact-head focused tests passed independently with the DXIL validator required. Hardware and WARP each ran the synthetic cases. The fixture checks the sign-extended value and SCC through separate shaders. @n-romanovich’s earlier #142 has a useful combined result that keeps the arithmetic result live while checking SCC. Earlier test

Next step

  • Retain one sign-extension implementation and these boundary tests. If this lands first, remove only the two repeated arms when rebasing #120 and preserve its four independent operations.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152945550 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2077#issuecomment-7152945550). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T04:33:03Z. --- **Triage verdict — Keep the focused sign extension and reconcile #120’s overlap** (`b92ae69`) **Evidence** - @geiyiliyabumo’s patch and @tedin7’s #120 use the same 32-bit shift pairs for the two sign-extension instructions and leave SCC unchanged. #120 separately implements absolute difference and three halfword packing instructions that current `main` still lacks. [Current patch](https://github.com/Marvisak/VIctory/pull/2077/files) · [#120 patch](https://github.com/Marvisak/VIctory/pull/120/files) **Checks and limits** - Both exact-head focused tests passed independently with the DXIL validator required. Hardware and WARP each ran the synthetic cases. The fixture checks the sign-extended value and SCC through separate shaders. @n-romanovich’s earlier #142 has a useful combined result that keeps the arithmetic result live while checking SCC. [Earlier test](https://github.com/Marvisak/VIctory/pull/142/files) **Next step** - Retain one sign-extension implementation and these boundary tests. If this lands first, remove only the two repeated arms when rebasing #120 and preserve its four independent operations. This verification was AI-assisted.
upipibi commented 2026-11-25 05:06:22 +00:00 (Migrated from github.com)

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


Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at b92ae69. victory-shader: 246 passed, 3 failed, 3 ignored; the new s_sext_i32_has_single_dword_operands_and_preserves_scc_in_ir and s_sext_i32_lowers_without_int64_and_preserves_scc_on_gpu 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:7153077865 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2077#issuecomment-7153077865). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T04:41:36Z. --- Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `b92ae69`. `victory-shader`: 246 passed, 3 failed, 3 ignored; the new `s_sext_i32_has_single_dword_operands_and_preserves_scc_in_ir` and `s_sext_i32_lowers_without_int64_and_preserves_scc_on_gpu` 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:32 +00:00 (Migrated from github.com)

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


Offline measurement on a retail dump

Result: no count change against main.

I merged head b92ae691 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:7158054040 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2077#issuecomment-7158054040). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T09:14:01Z. --- ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head b92ae691 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 11:05:23 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

This lowers s_sext_i32_i8 and s_sext_i32_i16 in Lower::sop (crates/victory-shader/src/emit/lower.rs) as shl followed by ashr by 24 or 16. That matches the GFX10 ISA: the low byte or halfword is sign-extended and SCC is not written. Main already decodes both opcodes (0x19 and 0x1a in gfx10/opcodes.rs) but did not lower them. The new tests check operand widths and SCC flow in the IR, that the shader does not use the Int64 feature, and boundary values on the GPU and WARP. CI passes.

This overlaps two arms of #120, which needs a rebase and only checks that lowering succeeds. If this merges first, #120 should drop those two arms. One retail census in the comments found no change in validated counts, so the title's benefit is not yet shown.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159766645 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2077#issuecomment-7159766645). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T10:29:29Z. --- <!-- victory-triage v1 head=b92ae69133a0630d4833aef7c0379bef68991cd6 verdict=merge-candidate at=2026-11-25T10:29:21Z --> Automated triage for the maintainers. This lowers `s_sext_i32_i8` and `s_sext_i32_i16` in `Lower::sop` (`crates/victory-shader/src/emit/lower.rs`) as `shl` followed by `ashr` by 24 or 16. That matches the GFX10 ISA: the low byte or halfword is sign-extended and SCC is not written. Main already decodes both opcodes (0x19 and 0x1a in `gfx10/opcodes.rs`) but did not lower them. The new tests check operand widths and SCC flow in the IR, that the shader does not use the Int64 feature, and boundary values on the GPU and WARP. CI passes. This overlaps two arms of #120, which needs a rebase and only checks that lowering succeeds. If this merges first, #120 should drop those two arms. One retail census in the comments found no change in validated counts, so the title's benefit is not yet shown. --- _Generated by [Claude Code](https://claude.ai/code)_
fuzeofficlal commented 2026-11-26 02:07:14 +00:00 (Migrated from github.com)

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


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

  • Code review (crates/victory-shader/src/emit/lower.rs:3995-4000):
    • Pure 32-bit Shl(a, 24/16) followed by AShr(..., 24/16) cleanly masks dirty upper bits and sign-extends low 8/16-bit values without touching SCC or requiring Int64.
  • 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
    • s_sext_i32 (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:7180047724 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2077#issuecomment-7180047724). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:42:42Z. --- Code review and RTX 5090 + WARP + DXIL verification at head `b92ae69133a0` merged cleanly onto `main` (`63bcca43c6a0`; `emit/lower.rs` = `520,887` B, `3,401` B under the 512 KiB cap): - **Code review (`crates/victory-shader/src/emit/lower.rs:3995-4000`)**: - Pure 32-bit `Shl(a, 24/16)` followed by `AShr(..., 24/16)` cleanly masks dirty upper bits and sign-extends low 8/16-bit values without touching `SCC` or requiring `Int64`. - **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 - `s_sext_i32` (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/2077:upstream-pr/2077'
git switch 'upstream-pr/2077'

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/2077'
git switch 'upstream-pr/2077'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2077'
git switch 'upstream-pr/2077'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2077'
git switch 'main'
git merge --squash 'upstream-pr/2077'
git switch 'main'
git merge --ff-only 'upstream-pr/2077'
git switch 'main'
git merge 'upstream-pr/2077'
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!2075
No description provided.