Skip to content

Shaders: hardware test for the scalar add/sub carry chain and the SOPK forms - #1875

Closed
LouisRiverstone wants to merge 1 commit into
Marvisak:mainfrom
LouisRiverstone:shaders/s-add-sub-carry-test
Closed

LouisRiverstone wants to merge 1 commit into
Marvisak:mainfrom
LouisRiverstone:shaders/s-add-sub-carry-test

Conversation

@LouisRiverstone

Copy link
Copy Markdown
Contributor

s_add_u32, s_sub_u32, s_add_i32, s_sub_i32, s_addc_u32, s_subb_u32, s_addk_i32 and s_mulk_i32 are lowered in lower.rs, with the carry going through SCC, but no hardware test ran them.

New test s_add_sub_carry_chain_and_k_forms_match_rdna2: the four plain forms over 25 pairs, then a 64-bit add (s_add_u32 + s_addc_u32) and subtract (s_sub_u32 + s_subb_u32) over 225 cases each, reading the high dword so the carry or borrow shows, then s_addk_i32/s_mulk_i32 with four immediates (sign-extended). Expected values come from wrapping_* and a u64 sum in Rust. Adds a small sopk encoder next to sop2.

Test only, no production change.

Verify: cargo test -p victory-shader s_add_sub_carry (Windows, hardware GPU or WARP). I type-checked it with clippy for x86_64-pc-windows-msvc, but could not run it locally: the shader test module is Windows-only.

🤖 Generated with Claude Code

@LouisRiverstone
LouisRiverstone force-pushed the shaders/s-add-sub-carry-test branch from 035433c to 124e45b Compare November 25, 2026 01:14

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (940d32f), cargo test → 144 passed, 0 failed. GPU execution tests are #[cfg(all(test, windows))] and run only on Windows.

victory-shader. Hardware test for the scalar add/sub carry chain: RDNA2-matched (Windows-gated).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

This is a test-only change: s_add_sub_carry_chain_and_k_forms_match_rdna2 in crates/victory-shader/src/emit/valu_tests.rs covers s_add/sub_u32/i32, the 64-bit carry and borrow chains through SCC (s_addc_u32, s_subb_u32, checked on the high dword), and s_addk_i32/s_mulk_i32 with sign-extended immediates. I checked the GFX10 opcodes (SOP2 0x00 to 0x05; SOPK 0x0f, 0x10) and the sopk encoding (0xB000_0000 | op<<23 | sdst<<16 | simm16). The SOPK forms overwrite s0 only after build_valu_cs has already copied it to v1, so the inputs are intact. The expected carry is (a + b) >> 32 and the borrow is a < b, which is the ISA's definition.

This inserts at the same place in the file as #1874 and #1876, so whichever merges later needs a trivial rebase.

CI: passing.


Generated by Claude Code

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 124e45b onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing as covered by #2015, which runs the same add/addc and sub/subb chains over 625 wide inputs (low dword, high dword and final carry), s_sub_u32 and s_sub_i32 over edge pairs, and s_addk_i32 and s_mulk_i32 with five immediates. s_add_u32 and s_add_i32 are already on main. The model here is right.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants