fix: lower signed 16-bit VOP3 add and subtract in VIctory #331

Open
mauroalvare wants to merge 6 commits from upstream-pr/331 into main
mauroalvare commented 2026-11-26 03:44:18 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-26T03:44:18Z.


Change

Neptune decodes v_add_nc_i16 and v_sub_nc_i16, then rejects them as unsupported before producing DXIL. tools/lancer_victory.ps1 builds the runtime whose GPU pipeline calls victory_shader::emit::translate and this VALU lowering.

Lower both instructions through the existing half_src and write_half paths with wrapping results by default and signed saturation with clamp. For clamped results, mask the in-range value before selecting the 16-bit saturation pattern. This keeps the other VDST half intact when NVIDIA folds the arithmetic. The code adapts the signed i16 part of VIctory #2094, with upipibi's mask-before-select workaround.

Verification

Base c4c93bdc413191a9dc909998d2d53080a3f0c880, fix 319c35861246d4725dc306fb9702fc2d8be3ab9e.

From third_party/victory on Windows:

$env:VICTORY_DXIL = 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\dxil.dll'
Remove-Item Env:VICTORY_WARP -ErrorAction SilentlyContinue
cargo test --locked --offline -j 2 -p victory-shader --lib signed_i16_ -- --nocapture --test-threads=1
  • With the two test cases on the base, both fail at lower: Unsupported at offset 40, naming the respective instruction.
  • With the fix, both pass. SDK validator 1.8.2502.11 accepts 32 synthetic shader containers. The tests create all 32 compute pipelines and compare 320 readbacks per backend to exact results on the NVIDIA GeForce RTX 5070 Ti (driver 621.40) and Microsoft WARP. Local diagnostic logging identified the adapter behind each D3D12 device.
  • The shader set exercises both operations with and without clamp and all eight selections of the two input halves and the destination half. It checks both saturation bounds, negative in-range results, and preservation of the other half of VDST.
Command Result
cargo test --locked --offline -j 2 -p victory-shader -- --nocapture --test-threads=1 244 passed, 0 failed, 2 ignored
cargo test --locked --offline -j 2 -p victory-loader --test load_probe 2 passed, 0 failed
cargo check --locked --offline -j 2 -p victory Finished successfully
cargo xtask policy 200 files OK
cargo build --release --locked --offline -j 2 --manifest-path rust/Cargo.toml Finished successfully
cargo test --release --locked --offline -j 2 --manifest-path rust/Cargo.toml 12 passed, 0 failed
python -m pytest -q tests/test_rdna2_exec_int16.py -k 'v_add_nc_i16 or v_sub_nc_i16' 5 passed, 90 deselected
python -m pytest -rs 1665 passed in 73.67s
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools All checks passed

The full shader run also reported four optional compiler-dependent skips, one WARP pipeline skip, and one hardware wave test whose pipeline the device did not accept. The two focused tests had zero skips. Pytest used Python 3.13.15, ANYXBOXX_REQUIRE_RUNTIME=1, and the existing native runtime and TomBox binaries.

Oracle and test data

The shaders are assembled from repository helpers. Each expected dword combines the untouched half of a preset destination with the exact signed sum or difference, narrowed by wrapping or saturation. The interpreter fixtures in AnyXboxX #232 independently cover these rules. Section 6.5 of the AMD RDNA 2 ISA guide defines integer clamp. LLVM 20.1.8 selects these clamped opcodes for GFX10 signed saturation. Signed add · Signed subtract

Checklist

  • One reviewable behavior with a regression for each opcode.
  • Both regressions fail on the base and pass with the fix.
  • Commands, adapters, results, and skips are recorded above.
  • Pytest verifies the README language copies.
  • All input shaders and executables are synthetic fixtures.
  • Third-party code is licensed and credited in THIRD_PARTY.md and the commit.

AI assistance by Codex for the port, regression tests, and Windows validation.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5503596311 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/331). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-26T03:44:18Z. --- ## Change Neptune decodes `v_add_nc_i16` and `v_sub_nc_i16`, then rejects them as unsupported before producing DXIL. `tools/lancer_victory.ps1` builds the runtime whose GPU pipeline calls `victory_shader::emit::translate` and this VALU lowering. Lower both instructions through the existing `half_src` and `write_half` paths with wrapping results by default and signed saturation with `clamp`. For clamped results, mask the in-range value before selecting the 16-bit saturation pattern. This keeps the other VDST half intact when NVIDIA folds the arithmetic. The code adapts the signed i16 part of [VIctory #2094](https://github.com/Marvisak/VIctory/pull/2094), with [upipibi's mask-before-select workaround](https://github.com/Marvisak/VIctory/pull/2094#issuecomment-7153371416). ## Verification Base `c4c93bdc413191a9dc909998d2d53080a3f0c880`, fix `319c35861246d4725dc306fb9702fc2d8be3ab9e`. From `third_party/victory` on Windows: ```powershell $env:VICTORY_DXIL = 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\dxil.dll' Remove-Item Env:VICTORY_WARP -ErrorAction SilentlyContinue cargo test --locked --offline -j 2 -p victory-shader --lib signed_i16_ -- --nocapture --test-threads=1 ``` - With the two test cases on the base, both fail at `lower: Unsupported` at offset 40, naming the respective instruction. - With the fix, both pass. SDK validator 1.8.2502.11 accepts 32 synthetic shader containers. The tests create all 32 compute pipelines and compare 320 readbacks per backend to exact results on the NVIDIA GeForce RTX 5070 Ti (driver 621.40) and Microsoft WARP. Local diagnostic logging identified the adapter behind each D3D12 device. - The shader set exercises both operations with and without clamp and all eight selections of the two input halves and the destination half. It checks both saturation bounds, negative in-range results, and preservation of the other half of VDST. | Command | Result | | --- | --- | | `cargo test --locked --offline -j 2 -p victory-shader -- --nocapture --test-threads=1` | 244 passed, 0 failed, 2 ignored | | `cargo test --locked --offline -j 2 -p victory-loader --test load_probe` | 2 passed, 0 failed | | `cargo check --locked --offline -j 2 -p victory` | Finished successfully | | `cargo xtask policy` | 200 files OK | | `cargo build --release --locked --offline -j 2 --manifest-path rust/Cargo.toml` | Finished successfully | | `cargo test --release --locked --offline -j 2 --manifest-path rust/Cargo.toml` | 12 passed, 0 failed | | `python -m pytest -q tests/test_rdna2_exec_int16.py -k 'v_add_nc_i16 or v_sub_nc_i16'` | 5 passed, 90 deselected | | `python -m pytest -rs` | 1665 passed in 73.67s | | `python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools` | All checks passed | The full shader run also reported four optional compiler-dependent skips, one WARP pipeline skip, and one hardware wave test whose pipeline the device did not accept. The two focused tests had zero skips. Pytest used Python 3.13.15, `ANYXBOXX_REQUIRE_RUNTIME=1`, and the existing native runtime and TomBox binaries. ## Oracle and test data The shaders are assembled from repository helpers. Each expected dword combines the untouched half of a preset destination with the exact signed sum or difference, narrowed by wrapping or saturation. The interpreter fixtures in [AnyXboxX #232](https://github.com/LooperSalty/AnyXboxX/pull/232) independently cover these rules. Section 6.5 of the [AMD RDNA 2 ISA guide](https://docs.amd.com/api/khub/documents/Et~wpu9g~Ffl7d9q0QZ~Og/content) defines integer clamp. LLVM 20.1.8 selects these clamped opcodes for GFX10 signed saturation. [Signed add](https://raw.githubusercontent.com/llvm/llvm-project/llvmorg-20.1.8/llvm/test/CodeGen/AMDGPU/saddsat.ll) · [Signed subtract](https://raw.githubusercontent.com/llvm/llvm-project/llvmorg-20.1.8/llvm/test/CodeGen/AMDGPU/ssubsat.ll) ## Checklist - [x] One reviewable behavior with a regression for each opcode. - [x] Both regressions fail on the base and pass with the fix. - [x] Commands, adapters, results, and skips are recorded above. - [x] Pytest verifies the README language copies. - [x] All input shaders and executables are synthetic fixtures. - [x] Third-party code is licensed and credited in `THIRD_PARTY.md` and the commit. AI assistance by Codex for the port, regression tests, and Windows validation.
mauroalvare commented 2026-11-27 19:49:11 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T19:49:11Z.


Updated to ec3b7348 after #545. The signed 16-bit add/subtract tests now sit alongside the new rounding and unsigned carry/saturation tests. All seven targeted tests and the VIctory asset policy passed on 08aea01a.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7226901450 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/331#issuecomment-7226901450). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-27T19:49:11Z. --- Updated to `ec3b7348` after #545. The signed 16-bit add/subtract tests now sit alongside the new rounding and unsigned carry/saturation tests. All seven targeted tests and the VIctory asset policy passed on `08aea01a`.
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/331:upstream-pr/331'
git switch 'upstream-pr/331'

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