rdna2spirv: route remaining 16-bit high-half readers through u16_half/i16_half (SHADER-HIGH-HALF-SHARED-READERS) #2366
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2366"
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 ubiquitarianism/leonida. Originally posted by ShotTechOp on 2026-11-26T15:46:00Z.
Item ID:
SHADER-HIGH-HALF-SHARED-READERSSummary
Routes all seven remaining 16-bit high-half readers in
tools/rdna2spirv.pythrough the sharedGen.u16_half/Gen.i16_halfhelpers, eliminating every remainingOpBitField{S,U}Extract ... 16 16across the translator (AMD Windows driver 25.10.36 on gfx1036 miscompiles offset-16 width-16 bitfield extracts by taking the offset mod 16 and reading the low half instead of the high half; seedocs/design.md"16-bit high-half reads", #1506 / SHADER-777):Gen.compare(v_cmp(x)_*_{u16,i16}withop_selhigh half)Gen.sdwa_src(src*_sel:WORD_1, both unsigned andsext())v_pk_{add,sub,mul_lo,mad,max,min}_{u16,i16}v_qsad_pk_u16_u8/v_mqsad_pk_u16_u8v_sad_u16v_mad_u32_u16/v_mad_i32_i16image_storewithd16Also adds
Gen.as_uint()alongsideGen.as_int()for clean%int->%uintbitcasts afteri16_half(), updates the "16-bit high-half reads" contract row indocs/design.md, and addstests/semantic/test_high_half_shared_readers.py. Does not touchv_pk_lshlrev/lshrrev/ashrrev_b16(covered separately by #1111).Verification
spirv_mini_interp; no local GPU/Vulkan/spirv-valinstalled)python -I tests/semantic/test_high_half_shared_readers.py -v-> 6/6 OK (structural + bit-exact semantic parity across all 7 families)test_image_cube_store_glc.py,test_image_store_d16.py,test_alu_mad_u16.py,test_alu_sad.py,test_alu_qsad.py,test_valu_int16.py,test_vcmp16_opsel.py,test_mutations.py,test_negative_controls.py-> all OKpython -I tests/test_text_write_line_endings.py-> 3/3 OKpython -m compileall -q tools/rdna2spirv.py tests/semantic/test_high_half_shared_readers.py-> exit 0python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_high_half_shared_readers.py docs/design.md-> exit 0git diff --check-> cleanorigin/main(tools/extracted fromorigin/main):tests/semantic/test_high_half_shared_readers.pyfails 6/6 tests (11 failures across every op family:OpBitField{U,S}Extract %uint ... %c10 %c10emitted at all 7 sites).Imported from ubiquitarianism/leonida. Originally posted by KushGene on 2026-11-26T16:19:42Z.
Independent verification on Linux (Python 3.15.2, CPU semantic interpreter, no game files), tested in a clean detached worktree at
main246791612with PR #2366 headb176c9f5a:git apply --check/git applyapplied cleanly with zero conflicts.main):python3 -I -m unittest discover -s tests/semantic -p test_high_half_shared_readers.py -v-> 6 tests run, 11 failures across all 7 op families (OpBitField{U,S}Extract %uint ... %c10 %c10still emitted).python3 -I -m unittest discover -s tests/semantic -p test_high_half_shared_readers.py -v-> 6/6 passed (Ran 6 tests).python3 -I scripts/run_semantic_tests.py tests/semantic-> 501 files, 6371 tests, 0 files failed in 99 s with 16 jobs.python3 -I tests/test_docs_links.py-> 17/17 passed.python3 -I tests/test_ci_registration.py-> 16/16 passed.python3 -I tests/test_text_write_line_endings.py-> 3/3 passed.python3 -m compileall -q make_game.py tools tests-> exit 0.python3 -I scripts/check_no_game_data.py docs/design.md tests/semantic/test_high_half_shared_readers.py tools/rdna2spirv.py-> exit 0.git diff --check-> clean.Code review notes: all 7 remaining high-half extract sites in
tools/rdna2spirv.pyroute cleanly throughGen.u16_half/Gen.i16_half(withGen.as_uint()added for signed->uint bitcasts), anddocs/design.mddocuments the contract update accurately as CPU-verified. No issues found.AI-assisted: yes (Antigravity)
Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-26T16:23:10Z.
I ran synthetic shaders for all seven changed instruction families through Vulkan on a physical RTX 4090 (Windows 11, NVIDIA 616.64). Readbacks from
b176c9f5aaand its parent2467916120were bit-identical, and both matched the expected values.The compute cases exercised signed and unsigned high-half compares, SDWA
WORD_1with and without sign extension, packed arithmetic, multiply-add, SAD, and both masked and unmasked QSAD. The input high half varied by lane. All 8,064 output words per revision matched, including the signed multiply-add case where selecting the high half of the third operand zero-extends it.For D16 stores I used the project's
vk_store_testwith a scratch readback writer. Each dispatch wrote distinct low and high halfwords to four-channel float, unsigned and signed images. The comparison covered all three 8×8 images, including the untouched rows in wave32. Both revisions preserved negative zero in the float image and correctly extended the high halfwords in the integer images.All 10 generated modules per revision passed
spirv-val --target-env vulkan1.2. Every parent module contained an offset-16, width-16 bitfield extract and none of the PR modules did. This provides NVIDIA regression coverage. Reproducing the original AMD driver behavior still requires a gfx1036 Vulkan run.Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T18:02:08Z.
Review: COMMENTED
Windows 11: all 6 targeted high-half semantic tests passed, including the new shared-reader coverage. No findings.
AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by wavehs on 2026-11-26T18:13:54Z.
Review: COMMENTED
macOS arm64 check of #2366 (SHADER-HIGH-HALF-SHARED-READERS). The whole change is the translator plus one semantic test, so it runs fully here; the GPU part is MoltenVK/KosmicKrisp, not the gfx1036 the rule is about.
Tested head
b176c9f5amerged ontomainbdbc7e923as merge1f6268c23(clean;git merge-treeclean too, the branch is 17 commits behind).Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, CPython 3.15.2, SPIRV-Tools v2026.4, llvm-mc 23.1.5, MoltenVK 1.4.0; KosmicKrisp and lavapipe = Mesa 26.3.0.
The new test passes, and its control bites
python -I tests/semantic/test_high_half_shared_readers.py:Ran 6 tests ... OKat the head and after merging ontobdbc7e923.tools/rdna2spirv.pyput back tomain's):FAILED (failures=11)covering all six test methods. Every failure is the structural assert -OpBitFieldUExtract %uint %t1 %c10 %c10still emitted - and none is a valueassertEqual, which is the useful part: onspirv_mini_interpthe old and new modules evaluate to the same values, so this is a lowering change, asdocs/design.mdrow:532says, not a value change.test_image_cube_store_glc.py(OK, skipped=1),test_image_store_d16.py,test_alu_mad_u16.py,test_alu_sad.py,test_alu_qsad.py,test_valu_int16.py,test_vcmp16_opsel.py,test_mutations.py,test_negative_controls.py, plustests/test_pk16_diff.py.tests/test_u16_high_half.pyneeds pytest, which the system interpreter here does not have; I did not set up the venv for it, so it is unrun.No regressions
mainbdbc7e923; 501 files / 6,373 tests / 0 files failed at the merge (+1 file, +6 tests = the new file).mainand the merge; the PASS/FAIL/SKIP lines are identical once the per-run temp directory is normalised. The 3/5 failures are the pre-existingmainones (cs_fma_fused,cs_imgatomic_ext,ps_ssharpon MV;cs_bvh,cs_bvh32,cs_imgatomic_ext,ps_cndmask_sign_mods,ps_valu16_mad_selon KK). This is a driver check that the lowering keeps the values, not a check of the 25.10.36 gfx1036 miscompile.Findings
runtime/test/shadersexercises onlyv_mad_u32_u16/v_mad_i32_i16(ps_valu16_mad.asm,ps_valu16_mad_sel.asm,cs_w32_misc_ext.asm), SDWAWORD_1(ps_sdwa_dword_hi.asm),v_pk_mul_lo_u16with a constant (cs_pk_mul_lo_const.asm), and a bufferd16store (cs_fmt_d16_xyz.asm, not theimage_store ... d16path). There is no fixture forv_cmp(x)_*_{u16,i16}withop_sel,v_sad_u16,v_qsad_pk_u16_u8/v_mqsad_pk_u16_u8,v_pk_{add,sub,min,max,mad}_{u16,i16}, orimage_store ... d16. A smallps_/cs_fixture for sad+qsad and one value-checkingimage_store d16would make the rule measurable on any GPU, instead of only on the CPU interpreter.spirv-val:translate_ps/translate_cscallrdna2spirv.translate()and inspect the text. Theimage_store d16case asserts only the absence of the extract and the two shift opcodes, with no value check (test_image_store_d16_uses_shared_high_half_shifts). A%int/%uinttype slip in that store path would pass it. The existingtests/semantic/test_image_store_d16.pydoes validate and passes, so the path is covered today, but routing the new cases through a validating helper (or asserting the operand types) would make the new test self-contained.tools/rdna2spirv.py:11573(%c10 %c7, a wave control word) and:4278(%c10 %c14, a stride). The measured 25.10.36 report and this row are width-16 only, so that is consistent; if the driver's offset-mod-16 behaviour is not width-specific, the row should say so, because those sites are outside this rule.python -I scripts/check_no_game_data.pyon the three changed files: clean.git diff --check: clean.No game files. AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:46:52Z.
Review: APPROVED
Approving
b176c9f5a.The remaining readers of a 16-bit high half (the SDWA and op_sel compares, the 16-bit field reads, the packed accumulator, the
v_*_u16/i16pair ops and the FSPX f16 reads) now go throughu16_half/i16_halflike the others, with one newas_uintbitcast where a signed half feeds a uint slot; there is one definition of each helper in the merged file, so nothing shadows another.test_high_half_shared_readers.py6 passed (6 subtests). Merged ontomaind1dff7949together with #2397, #2416 and the other three of this series below (no conflicts), on Linux with Python 3.13. The full translator suite (run_semantic_tests.py tests/semantic) on that tree has only the 8 failuresmainhas here (7 intest_fspx_dot4_op_sel_disasm,test_int32_to_f64), andtests/test_translate.pyonlymain's ownps_sdwa_f16_const.asm(an llvm-mc version difference in this environment). AI-assisted (Claude Code, Claude Opus 5.5).Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-28T03:20:55Z.
Review: APPROVED
Verified head
b176c9f5a(vs parent246791612) on Windows 11 across both AMD Radeongfx1036(driver32.0.21030.2001/25.10.30.02, Vulkan SDK1.4.363.0Core + SyncVal) and NVIDIA RTX 5080 (616.64).Static & semantic checks:
v_cmp_*_u16/i16,sdwa_srcWORD_1unsigned &sext,v_pk_*,v_sad_u16,v_qsad_pk_u16_u8/v_mqsad_pk_u16_u8,v_mad_{u32_u16,i32_i16}, and D16image_store) throughu16_half/i16_halfeliminatesOpBitField{S,U}Extract ... 16 16while preserving signedness, packed component order, andv_mad_i32_i16third-operand zero-extension.tests/semantic/test_high_half_shared_readers.py— 6/6 OK.tests/semantic/test_image_store_d16.py— 5/5 OK.tests/test_u16_high_half.py— 33/33 cases PASS.Dual-GPU hardware checks (Vulkan SDK
1.4.363.0Core + SyncVal):ps_sdwa_dword_hi,ps_valu16_mad_sel,cs_pk_mul_lo_const): PASS (exit 0 under Core + SyncVal) on both AMD Radeongfx1036and RTX 5080.v_cmp_gt_u16/v_cmp_lt_i16op_sel:[1,1], SDWAWORD_1unsigned &sext,v_pk_{add_u16,sub_i16 clamp,mul_lo_u16,min_i16,max_u16,mad_i16},v_mad_{u32_u16,i32_i16}with0xffffthird-source high half,v_sad_u16,v_qsad_pk_u16_u8,v_mqsad_pk_u16_u8, 512 readback words):246791612: 29OpBitField{S,U}Extract ... %c10 %c10sites in emitted SPIR-V; 0/512 mismatches on RTX 5080 andgfx1036driver32.0.21030.2001(note: the reported miscompile is on driver25.10.36, so this run provides additionalgfx1036+ Blackwell parity coverage rather than reproducing the25.10.36miscompile).b176c9f5a: 0OpBitField{S,U}Extract ... %c10 %c10sites; 0/512 mismatches on both AMD Radeongfx1036and RTX 5080 (0 VUIDs).No game data used. AI-assisted review (Codex static audit + Gemini dual-GPU verification).
Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T10:45:12Z.
#2366 | head
b176c9f5aafff117a49d22a84e54c64803aca632|python3 -m unittest discover -s tests/semantic -p test_high_half_shared_readers.py -v| red: 6 run, 11 failures | green: 6 passed | Red → greenBaseline failures included image_store_d16 high-half reads and the signed and unsigned SDWA WORD_1 cases.
Captured 15 distinct complete SPIR-V module(s) emitted while rerunning test_high_half_shared_readers.py on the merged tree. All assembled and passed spirv-val for Vulkan 1.2 with --allow-offset-texture-operand.
Base
3bd936ecd98995bca3e1da83d5e28d2343001aefwas merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. Batch claim.Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T11:53:55Z.
Merged, thank you @ShotTechOp! This translator PR (rdna2spirv: route remaining 16-bit high-half readers through u16_half/i16_half (SHADER-HIGH-HALF-SHARED-READERS)) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch.
AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.