Skip to content

fix: honor clamp on unsigned VOP3 add and subtract - #327

Open
mauroalvare wants to merge 4 commits into
LooperSalty:mainfrom
mauroalvare:codex/victory-u32-clamp
Open

mauroalvare wants to merge 4 commits into
LooperSalty:mainfrom
mauroalvare:codex/victory-u32-clamp

Conversation

@mauroalvare

@mauroalvare mauroalvare commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Change

Neptune rejected unsigned VOP3 and VOP3B add/subtract with clamp as integer output modifiers before it emitted DXIL. The resource tracer also treated a clamped sum relative to s_getpc_b64 as an ordinary code-table address.

tools/lancer_victory.ps1 builds and launches the runtime that uses victory-gpu and victory_shader::emit::translate. These regressions exercise that translator's lowering and resource tracing.

Use carry or borrow to saturate the VGPR result and preserve the lane bit written to SDST. For v_add3_u32, overflow in either addition saturates the result. Resource tracing refuses a saturated PC-relative address with an explicit diagnostic because the lowered PC is an offset into the shader.

This adapts VIctory #1398 by EatCodeSleep2 from commit 38ddebf954267e2ae46dce6f3f3dbfdb622219ee and adds Neptune-specific tests. The commit and THIRD_PARTY.md credit the source.

Verification

Commit 7e79fcee0443a2fff09f5b296dcb021f93553a76 is based on c4c93bdc413191a9dc909998d2d53080a3f0c880.

Run this from third_party/victory with the Windows SDK validator and cached dependencies.

$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 clamped_u32_ -- --nocapture --test-threads=1
  • On base c4c93bdc413191a9dc909998d2d53080a3f0c880 with the regression tests, all four fail. The three arithmetic tests stop in lowering at byte 36. The fourth shows the tracer returning CODE + 4 with a dynamic term for the saturated sum.
  • With the fix, all four pass. Locally logging the D3D12 adapter LUID confirmed dispatches on the NVIDIA GeForce RTX 5070 Ti (driver 621.40) and Microsoft WARP. SDK DXIL validator 1.8.2502.11 accepted 16 containers. All 16 compute pipelines produced the expected readbacks on both backends, including carry-in and borrow-in cases. The address regression exercises the reject path independently.

Additional checks on the committed tree:

Command Result
cargo test --locked --offline -j 2 -p victory-shader -- --nocapture --test-threads=1 246 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 -rs 1665 passed in 220.46s
python -m ruff check --select W605,F,E9 PrototypeScarlett tests tools All checks passed

The full shader run also reported four optional console-compiler skips, one WARP pipeline skip, and one hardware wave test whose pipeline the device did not accept. The focused regression ran all 16 containers on both backends. Pytest used Python 3.13.15, ANYXBOXX_REQUIRE_RUNTIME=1, and the existing native runtime and TomBox builds.

Oracle and test data

The regression assembles one-thread synthetic compute shaders using the repository's GFX10 encoders. It compares every readback to exact integer arithmetic, using the representable range from section 6.5 of the AMD RDNA 2 ISA guide. The expected carry and borrow are based on the exact unsaturated result, as in the independently implemented interpreter and HLSL tests for the nine two-input variants in AnyXboxX #235.

Checklist

  • Focused regression fails on the base and passes on the patched tree.
  • Commands, adapters, results, and skips are recorded above.
  • The unsupported saturated PC-relative address is reported explicitly.
  • Repository fixtures supply all input shaders and executables.
  • Pytest verifies the README language copies.
  • The GPL-compatible port is credited in THIRD_PARTY.md and the commit.

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

Rebase verification

Rebased on 58d2f53 and merged the upstream credit into the current THIRD_PARTY.md table. cargo test --locked --offline -j 5 -p victory-shader clamped_u32 -- --nocapture --test-threads=1 passed all 4 tests on the rebased code.

The size check in CI found that lower.rs exceeded the 512 KiB limit. The existing add/subtract carry helper now lives in integer_carry.rs. After the move, cargo xtask policy passed for all 215 files and all 4 targeted tests passed again.

@LooperSalty

Copy link
Copy Markdown
Owner

This PR now conflicts with main in THIRD_PARTY.md (the sources table moved after the recent merges, including #351). Please rebase on main (git fetch origin && git rebase origin/main), keep both sides of the table rows, and force-push your branch; CI must then pass again before review.

🤖 Generated with Claude Code

Use the carry or borrow to saturate unsigned VOP3 add and subtract
results, including three-input addition. Preserve the carry or borrow
written to SDST. Keep clamped additions out of plain address tracing
and diagnose clamped PC-relative addresses before lowering.

Source: Marvisak/VIctory #1398 (38ddebf954267e2ae46dce6f3f3dbfdb622219ee)
Co-authored-by: EatCodeSleep2 <52021568+EatCodeSleep2@users.noreply.github.com>

# Conflicts:
#	THIRD_PARTY.md
@mauroalvare
mauroalvare force-pushed the codex/victory-u32-clamp branch from 7a2c911 to ca0c86b Compare November 26, 2026 18:08

Copy link
Copy Markdown
Contributor Author

Rebased and pushed over #387, with the VOP3 clamp attribution in the current THIRD_PARTY.md table. I moved the carry helper into its own module to keep lower.rs below the 512 KiB limit.

All four clamp tests passed, and the asset-policy check passed for the updated branch.

The latest CI run passed.

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.

2 participants