Skip to content

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

Open
mauroalvare wants to merge 4 commits into
LooperSalty:mainfrom
mauroalvare:codex/victory-signed-i16
Open

mauroalvare wants to merge 4 commits into
LooperSalty:mainfrom
mauroalvare:codex/victory-signed-i16

Conversation

@mauroalvare

Copy link
Copy Markdown
Contributor

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.

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: 给伊莉雅补魔 <98532177+geiyiliyabumo@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant