Repository navigation
Shaders: lower v_sad_u8, v_sad_hi_u8, v_sad_u16, v_sad_u32 and v_msad_u8 - #162
Conversation
|
Tested
No game data used. |
…6, v_sad_u32 and v_msad_u8) into the integration Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
|
RDNA2 hardware measurement of the five rules, including the Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. A HIP kernel (assembled by the AMD driver's amd_comgr) runs
Mask examples: src0 So the reading you were least sure of, a zero byte in src1 being skipped, is what the hardware does. AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run. |
catminou4
left a comment
There was a problem hiding this comment.
Verified locally on macOS 26 arm64, rustc 1.98.1 (aarch64-apple-darwin) at head 318082f:
cargo test -p victory-shader --locked: compiles clean, all ungated tests pass (no regressions vs main's 56).
Scope note: valu_tests/image_tests in victory-shader are #[cfg(all(test, windows))] — they need the Windows host backend (D3D12/dxil.dll), so they did not run here. What I verified is compilation on macOS plus all ungated tests. For this PR that means the new v_sad/v_msad lowering coverage still needs a Windows run before merge — I can't execute it on this machine. The lowering changes themselves compile everywhere.
The high dword of the 48-bit product whose low dword v_mul_u32_u24 and v_mul_i32_i24 already give: the low 24 bits of each operand, zero- or sign-extended, through the existing mul_hi. The test module gets lowers_valu, a one-thread compute program with root constants in v1..v4 and a buffer store of v0 (built with lower_with), so a vector instruction can be checked for lowering without a GPU. AI-assisted (Claude Code).
src2 plus the sum of the unsigned differences |a - b| of the operands' bytes (v_sad_u8), halves (v_sad_u16) or whole dwords (v_sad_u32), wrapping at 32 bits. v_sad_hi_u8 adds the byte sum shifted to the high half; v_msad_u8 leaves out a byte whose mask byte (src1) is 0. AI-assisted (Claude Code).
318082f to
5d6889e
Compare
…v_sad_u32 and v_msad_u8
…v_sad_u32 and v_msad_u8
…fied together Merges Marvisak#156 Marvisak#162 Marvisak#168 Marvisak#169 Marvisak#368 Marvisak#379 Marvisak#456 Marvisak#587 Marvisak#990 Marvisak#1021 Marvisak#1048 Marvisak#1052 Marvisak#1053 Marvisak#1095 Marvisak#1142 Marvisak#1190 Marvisak#1211 Marvisak#1223 Marvisak#1259 Marvisak#1293 on top of the bundle of Marvisak#1402 (which is on Marvisak#1319, on main ffe310e), each head unchanged. Hunks that conflicted in emit/lower.rs, emit/valu_tests.rs and emit/diff_tests.rs were merged by keeping both sides (additions next to each other); a PR was kept only if cargo clippy -p victory-shader --all-targets -- -D warnings still passed with it. No instruction name is handled in two places. Marvisak#98 is not in this version: an offline measurement on a retail dump showed it loses 31 programs that validate on Marvisak#1402. cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features, is clean and cargo test --workspace --locked passes (381 passed, 6 ignored; main has 342 passed, 6 ignored). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…v_sad_u32 and v_msad_u8
Stacked on #156; only the top commit (
5d6889e) belongs here. Rebuilt on #156's new head344704e(mainffe310e); the change is the same as318082f. It needs #156'slowers_valutest helper. I will rebase this ontomainwhen #156 lands.The five sum-of-absolute-differences instructions, which the emitter refuses by name, now translate. The top commit adds 48 lines to
crates/victory-shader/src/emit/lower.rs: 38 of lowering and a 10-line test.What is in it
One arm in
Lower::integer, next to the 24-bit multiply-adds:v_sad_u8: src2 + the sum over the four bytes of |a − b|, unsigned, wrapping at 32 bits.v_sad_hi_u8: (that byte sum << 16) + src2.v_sad_u16: src2 + the sum over the two halves.v_sad_u32: |a − b| + src2 on the whole dwords.v_msad_u8: asv_sad_u8, leaving out a byte whose mask byte (src1) is 0.|a − b| is the larger minus the smaller (an unsigned compare and two selects), so nothing wraps inside a part.
A test,
sums_of_absolute_differences_lower, lowers all five (VOP3 0x15A to 0x15D and 0x171).Tested
macOS 27 arm64, Rust 1.98.1, debug, no GPU and no game files:
cargo test -p victory-shader: 98 passed, 0 failed, 1 ignored (97 on Shaders: lower v_mul_hi_u32_u24 and v_mul_hi_i32_i24 #156's head, plus the new test).cargo fmt -p victory-shader -- --check: no diff in the lines this PR adds.cargo clippy -p victory-shader --all-targets --locked -- -D warningsstops on two unused imports inemit/mod.rson macOS, onmainas well, so clippy as CI runs it was not checked here.cargo xtask policy: 154 files ok.Checked on hardware by others (see the comments)
v_msad_u8skipping a byte whose src1 byte is 0 (the src0 reading matches only 443 of 900).cargo test -p victory-shaderon Arch Linux, 58 passed.These are measurements of the instruction rules on hardware, not runs of this PR's emitted DXIL.
Not tested (by me)
v_msad_u8's mask (a zero byte in src1 is skipped) is the one I would most like checked on hardware.No game data: the test input is hand-written instruction words.
AI-assisted: yes (Claude Code).
🤖 Generated with Claude Code