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

Open
github-bot wants to merge 1 commit from github-bot/gh-331 into main AGit
Owner

@⁠mauroalvare on GitHub · 2026-11-26 03:44 UTC · original
mauroalvare:codex/victory-signed-i16 → main · +81 −3 · 3 files · 1 commits · open

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.

**@⁠mauroalvare** on GitHub · 2026-11-26 03:44 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/331) `mauroalvare:codex/victory-signed-i16` → `main` · +81 −3 · 3 files · 1 commits · open ## 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://git.gtahub.st/github/LooperSalty--AnyXboxX/pulls/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.
Lower v_add_nc_i16 and v_sub_nc_i16 using the existing half-register
paths. Mask the result before the saturation selects so the preserved
half of VDST stays intact on NVIDIA. Cover all source and destination
half selections with and without clamp.

The mask-before-select workaround was proposed by upipibi in review.

Source: Marvisak/VIctory #2094 (48590903d4ce14cb3c1d2e9de12b86339ce8dd48)
Co-authored-by: 给伊莉雅补魔 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:43:19 +00:00
This pull request can be merged automatically.
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/331/head:github-bot/gh-331'
git switch 'github-bot/gh-331'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-331'
git switch 'github-bot/gh-331'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-331'
git switch 'github-bot/gh-331'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-331'
git switch 'main'
git merge --squash 'github-bot/gh-331'
git switch 'main'
git merge --ff-only 'github-bot/gh-331'
git switch 'main'
git merge 'github-bot/gh-331'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.