Shaders: honor clamp on unsigned VOP3 add and subtract (port of upstream VIctory #1398) #947
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/948"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from fxceless/victory-fork. Originally posted by Moon0755 on 2026-11-25T13:29:15Z.
Ports upstream Marvisak/VIctory#1398 (
EatCodeSleep2), plus additionalclampguards invictory-shader's descriptor tracer and wave-prefix analysis.Problem
On RDNA2 / Xbox Series X, VOP3 integer instructions can carry the
clampmodifier (bit 15) to perform unsigned saturating arithmetic (u32::MAXon unsigned add overflow,0on unsigned subtract borrow) while still writing the true unclamped carry/borrow mask tosdst/VCC.Previously,
Lower::write_irejected every integer VALU instruction withv.clamp(Err("integer output modifiers")).What changed
crates/victory-shader/src/emit/lower.rs(Lower::write_i&Lower::valu_op):v.clampinLower::valu_op'sinthelper by default so unsupported integer ops still fail translation loudly, while allowingv.clampthroughLower::write_i.v_add_co_u32,v_sub_co_u32,v_subrev_co_u32,v_add_co_ci_u32,v_sub_co_ci_u32, andv_subrev_co_ci_u32atu32::MAX/0whenv.clampis set, while preserving the unclampedcarry/ borrow mask written tolane_bits.v.clamponv_add_nc_u32,v_sub_nc_u32,v_subrev_nc_u32, andv_add3_u32(ORing both carry stages forv_add3_u32).v_add_nc_u32andv_sub_nc_u32in wave-prefix analysis so saturating operations are not treated as modular wave sums/prefixes.crates/victory-shader/src/resource.rs(Tracer::vadd&Tracer::carried):f.clampwhen matchingv_add_co_u32,v_add_nc_u32, andv_add_co_ci_u32during descriptor address tracing so saturating arithmetic is not mistaken for a linear base+offset or 64-bit high-dword carry chain.crates/victory-shader/src/emit/valu_tests.rs(vop3_unsigned_add_sub_clamp):clamp = falseandclamp = trueacross edge-case inputs, independently reading back the carry/borrow mask for the 6 carry-out ops.Verification
Verified on Windows (
windows-latest+dxil.dll+ D3D12 WARP) via a temporary scoped CI branch on the fork:cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings: passedcargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings: passedcargo test -p victory-shader -p xtask --locked -- --nocapture:victory-shader216 passed; 0 failed; 3 ignored(test emit::valu_tests::vop3_unsigned_add_sub_clamp ... ok, validated viadxil.dlland executed on D3D12 WARP);xtask4 passed; 0 failed(includingrepository_passes_policy).Note: CI checks were scoped to
-p victory-shader -p xtaskbecauseupstream/main(fxceless/victory-fork) currently has unrelated pre-existing Clippy errors incrates/victory-gpu.— Neon
Imported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-25T18:00:51Z.
A hardware run of this PR's new test:
vop3_unsigned_add_sub_clamppasses on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with #402's Agility SDK runtime. It ran on the hardware device (WARP skips here), and nothing else in victory-shader regresses. The setup, and the same run for eight related ports, are in one table on #1030: https://github.com/fxceless/victory-fork/pull/1030#issuecomment-7170315986Pull request closed