Shaders: lower VOP3 integer clamp saturation for add/sub ops #1478

Closed
github-bot wants to merge 1 commit from gh-pr/1478/head into gh-pr/1478/base
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 18:18 UTC · original
geiyiliyabumo:fix/shader-vop3-int-clamp → main · +206 −17 · 2 files · 1 commits · closed without merging

Summary

Implements VOP3 integer \clamp\ saturation for RDNA2 / GFX10.3 integer add/sub instructions in \ ictory-shader\ (tracking issue #1242, \VIC-BT-010).

Previously, \Lower::write_i\ rejected any integer VALU instruction with \ .clamp, refusing valid clamped integer add/sub instructions emitted by console shaders.

Changes

  • \crates/victory-shader/src/emit/lower.rs:
    • Allow \write_i\ to accept instructions whose \ .clamp\ has been explicitly handled while still rejecting unsupported \ .clamp\ or non-zero \ .omod.
    • Saturate unsigned overflow to \
**@⁠geiyiliyabumo** on GitHub · 2026-11-24 18:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1478) `geiyiliyabumo:fix/shader-vop3-int-clamp` → `main` · +206 −17 · 2 files · 1 commits · closed without merging ## Summary Implements VOP3 integer \clamp\ saturation for RDNA2 / GFX10.3 integer add/sub instructions in \ ictory-shader\ (tracking issue #1242, \VIC-BT-010\). Previously, \Lower::write_i\ rejected any integer VALU instruction with \ .clamp\, refusing valid clamped integer add/sub instructions emitted by console shaders. ### Changes - \crates/victory-shader/src/emit/lower.rs\: - Allow \write_i\ to accept instructions whose \ .clamp\ has been explicitly handled while still rejecting unsupported \ .clamp\ or non-zero \ .omod\. - Saturate unsigned overflow to \
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:33:27 +00:00
github-bot closed this pull request 2026-11-26 04:33:27 +00:00
Author
Owner

@⁠AnoHunted on GitHub · 2026-11-24 18:38 UTC · original

Independent NVIDIA hardware run. No game files were used.

Machine: Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1, DXC dxil.dll 1.9.2609 (SDK 10.0.26100) validating.

Applied on main (ffe310e), cargo test -p victory-shader --features host -- --test-threads=1:

  • 124 passed, 0 failed, 1 ignored (main: 120 / 0 / 1).
  • The four added tests (vop3_unsigned_clamp_preserves_carry_and_borrow_out, vop3_unsigned_no_carry_add_sub_respect_clamp, vop3_signed_no_carry_add_sub_respect_clamp, v_add3_u32_wraps_on_double_carry) execute through run_cases/run_cases_with_output on the RTX 5080 (and WARP) and all pass.

Not tested: the in-game effect; AMD.

**@⁠AnoHunted** on GitHub · 2026-11-24 18:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/1478#issuecomment-7140921085) Independent NVIDIA hardware run. No game files were used. Machine: Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1, DXC `dxil.dll` 1.9.2609 (SDK 10.0.26100) validating. Applied on main (`ffe310e`), `cargo test -p victory-shader --features host -- --test-threads=1`: - **124 passed, 0 failed, 1 ignored** (main: 120 / 0 / 1). - The four added tests (`vop3_unsigned_clamp_preserves_carry_and_borrow_out`, `vop3_unsigned_no_carry_add_sub_respect_clamp`, `vop3_signed_no_carry_add_sub_respect_clamp`, `v_add3_u32_wraps_on_double_carry`) execute through `run_cases`/`run_cases_with_output` on the RTX 5080 (and WARP) and all pass. Not tested: the in-game effect; AMD.
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 18:48 UTC · original

Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at 1905213. cargo test -p victory-shader --lib -- --test-threads=1 --nocapture gives 124 passed, 0 failed, 1 ignored.

#1398 covers the same VIC-BT-010 item, so I ran each PR's tests against the other PR's code (tests copied in, everything else unchanged):

tests from on #1478 on #1398
#1478: vop3_unsigned_clamp_preserves_carry_and_borrow_out, vop3_unsigned_no_carry_add_sub_respect_clamp, v_add3_u32_wraps_on_double_carry pass pass
#1478: vop3_signed_no_carry_add_sub_respect_clamp pass refused: v_add_nc_i32 isn't lowered there
#1398: vop3_unsigned_add_sub_clamp refused (integer output modifiers) only for v_add3_u32 with clamp; the other 9 ops pass pass

So the two agree on every value both produce on this hardware. Each one covers something the other doesn't: this PR adds signed v_add/sub_nc_i32 with clamp, and #1398 adds clamped v_add3_u32 (saturating when either add carries). I also checked the signed saturation here: overflow when the sign of b disagrees with whether the result moved below a, and the limit follows the sign of a. That looks right.

**@⁠marquezinii** on GitHub · 2026-11-24 18:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1478#issuecomment-7141173128) Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at `1905213`. `cargo test -p victory-shader --lib -- --test-threads=1 --nocapture` gives 124 passed, 0 failed, 1 ignored. #1398 covers the same VIC-BT-010 item, so I ran each PR's tests against the other PR's code (tests copied in, everything else unchanged): | tests from | on #1478 | on #1398 | |---|---|---| | #1478: `vop3_unsigned_clamp_preserves_carry_and_borrow_out`, `vop3_unsigned_no_carry_add_sub_respect_clamp`, `v_add3_u32_wraps_on_double_carry` | pass | pass | | #1478: `vop3_signed_no_carry_add_sub_respect_clamp` | pass | refused: `v_add_nc_i32` isn't lowered there | | #1398: `vop3_unsigned_add_sub_clamp` | refused (`integer output modifiers`) only for `v_add3_u32` with clamp; the other 9 ops pass | pass | So the two agree on every value both produce on this hardware. Each one covers something the other doesn't: this PR adds signed `v_add/sub_nc_i32` with clamp, and #1398 adds clamped `v_add3_u32` (saturating when either add carries). I also checked the signed saturation here: overflow when the sign of `b` disagrees with whether the result moved below `a`, and the limit follows the sign of `a`. That looks right.
Author
Owner

@⁠wwwwwwww3333333 on GitHub · 2026-11-24 19:15 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 1905213 on main ffe310e (clean merge).

cargo test -p victory-shader --lib -- --test-threads=1: 124 passed, 0 failed, 1 ignored (main alone: 120 passed). v_add3_u32_wraps_on_double_carry, vop3_signed_no_carry_add_sub_respect_clamp, vop3_unsigned_clamp_preserves_carry_and_borrow_out, vop3_unsigned_no_carry_add_sub_respect_clamp ran on the hardware adapter and then on WARP, and passed on both. This adds an AMD result to the NVIDIA runs already posted.

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:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/1478#issuecomment-7141821681) 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 1905213 on main ffe310e (clean merge). `cargo test -p victory-shader --lib -- --test-threads=1`: **124 passed, 0 failed**, 1 ignored (main alone: 120 passed). `v_add3_u32_wraps_on_double_carry`, `vop3_signed_no_carry_add_sub_respect_clamp`, `vop3_unsigned_clamp_preserves_carry_and_borrow_out`, `vop3_unsigned_no_carry_add_sub_respect_clamp` ran on the hardware adapter and then on WARP, and passed on both. This adds an AMD result to the NVIDIA runs already posted. 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:13 UTC · original

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

Result: no count change against main.

Offline. I merged head 1905213 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 124, 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:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/1478#issuecomment-7143214917) ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head 1905213 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 124, 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

@⁠geiyiliyabumo on GitHub · 2026-11-24 21:07 UTC · original

Thanks @⁠catminou4 for the macOS verification and review! Just a quick note on point #2: commit 1905213 already includes vop3_signed_no_carry_add_sub_respect_clamp testing v_add_nc_i32 and v_sub_nc_i32 with clamp on/off across positive/negative overflow and boundary cases — verified passing above by @⁠AnoHunted (RTX 5080), @⁠marquezinii (RTX 5070), @⁠wwwwwwww3333333 (RX 6750 XT), @⁠sinan-cmyk (RTX 4070 SUPER), and on our RX 9060 XT + WARP. Happy to rebase onto #1398 if #1398 lands first.

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 21:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/1478#issuecomment-7144498682) Thanks @⁠catminou4 for the macOS verification and review! Just a quick note on point #2: commit `1905213` already includes `vop3_signed_no_carry_add_sub_respect_clamp` testing `v_add_nc_i32` and `v_sub_nc_i32` with `clamp` on/off across positive/negative overflow and boundary cases — verified passing above by @⁠AnoHunted (RTX 5080), @⁠marquezinii (RTX 5070), @⁠wwwwwwww3333333 (RX 6750 XT), @⁠sinan-cmyk (RTX 4070 SUPER), and on our RX 9060 XT + WARP. Happy to rebase onto #1398 if #1398 lands first. *AI-assisted; synthetic tests only, no game files.*
Author
Owner

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

Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #1398. clamp on VOP3 integer add/sub. The unsigned carry and no-carry code is the same as in #1398 (identical lines), which also guards descriptor tracing; the extra signed v_add_nc_i32/v_sub_nc_i32 are also in #92. Neither is used by the title.

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 00:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1478#issuecomment-7148766134) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #1398. clamp on VOP3 integer add/sub. The unsigned carry and no-carry code is the same as in #1398 (identical lines), which also guards descriptor tracing; the extra signed v_add_nc_i32/v_sub_nc_i32 are also in #92. Neither is used by the title. 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.

Pull request closed

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!1478
No description provided.