mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 22:45:53 +01:00
[PR #508] wave64_halves: v_sat_pk_u8_i16 keeps its high half (SHADER-SATPK-HALVES) #556
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#556
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/508
Author: @milk4sale
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:shader-satpk-halves📝 Commits (6)
6446e3crdna2spirv: translate v_sat_pk_u8_i16 (SHADER-SATPK-U8)8fd02b4Merge main into shader-satpk-u8 (#338) for the wave64_halves partial-write code of #2654234449wave64_halves: v_sat_pk_u8_i16 keeps its high half (SHADER-SATPK-HALVES)d093c0cMerge main into shader-satpk-halves232a2cedesign.md: the v_sat_pk_u8_i16 high-half keep is the translator's choice (SHADER-SATPK-HALVES)38623a9Merge main into shader-satpk-halves📊 Changes
14 files changed (+439 additions, -5 deletions)
View changed files
📝
docs/design.md(+2 -0)📝
docs/fssm_crosscheck.md(+1 -1)➕
runtime/test/shaders/ps_w64_a_sat_pk_hi.asm(+49 -0)➕
runtime/test/shaders/ps_w64_c_sat_pk_hi.asm(+35 -0)📝
runtime/test/shaders/w64_graphics.py(+23 -0)➕
tests/semantic/fixtures/sat_pk_u8_i16.asm(+16 -0)➕
tests/semantic/fixtures/w64_sat_pk_hi.asm(+23 -0)➕
tests/semantic/test_alu_sat_pk_u8_i16.py(+94 -0)➕
tests/semantic/test_wave64_halves_sat_pk.py(+149 -0)📝
tests/test_f16_op_sel.py(+1 -1)📝
tests/test_translate.py(+1 -1)📝
tests/test_wave64_halves_fixtures.py(+10 -0)📝
tools/rdna2spirv.py(+29 -0)📝
tools/wave64_halves.py(+6 -2)📄 Description
Claimed in the coordination issue as: SHADER-SATPK-HALVES
Depends on: #338
What and why
#265 added
v_sat_pkto_FULL32_V16_PREFIXESintools/wave64_halves.py, so_preserves_dsttreatsv_sat_pk_u8_i16as a full 32-bit write.partial_writealso read the op's first type,u8, as an 8-bit result. #338 translates the op and writes the two saturated bytes withwrite_lo16, which keeps the high half in the_e32,_e64and DPP forms. With both merged, a high half that depends on the lane lost its taint, and a wave64 VS/PS/GS passed as tier A, or tier B throughreadlane-uniform, although its export changes when the wave is cut into two 32-lane halves. NolanCotter reported this in #14.This change removes
v_sat_pkfrom the tuple, so the op falls to the_i16rule, and makespartial_writesay partial for it. Per encoding:_e32(VOP1 0x62),_e64(VOP3 0x1e2) and DPP keep the high half.BYTE/WORDdst_selandUNUSED_PRESERVE;dst_sel:DWORD,UNUSED_PADandUNUSED_SEXTwrite the whole register. This was already right.op_selon the_e64form for gfx1030.References. Neither compiler says the high half is kept on GFX10, and the cited references don't either:
instr_is_16bitis false for the op before GFX11. It is not in the list, andcan_use_opselfalls through toget_gfx11_true16_mask, which lists it next tov_cvt_f16_f32for GFX11+ only (aco_ir.cpp, Mesa99abc485).VOP1Inst_t16is the plain VOP1 instruction on GFX10, with the true16 forms GFX11+ only.GCNSubtarget::zeroesHigh16BitsOfDestdoes not list the op (LLVMe2b0a1e1).The rule here follows what the translator emits. If RDNA2 turns out to zero the high half, calling the op partial is still the safe side: it costs tier A at most, never exactness. The RDNA2 behaviour is not measured. The contract row in
docs/design.mdsays so.#338's own
v_sat_pk_u8_i16row cited ACOinstr_is_16bitfor the kept high half, which the halves row contradicts (review on this PR). This branch rewords that row: the keep is the translator's choice (write_lo16), not measured on RDNA2, with a pointer to the halves row's references. If #338 rewords the row first, take #338's wording when merging. #338's translator comment and thetest_alu_sat_pk_u8_i16.pydocstring cite ACO the same way; they are left to #338, where this was raised.The halves analysis runs only for wave64 VS/PS/GS, never for compute or under
--wave64-emulate(halves_analysisinrdna2spirv.py). So the GPU fixtures areps_w64_*ones run byw64_graphics.py, notcs_*:ps_w64_a_sat_pk_hi, tier A: the four encodings that keep the high half, a different high half per pixel, and both halves of SRC0 saturating below 0 and above 255 across the target. Every word is a function of the pixel, so a 32-only GPU checks all of them.ps_w64_c_sat_pk_hi, tier C: the high half is the lane id. It is pinned to tier C,lane-id, intests/test_wave64_halves_fixtures.py. On a GPU it needs both subgroup sizes, orW64G_REF.Tested
tests/semantic/test_wave64_halves_sat_pk.pywith the hand-writtentests/semantic/fixtures/w64_sat_pk_hi.asm: 5 OK. It runs on the strict wave interpreter as 64 lanes and as two waves of 32, covers every encoding and thereadlane-uniformcase, and checksoperands()andpartial_writeper encoding.6446e3ce7): 12 subtests fail. That head predates #265, so it has no partial-destination handling at all.mainwithout this change: 9 fail (e32/e64/DPP tier A instead of C, readlane tier B instead of C).python -I scripts/run_semantic_tests.py tests/semantic: 467 files, 6114 tests, 0 failed (70 s, 24 jobs).python -m pytest tests/test_wave64_halves_fixtures.py tests/test_w64_graphics_args.py tests/test_w64_graphics_probe.py tests/test_w64_graphics_reference.py: 22 passed. Without the fix,test_fixtures_are_classified_as_their_headers_sayfails:ps_w64_c_sat_pk_hiis tier A instead of C.tests/test_design_contract_rows.py,tests/test_docs_design_rows.py,tests/test_text_write_line_endings.pyandtests/test_semantic_translator_use.pypass. So dopython -m compileall -q make_game.py tools testsandpython -I scripts/check_no_game_data.pyon every added or changed file.232a2ce6d, docs only): the four tests above,tests/test_wave64_halves_fixtures.pyand the twosat_pksemantic test files pass again, andcheck_no_game_data.py docs/design.mdexits 0.w64_graphics.pyon the RTX 4070 Ti:ps_w64_a_sat_pk_hiA ok,ps_w64_c_sat_pk_hiC SKIP (32 is the only fragment subgroup size). The verdicts are the same without the fix: a 32-only GPU cannot see the classification, so the tests above catch it. NVIDIA runs the translated SPIR-V, so this confirms the translator's semantics, not the AMD instruction. The expected low half comes from the ISA pseudocode's SAT8 packing; the expected high half is the translator's rule.python -I scripts/run_gpu_tests.pyon the RTX 4070 Ti, #338's head against this branch, each with its own runtime build. Both: 257 shaders, 257 translated, 257 pass spirv-val.LEONIDA_W64_EMULATE=1: 229/248 passed, 17 skipped.cs_imgload_tfeandcs_imgload_d16_tfe, fail on #338's head too. They are the pair reported on an RTX 3080 Ti in #338's review.GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 620.70.06, Vulkan 1.4.357, CachyOS Linux (kernel 7.3.3), pinned with
VK_LOADER_DRIVERS_SELECT=*nvidia*andLEONIDA_VK_DEVICE=4070. llvm-mc 23.1.4, SPIRV-Tools v2026.4.AI-assisted: yes (Claude Code)
Checklist
6446e3ce7) plusmain1c93c8697, merged in rather than rebased so #338's commit keeps its SHA. Once #338 lands, the diff is this change only.docs/design.md, with how it was confirmed.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.