Repository navigation
Conversation
In VOP3 form these two conversions apply the abs and neg source modifiers to their 16-bit integer source as to a sign bit: abs clears bit 15 and neg flips it, before the integer is converted. The lowering ignored both, so v_cvt_f16_u16_e64 v0, -v1 of 0 gave 0 where RDNA2 gives 32768.0 (0x7800), and v_cvt_f16_i16_e64 v0, |v1| of -1 gave -1.0 where RDNA2 gives 32768.0 (0x7fff rounded). Measured on a gfx1036 (RDNA2) iGPU: with abs, neg and both, on 512 input rows each, every result equals the plain conversion of the source with bit 15 cleared, flipped or set; clamp is applied after. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…it 15
The 16-bit integer operations (v_add_nc_u16, v_sub_nc_u16, v_mul_lo_u16,
the 16-bit shifts and min/max) and the u16/i16 compares apply VOP3 abs
and neg the same way as v_cvt_f16_u16/i16: to bit 15 of the source,
which abs clears and neg flips. There is no integer negation: on RDNA2
v_add_nc_u16_e64 v0, -v1, v2 of 0 and 10 is 0x800a, not 10.
The operations refused these modifiers ("modifiers on a 16-bit integer
operation"); the compares ignored them. Both now go through int16_mods,
which v_cvt_f16_u16/i16 use too. clamp and omod stay refused, and so do
abs and neg on the f16 source of v_cvt_u16_f16 / v_cvt_i16_f16.
Measured on a gfx1036 (RDNA2) iGPU: abs, neg and both, on each source of
seven of these operations, give the bit 15 results on all 640 input
rows.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A GPU test for the compare half of the previous commit: v_cmp_lt_u16, v_cmp_lt_i16 and v_cmp_eq_u16 in VOP3 form with neg, abs and both on either source, on eight rows, with the results of a gfx1036 (RDNA2) iGPU. On main the compares ignore the modifiers and the test fails: v_cmp_lt_u16 with neg on src0, of 0 and 10, gives 1 there; the hardware compares 0x8000 with 10 and gives 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dukestar69
approved these changes
Nov 26, 2026
Dukestar69
left a comment
There was a problem hiding this comment.
LGTM — verified on RTX 5090 and VICTORY_WARP=1 (Windows / D3D12) against origin/main (63bcca4).
- Applying
abs(clear bit 15) andneg(toggle bit 15) on 16-bit integer sources acrossv_cvt_f16_{u16,i16}, 16-bit integer ALU ops, and 16-bit integer compares matches RDNA2 hardware behavior cleanly on both RTX 5090 and WARP. cargo test -p victory-shader --lib take_abs_and_neg_on_bit_15 -- --test-threads=1: 3 passed, 0 failed on RTX 5090 and 3 passed, 0 failed onVICTORY_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).
fuzeofficlal
approved these changes
Nov 26, 2026
fuzeofficlal
left a comment
Contributor
There was a problem hiding this comment.
LGTM — int16_mods cleanly applies abs (clear bit 15) before neg (flip bit 15) after half_src's 0xFFFF mask, without affecting float sources or leaking high-half bits.
Verified
crates/victory-shader/src/emit/lower.rs(6837-6856,7077,7127-7155,8028): all 16-bit integer conversions (v_cvt_f16_{u16,i16}), 16-bit integer ops, andu16/i16compares mask to the selected 16 bits viahalf_srcfirst, applyint16_mods, and then sign- or zero-extend, while keepingclamp/omodandv_cvt_{u16,i16}_f16float-source modifiers refused.crates/victory-shader/src/emit/lower.rssize: 521,856 bytes (under the 524,288-byte limit).cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default &--all-features): clean.rustfmt --edition 2024: clean on all PR-touched hunks in bothlower.rsandvalu_tests.rs.emit::valu_tests(RTX 5090 + WARP viarun_cases): 38 passed, 0 failed, including all three new tests (v_cvt_f16_u16_and_i16_take_abs_and_neg_on_bit_15,sixteen_bit_integer_operations_take_abs_and_neg_on_bit_15,sixteen_bit_integer_compares_take_abs_and_neg_on_bit_15).
Minor non-blocking note
- Test coverage focuses on standard low-half VOP3 encodings (
op_sel = 0), leavingop_sel = 1,v_cmpx_*_{u16,i16}, SDWA, and right shifts untested directly (andabson thev_lshlrev_b16shift count only reads bits3:0so a dropped modifier there wouldn't show up in that one row).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
VOP3
absandnegon a 16-bit integer source act on its bit 15, the place of a sign bit:absclears it,negflips it, both set it. There is no integer negate or absolute value.mainhandled this three ways, all different from the hardware:v_cvt_f16_u16andv_cvt_f16_i16ignored the modifiers: the unmodified integer was converted, with no message.v_cmp_*_u16,v_cmp_*_i16) ignored them too.v_add_nc_u16,v_sub_nc_u16,v_mul_lo_u16, the 16-bit shifts, min and max) refused them ("modifiers on a 16-bit integer operation").Examples, v0 =
0x0BAD_F00Dbefore (the high half is kept):mainv_cvt_f16_u16_e64 v0, -v1, v1 =0x0000_00000x0BAD_7800(0x8000 = 32768.0)0x0BAD_0000v_cvt_f16_i16_e64 v0, |v1|, v1 =0x007F_FFFF0x0BAD_7800(0x7fff)0x0BAD_BC00(-1.0)v_cvt_f16_i16_e64 v0, -v1, v1 =0x0000_00010x0BAD_F800(0x8001 = -32767, rounded)0x0BAD_3C00(1.0)v_add_nc_u16_e64 v0, -v1, v2, v1 =0x0000_0000, v2 =0xB8D1_B7170x0BAD_3717(0x8000 + 0xb717)v_max_i16_e64 v0, -v1, v2, v1 =0x0000_0001, v2 =0x477F_EFFF0x0BAD_EFFF(max(-32767, -4097))v_cmp_lt_u16_e64 s20, -v1, v2, v1 =0x0000_0000, v2 =0x0000_000Av_cmp_lt_i16_e64 s20, |v1|, v2, v1 =0x0000_8000, v2 =0x0000_0000This settles the open question of #2374 (closed, "evidence needed"), which lowered
negon these operations as a two's-complement negation: on RDNA2 it is the bit-15 flip that a comment there predicted from the other measured integer forms (-v1 + v2of 0 and 10 is0x800a, of 0x8000 and 0 it is 0).What changed
Lower::int16_mods(inst, k, x)appliesabs/negof sourcekto bit 15 of a 16-bit integer source.v_cvt_f16_u16/v_cvt_f16_i16, the generic 16-bit integer operations and the u16/i16 compares use it, before any sign extension.clampandomodon the 16-bit integer operations, and forabs/negon the f16 source ofv_cvt_u16_f16/v_cvt_i16_f16(Shaders: allow abs/neg source modifiers on v_cvt_{u16,i16}_f16 #2963 lowers those).How it was found and measured
A differential sweep of the translator against RDNA2 hardware, VOP3 conversions and 16-bit operations with every source modifier among the cases:
v_cvt_f16_u16,v_cvt_f16_i16withabs,neg, both, andneg+clamp: 640 of 640 rows each (512 of 512 in a first run).v_add_nc_u16,v_sub_nc_u16,v_mul_lo_u16,v_max_u16,v_min_u16,v_max_i16,v_lshlrev_b16withnegon either source,abson either source, and both on src1: 640 of 640 rows each, where a two's-complement model fails.v_cmp_lt_u16,v_cmp_ge_u16,v_cmp_eq_u16,v_cmp_lt_i16,v_cmp_gt_i16,v_cmp_ne_i16withneg,absand both on either source (36 forms): 640 of 640 rows each.-v1 + v2of 0 and 10 is0x800a, and of 0x8000 and 0 it is 0.semantics_tests::programandlower::lower, on the same Radeon and on an RTX 5080 (driver 610.88). Onmain, the 14 conversion forms and 36 of the 42 compare forms (all but the six without modifiers) differ from the hardware, and the 35 forms of the integer operations are refused. With this change all 85 match on both hosts, and none of the other ~3,600 cases of the sweep (VOP3 with modifiers, VOP3P, LDS, DPP16 and SDWA forms) changes on either host.This is PC RDNA2 silicon, not the console's GPU. No game data was used.
Tests
Three GPU tests in
valu_tests.rs, each on measured rows with the gfx1036 results as the expected values:v_cvt_f16_u16_and_i16_take_abs_and_neg_on_bit_15: both conversions with no modifier,neg,absand both, on 8 rows (low halves 0, 1, 0xffff, 0x8000, 0x8001, 0xfc00, 0x7fff, 0xff, junk in the high halves); the destination's high half is checked too.sixteen_bit_integer_operations_take_abs_and_neg_on_bit_15: 12 operation/modifier forms of 7 operations on 7 rows.sixteen_bit_integer_compares_take_abs_and_neg_on_bit_15:v_cmp_lt_u16,v_cmp_lt_i16andv_cmp_eq_u16with 6 modifier forms on 8 rows, throughv_cndmask_b32.Results:
main's lowering the three tests fail, on the Radeon iGPU and on the RTX 5080:hardware: v_cvt_f16_u16 (abs 0, neg 1) of 0x0000 = 0x0bad0000, want 0x0bad7800;build: Unsupported { offset: 40, what: "modifiers on a 16-bit integer operation" };hardware: v_cmp_lt_u16 (abs 0b00, neg 0b01) of 0x0000, 0x000a = 1, want 0.hardware_adapter, not part of this PR), and on WARP, whichrun_casesruns too.cargo test -p victory-shader --lib -- --test-threads=1(Windows 11, default adapter): 299 passed, 5 failed, 3 ignored.main63bcca4on this machine: 296 passed and the same 5 failed (rect::tests::rectangles_get_their_fourth_corner, twostride_tests,synthetic_tests::gathers_at_a_level_match_the_hardware,tests::elements_sharing_a_row_keep_their_order). Both runs skipmemory_tests::heap_direct_texture_reads_mark_their_heap_index, which ends the test process with an access violation onmainhere as well.cargo clippy -p victory-shader --lib --tests -- -D warnings: clean.cargo xtask policy: 191 files ok. The new code adds norustfmtdifferences (the two files have the samerustfmt --checkoutput as onmain).Related
v_cvt_u16_f16/v_cvt_i16_f16) changes the same refusal line the other way round: it lets the float-source conversions through and keeps refusing the integer ones. With both, onlyclampandomodstay refused (if v.clamp || v.omod != 0); whichever lands second resolves that one line.fix/vop3-promoted-16bit-opsel) editshalf_srcandwrite_half, not the lines here;lower.rsmerges cleanly. Both add tests at the end ofvalu_tests.rs; keep both.Not tested
neg/absbits; the comment on Shaders: 16-bit integer operations take their neg modifiers #2374 cites a gfx1036 measurement of the bit-15 rule for SDWAv_cvt_f16_u16/i16and SDWA u16/i16 compares (feat(shader): accept neg/abs on 16-bit integer DPP and SDWA sources boykopovar/AnyPS5#19592), which I did not repeat.AI use: Claude Code (Claude Opus 5.5) wrote the hardware sweep, found this with it, wrote the change and the tests, and ran everything above.
🤖 Generated with Claude Code