fix: share SDWA/DPP operand types between interpreter and HLSL #215
No reviewers
Labels
No labels
accessibility
bloqué : binaire console
bug
chargeur
console-dll
cpu
documentation
duplicate
enhancement
good first issue
gpu
help wanted
invalid
performance
question
runtime-gdk
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LooperSalty--AnyXboxX!215
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/215/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?
@KainanP on GitHub · 2026-11-25 16:02 UTC · original
KainanP:fix/shared-operand-float-flags→main· +161 −33 · 12 files · 2 commits · merged 2026-11-25 18:10 UTCChange
Since #133, the interpreter (
rdna2_exec_ext.py) and the HLSL recompiler (rdna2_hlsl_ext.py) each had their own_operand_float_flags, and only the interpreter's was updated. This PR keeps one definition,operand_float_flags, inrdna2_exec_ext.py;rdna2_hlsl_ext.pyimports it (the same wayrdna2_hlsl.pyalready importsfloat_result/float_inputsfrom the interpreter for VOP3).The function reads the operand types from the mnemonic. When it names two types, the destination type comes first, as in LLVM's VOP profiles (
v_cvt_flr_i32_f32,v_cvt_off_f32_i4,v_frexp_exp_i32_f32,v_cvt_f32_ubyte0). Otherwise one type covers both. It returns(src_is_f32, dst_is_f32). SDWA applies neg/abs to f32 sources and sext to the others, and omod/clamp to f32 results. DPP16 applies neg/abs to f32 sources.v_cvt_flr_i32_f32,v_cvt_rpi_i32_f32v_cvt_off_f32_i4v_frexp_exp_i32_f32The issue's table lists
v_cvt_off_f32_i4as (False, False) on the HLSL side. The HLSL code actually returned (True, False), because it readparts[3] = "f32"as the source type. That difference doesn't show in the result: neg/abs only touch bit 31, sext only touches bits above the selected byte, and the conversion reads bits 3:0. The destination flag is what showed.The new function gives the interpreter's old answer for every VOP1/VOP2/VOPC mnemonic in
rdna2_ops.py(319 names, checked by script). It differs from the old HLSL copy only on the four instructions above and onv_cvt_pkrtz_f16_f32, which neither back end implements yet.One behaviour change on both sides: SDWA omod on an integer result is now refused by name, the same way SDWA clamp already was ("SDWA clamp/omod not supported on an integer result"). Before, the interpreter ignored it and the HLSL applied it to
v_frexp_exp_i32_f32. LLVM only encodes SDWA omod when the destination is a float (HasSDWAOMod), and what hardware does with it on an integer result has not been measured. Under rule 3 the instruction is refused instead of guessing.Linked issue: Fixes #205
Verification
The runtime was built from this branch with VS 2022 Build Tools CMake (
cmake -S runtime -B runtime/build -A x64,cmake --build runtime/build --config Release). Laptop with three adapters:Why tests were skipped: 15 need the Rust crates or the TomBox DLLs, which this PR doesn't touch and which weren't built here. 2 need
spirv-as/spirv-val. On Intel, 2 more are FP64 tests.Same GPU tests with
rdna2_exec_ext.pyandrdna2_hlsl_ext.pyreverted tomain(the new test file kept), on each of RTX, WARP and Intel:3 failed, 1 passed.[flr_rpi_neg_abs]: the output memory differs, because the HLSL drops neg/abs.[cvt_off_omod_sext]: the output memory differs, because the HLSL drops omod.[cvt_off_clamp]:Untranslatable: SDWA clamp ... v_cvt_off_f32_i4.[frexp_exp_neg_abs]passes onmain, as expected: both sides already applied neg/abs to its f32 source, and its divergence was on the destination. That divergence is covered by the refusal test below.Oracle and test data
New file
tests/test_rdna2_sdwa_dpp_types.py(23 tests). It builds its programs from the existing encoders (vop1,sdwa_word,dpp16_word,run_wave,compare,store_lane), so it adds no external data.test_sdwa_and_dpp16_type_modifiers_match_interpreter_on_gpu[...](4 groups) is the byte-for-byte interpreter/HLSL comparison (rule 4) on GPU or WARP. The groups cover: SDWA neg, abs and neg+abs, and DPP16quad_perm:[1,0,3,2]neg/abs, on flr/rpi with 16 f32 inputs per lane (±halves, −0.0, 1e10 saturation, 1e-3); SDWA neg+abs and DPP16 neg onv_frexp_exp_i32_f32; SDWA omod ×2 and ×0.5 withBYTE_1+ sext, and clamp, onv_cvt_off_f32_i4. 4 → 3 fail onmain(see above).test_sdwa_output_modifiers_on_an_integer_result_are_refused_by_name(4 cases): clamp or omod on the i32 results ofv_frexp_exp_i32_f32,v_cvt_flr_i32_f32andv_cvt_rpi_i32_f32must be refused by name in both back ends. 3 of 4 fail onmain; the rpi + clamp case was already refused by both.floor(-2.5) = -3,floor(-|2.5| + 0.5) = -2,7/16 × 2 = 0.875,clamp(-1/16) = 0,-1/16 × 0.5 = -0.03125. These already passed onmain, because the interpreter was right.test_operand_types_follow_the_mnemonic(12 names) andtest_interpreter_and_hlsl_share_one_definitionfail onmain, because the shared function doesn't exist there.The suite crosses 1,200 tests, so the 9 READMEs go from
1100+to1200+.Out of scope
Both back ends treat these the same way, so there is no parity bug, but they may be wrong compared with hardware or LLVM:
v_cmp_class_f32/v_cmpx_class_f32in SDWA: src1 is the i32 class mask. LLVM gives it sext (Int32SDWAInputMods), but both back ends treat it as f32 (neg/abs, no sext). The interpreter has no SDWA table entry for class compares (VECTOR_COMPARE), so only the HLSL would translate it today.v_cvt_f32_f16,v_*_f16): neg/abs should act on bit 15, but both back ends treat these sources as integers and ignore neg/abs. Most of these instructions aren't implemented in either back end yet.Checklist
E_NOTIMPL), never a fake success.test_readme_sync.pychecks it).AGENTS.mdallows (names, slots, argument shapes, flag values, HRESULTs, IIDs, counts), with how they were obtained; no address or RVA.THIRD_PARTY.md. (None taken.)AI use: written with Claude Code (Claude Opus 5.5). I reviewed and ran it on the three adapters above.
🤖 Generated with Claude Code