Shaders: an audit of which opcodes lower, and 100 more that do #163
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!163
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/163/head"
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?
@r4tedx on GitHub · 2026-11-24 01:01 UTC · original
r4tedx:shader/opcode-coverage→main· +2089 −139 · 6 files · 2 commits · closed without mergingMeasured on the title's shaders (by a tester)
EduAzevedo ran
victory translate --jobs 8 --listover the retail shaders (v1.0.2.1, 26,148 programs) onmaind2a4baeand on this headce1f138, compared program by program (result): 0 programs gained, 0 programs lost. The only change is the refusal reason of the 4 programs that usev_cvt_f32_f64: they now stop atfloating-point arithmetic in f64 is not implemented by the DXIL emitter.So this PR does not change what translates in this title today. It adds coverage and is tested on synthetic programs only; it can wait behind PRs that unblock programs the title uses.
Rebased onto
main7c8cecb(2026-11-24)#117 (
s_bitcmp*) and #140 (v_cmp_class_f16) merged and conflicted with this branch inemit/lower.rs. As promised under Overlap, this branch now keeps their lowering and drops its own for those six instructions (s_bitcmp{0,1}_b{32,64},v_cmp_class_f16,v_cmpx_class_f16), so it adds 100 instructions instead of 106. This branch's GPU tests for those six still run, now against the merged code, and pass on the RTX 5070. Head6035910; the measurement above was taken on the earlier head.What
One instruction the translator refuses fails its whole shader, and nobody had a list of which instructions those are. Two commits:
1. An audit. For every entry of the opcode table, a test assembles one compute fixture containing that instruction, runs it through
ir::build→resource→io→structure→lower, and records whether it lowers or which pass refuses it and why. The audit runs in a child test process with a per-case timeout, so a panic, stack overflow or hang names its opcode. It found none.cargo test -p victory-shader opcode_coverage_table -- --ignored --nocaptureprints the table grouped by encoding and reason.refused_opcodes(a regular test) compares againstopcode_refusals.txt. An opcode that stops lowering fails it. One that starts lowering only makes its line stale and prints a note, so other PRs that lower opcodes need not touch the list.2. 100 more instructions lower (the list goes from 500 to 400 entries on
main7c8cecb):s_absdiff_i32,s_bcnt0_i32_b{32,64},s_bfe_{i,u}64,s_bfm_b64,s_bitreplicate_b64_b32,s_bitset{0,1}_b64,s_brev_b64,s_ff0_i32_b{32,64},s_flbit_i32_{b64,i64},s_pack_{ll,lh,hh}_b32_b16,s_sext_i32_i{8,16}.v_mul_hi_{i32_i24,u32_u24},v_mad_{i16,u16,i32_i16,u32_u16,i64_i32,u64_u32},v_{min3,max3,med3}_{i16,u16},v_sad_{u8,hi_u8,u16,u32},v_msad_u8,v_qsad_pk_u16_u8,v_mqsad_pk_u16_u8,v_mqsad_u32_u8,v_lerp_u8.v_dot2_{i32_i16,u32_u16},v_dot4_{i32_i8,u32_u8},v_dot4c_i32_i8,v_dot8_u32_u4,v_cvt_off_f32_i4,v_cvt_pk_{i16_i32,u16_u32},v_sat_pk_u8_i16.frexpmantissa and exponent for f16/f32/f64, class compares for f64, the 16 f64 comparison predicates, and the always-false/true i64/u64 compares (v_cmpandv_cmpx), all on IEEE bits so NaNs, signed zeros and denormals survive.Left refused with a reason, because rounding, exceptional values or carries could differ from the hardware:
ldexp, the normalized conversions, half FMA and half dot products,v_mullit_f32, general f64 arithmetic.Not verified
No game files were used. Semantics are from AMD's RDNA 2 ISA reference and LLVM's AMDGPU backend; the GPU tests compare against CPU references written from the same documents, so they catch translation mistakes, not a misreading of the documents.
Overlap
s_bitcmp*,s_sext_*), #120 (s_absdiff_i32,s_sext_*,s_pack_*), #140 (v_cmp_class_f16), #148 and #165 (s_bcnt0_*,s_ff0_*,s_flbit_*64), #156, #157 and #162 (v_mul_hi_*24), #157 (v_cvt_pk_*, integer dots), #162 (v_sad_*,v_msad_u8), #166 (s_bitset*_b64,s_brev_b64,s_bitreplicate_b64_b32), #171 (v_mad_{u64_u32,i64_i32}). I compared each diff with this branch: the results agree except the carry-out ofv_mad_i64_i32(#171 computes signed overflow, this branch bit 64 of the 65-bit result); see the comment below.emit/lower.rs; #465 lowersv_dot2_f32_f16andv_dot2c_f32_f16, which stay refused here; #499 lowersv_sat_pk_u8_i16, also lowered here (not compared). #168 changes the SCC ofs_min,s_maxands_lshl1-4_add_u32; it merges cleanly into this branch and its version should win.s_cmov*) and #92 (v_add_nc_i32,v_sub_nc_i32,v_mul_lo_i32, signed 16-bit add/sub) are deliberately not included and stay on the list.Tested
Windows 11, NVIDIA RTX 5070, synthetic only:
dxil.dllvalidation).cargo test -p victory-shaderat6035910: 89 passed, 3 ignored. The audit test takes about 40 s.cargo clippy -p victory-shader --all-targets: nothing new.cargo xtask policy: ok.The title was not used in these tests. AI-assisted.
🤖 Generated with Claude Code
@DaviTostes on GitHub · 2026-11-24 01:18 UTC · original
Tested
ce1f138on Arch Linux x86_64, rustc 1.98.1: pass.cargo test -p victory-shader: 57 passed, 0 failed, 2 ignored (2 test binaries), including the 14 tests this PR adds.emit::opcode_audit::audit_workerandopcode_coverage_table(the audit helpers).victory-gpuE0425.No game data used.
@DaviTostes on GitHub · 2026-11-24 01:19 UTC · original
Coordination note after testing the queue: this branch already lowers instructions that other open PRs cover, in
lower.rs:v_sad_*/v_msad_u8— also #162;s_bcnt0_i32_*/s_ff0_i32_*— also #165;s_bitset*_b64/s_brev_b64— also #166.The branch passes on Linux (
cargo test -p victory-shader: 57 passed, 2 ignored — the audit helpers), including its 14 new tests. Could you state in the PR which of those it supersedes, so the coordinator can close the redundant ones instead of reviewers checking each separately? It does not touchv_mad_u64(#171),tbuffer_load_format_d16(#169) or image atomics (#173), so those remain separate.No game data used.
@r4tedx on GitHub · 2026-11-24 01:24 UTC · original
Thanks for testing, and for the coordination note. I went through the open single-opcode PRs and compared each diff with this branch. Of the 106 instructions here, 38 are also in another open PR and 68 are only here.
s_bitcmp{0,1}_b{32,64}; #142 alsos_sext_i32_i{8,16}s_absdiff_i32,s_sext_i32_i{8,16},s_pack_{ll,lh,hh}_b32_b16v_cmp_class_f16,v_cmpx_class_f16s_bcnt0_i32_b{32,64},s_ff0_i32_b{32,64}; #148 alsos_flbit_i32_{b64,i64}v_mul_hi_{u32_u24,i32_i24}v_cvt_pk_{u16_u32,i16_i32},v_dot2_{i32_i16,u32_u16},v_dot4_{i32_i8,u32_u8},v_dot8_u32_u4v_ldexp_f32, which this branch leaves refusedv_sad_{u8,hi_u8,u16,u32},v_msad_u8s_bitset{0,1}_b64,s_brev_b64,s_bitreplicate_b64_b32v_mad_u64_u32,v_mad_i64_i32So this branch does cover #171 too (the note above lists it as separate). #169 and #173 are indeed untouched.
One real disagreement, with #171 on the carry-out of
v_mad_i64_i32. This branch takes the ISA's{carry, D}as the 65-bit sign-extended result, so the carry is bit 64 (unsigned carry out of bit 63, xor the two operands' signs). #171 computes signed overflow of the 64-bit add. They differ whenever both addends are negative without overflowing, e.g.(-1) * 1 + (-1): bit 64 is 1, signed overflow is 0. I have not checked this on hardware, so one of the two is wrong and whoever has a console reference could settle it with that input. The 64-bit result itself is the same in both.I would rather not call any of those PRs redundant myself, since that is the maintainers' call and the small ones are easier to review. Either order works for me:
No game data used.
@Sunkiller-qc on GitHub · 2026-11-24 01:29 UTC · original
The audit is useful. A few overlaps beyond the ones listed in the description, from PRs opened since: #165 (
s_bcnt0/s_ff0), #166 (s_bitset*_b64,s_brev_b64,s_bitreplicate_b64_b32), #171 (v_mad_u64_u32/v_mad_i64_i32), #162 (v_sad*,v_msad_u8) and #157 (24-bitmul_hi,cvt_pk,dot,ldexp). Onv_mad_i64_i32,wide_mad(lower.rs:5043) matches the ISA's 65-bit definition of the carry and #171 doesn't, so I'd keep this one there.Separately, #168 fixes SCC for
s_min/s_maxands_lshl1-4_add_u32. Main sets it to "result != 0", and this branch keeps that (lower.rs:2782-2797). If #168 lands first, the rebase should keep its version.Static review, not built or run.
@r4tedx on GitHub · 2026-11-24 01:42 UTC · original
Follow-up on the
v_mad_i64_i32carry: I looked it up in AMD's ISA references, and this branch's reading holds.V_MAD_I64_I32:{ D1.i1, D0.i64 } = 65'B(65'I(S0.i) * 65'I(S1.i) + 65'I(S2.i64)), and forV_MAD_U64_U32:{ D1.u1, D0.u64 } = 65'B(65'U(S0.u) * 65'U(S1.u) + 65'U(S2.u64)).{vcc_out,D.i64} = S0.i32 * S1.i32 + S2.i64.So the flag is bit 64 of the sum of the operands widened to 65 bits (sign-extended in the signed form), not signed overflow of the 64-bit add. For
(-1) * 1 + (-1)that is 1. I left a note on #171.While checking the other overlaps against the same documents I also found a mistake of my own in #160 (a16 does not make derivatives 16-bit on GFX10.3) and fixed it there. Nothing else in this PR changed.
No game data used.
@r4tedx on GitHub · 2026-11-24 05:54 UTC · original
@Sunkiller-qc a late answer to your second point: agreed. A trial merge (
git merge-tree) of #168's headae8967cinto this branch (ce1f138) is clean, so its SCC fors_min,s_maxands_lshl1-4_add_u32comes through whichever lands first, and I will check those lines when I rebase.Three more overlaps from PRs opened since, now in the description:
emit/lower.rs.v_dot2_f32_f16andv_dot2c_f32_f16, which this PR leaves refused. No conflict.v_sat_pk_u8_i16, which this PR lowers too. The trial merge is clean textually; I have not compared the two lowerings.Trial merges only; nothing was built or run for this note. AI-assisted.
Pull request closed