Repository navigation
startup: spill descriptors, pointers and lane masks to VGPR lanes in compute - #2759
Conversation
Symptom: the constant-lane spill idiom v_writelane_b32 vN, sM, k /
v_readlane_b32 sD, vN, k was refused for k >= 32 ("lane 40 outside 0..31")
and in every vertex stage ("lowered in pixel stages only"), although a wave64
program spills into lanes 0..63 and a vertex stage uses the same idiom.
Root cause: the slot model (one scalar per (VGPR, lane)) was limited to
wave32 lanes and pixel stages. Neither limit is needed by the model: the two
instructions touch only lane k and ignore EXEC in every stage.
Change: lanes 0..63 and vertex stages are accepted. The translator does not
know the wave size and a wave32 program takes the lane select modulo 32, so a
spill VGPR whose lanes include k and k + 32 (one slot in wave32, two in
wave64) is refused by name. Lane 64+, compute stages, register lanes,
branches (open R0Y00#2524 territory) stay refused.
Test: tests/startup_gfx2hlsl_spill_wave64_check.py (controls fail before:
lanes 32..63 and the vertex stage refused). The existing sgpr_spill controls
now expect lane 64 and the k/k+32 pair refused and the vertex stage accepted.
Win2025 WARP dev and release, DXC and FXC: the pixel draw matches the slot
reference on 256/256 pixels, the vertex draw exports the reference param0,
and all five wrong-lane/ignored-overwrite mutations fail.
(cherry picked from commit c7fe3e44b10ffb4ebdf40caab7d8306926b3a881)
…only, slot 57 mesh is always wave64
Symptom: compute programs that park a descriptor or a pointer in a VGPR lane (v_writelane_b32 vN, sM, k) around branches and reload it with v_readlane_b32 were refused: the spill is lowered in pixel, vertex and mesh stages only, and a source holding a descriptor was refused as "lane mask or descriptor". Change: cs joins SPILL_STAGES and, like ps, may branch, through the same write-before-read proof (a write on every path, regions the wave runs while a thread skips them, loop-carried reads). A descriptor or pointer word has no run-time value in the translation, so the slot carries the symbol (desc, ptr, ptrhi) and the reload restores the same one; a word whose symbol does not name one value (modified descriptor word, pointer with a non-numeric offset) and different symbols joined at a read stay refused. Lane masks keep their refusal. A reload also keeps the provenance the formatted loads require: the write records whether the word passed the entry-block or local table load proof where it was spilled, and formatted_descriptor_from_block accepts a reloaded word only if every write that can supply it did. Test: tests/startup_gfx2hlsl_compute_spill_check.py builds two gfx1013 compute fixtures from source, eight refused variants, probes, eleven translator mutations and a WARP/hardware dispatch. The two existing controls that expected cs to be refused now expect it to be accepted. Part of R0Y00#1723. Refs R0Y00#2022.
Accept v_writelane_b32 of vcc_lo or of an SGPR tracked as a lane mask in compute stages, and the matching v_readlane_b32 into an SGPR or vcc_lo. The translator models a lane mask per invocation as that invocation's own bit. The write and the reload both ignore EXEC and copy the whole wave mask, so a reload that is only used as a mask has, in every invocation, the bit that invocation had at the write: the spill is the identity on the per-invocation bit. The slot variable takes the mask's variable at the write and the reload copies it back and marks the destination a mask again. The existing write-before-read proof decides what a reload sees; a reload that may see two writes of which one is a mask is refused, as are exec, vcc_hi and m0 sources, a mask not proven on every path, and a reload that an instruction reads as data (the translator does not refuse every numeric read of a marked register). Part of R0Y00#1723.
CI assembles with LLVM 15, but the words were recorded from a newer llvm-mc. For VOP3 v_readlane_b32, v_writelane_b32 and v_cmp the unused src2 field is 0 in LLVM 15 and the inline constant 0 (128) in newer LLVM, so every fixture holding one mismatched in CI. assemble_labels now clears that unused field, and the recorded words are the LLVM 15 output, so the check holds with both versions. All other bits are still compared.
|
Review of head dc8e0f3 (comment review, no approval). What I checked
Commands run locally
Windows WARP results follow in a separate receipt. Real-GPU run not available (RunPod stopped). AI-assisted; commands listed were executed locally. |
|
Win2025 WARP receipt for head dc8e0f3 (real-GPU run not available, RunPod stopped). Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
AI-assisted; commands listed were executed locally. |
tedin7
left a comment
There was a problem hiding this comment.
Review of head dc8e0f3 (comment review, no approval).
What I checked
- Overlap: #2712, #2637, #2524, #2171 (spill families) are merged. No open PR covers compute-stage spills of descriptor, pointer or lane-mask words.
- Translator change (
tools/startup/gfx2hlsl.py):csjoinsSPILL_STAGES. Descriptor/pointer words travel as symbols and the reload only passes the formatted-load proof if every supplying write passed it (formatted_descriptor_from_block). Thefirst[3] + 4tofirst[3] + widthchange is consistent with the new width. Lane masks are refused unless only read as masks (require_mask_reads_only). I found no bug. - Tests: the new checks include real D3D12 dispatch tests (
dispatchmode, warp and hardware adapters) that compare readback against the expected output, plus refused-reason controls and translator mutations. Both CMake and the Linux CI lists andAGENTS.mdare updated consistently. - CI change (
.github/workflows/windows.yml, +4): the PR's own CI run executed both new checks (startup_gfx2hlsl_compute_spill_check.py (ok),startup_gfx2hlsl_compute_mask_spill_check.py (ok)), so the workflow edit is exercised.
Commands run locally
git diff --check origin/main...HEAD: cleanpython3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py: passpython3 -B tests/startup_gfx2hlsl_compute_spill_check.py,..._compute_mask_spill_check.py,..._sgpr_spill_check.py,..._spill_wave64_check.py: all PASS- Mutation 1: remove
'cs'fromSPILL_STAGES: compute_spill check fails (rc=1) - Mutation 2: drop the "several writes, one is a mask" refusal: compute_mask_spill check fails (rc=1)
Windows WARP results follow in a separate receipt. Real-GPU run not available (RunPod stopped).
AI-assisted; commands listed were executed locally.
Part of #1723. Refs #2022 (claim and counts: #2022 (comment))
Builds on #2712 (@tedin7, wave64 and vertex-stage spills), now merged.
mainis merged into this branch (16471bef); the change is the two commits6bbc8e4e(descriptors and pointers) and1ce4ae91(lane masks).Change
gfx2hlslnow accepts constant-lane SGPR spills (v_writelane_b32/v_readlane_b32) in compute stages when the spilled word is a descriptor or pointer word.csjoinsSPILL_STAGESand may branch likeps. The same proof applies: a write on every path before the read, the existing rules for non-uniform regions, and the refusal of a read carried by a loop. Av_writelane_b32inside ans_cbranch_execzblock was already refused byexecz_refusals, so writes stay outside those regions; only reads enter them.desc,ptr,ptrhi) have no run-time value to store. The lane slot carries the tracked symbol, nothing is emitted, and the reload restores the same symbol. Refused, by name: a symbol that does not name one value (a modified word, a pointer with a non-numeric offset), and different symbols joined at one read.formatted_descriptor_from_blockfollows av_readlane_b32back to those writes, and accepts the reload only if every write passed it. So a reloaded descriptor is accepted exactly when the original would have been.v_cmpstoresw, orexec & wwhen EXEC is unknown, so an inactive lane's bit is already 0).v_writelane_b32/v_readlane_b32ignore EXEC and copy the whole wave mask, so when the reloaded value is only read as a mask the spill is the identity on each invocation's bit: the slot takes the mask variable and the reload copies it back, re-marked as a mask (or intovccfor avcc_lodestination).reject_lane_mask_datacovers only some ops (av_add_nc_u32on a mask is accepted today, spill or not), so a newrequire_mask_reads_onlyrefuses the reload if any instruction reachable before its next write reads it other than as a lane select or carry-in, bys_cbranch_vccz/vccnz, as a copy intoexec_lo/vcc_lo, or by another spill. Also refused: several writes of which one is a mask, sourcesexec*,vcc_hi,m0, and a mask not proven on every path.Test
New
tests/startup_gfx2hlsl_compute_spill_check.py(registered in CMake, both Linux CI lists andAGENTS.md), with source-built gfx1013 programs assembled byllvm-mc:buffer_load_format_xyzwand a store.s_loadthrough it.v_cmpinto an SGPR), wrong lane, unproven descriptor (spilled in the arms), write inside an execz region, loop.csrefused, loop, write-before-read.startup_gfx2hlsl_sgpr_spill_check.pyandstartup_gfx2hlsl_spill_wave64_check.py: the "csis refused" control becomes "csis accepted", and agscontrol takes its place.Linux: all
tests/startup_gfx2hlsl_*_check.pygive 111 passed and 2 failed (export_null_draw,mul24_align_draw). Those two fail the same way on #2712's head (110 passed), so this adds no regression. After mergingmain(16471bef): the four spill checks andstartup_gfx2hlsl_compute_check.pypass, same two usage-only failures in the sweep, and CI is green.dc8e0f34records the fixture words in the LLVM 15 encoding the CI assembler emits (the unused src2 field of VOP3v_readlane_b32/v_writelane_b32/v_cmp*_e64is 0 there, inline constant 0 in newer LLVM; the comparison masks only that field). Atdc8e0f34, Windows 11 26200 Release build,ctest -R "startup_gfx2hlsl_(compute_spill|compute_mask_spill|sgpr_spill|spill_wave64)": 24/24 passed on WARP and the RTX 2070.Windows 11 26200, Release build, debug layer per
offscreen_checkdefaults,ctest -R startup_gfx2hlsl_compute_spill: 9/9 passed. On WARP and on an RTX 2070 (driver 32.0.16.1088), the dispatches of S and P read back all 320 expected words, and the three dispatch mutations (s-arm-swapped,s-store-dropped,p-store-dropped) are rejected on both adapters.Second commit: new
tests/startup_gfx2hlsl_compute_mask_spill_check.py. Fixtures M (vcc_loand an SGPR mask spilled, a branch, reload into an SGPR,v_cndmask_b32_e64,s_and_saveexec_b32) and V (reload intovcc_lo,v_cndmask_b32_e32,s_cbranch_vccz); 12 refused controls (m0, exec, vcc_hi, numeric reads of an SGPR and of vcc, two masks joined, a mask joined with a number, reload before write, a number reloaded intovcc_lo, a mask computed in one arm only, write in an execz block, loop) plus a pixel-stage probe; 14 translator mutations, each caught. Linux: 112 passed, the same 2 failures. Windows:ctest -R startup_gfx2hlsl_compute_(mask_)?spill18/18 on WARP and the RTX 2070, M and V read back 320 exact words, and the dispatch mutationsm-saveexec-dropped,m-mask-inverted,v-branch-invertedare rejected on both.Note: fixture V branches on a
vccthat is uniform per group, becauses_cbranch_vccz/vccnzis translated per invocation as(vcc & 1); on avccthat differs between lanes the wave should follow one path. That is independent of spills and I am checking it separately.Effect on run-time requests
On a local run (
main0827f43c), 68 slot-67 compute requests stop atv_writelane_b32 is lowered in pixel and mesh stages only. With #2712 and both commits, none stops at a spill any more: 33 next stop atv_or_b32_dpp(DPP in compute outside the straight-line pixel case), 32 ats_nand_b32on a lane mask (#2030), 2 at a resource-heap records_load(#2580), and 1 at lanes k and k+32 of one VGPR. None translates fully yet; these programs need those other forms too.AI-assisted (Claude Code).