rdna2spirv: a lane mask read as a number is the wave's mask word (SHADER-MASK-AS-DATA) #1043
Closed
leonida/mandy
thesubtleties wants to merge 0 commits from
mask-as-data into main
pull from: mask-as-data
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!1043
Loading…
Reference in a new issue
No description provided.
Delete branch "mask-as-data"
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 closed
This pull request cannot be reopened because the branch was deleted.
Claimed in the coordination issue as: SHADER-MASK-AS-DATA
What and why
A lane mask is one word for the wave on hardware; the translator keeps each lane's own 0 / ~0. An op that read the mask as a number therefore got a different wrong value per lane, with no error: with mask
0x3ff,s_add_u32 d, mask, 1was 0 or 1 andv_mov_b32 v, maskwas 0 or ~0 (crosslane_fuzz.py"maskdata", the old #293).s_bcnt/s_ff/s_flbitalready rebuild the word. This does the same for:lane_masks.NUMBER_READERS);v_mov_b32of a mask, when nov_readfirstlane_b32or vector bitwise op reads that value as a mask. Each copy is followed forward, through VGPR-to-VGPR copies (second commit).The emulation planner counts such an op as an exchange, it never joins an active run, and
wave32_pixel_scan.pycounts it asmask_word.Partial on purpose. Not covered: the values excluded above (the v_mov / v_or3 / v_readfirstlane idiom needs each lane's own bit), compares, SDWA and DPP, and 16-bit, float and 64-bit ops.
Three existing tests changed:
test_salu_movrels_lane_mask,test_scselect_b64_dataandtest_salu64_bitwise_dataread a mask back withv_mov_b32and expected the lane's own 0 / ~0; they now expect the mask word.Tested
Measured on base
82a2aabc, then rebased; the semantic suite and the touched tests were rerun after the rebase.tests/semantic/test_mask_as_data.py(wave32, native wave64, partial EXEC, the through-a-VGPR idiom, emulated translation): fails onmain, passes here.run_semantic_tests.py: 0 files failed.crosslane_fuzz.py, hard mismatches, main -> this PR; no program fails here that passed on main:--ext, seed 880606 (300), 3080 and gfx1036--ext, seed 880707 (300), gfx1036The 880xxx main rows were run on
98a977b4. With--no-maskdatathere are no hard mismatches there on main. Correction: the first version of this text said the remaining mismatches werev_readfirstlanereads. Minimizing them showed most came from a plain VGPR-to-VGPR copy that the first commit counted as a mask read; the second commit fixes that. What is left on wave32 seeds 991201, 991202 and 993301 (11 mismatches, plus 4 programs with a hypothesis op) is now minimized on the 3080: every reduction contains av_mov_b32of a mask into a VGPR that av_readfirstlane_b32or a vector bitwise op then reads, the idiom this PR leaves alone. The shortest isv_cmp_ne_u32_e32 vcc_lo, 9, v6/v_mov_b32_e32 v2, vcc_lo/v_readfirstlane_b32 s8, v2. The wave64 leftovers (seed 880606 emulated on the 3080, seed 880707 native on gfx1036) minimize to the same idiom. Caveat: two hard reductions stayed at 14 and 17 lines, where the pattern is present but not shown to be the cause, and the six programs with a hypothesis op (4 wave32, 2 wave64 native) are not explained.cf_diff.py: 2,000 programs on the second commit (wave32 and wave64), 0 mismatches.run_gpu_tests.py: per-test results identical to main: 3080 201/252, 3080 emulated 233/252, gfx1036 234/252, gfx1036 emulated 234/252; only the two known tfe fixtures fail (#31). Rerun on the second commit.GPUs tested: NVIDIA RTX 3080 (620.73.04) and AMD RDNA2 iGPU gfx1036 (RADV, Mesa 26.3.1), CachyOS Linux 7.3.5
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.Independent Linux check (stdlib only, no game/GPU): all four files pass on head 02d62939f — test_mask_as_data 9/9, test_salu64_bitwise_data 11/11, test_salu_movrels_lane_mask 3/3, test_scselect_b64_data 12/12. Same files against the unmodified tools fail 172+9+32+2 respectively, so the tests fully exercise the change. Not claiming; review evidence.
Verified on exact head 02d62939f62b5ed8d6a8835ed3f3030b4f843ae8 (base 96e1e222614898097e363c74cda966a048920f78). Focused tests pass: new mask-as-data 9/9; updated SALU64, MOVRELS and SCSELECT regressions 11/11, 3/3 and 12/12; lane-mask, planner and pixel-scan unit suites also pass (including wave64 emulation 31/31). One additional SPIR-V validation test skipped because
spirv-as/spirv-valare absent. The full semantic run covered 471 files / 6,174 tests; onlytest_sopc_validationandtest_unary_f16_validationfailed, both because those executables are missing, so I do not report the full suite as green. Changed-file no-game-data/diff checks and merge-tree pass. The addeddocs/design.mdcontract entry is present. CPU semantic validation only; no local GPU or game-data run.Thanks @morodirule and @KernelSmoker. I pushed a second commit, so your checks cover
02d62939fand not the new head. It changes only howlane_masks.number_movesdecides whichv_mov_b32copies are read as numbers: a VGPR-to-VGPR copy no longer counts as a mask read. Wave32 fuzz mismatches go from 10 to 0 (seed 880505). My earlier explanation of those 10 was wrong, and the description is corrected. AI-assisted (Claude Code).Tested 68b964e4 on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32..32), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300): pass, and a GPU before/after with
crosslane_fuzzRuntime built with
scripts\build_runtime.ps1(MSVC 19.51; this PR changes no runtime file);llvm-mc23.1.6, SPIRV-Tools 2026.4. No game files.crosslane_fuzz.py --wave both --modes both --programs 300 --seed 20261123(the samevk_compute_test), on this PR's based4de3a7dand at this head. "Flagged" = programs reported asmismatch, including the hypothesis-op ones; every flagged program in both columns containsmaskdata:--dpp--extThe base counts are identical to a run of the same seed on
main867d922fthe day before, so the drop is this change. 0 rejected and 0 harness errors in all runs. Still flagged at this head (seed 20261123, reproducible with--show):cs_xl32_2026173083373,cs_xl64_2026173083374,…396,…450,…524,…564,…632,…660--dpp:cs_xl32_2026173083409,…425,…639,cs_xl64_2026173083512,…528,…580,…642--ext:cs_xl32_2026173083373,cs_xl64_2026173083562Also at this head:
test_mask_as_data.py13 OK,test_salu64_bitwise_data.py11 OK,test_salu_movrels_lane_mask.py3 OK,test_scselect_b64_data.py12 OK (unittest discover). GPU suite: 261 shaders, 261 translated, 261 pass spirv-val; native 201/252, emulated 233/252; the only failures arecs_imgload_tfe/cs_imgload_d16_tfe, as onmainon this card (#892).More evidence on head
68b964e42; no code change.tools/wave_diff.py --masks-as-data(CPU only, seed 551117, 2,000 programs per wave size), main3aa97542against this branch:The first remaining failure in each is a
v_mov_b32of a mask followed by av_readfirstlane_b32of that VGPR, the idiom this PR leaves alone. I did not check the other 26 one by one (that tool has no minimizer).The wave64
crosslane_fuzz.pyleftovers from the description are minimized now (seed 880606 emulated on the 3080, seed 880707 native on gfx1036): all 4 contain the same idiom, the shortest beingv_cmp_ge_u32_e64 vcc, v6, v1/v_mov_b32_e32 v5, vcc_hi/v_readfirstlane_b32 s8, v5. The description is updated to say so.Not tested: the game corpus and RDNA2 console hardware. AI-assisted (Claude Code)
Tested
68b964e42on an RTX 3080 with--wave64-emulate. A synthetic loop counting four set bits should return 4 in every lane. GPU readback returned 32 in four lanes and 2 in the other 60. A local change that converts the lane mask to a scalar word before entering the loop returned 4 in all 64 lanes. Both modules passed Vulkan 1.2 validation. AI-assisted test, no game files used.Local translator change. On entry to the scalar bit-scan loop,
s8represents the low half of a per-lane mask. On the back edge,s_mov_b32 s8, s14carries an ordinary scalar after clearing one bit. The analysis drops the mask classification at the join. The firsts_ff1_i32_b32then sees a different value across lanes. The local fix gathers the low 32 predicate bits into one uniform word at the entry zero-test, while the source is still known to be a mask (Gen.lane_mask_word). It stores that word in the SGPR and treats the register as scalar on both outgoing paths and at the loop header. The fix was tested on an experimental translator branch with single-wave, 64-thread compute groups.Reproduce on the PR head with Python only
From the repo root at
68b964e42, run the following Python. Each of the 64 output words should be 4. The interpreter printsCounter({2: 60, 32: 4}), matching the RTX 3080 readback.For the GPU check, the same
asmwas assembled withspirv-as --target-env vulkan1.2and validated withspirv-val --target-env vulkan1.2. The module was run withvk_compute_test scan.spv 1 inspectandVKC_DUMPset to an output file. All 64 little-endian uint32 values in the dump were counted.Thanks @MynFriend, I reproduced this in the CPU interpreters at
68b964e42: wave64 native and emulated, and a wave32 version. Main82a2aabcgives the same wrong values, so it isn't a regression, but this PR doesn't fix it. It's a mask meeting plain data at a join, where the analysis drops the mask.While checking I found a straight-line relative:
s_xor_b32of a mask and plain data reads one lane's bit. I have a local prototype for that second case only (semantic suite clean, no GPU run yet). If you'd like to send your entry-test fix as its own PR, please do; I won't start on the loop case.CPU only. AI-assisted (Claude Code)
Native RDNA2 (gfx1036,
tools/hw_oracle): all 21 programs left over in the description (15 hard, 6 with a hypothesis op) match the fuzzer's model, so those are translator bugs, not model errors. Four short versions of the idiom also match. The cause is still shown only for the short reductions.GPU suite on this head: the only failures are the two
tfefixtures fixed by #892. AI-assisted (Claude Code)Rebased by merging main
bfef489c; two conflicts, both independent additions.test_slot67_operand_formsloses anexpectedFailurethat this fixes.Semantic suite: 488 files / 6,292 tests, 0 failed. GPU suite on the 3080 and gfx1036, native and emulated: per-test identical to main. Earlier approvals cover older heads. #1397 overlaps; I commented there. AI-assisted (Claude Code)
RTX 3090 / 621.40, crosslane fuzz with maskdata, seed 309700: mismatches go 56+29 -> 12+9 (w32+w64) with this PR. Remaining are still mask-as-data, e.g. cs_xl32_30970929176 (native, group 50):
minimized repro
s14: expected 0x00000000; threads 0-31 got 0xfffeef3a, threads 32-49 got 0x0002ef3a.
Fix for the remaining mismatches: https://github.com/ubiquitarianism/leonida/compare/thesubtleties:mask-as-data...ammonium231:fix-1043-number-moves (on top of this PR, 4 files, +123/-10). number_moves dropped a plain v_mov of a mask when a later v_readfirstlane / v_and read the copy, so inactive lanes leaked into the mask. RTX 3090 fuzz, 2000 programs/seed, --dpp --ext: 309700 984/12/4 + 989/9/2 -> 1000/1000 both waves; held-out 309900 (36 failing) and 310100 (29 failing) -> 0, no new failures. Semantic suite 6296/0.
Checked 4d58a05d merged into main 2859d0c9 (merges cleanly), by Claude Code (AI-assisted) on my behalf. Linux,
Mesa lavapipe,
--wave64-emulate.tests/semantic: 501 files, 6,387 tests, 0 failed.crosslane_fuzz.py --wave 64 --modes emulate --dpp --ext: seed 205, 150 programs: 150 match (main: 5 mismatch,2 hyp_only); seed 311, 300 programs: 299 match, 1 hyp_only,
cs_xl64_31101202(main: 10 mismatch, 4 hyp_only).That one is on main too, and #1397's head (e3e119a) matches it, so it is one place where the two differ.
Not run: a hardware GPU, native wave32.
Generated by Claude Code
RTX 3090 / 621.40, crosslane_fuzz 2000 programs on main 431ceba4f: this PR takes mismatches from 59/26 (native/emulated) to 13/2. The rest are a plain v_mov of a mask feeding a vector bitwise op (v_cmp_ne_u32_e64 s16 / v_mov_b32 v4, s16 / v_xor_b32 v7, v5, v4).
Closing this competing variant in favor of #1397 for
SHADER-MASK-AS-DATA(lane-mask operands read as numeric values).Side-by-side comparison:
#1043'snumber_movesforward-lookahead heuristic still leaves remainingcrosslane_fuzzmismatches on RTX 3090 (13 native / 2 emulated out of 2,000 programs measured by@ammonium231, e.g.v_cmp→v_mov_b32→v_readfirstlane_b32andv_cmp→v_mov_b32→v_xor_b32) as well ascs_xl64_31101202(measured by@kawaii-shakal).#1397avoids lookahead fragility by maintaining a single invariant: VALU data reads (src_u) always materialize the wave's 32-bit mask word, while mask consumers (mask_srcandv_readfirstlane_b32into mask-tracked destinations) extract this lane's bit back via_vgpr_mask_lane_bit(half-aware in wave64) and broadcast from the first active lane.#1397also incorporates the scalarMASK_NUMBER_READERSset from#1043.#1043currently conflicts withmainand has failing CI.#1397is cleanly rebased ontomain(MERGEABLE/CLEAN), has all 7 CI checks green, adds thecs_exec_copy.asmGPU fixture plus 280 lines of semantic tests, and passed independent RTX 4090 hardware verification (50/50 native wave32 and 50/50 emulated wave64 programs, 0/103,180 word mismatches vs. 422/103,180 onmain).Thanks
@thesubtleties— yourNUMBER_READERSanalysis directly contributed to the landed solution in#1397.(AI-assisted review.)