Shaders: VOP3 forms of VOP1 and VOP2 16-bit operations ignore op_sel #3364
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3364
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3364"
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?
@Lyrnc on GitHub · 2026-11-26 20:36 UTC · original
Lyrnc:fix/vop3-promoted-16bit-opsel→main· +80 −8 · 2 files · 1 commits · openWhat was wrong
On RDNA2, the VOP3
op_selbits do nothing on a VOP1 or VOP2 opcode in its VOP3 form. Each source is read from its low half. The result goes to the low half of the destination, and the high half is kept. Only the VOP3-only 16-bit opcodes use the bits.half_src,write_halfand thev_fmac_f16accumulator honourop_selfor every 16-bit operation, so the VOP3 forms of the VOP1 and VOP2 ones read and write the wrong half.Examples on gfx1036. Each register holds two different halves (v1 =
0xbe05_43e7, v2 =0x4f2f_2804), and v0 starts as0xa9f1_cf51:v_add_f16_e64 v0, v1, v2 op_sel:[1,0,0]0xa9f1_43f7(low + low)0xa9f1_bde5(high half of v1)v_add_f16_e64 v0, v1, v2 op_sel:[0,0,1](destination high)0xa9f1_43f70x43f7_cf51v_cvt_u16_f16_e64 v0, v1 op_sel:[0,1]0xa9f1_00030x0003_cf51It is the same with
v_cvt_u16_f16andv_cvt_i16_f16, the conversions between f16 and 16-bit integers or f32, and withv_rcp_f16,v_sqrt_f16,v_floor_f16,v_fract_f16,v_cvt_norm_i16_f16,v_add_f16,v_mul_f16,v_max_f16andv_fmac_f16. On all of them, every op_sel value gives the result that op_sel 0 gives, on all 64 rows. The VOP3-onlyv_fma_f16,v_med3_f16,v_add_nc_u16,v_mul_lo_u16,v_max_u16andv_lshlrev_b16do use the bits, and main already matches them.What changed
half_opsel(inst)returns the op_sel bits that pick halves. It is 0 for VOP3 opcodes 0x100..0x13f (VOP2) and 0x180..0x1ff (VOP1), andv.opselotherwise.half_src,write_halfand thev_fmac_f16accumulator read it in place ofv.opsel. Compares (VOPC) and the VOP3P paths are unchanged.Tests
valu_tests::vop3_forms_of_vop1_and_vop2_16bit_ops_ignore_op_sel. It covers 15 VOP1/VOP2 operations with up to four op_sel values each, plus VOP3-only controls (v_fma_f16,v_add_nc_u16). The rows and results were measured on gfx1036 with the same instruction words.hardware: v_cvt_f16_u16 op_sel 0b0001.run_cases, and passes.cargo test -p victory-shader --lib, lib tests (cargo test -p victory-shader --lib -- --test-threads=1 --skip heap_direct_texture_reads_mark_their_heap_index; that test crashes the process on main too): 297 passed, 5 failed, 3 ignored. main63bcca4on this machine: 296 passed and the same 5 failed (rect::tests::rectangles_get_their_fourth_corner,stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,synthetic_tests::gathers_at_a_level_match_the_hardware,tests::elements_sharing_a_row_keep_their_order).cargo clippy -p victory-shader --lib --tests -- -D warnings: clean.cargo xtask policy: ok (191 files).Hardware comparison
A probe runs the same instruction words through the hw oracle on gfx1036 (one row per lane) and through the translator (a local
build_valu_csharness, a local adapter-name filter inhardware_adapter). The comparison covers 22 16-bit opcodes, 64 rows each, with op_sel 0 and three or seven other values, for 8,448 results.These counts leave out
v_mad_u16: main refuses it, so its 512 results are not compared."NaN payload only" means both results are NaN with different payloads. These are the signalling NaN that
v_fmac_f16quietens, and, on the 5080, the host's NaN fromv_sqrt_f16of a negative number. Both are the same at op_sel 0.Related
v_cvt_{u16,i16}_f16): independent.lower.rsmerges cleanly.valu_tests.rsconflicts only because both PRs add a test at the end of the file; keep both tests.half_src, so whichever lands second needs a small rebase.half_opselcould take the compares too.Not tested
v_ldexp_f16andv_cvt_pkrtz-style 32-bit-source VOP2 ops in VOP3 form. Main refuses the first. The second has no 16-bit source.v_cmp_class_f16and the other compares (see #926).AI use
Claude Code (Claude Opus 5.5) wrote the probes, the fix and the test, and ran them on the GPUs above. The numbers come from those runs. No game data was used.
🤖 Generated with Claude Code
@fuzeofficlal on GitHub · 2026-11-26 20:48 UTC · original · approved these changes
LGTM —
half_opsel(Encoding::Vop3with opcodes0x100..0x140 | 0x180..0x200) cleanly masks outop_selacross all 27 promoted VOP1/VOP2 16-bit instructions reachinghalf_src,write_half, and thev_fmac_f16accumulator while leaving VOP3-only ops, SDWA (Encoding::Vop1/Vop2), VOP3P, and VOPC intact.Verified
crates/victory-shader/src/emit/lower.rssize: 521,548 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 inlower.rsandvalu_tests.rs.emit::valu_tests::vop3_forms_of_vop1_and_vop2_16bit_ops_ignore_op_sel(RTX 5090 + WARP): passed;emit::lower: 33 passed, 0 failed.Minor non-blocking note
v_sub_f16,v_subrev_f16,v_min_f16,v_rsq_f16,v_log_f16,v_exp_f16,v_ceil_f16,v_trunc_f16,v_rndne_f16,v_sin_f16,v_cos_f16,v_cvt_norm_u16_f16) share the exact samehalf_opselrouting without dedicated rows.@Dukestar69 on GitHub · 2026-11-26 20:51 UTC · original · approved these changes
LGTM — verified on RTX 5090 and
VICTORY_WARP=1(Windows / D3D12) againstorigin/main(63bcca4).op_selon VOP3-encoded forms of VOP1 and VOP2 16-bit operations matches GFX10/RDNA2 ISA semantics cleanly on both RTX 5090 and WARP.cargo test -p victory-shader --lib emit::valu_tests::vop3_forms_of_vop1_and_vop2_16bit_ops_ignore_op_sel -- --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).
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 21:12 UTC · original
I combined
55d58e0with the published #2623/#3192 resolution ind7e90f3. The new regression usesv_fmac_f16_e64with distinct register halves, four accumulator modifier combinations, and fiveop_selpatterns. It checks the low-half result and the untouched upper half, including signed subnormals on either side of the minimum normal. Your gfx1036 measurements fit the LLVM GFX1030 operand table, which listsop_selforv_fma_f16and omits it forv_fmac_f16_e64.The #2623/#3192 control matches all 16 cases with
op_sel=0and differs in all 64 with nonzero bits. With #3364 integrated, all 80 match on app-local WARP. The exact final tree passes 112 VALU, semantics and lowering tests, with one ignored. Both strict Clippy configurations pass. The combinedlower.rsfirst exceeded the asset limit by 61 bytes, so the same half selection rule now lives on the decoded IR instruction.lower.rsis 523,424 bytes and the asset policy check passes.@Lyrnc, if you take the regression or the integration fix, please keep the Git author or use
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.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.