Shaders: abs / neg on the shift-add and align ops act on the sign bit #2018
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2020"
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 Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T03:16:10Z.
VOP3
absandnegonv_lshl_add_u32,v_add_lshl_u32,v_alignbit_b32andv_alignbyte_b32stopped translation with "integer operand modifiers". RDNA2 applies them to a source's bit 31, as for a float:absclears it andnegflips it. There is no integer negate or absolute value.Sources: boykopovar/AnyPS5#25964 measured every
abs/negcombination on the two shift-adds on gfx1036 (RDNA2) and gfx1201 (RDNA4), 196/196 words matching on each. boykopovar/AnyPS5#25799 measured the align ops on gfx1036: on src1 the bit reaches the result, and on src0 and the shift amount it can't change it. xcl-dev/xcl#2058 is the same fix in XCL, where the modifiers were silently dropped.What is in it
emit/lower.rs,src: for those four opcodes,absandnegbecomex & 0x7fffffffandx ^ 0x80000000on the source. Every other integer operation still returns "integer operand modifiers" when it has them, since only these four are measured.emit/valu_tests.rs:shift_add_and_align_take_sign_bit_modifierscovers neg on src2 ofv_lshl_add_u32, abs on src0 ofv_add_lshl_u32, and neg and abs on src1 of both align ops. Each case is built so the modifier can't be shifted out.Tested on Windows 11, RTX 3070 (Ampere, driver 616.56), debug, on
main940d32f:lower.rschange the build stops withUnsupported { what: "integer operand modifiers" }.cargo test -p victory-shader --locked: 245 passed, 3 failed, 3 ignored. The 3 are #1744's NVIDIA failures onmain.cargo clippy -p victory-shader --all-targets --locked -- -D warningsandcargo xtask policy: pass.Not tested: AMD hardware, a title.
AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:34:32Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.144 passed / 0 failed. abs/neg on shift-add and align ops act on the sign bit — ALU semantics fix for the packed shift-add path.
Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T03:33:30Z.
Triage verdict — Ready for maintainer decision; one useful test addition (
ea7dff7)Evidence
srclimits the sign-bit handling to the four measured opcodes. For those, it clears bit 31 before flipping it, consistent with the published shift-add and align measurements. Other integer opcodes still reject these modifiers.Checks and limits
Next step
This verification was AI-assisted.
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T03:39:34Z.
Added the combined case in
eed34ee. Two rows now set ABS and NEG on the same source:v_add_lshl_u32with-|src0|andv_lshl_add_u32with-|src2|on0x8000_0001. Both must give bit 31 set. With the two operations swapped locally (neg, then abs), the first row fails on hardware (0x00000004, want0x80000004), so the order is pinned now. RTX 3070 (616.56): the test passes, andvictory-shadergives 245 passed with only #1744's 3 NVIDIA failures, the same asmain.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T03:42:55Z.
Verified on Windows 10 19045 (RX 7800 XT), head
eed34eeplus the device-skip patch from #1991 (this host has no SM 6.6 device, so the probes would otherwise fail for an unrelated reason):cargo test -p victory-shader --lib— 248 passed, 0 failed, 3 ignored, includingabs and neg together on one shift-add source give -|x|.On the semantics: treating
absas clearing bit 31 andnegas flipping it is the right model for these four ops if the hardware does them as sign-bit operations rather than two's complement — and the order (abs then neg, so both set gives -|x|) matches the float convention the comment cites. Restricting it to the four names and keeping the refusal for the other integer ops is the conservative half, which I would keep.The GPU-valued cases skip here and run in CI; no unrelated failure in the suite on this tree.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:18:26Z.
Automated triage for the maintainers.
Merge candidate. Recommending a look, not approving.
emit/lower.rssrc, VOP3abs/negonv_lshl_add_u32,v_add_lshl_u32,v_alignbit_b32andv_alignbyte_b32now clear bit 31 (abs) and then flip it (neg) instead of stopping translation. Every other integer op still returns "integer operand modifiers". The evidence is cited: per-combination measurements on RDNA2/RDNA4 hardware in another project, linked in the PR.valu_tests.rsshift_add_and_align_take_sign_bit_modifiers, including the two combined abs+neg rows that fix the order of the two operations. Applying the bit operation to the align ops' shift operand is harmless because only its low bits are used.srcin a different way, so whichever lands second needs a small rebase.CI:
checkpassing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T09:50:54Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
eed34eedontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 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).
Imported from Marvisak/VIctory. Originally posted by bvtterbroot on 2026-11-25T18:40:16Z.
AMD check at
eed34ee(base940d32f), on an RDNA3 and an RDNA2 GPU:cargo test -p victory-shader -p victory-gpu --locked: 391 passed, 0 failed, 5 ignored, on both GPUs. That includes its new test (shift_add_and_align_take_sign_bit_modifiers).Synthetic tests only, no game files. Tested with AI assistance (Claude Code).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T18:53:28Z.
Review: APPROVED
Verified
eed34eed1351db4dd0b2fe837168ebc2b126a678cleanly merged ontomain(63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP + Windows SDKdxil.dll):Lower::src(crates/victory-shader/src/emit/lower.rs:2122-2155) cleanly scopes sign-bitabs(& 0x7FFF_FFFF) followed byneg(^ 0x8000_0000) tov_lshl_add_u32,v_add_lshl_u32,v_alignbit_b32, andv_alignbyte_b32, while continuing to reject modifiers on other integer ops.emit/lower.rssize: 521,313 B (under 524,288 B);cargo test -p xtask --locked policy::tests::repository_passes_policy:1 passed(asset policy: 191 files ok).cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features): clean.emit::valu_tests::shift_add_and_align_take_sign_bit_modifiers(1.60sRTX 5090 /0.05sWARP),emit::tests::constant_color_validates, andemit::lower::tests::(33 passed, 0 failed) all pass on both RTX 5090 and WARP.Ready to merge.
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T22:51:17Z.
Review: APPROVED
LGTM — verified on RTX 5090 and
VICTORY_WARP=1(Windows / D3D12) againstorigin/main(63bcca4).abs/negmodifiers on bit 31 for shift-add and align ops matches RDNA2 hardware behavior cleanly on both RTX 5090 and WARP.cargo test -p victory-shader --lib emit::valu_tests::shift_add_and_align_take_sign_bit_modifiers -- --test-threads=1: passed on RTX 5090 andVICTORY_WARP=1.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.