Skip to content

Shaders: honor clamp on unsigned VOP3 add and subtract (port of upstream VIctory #1398) - #948

Closed
Moon0755 wants to merge 1 commit into
fxceless:mainfrom
Moon0755:fix/vop3-unsigned-add-sub-clamp
Closed

Moon0755 wants to merge 1 commit into
fxceless:mainfrom
Moon0755:fix/vop3-unsigned-add-sub-clamp

Conversation

@Moon0755

Copy link
Copy Markdown

Ports upstream Marvisak/VIctory#1398 (EatCodeSleep2), plus additional clamp guards in victory-shader's descriptor tracer and wave-prefix analysis.

Problem

On RDNA2 / Xbox Series X, VOP3 integer instructions can carry the clamp modifier (bit 15) to perform unsigned saturating arithmetic (u32::MAX on unsigned add overflow, 0 on unsigned subtract borrow) while still writing the true unclamped carry/borrow mask to sdst / VCC.

Previously, Lower::write_i rejected every integer VALU instruction with v.clamp (Err("integer output modifiers")).

What changed

  • crates/victory-shader/src/emit/lower.rs (Lower::write_i & Lower::valu_op):
    • Keep rejecting v.clamp in Lower::valu_op's int helper by default so unsupported integer ops still fail translation loudly, while allowing v.clamp through Lower::write_i.
    • Saturate v_add_co_u32, v_sub_co_u32, v_subrev_co_u32, v_add_co_ci_u32, v_sub_co_ci_u32, and v_subrev_co_ci_u32 at u32::MAX / 0 when v.clamp is set, while preserving the unclamped carry / borrow mask written to lane_bits.
    • Support v.clamp on v_add_nc_u32, v_sub_nc_u32, v_subrev_nc_u32, and v_add3_u32 (ORing both carry stages for v_add3_u32).
    • Also guard v_add_nc_u32 and v_sub_nc_u32 in wave-prefix analysis so saturating operations are not treated as modular wave sums/prefixes.
  • crates/victory-shader/src/resource.rs (Tracer::vadd & Tracer::carried):
    • Reject f.clamp when matching v_add_co_u32, v_add_nc_u32, and v_add_co_ci_u32 during 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):
    • Add an end-to-end synthetic compute shader test covering all 10 instructions with clamp = false and clamp = true across 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:

  • CI run: https://github.com/Moon0755/victory-fork/actions/runs/45623437448
  • cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings: passed
  • cargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings: passed
  • cargo test -p victory-shader -p xtask --locked -- --nocapture: victory-shader 216 passed; 0 failed; 3 ignored (test emit::valu_tests::vop3_unsigned_add_sub_clamp ... ok, validated via dxil.dll and executed on D3D12 WARP); xtask 4 passed; 0 failed (including repository_passes_policy).

Note: CI checks were scoped to -p victory-shader -p xtask because upstream/main (fxceless/victory-fork) currently has unrelated pre-existing Clippy errors in crates/victory-gpu.

— Neon

triippywhale pushed a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
…and subtract

Hand port of PalmVIDev 6bfa714f8 (in fxceless#239; fxceless#948,
upstream VIctory #1398) onto this tree's unsplit lower.rs: a clamped
v_add_co/sub_co/subrev_co(_ci)_u32, v_add/sub/subrev_nc_u32 and v_add3_u32
saturate at all ones or zero instead of being refused ("integer output
modifiers"). Other integer results with clamp are still refused (write_i);
only these go through write_i_clamped. The resource tracer and the
wave-local check no longer take a clamped add for a plain one. PalmVIDev's
GPU tests for it are not ported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HAL9000RELOADED

Copy link
Copy Markdown

A hardware run of this PR's new test: vop3_unsigned_add_sub_clamp passes 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: #1030 (comment)

@Moon0755 Moon0755 closed this Nov 26, 2026
HAL9000RELOADED added a commit to HAL9000RELOADED/victory-fork that referenced this pull request Nov 26, 2026
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