Repository navigation
rdna2spirv: fix s_cmp_eq_u64/s_cmp_lg_u64 on split, swapped, and mixed SGPR mask pairs - #3007
Conversation
…d SGPR mask pairs
kacper-serewis
left a comment
There was a problem hiding this comment.
SHADER-551 independent Windows RTX 5070 readback, NVIDIA 616.56. Comparing one result word per invocation against an independent CPU lane-mask calculation, parent 89c2d9a missed 64/97 in the 97-thread dispatch and 104/104 in the 104-thread dispatch. Head 6ab975e matched all 201 words. Both comparisons were exercised with split, swapped and mixed pairs under Wave64 emulation on fixed 32-lane subgroups. All four synthetic modules passed spirv-val and created Vulkan pipelines. These are compute-stage results. GPU report. AI-assisted.
|
Independent GPU check of For the GPU adaptation, assigned a separate output region per lane to avoid concurrent writes to the same address. Verified that every active lane matched the literal expected comparison results. All six generated compute modules passed |
|
AI-assisted retail census for SHADER-551. All 26,503 indexed listings were present. The parser recognized 1,196 s_cmp_eq_u64 and 7 s_cmp_lg_u64 sites across 221 listings. Of 1,473 listings with invalid-encoding diagnostics, one contained a recognized compare. Native-byte re-anchoring and reachability pruning removed its single s_cmp_lg_u64 site. That leaves 1,202 reachable compares in 220 listings. The translator’s control-flow mask analysis found zero split, swapped, duplicated, or mixed mask pairs at those sites. Both SGPR words at every reachable compare had scalar memory loads as their last writers in the same basic block. At 948 sites a compared register held a mask elsewhere in the shader, which explains why register-number matching alone would overcount. No reachable site required an ambiguous predecessor to determine the last writer. Undecoded words are outside the recognized-instruction count. Using the normal translator and assembler on all 221 candidate listings with local native blobs and stage metadata, parent 89c2d9a and head 6ab975e each translated and passed Vulkan 1.2 spirv-val on 221/221. All 221 SPIR-V binaries were byte-identical between revisions. This static census found no retail instance exercising the fix in this index. The earlier GPU readback exercised synthetic inputs. No retail GPU execution was performed. |
Kam471
left a comment
There was a problem hiding this comment.
Verified on the PR head: tests/semantic/test_scmp_u64_mask_pairs.py -> 6 tests OK; current main fails 8 (6/8 split/swapped subcases, the 40-thread (vcc_lo,-1), and wave32 mixed). An independent 780-case differential against a Python u64 reference (40 random full-wave64 cases x 15 compare/mask ops, plus 18 partial-wave64 40-thread cases x 10 ops) gives 0 mismatches; split (vcc_lo,0), (0,vcc_hi), swapped, mixed and canonical pairs all agree, and the SCC is a single uniform value per case. Mutation of the expected slot-9 halves gives 5 subtest failures. Regressions (wave64_scmp_masks 16, scalar_bitcmp 21, scalar_alu_misc 21, wave64_halves 66, scselect_b64_data 12, export_valid_mask 16, cf_ref 25, hygiene, compileall) all pass. No game data or absolute paths. Approve.
Minor: the PR adds no docs/design.md contract row (CONTRIBUTING asks for one on a new translator rule) and is 2 commits behind main, though the touched file blob is identical.
|
Added the required SHADER-551 contract entry in docs/design.md in 81cbf33. It distinguishes canonical whole-mask vote comparisons from exact reconstructed SGPR words, covers partial waves/all-ones comparisons and separates CPU tests from the independent Vulkan readback already reported here. Six focused mask-pair tests plus sixteen wave64 scalar-comparison regressions passed on Windows CPython 3.12.10. No native RDNA2 oracle run locally. AI-assisted. |
Claim
Problem
In
tools/rdna2spirv.py,s_cmp_eq_u64/s_cmp_lg_u64miscomputedSCCfor SGPR pairs whose two 32-bit halves did not both hold the same full-wave mask representation:(vcc_lo, 0),(0, vcc_hi),(vcc_lo, -1), or(vcc_lo, exec_hi)satisfiedholds_lane_mask(...), so comparing against0or another mask took theuse_votebranch. Inhalves(), SGPR pairs skippedmask_src()and loaded both raw registers(sgpr[r], sgpr[r+1])directly. Because each lane'ssgpr[r]holds that lane's own bit (e.g. lanes 32..63 hold their ownvccbits in aMASK_LOregister, and lanes 0..31 hold their ownexecbits in aMASK_HIregister), comparing both words in every lane produced wrongSCCvalues.(MASK_LO, -1)pairs: on a 40-thread wave64, a per-lane vote over launched lanes cannot distinguish unlaunched lane bits (0invcc_hi = 0x000000FFvs1in-1 = 0xFFFFFFFF), so pairs withEITHER(0/-1) halves must not take the vote path.(vcc_hi, vcc_lo),(vcc_lo, vcc_lo)) and mixed mask + plain data pairs ((vcc_lo, s7),(s6, vcc_hi)on wave64 or wave32):holds_lane_mask()isFalsefor mixed pairs, causing raw per-lane0xFFFFFFFF/0bits to be compared against scalar words; for swapped/duplicated pairswave_mask(pair)read the wrong half per lane.Fix
tools/rdna2spirv.py(s_cmp_eq_u64/s_cmp_lg_u64):wave_equalvote fast path to canonical full-wave masks (exec, maskvcc, or a wave64(MASK_LO, MASK_HI)SGPR pair) compared against another canonical full-wave mask or0, and read each lane's bit viaself.mask_src(...)(which selectssgpr[r]for lanes0..31andsgpr[r+1]for lanes32..63).self.wave_mask(s)for canonical full-wave masks, and materialize non-canonical SGPR pairs word-by-word: each mask word useswave_mask(reg)(hifor wave64MASK_HI,lootherwise) and each plain-data/EITHERword usesload_reg("sgpr", r). Also handlenull(0, 0) and data-modevcc(%vcc, %vcc_hi).tests/semantic/test_scmp_u64_mask_pairs.py(new file, disjoint from test_wave64_scmp_masks: drop the ctypes int patch, GFX10-less u64 compares and a self-check (follow-up to #2280) #2929 and wave64_halves: s_cmp_eq_u64 and s_mov exec no longer pass as votes the wrong way (false tier A) #2675):(vcc_lo, 0),(0, vcc_hi),(vcc_lo, -1),(vcc_lo, exec_hi)), swapped/duplicated halves ((vcc_hi, vcc_lo),(vcc_lo, vcc_lo)), mixed mask+data pairs ((vcc_lo, s7),(s6, vcc_hi)), 40-thread partial wave64(vcc_lo, -1)vsvcc, wave32 mask pairs,--wave64-emulateassembly check (spirv_asm.assemble), fast-path vote preservation, and plain-data zero-subgroup-op check.Validation
Environment: Windows 11, portable Python 3.12.10 (stdlib only,
python -I), synthetic compute shaders only.tools/rdna2spirv.pyat89c2d9a):python -I tests/semantic/test_scmp_u64_mask_pairs.py -v-> failed on wave64 split/swapped/mixed pairs (6/8 subtests failed), 40-thread partial wave64(vcc_lo, -1)failed, and wave32 mixed pair failed.89c2d9a):python -I tests/semantic/test_scmp_u64_mask_pairs.py -v-> 6 tests OKpython -I tests/semantic/test_wave64_scmp_masks.py-> 16 tests OKpython -I tests/test_resource_hygiene.py-> 2 tests OKpython -I tests/test_text_write_line_endings.py-> 2 tests OKpython -m compileall -q make_game.py tools tests-> exit 0Limitations
tests/semantic/spirv_mini_interp.py) and assembled withtools/spirv_asm.pyon synthetic shaders only;spirv-valand GPU execution were not run in this environment (the--wave64-emulatecase checks translation, absence ofOpGroupNonUniform*, and binary SPIR-V assembly becausespirv_mini_interp.pydoes not implementOpControlBarrier).AI Assistance