Shaders: abs / neg on the shift-add and align ops act on the sign bit #2020

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

@⁠upipibi on GitHub · 2026-11-25 03:16 UTC · original
upipibi:fix/int-sign-mods → main · +52 −5 · 2 files · 2 commits · open

VOP3 abs and neg on v_lshl_add_u32, v_add_lshl_u32, v_alignbit_b32 and v_alignbyte_b32 stopped translation with "integer operand modifiers". RDNA2 applies them to a source's bit 31, as for a float: abs clears it and neg flips it. There is no integer negate or absolute value.

Sources: boykopovar/AnyPS5#25964 measured every abs/neg combination on the two shift-adds on gfx1036 (RDNA2) and gfx1201 (RDNA4), 196/196 words matching on each. boykopovar/AnyPS5#25799 measured the align ops on gfx1036: on src1 the bit reaches the result, and on src0 and the shift amount it can't change it. xcl-dev/xcl#2058 is the same fix in XCL, where the modifiers were silently dropped.

What is in it

  • emit/lower.rs, src: for those four opcodes, abs and neg become x & 0x7fffffff and x ^ 0x80000000 on the source. Every other integer operation still returns "integer operand modifiers" when it has them, since only these four are measured.
  • emit/valu_tests.rs: shift_add_and_align_take_sign_bit_modifiers covers neg on src2 of v_lshl_add_u32, abs on src0 of v_add_lshl_u32, and neg and abs on src1 of both align ops. Each case is built so the modifier can't be shifted out.

Tested on Windows 11, RTX 3070 (Ampere, driver 616.56), debug, on main 940d32f:

  • new test: passes on the hardware. WARP skips the wave-32 shader. Without the lower.rs change the build stops with Unsupported { what: "integer operand modifiers" }.
  • cargo test -p victory-shader --locked: 245 passed, 3 failed, 3 ignored. The 3 are #1744's NVIDIA failures on main.
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings and cargo xtask policy: pass.

Not tested: AMD hardware, a title.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠upipibi** on GitHub · 2026-11-25 03:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2020) `upipibi:fix/int-sign-mods` → `main` · +52 −5 · 2 files · 2 commits · open VOP3 `abs` and `neg` on `v_lshl_add_u32`, `v_add_lshl_u32`, `v_alignbit_b32` and `v_alignbyte_b32` stopped translation with "integer operand modifiers". RDNA2 applies them to a source's bit 31, as for a float: `abs` clears it and `neg` flips it. There is no integer negate or absolute value. Sources: boykopovar/AnyPS5#25964 measured every `abs`/`neg` combination on the two shift-adds on gfx1036 (RDNA2) and gfx1201 (RDNA4), 196/196 words matching on each. boykopovar/AnyPS5#25799 measured the align ops on gfx1036: on src1 the bit reaches the result, and on src0 and the shift amount it can't change it. xcl-dev/xcl#2058 is the same fix in XCL, where the modifiers were silently dropped. **What is in it** - `emit/lower.rs`, `src`: for those four opcodes, `abs` and `neg` become `x & 0x7fffffff` and `x ^ 0x80000000` on the source. Every other integer operation still returns "integer operand modifiers" when it has them, since only these four are measured. - `emit/valu_tests.rs`: `shift_add_and_align_take_sign_bit_modifiers` covers neg on src2 of `v_lshl_add_u32`, abs on src0 of `v_add_lshl_u32`, and neg and abs on src1 of both align ops. Each case is built so the modifier can't be shifted out. **Tested** on Windows 11, RTX 3070 (Ampere, driver 616.56), debug, on `main` `940d32f`: - new test: passes on the hardware. WARP skips the wave-32 shader. Without the `lower.rs` change the build stops with `Unsupported { what: "integer operand modifiers" }`. - `cargo test -p victory-shader --locked`: 245 passed, 3 failed, 3 ignored. The 3 are #1744's NVIDIA failures on `main`. - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` and `cargo xtask policy`: pass. **Not tested:** AMD hardware, a title. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
VOP3 abs and neg on v_lshl_add_u32, v_add_lshl_u32, v_alignbit_b32 and
v_alignbyte_b32 stopped translation as integer operand modifiers. RDNA2
applies them to a source's bit 31, as on a float: abs clears it, neg
flips it (boykopovar/AnyPS5#25964, all combinations on gfx1036 and
gfx1201; #25799 for the align ops). Other integer operations still
refuse them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two cases set both modifiers on the same source (add_lshl src0, lshl_add
src2): abs clears bit 31, then neg sets it. They fail if the two are applied
the other way round (checked by swapping them locally).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:51:49 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-25 03:33 UTC · original

Triage verdict — Ready for maintainer decision; one useful test addition (ea7dff7)

Evidence

  • src limits the sign-bit handling to the four measured opcodes. For those, it clears bit 31 before flipping it, consistent with the published shift-add and align measurements. Other integer opcodes still reject these modifiers.

Checks and limits

  • The exact-head Windows check passed. The author reports that the targeted test ran on hardware and WARP skipped the wave32 shader. I reviewed the diff and the published measurements without rerunning the GPU test.

Next step

  • Keep this scoped to the measured opcodes. A combined ABS+NEG case on the same source would pin the operation order in the local fixture. The current cases set one modifier at a time, so they would also pass if those two operations were accidentally reversed.

This verification was AI-assisted.

**@⁠jeremygold02** on GitHub · 2026-11-25 03:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2020#issuecomment-7152025898) **Triage verdict — Ready for maintainer decision; one useful test addition** (`ea7dff7`) **Evidence** - `src` limits the sign-bit handling to the four measured opcodes. For those, it clears bit 31 before flipping it, consistent with the published [shift-add](https://github.com/boykopovar/AnyPS5/pull/25964) and [align](https://github.com/boykopovar/AnyPS5/pull/25799) measurements. Other integer opcodes still reject these modifiers. **Checks and limits** - The [exact-head Windows check](https://github.com/Marvisak/VIctory/actions/runs/45538798985/job/138951917423) passed. The author reports that the targeted test ran on hardware and WARP skipped the wave32 shader. I reviewed the diff and the published measurements without rerunning the GPU test. **Next step** - Keep this scoped to the measured opcodes. A combined ABS+NEG case on the same source would pin the operation order in the local fixture. The current cases set one modifier at a time, so they would also pass if those two operations were accidentally reversed. This verification was AI-assisted.
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 03:39 UTC · original

Added the combined case in eed34ee. Two rows now set ABS and NEG on the same source: v_add_lshl_u32 with -|src0| and v_lshl_add_u32 with -|src2| on 0x8000_0001. Both must give bit 31 set. With the two operations swapped locally (neg, then abs), the first row fails on hardware (0x00000004, want 0x80000004), so the order is pinned now. RTX 3070 (616.56): the test passes, and victory-shader gives 245 passed with only #1744's 3 NVIDIA failures, the same as main.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 03:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/2020#issuecomment-7152123069) Added the combined case in `eed34ee`. Two rows now set ABS and NEG on the same source: `v_add_lshl_u32` with `-|src0|` and `v_lshl_add_u32` with `-|src2|` on `0x8000_0001`. Both must give bit 31 set. With the two operations swapped locally (neg, then abs), the first row fails on hardware (`0x00000004`, want `0x80000004`), so the order is pinned now. RTX 3070 (616.56): the test passes, and `victory-shader` gives 245 passed with only #1744's 3 NVIDIA failures, the same as `main`. AI-assisted (Claude Code).
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 03:42 UTC · original

Verified on Windows 10 19045 (RX 7800 XT), head eed34ee plus the device-skip patch from #1991 (this host has no SM 6.6 device, so the probes would otherwise fail for an unrelated reason):

cargo test -p victory-shader --lib — 248 passed, 0 failed, 3 ignored, including abs and neg together on one shift-add source give -|x|.

On the semantics: treating abs as clearing bit 31 and neg as flipping it is the right model for these four ops if the hardware does them as sign-bit operations rather than two's complement — and the order (abs then neg, so both set gives -|x|) matches the float convention the comment cites. Restricting it to the four names and keeping the refusal for the other integer ops is the conservative half, which I would keep.

The GPU-valued cases skip here and run in CI; no unrelated failure in the suite on this tree.

**@⁠Calvix2k** on GitHub · 2026-11-25 03:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2020#issuecomment-7152174399) Verified on Windows 10 19045 (RX 7800 XT), head `eed34ee` plus the device-skip patch from #1991 (this host has no SM 6.6 device, so the probes would otherwise fail for an unrelated reason): `cargo test -p victory-shader --lib` — **248 passed, 0 failed, 3 ignored**, including `abs and neg together on one shift-add source give -|x|`. On the semantics: treating `abs` as clearing bit 31 and `neg` as flipping it is the right model for these four ops if the hardware does them as sign-bit operations rather than two's complement — and the order (abs then neg, so both set gives -|x|) matches the float convention the comment cites. Restricting it to the four names and keeping the refusal for the other integer ops is the conservative half, which I would keep. The GPU-valued cases skip here and run in CI; no unrelated failure in the suite on this tree.
Author
Owner

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

Automated triage for the maintainers.

Merge candidate. Recommending a look, not approving.

  • In emit/lower.rs src, VOP3 abs/neg on v_lshl_add_u32, v_add_lshl_u32, v_alignbit_b32 and v_alignbyte_b32 now clear bit 31 (abs) and then flip it (neg) instead of stopping translation. Every other integer op still returns "integer operand modifiers". The evidence is cited: per-combination measurements on RDNA2/RDNA4 hardware in another project, linked in the PR.
  • I checked the opcode numbers (0x346/0x347/0x14E/0x14F for GFX10 VOP3) and the expected values of the test cases in valu_tests.rs shift_add_and_align_take_sign_bit_modifiers, including the two combined abs+neg rows that fix the order of the two operations. Applying the bit operation to the align ops' shift operand is harmless because only its low bits are used.
  • No overlapping open PR adds this. #1275 restructures the same check in src in a different way, so whichever lands second needs a small rebase.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 09:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2020#issuecomment-7158153282) <!-- victory-triage v1 head=eed34eed1351db4dd0b2fe837168ebc2b126a678 verdict=merge-candidate at=2026-11-25T09:18:19Z --> Automated triage for the maintainers. **Merge candidate.** Recommending a look, not approving. - In `emit/lower.rs` `src`, VOP3 `abs`/`neg` on `v_lshl_add_u32`, `v_add_lshl_u32`, `v_alignbit_b32` and `v_alignbyte_b32` now clear bit 31 (abs) and then flip it (neg) instead of stopping translation. Every other integer op still returns "integer operand modifiers". The evidence is cited: per-combination measurements on RDNA2/RDNA4 hardware in another project, linked in the PR. - I checked the opcode numbers (0x346/0x347/0x14E/0x14F for GFX10 VOP3) and the expected values of the test cases in `valu_tests.rs` `shift_add_and_align_take_sign_bit_modifiers`, including the two combined abs+neg rows that fix the order of the two operations. Applying the bit operation to the align ops' shift operand is harmless because only its low bits are used. - No overlapping open PR adds this. #1275 restructures the same check in `src` in a different way, so whichever lands second needs a small rebase. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

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

Offline measurement on a retail dump

Result: no count change against main.

I merged head eed34eed 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:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2020#issuecomment-7158881952) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head eed34eed 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

@⁠bvtterbroot on GitHub · 2026-11-25 18:40 UTC · original

AMD check at eed34ee (base 940d32f), on an RDNA3 and an RDNA2 GPU:

  • Windows 11, Rust 1.98.1. Radeon RX 7900 XTX (RDNA3, driver 32.0.32029.2010) and the Ryzen 7 7800X3D's iGPU (RDNA2, gfx1036, driver 32.0.21045.29003). I picked each as the hardware adapter of the shader test host with a local patch that is not part of this PR. WARP runs in each pass as well.
  • cargo test -p victory-shader -p victory-gpu --locked: 391 passed, 0 failed, 5 ignored, on both GPUs. That includes its new test (shift_add_and_align_take_sign_bit_modifiers).

Synthetic tests only, no game files. Tested with AI assistance (Claude Code).

**@⁠bvtterbroot** on GitHub · 2026-11-25 18:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2020#issuecomment-7171230849) AMD check at `eed34ee` (base `940d32f`), on an RDNA3 and an RDNA2 GPU: - Windows 11, Rust 1.98.1. Radeon RX 7900 XTX (RDNA3, driver 32.0.32029.2010) and the Ryzen 7 7800X3D's iGPU (RDNA2, gfx1036, driver 32.0.21045.29003). I picked each as the hardware adapter of the shader test host with a local patch that is not part of this PR. WARP runs in each pass as well. - `cargo test -p victory-shader -p victory-gpu --locked`: **391 passed, 0 failed**, 5 ignored, on both GPUs. That includes its new test (`shift_add_and_align_take_sign_bit_modifiers`). Synthetic tests only, no game files. _Tested with AI assistance (Claude Code)._
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/2020/head:github-bot/gh-2020'
git switch 'github-bot/gh-2020'

Merge

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