Shaders: a signed 64-bit operand sign-extends its 32-bit literal (port of VIctory#447) #188

Open
lcg007xd-c wants to merge 1 commit from upstream-pr/188 into main
lcg007xd-c commented 2026-11-25 20:25:42 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by lcg007xd-c on 2026-11-25T20:25:42Z.


Port of Marvisak/VIctory#447 by Duff. It is cherry-picked with -x, so the commit keeps its author and its upstream hash. This fork's main (000ffdd) does not have it, and it is not in #142.

What it fixes

A 32-bit literal in a signed 64-bit operand is sign-extended on the hardware (LLVM's AMDGPU operand rules), but the fork zero-extended every literal except s_bfe_i64's: v_cmp_lt_i64 v[1:2], -100 compared against 4294967196, and s_ashr_i64 of a negative literal shifted in zeros. Upstream's rule (every _i64 instruction) covers the fork's s_bfe_i64 case, so that one now follows it.

Tested (Linux, Rust 1.98.1)

  • Upstream's valu_tests::signed_64_bit_operands_sign_extend_their_literal (Windows/GPU) is included. On Linux I checked the lowered IR with a temporary test (VOP3 v_cmp_lt_i64 with -100, and s_ashr_i64): passes with the port, fails without; not committed.
  • cargo test -p victory-shader --lib on this branch alone: no failures.
  • It applies to main without conflicts, and does not depend on the other open ports.

Not run here: Windows/GPU tests, since I have no Windows machine.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5498603819 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/188). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T20:25:42Z. --- Port of [Marvisak/VIctory#447](https://github.com/Marvisak/VIctory/pull/447) by Duff. It is cherry-picked with `-x`, so the commit keeps its author and its upstream hash. This fork's `main` (000ffdd) does not have it, and it is not in #142. ## What it fixes A 32-bit literal in a signed 64-bit operand is sign-extended on the hardware (LLVM's AMDGPU operand rules), but the fork zero-extended every literal except `s_bfe_i64`'s: `v_cmp_lt_i64 v[1:2], -100` compared against 4294967196, and `s_ashr_i64` of a negative literal shifted in zeros. Upstream's rule (every `_i64` instruction) covers the fork's `s_bfe_i64` case, so that one now follows it. ## Tested (Linux, Rust 1.98.1) - Upstream's `valu_tests::signed_64_bit_operands_sign_extend_their_literal` (Windows/GPU) is included. On Linux I checked the lowered IR with a temporary test (VOP3 `v_cmp_lt_i64` with -100, and `s_ashr_i64`): passes with the port, fails without; not committed. - `cargo test -p victory-shader --lib` on this branch alone: no failures. - It applies to `main` without conflicts, and does not depend on the other open ports. **Not run here:** Windows/GPU tests, since I have no Windows machine. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MamaLeVrai commented 2026-11-26 05:00:18 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by MamaLeVrai on 2026-11-26T05:00:18Z.


RDNA2 data point. This PR (8394b7e) merged on main 4f62c2a, cargo test --release -p victory-shader --lib on an RX 6950 XT (Windows 11 build 26300, Rust 1.98.1):

  • main: 275 passed, 2 failed.
  • This PR: 276 passed, 2 failed. The new test passes.

The 2 failures are the same as on main: the RDNA2 wave-size tests scalar_counted_in_a_divergent_loop_read_after_it and scalar_counted_in_nested_divergent_loops, fixed by #110 and #204. No regression here. One run ended without a result line, which this test binary does now and then on this machine, on main too. Not run in the game.

harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300

AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7183092367 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/188#issuecomment-7183092367). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-26T05:00:18Z. --- RDNA2 data point. This PR (`8394b7e`) merged on `main` `4f62c2a`, `cargo test --release -p victory-shader --lib` on an RX 6950 XT (Windows 11 build 26300, Rust 1.98.1): - `main`: 275 passed, 2 failed. - This PR: 276 passed, 2 failed. The new test passes. The 2 failures are the same as on `main`: the RDNA2 wave-size tests `scalar_counted_in_a_divergent_loop_read_after_it` and `scalar_counted_in_nested_divergent_loops`, fixed by #110 and #204. No regression here. One run ended without a result line, which this test binary does now and then on this machine, on `main` too. Not run in the game. harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300 AI-assisted (Claude Code); no game data.
adrianmjim commented 2026-11-26 19:43:39 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-26T19:43:39Z.


Tested on Windows 11, RX 7900 XT (RDNA3, driver 32.0.32029.2010), Rust 1.98.1.

The branch is based on 000ffdd. I tested it merged onto main 4f62c2a, which gives the same tree as refs/pull/188/merge.

GPU test:

  • signed_64_bit_operands_sign_extend_their_literal passes on both the hardware adapter and WARP.
  • With only the test change applied to 4f62c2a, it fails on the hardware adapter at the first case (v_cmp_eq_i64, -100: got 0, want 1).
  • With the two v_cmp cases taken out, the s_ashr_i64 case also fails on 4f62c2a (high dword: got 0, want 0xffffffff). So both the vector and the scalar change are covered.
  • cargo test -p victory-shader --lib -- --test-threads=1: 278 passed, 0 failed, 6 ignored. On 4f62c2a: 277 passed, 0 failed, 6 ignored.

Full shaders.rpf of the title (translate --validate --host-lanes 32-64):

  • 26084 of 26084 programs translated. All emitted DXIL validates. The refusals are the same as on 4f62c2a.
  • No program's DXIL changes (0 of 25623). The IR instruction total is unchanged.
  • That is expected. The archive's disassembly has no _i64 instruction at all, and no instruction with an _i64, _u64 or _b64 mnemonic has a literal operand.

So for this title the change is a correctness fix with no effect on this archive.

Not tested: other games, the branch head on its own, or a run in game.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7201897532 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/188#issuecomment-7201897532). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-26T19:43:39Z. --- Tested on Windows 11, RX 7900 XT (RDNA3, driver 32.0.32029.2010), Rust 1.98.1. The branch is based on 000ffdd. I tested it merged onto main 4f62c2a, which gives the same tree as refs/pull/188/merge. GPU test: - `signed_64_bit_operands_sign_extend_their_literal` passes on both the hardware adapter and WARP. - With only the test change applied to 4f62c2a, it fails on the hardware adapter at the first case (`v_cmp_eq_i64`, -100: got 0, want 1). - With the two `v_cmp` cases taken out, the `s_ashr_i64` case also fails on 4f62c2a (high dword: got 0, want 0xffffffff). So both the vector and the scalar change are covered. - `cargo test -p victory-shader --lib -- --test-threads=1`: 278 passed, 0 failed, 6 ignored. On 4f62c2a: 277 passed, 0 failed, 6 ignored. Full shaders.rpf of the title (`translate --validate --host-lanes 32-64`): - 26084 of 26084 programs translated. All emitted DXIL validates. The refusals are the same as on 4f62c2a. - No program's DXIL changes (0 of 25623). The IR instruction total is unchanged. - That is expected. The archive's disassembly has no `_i64` instruction at all, and no instruction with an `_i64`, `_u64` or `_b64` mnemonic has a literal operand. So for this title the change is a correctness fix with no effect on this archive. Not tested: other games, the branch head on its own, or a run in game.
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/188:upstream-pr/188'
git switch 'upstream-pr/188'

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