Repository navigation
Conversation
…visak#823) `write_half` took `dst_sel` WORD_0 with `dst_unused` UNUSED_SEXT (1) as UNUSED_PAD, so a negative 16-bit result came out zero-extended (v_cvt_i16_f16_sdwa of -1.0 gave 0x0000ffff, not 0xffffffff). The 32-bit path, `place_bits`, already sign-extends for `unused == 1`; the 16-bit path now does the same shift. Reserved `dst_unused` 3 on WORD_0 or WORD_1 is refused instead of being read as UNUSED_PAD. Ported from AndyLatimer's fork branch fix/shader-sdwa-word0-sext (24011cf), rebased onto current main: tests moved past the ones main added since. Co-authored-by: Manuel Pérez <manuelperezardanuy@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated triage for the maintainers. Merge candidate. This fixes #823. On CI: Generated by Claude Code |
Dukestar69
left a comment
There was a problem hiding this comment.
Verified on RTX 5090 & WARP against origin/main (63bcca4):
cargo test -p victory-shader --lib sdwa_16bit_ -- --test-threads=1: 2/2 passed on RTX 5090 and WARP (sdwa_16bit_reserved_dst_unused_is_refusedandsdwa_16bit_dst_unused_sext_sign_extends_word0).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Cleanly sign-extends SDWA WORD_0 results when UNUSED_SEXT is set and refuses reserved dst_unused encodings.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal
left a comment
There was a problem hiding this comment.
In Lower::write_half, (x << 16) >>a 16 for (4, 1) (WORD_0 + UNUSED_SEXT) discards any stale upper bits and sign-extends bit 15, matching place_bits. The remaining WORD_0/WORD_1 modes (PAD/PRESERVE/reserved dst_unused = 3) and valu_tests.rs assertions (with 0xABCD_1234 pre-seed distinguishing sext/pad/preserve across v_cvt_i16_f16_sdwa, v_cvt_norm_i16_f16_sdwa, and v_add_f16_sdwa) are sound, and emit/lower.rs is 521,941 bytes (within the 512 KiB limit).
One question: (4, 0) | (6, _) still accepts reserved dst_unused = 3 when dst_sel == 6 (DWORD), matching write/sdwa_dst (dst_sel >= 6), whereas WORD_0 and WORD_1 now reject 3 as tested in sdwa_16bit_reserved_dst_unused_is_refused. Could you clarify whether DWORD intentionally ignores dst_unused = 3 (since DWORD writes the full 32-bit destination) or should reject it as well?
Verified locally on Windows 11 x64 (RTX 5090 + WARP + dxil.dll, ac958c93):
cargo run --locked -p xtask -- policy: passed (191 files ok)cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default and--all-features): cleanemit::lower::tests: 34 passed, 0 failedsdwa_16bit_ -- --test-threads=1(RTX 5090 andVICTORY_WARP=1): 2 passed, 0 failed on both
Fixes #823
What
Lower::write_half(crates/victory-shader/src/emit/lower.rs) matched SDWA destinations of 16-bit VALU operations as(4 | 6, _) => keep = false, sodst_selWORD_0 withdst_unusedUNUSED_SEXT (1) zero-filled bits 31:16 instead of copying bit 15 into them.v_cvt_i16_f16_sdwa v0, v1 dst_sel:WORD_0 dst_unused:UNUSED_SEXTof -1.0 gave0x0000ffff, not0xffffffff. The 32-bit path,place_bits, already sign-extends forunused == 1. Now:(4, 1)sign-extends the low word ((x << 16) >>a 16), the same shiftplace_bitsuses.dst_unused3 on WORD_0/WORD_1 is refused instead of being read as PAD. llvm-mc rejects that encoding.This is AndyLatimer's fork branch
fix/shader-sdwa-word0-sext(24011cf) from the issue, rebased onto currentmain. He is credited as co-author. The only conflict was the two test files, wheremainhad added tests at the same place. #1285 touches the same match, but it also rewrites the 16-bit source reads and inline constants. It has conflicted withmainsince 2026-11-25. This PR is only the destination fix.Tests
emit::lower::tests::sdwa_16bit_reserved_dst_unused_is_refusedneeds no GPU (lowering only). Fails onmain, because the reserved encoding is accepted. Passes with the fix.emit::valu_tests::sdwa_16bit_dst_unused_sext_sign_extends_word0(hardware + WARP throughrun_cases) checksv_cvt_i16_f16_sdwa,v_cvt_norm_i16_f16_sdwa(src0 WORD_1) andv_add_f16_sdwawith UNUSED_SEXT, plus every other dst_sel/dst_unused mode.cargo test -p victory-shader --lib --lockedon Windows 11 withmain63bcca4:mainmain'swrite_halfheap_direct_texture_reads_mark_their_heap_index, #2571)gathers_at_a_level_match_the_hardware(#2317)hardware: v_cvt_i16_f16_sdwa(0xbc00, WORD_0, UNUSED_SEXT) = 0x0000ffff, want 0xffffffffVICTORY_WARP=1)The new tests pass on all three adapters. No test that passes on
mainfails with this PR.cargo clippy -p victory-shader --all-targets [--all-features] --locked -- -D warnings: clean.rustfmt --checkreports nothing on the changed hunks.Not tested: AMD hardware. Synthetic programs only, no game data.
AI use: Claude Code (Claude Opus 5.5) ported the fork commit, resolved the test-file conflict and ran the tests above on my machine. I reviewed the change.
🤖 Generated with Claude Code