shader: support Wave32 exec_lo execution mask operations in pixel_aot #678
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/684"
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 R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-22T19:56:48Z.
Summary
In RDNA 2 / GFX1013 Wave32 mode, execution masks operate on 32-bit
exec_loand are commonly saved to and restored from single SGPRs (sN), as well as restored directly vias_mov. Previously,pixel_aotonly recognized Wave64 SGPR pairs (s[N:N+1]) and 64-bitexec, causing Wave32 shaders to fail with unsupported instruction errors ons_mov_b64ands_and_b64.This change:
exec_loto a single SGPR vias_mov_b64ors_mov_b32.exec_lovias_wqm_b64ors_wqm_b32.exec_lofrom a single SGPR vias_and_b64/s_and_b32or directs_mov_b64/s_mov_b32.execand SGPR pairs.tools/scan_unsupported_shaders.pyandtools/pixel_cb_read.pywith the recognized Wave32 forms.tests/pixel_aot_check.pyandtests/rdna2_tools_check.py.Verification
All 6 test suites passed:
tests/pixel_aot_check.py: Wave32 execution mask lifecycle, direct restore, and negative controls passed.tests/rdna2_tools_check.py: Ran 54 tests (includingtest_accepted_full_shader_wave32andtest_accepted_full_shader_wave32_direct_restore), all passed.tests/pso_readiness_check.py: Passed.tests/form_coverage_check.py: Passed.tests/docs_links_check.py: Checked 10 Markdown files and 127 links, all passed.tests/bidi_controls_check.py: Checked 580 tracked files, all passed.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T07:20:26Z.
Review: DISMISSED
The pair-range fixes and RX 9070 XT retest look good. I found one remaining restore boundary: the lowerer currently accepts a 32-bit restore after
s_wqm_b64 exec, execwith no established wave32 input, and the shorthands_mov_b64 exec, s50checks onlys50even when the saved pair’ss51was overwritten. Please keep the full-width restore tied to both saved halves. Require an explicit wave32 precondition for low-only restores, or reject mixed-width streams whose upper half is unknown. Add controls for a clobbered high SGPR and a b64 expansion followed by a low-only restore without that precondition.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-22T21:53:19Z.
Thank you for the thorough review and hardware verification @thepatrickworld!
I have addressed all three points in the updated commit:
translate byte-identically to ase_wave32. Added negative controls rejecting unaligned single registers (e.g. s51) and ensuring s_mov_b32 cannot satisfy a 64-bit pair restore.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-22T21:22:04Z.
Verification: #684
shader: accept the Wave32 execution mask lifecycleHead
8e85a052, merged withmain. Five files, +144/−8. Unlike the coverage PRs, this one changesthree tools:
tools/pixel_aot.py,tools/pixel_cb_read.pyandtools/scan_unsupported_shaders.py.What it changes
The execution-mask lifecycle was only understood in its Wave64 spelling, where
execis an SGPRpair. On RDNA4 a wave32 shader names the same register as a single 32-bit
exec_lo. The PR teachesthe three parsers to accept both spellings:
s_mov_b64|s_mov_b32 sN, exec|exec_lo, ors_mov_b64 s[N:N+1], exec|exec_lo;s_wqm_b64|s_wqm_b32 exec|exec_lo, exec|exec_lowhile the mask is stillentry;s_and_b64|s_and_b32 exec|exec_lo, exec|exec_lo, sN, ors_mov_b64 exec|exec_lo, sN.The mask bookkeeping is untouched: the same
quad→entrytransition fires either way.Environment
Windows 11 25H2 (build 26200.9711), MSVC 19.44.35230, DXC 1.9.2602.17, AMD RX 9070 XT
(vendor
1002, device7550), driver 32.0.32029.2010, native wave64.Commands and output
Twenty-two
pixel_aot_*plusrdna2_tools_check, which is the one that covers the other two toolsthis PR edits. Nothing pre-existing changed behaviour.
Negative control: I removed
exec_lofrom the save pattern(
(?:s_mov_b64|s_mov_b32) sN, (?:exec|exec_lo)→(?:exec)), which makess_mov_b64 s14, exec_lounrecognised, and re-ran
^pixel_aot_hardware$:The Wave32 cases do catch a parser that stops accepting
exec_lo.The reserve: two real bugs the suite cannot see
The central assertion is
translate(w32) == translate(base_wave32): four Wave32 spellings mustproduce byte-identical HLSL to the Wave64 original. That is the right property for a translator whose
output is wave-agnostic — but it also means nothing here observes a wave32 shader executing on
hardware, and there is more than that wrong underneath.
(a) The save loses the high half of a pair.This is not a hypothetical dialect. The repository's owndisassembler emits the single-register spelling for every SOP1/SOP2
_b64:tools/disasm_rdna2.pyformats those with
decode_s_reg, and only SOPC/VOPC reachdecode_s_reg64. So a real encodings_mov_b64 s[50:51], exec(word0xBE32807E) comes out ass_mov_b64 s50, exec_lo, and the matchingrestore as
s_and_b64 exec_lo, exec_lo, s50. That is the normal output of this project's toolchainon a wave64 shader, not a fiction.
The parser then records only
scalar["s50"] = ("entry", 0). The high half is dropped, so a followings_and_b64 exec, exec, s[50:51]is rejected even though the shader is legal. The fixture cannot seeit: its four variants are width-consistent, and the one
s15read it builds is an expected rejection.(b) The scanner and the translator disagree, and the scanner drives the instruction-level accounting.scan_unsupported_shaders.pyl. 72 acceptss_mov_b64with a single destination ands_mov_b32with a pair destination, with no cross-constraint between mnemonic and width. The translator is strict.
Measured on the two real functions:
Correction, after re-reading the scanner: the impact is narrower than I first wrote.
is_fully_supportedisopcodes_recognized and translator_accepted(l. 457), andtranslator_acceptedcomes from a reallower()call (l. 423-433) — so a shaderpixel_aotrefuses was never counted as fully supported,and
docs/coverage/*.tsvis generated byform_reference.pyfrom the LLVM.rst, not by thisscanner.
What is actually wrong is the per-instruction accounting:
out/shader-scan/PROGRESS.mdandprogress.jsonreport "Supported Instruction Instances", the coverage percentage, thepartially supportedcategory, and the per-line ranking of blocking opcodes. These two spellings arecounted as supported there while the translator rejects them, so the denominator and the blocking-opcode
ranking are both off. Still a bug shipped by this PR, still invisible to my runs because both fixtures
are width-consistent — but not a claim about
is_fully_supported.(c) The three parsers have already diverged.Not a risk for later: in this very PR the scanner andthe translator no longer agree on those two spellings.
rdna2_tools_checkpasses because it onlychecks that the scanner returns True on a list of accepted forms, never that the translator agrees.
What I would add
In
pixel_aot.pyaround l. 1517: if the mnemonic isb64with a single destination, record thehigh half too (
scalar[reg] = (mask, 0)andscalar[reg+1] = (mask, 1)), or reject explicitly.Then a case that must now be accepted:
Today it is rejected; it should translate identically to the wave64 original.
Make the scanner patterns width-aware, one line each:
An agreement table in
rdna2_tools_check.py(~10 lines): for each spelling, assertis_instruction_supported(line) == (translate(...) accepts). That kills the class of bug (b), notjust this instance.
What this does not prove
s_wqm_b32with a partial mask, orexec_loinside a branch.rdna2_tools_check's own assertions, which — per (b) — donot compare them against the translator.
AI-assisted; runs executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-22T22:20:24Z.
Follow-up on
f05ead9— two fixes hold, three paths are still openRe-ran on
f05ead9:ctest --preset dev --no-tests=error -R "^pixel_aot_|^rdna2_"gives 23/23, includingrdna2_tools_check. Note the head neededgit reset --hard FETCH_HEAD, since the rewrite makes--ff-onlyfail — easy way to re-test the old commit by accident.First, a correction to my own report
I wrote that
is_fully_supportedfeedsdocs/coverage/*.tsvand that a shaderpixel_aotrefuses was counted as supported. That is wrong, and I should have read the scanner before saying it.is_fully_supported = opcodes_recognized and translator_accepted(l. 457), andtranslator_acceptedcomes from a reallower()call (l. 423-433) — so a refused shader was never counted.docs/coverage/*.tsvis generated byform_reference.pyfrom the LLVM.rst, not by this scanner.The impact is narrower and still real:
out/shader-scan/PROGRESS.mdandprogress.jsonreport "Supported Instruction Instances", the coverage percentage, thepartially supportedcategory, and the per-line ranking of blocking opcodes. Those spellings are counted as supported there while the translator rejects them. I have edited my original comment accordingly.What now holds
s_mov_b64 s50, exec_lofollowed bys_and_b64 exec, exec, s[50:51]is ACCEPT, and the output is byte-identical to theb32baseline. Same withs_mov_b64 exec, s[50:51]as the restore.s_mov_b64 s51, exec_lo→Invalid 64-bit scalar register pair: s51.s_mov_b32cannot satisfy a pair restore.scalar[f"s{n+1}"] = (mask, 1)fails 7 of 23 tests,rdna2_tools_checkincluded.Still open
1. The pair validation is applied on one path only.
N % 2 == 0andN + 1 <= 105exist only for the mono-register spelling. The explicit pair path bypasses them:sgpr_pair(), in the same file, refusess[49:50]ands[105:106]. So the same instruction is invalid by one path and valid by another. Routing the pair token throughsgpr_pair()closes it.2. The mono-register spelling is accepted on save and rejected on restore. If it exists for a disassembler that prints
s50afters_mov_b64, it exists in both directions:Either the restore accepts it too, or the spelling is dropped on both sides — scanner included.
3.
pixel_cb_readwas not extended. My point (c) was about the three parsers; two were fixed.pixel_cb_readcomputes descriptor bases from scalar writes. A traced case wheres51holds a descriptor origin, thens_mov_b64 s50, exec_lo(which clobbers 50 and 51), then a copy ofs51, makesfirst_descriptorreturn a live-looking base built from a dead register. Before this PR that path was unreachable because the translator rejected the spelling; this PR makes it reachable without fixing the third parser. The agreement table does not testpixel_cb_read.4. The
b32patterns are still a wildcard. The pre-existing line 89,(?:s_mov_b32|s_movk_i32)\s+(?:s\d+|m0),\s+.*, accepts anything:So "width-sensitive" holds for
b64only, and the scanner/translator mismatch survives through this door.On the agreement table
It is not a tautology — the scanner regex and a real
lower()call are two independent implementations, and the expected value is written out by hand for each case. That is the right shape, and it does close the class of bug I reported.But it is 19 hand-written cases. The six lines above pass through it, it does not touch
pixel_cb_read, andtranslator_accepts_*catchesExceptionblind, so a rejection for the wrong reason is indistinguishable from a semantic one. Enumerating mnemonic × dst × src and asserting zero disagreements in both directions would make it a real guard.What I would ask
sgpr_pair()instead of accepting it as-is.pixel_cb_readto cover both registers of ab64destination.out/shader-scan/PROGRESS.md/progress.json, notis_fully_supported.The core of (b) is genuinely fixed and the controls are good work. It is the "all three addressed" claim that does not hold yet.
AI-assisted; runs executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-22T22:47:17Z.
Thanks again @thepatrickworld for the razor-sharp review and for verifying all the edge cases!
All four points have been addressed in the latest push:
sgpr_pair():s_mov_b64 s[N:N+1], ...) and restore (s_and_b64 ..., s[N:N+1]ands_mov_b64 ..., s[N:N+1]) now route explicit register pairs throughsgpr_pair().s[49:50]) and out-of-range bounds (s[105:106], clobberingvcc_lo) are now rejected on both save and restore paths, with negative controls added intests/pixel_aot_check.py.sNnow symmetrically accept bothexecandexec_loacrosss_and_b64,s_and_b32,s_mov_b64, ands_mov_b32in bothpixel_aot.pyandscan_unsupported_shaders.py.tests/pixel_aot_check.pyand intest_exec_mask_scanner_translator_agreementintests/rdna2_tools_check.py.pixel_cb_read.pycovers both registers of 64-bit destination:scalar_writes("s_mov_b64 s50, exec_lo")now returnsrange(50, 52)({50, 51}), matchings[50:51].tests/rdna2_tools_check.py.s_mov_b32pattern in scanner:(?:s_mov_b32|s_movk_i32)source from.*wildcard to(?:{SCALAR32_SOURCE}|exec|exec_lo), eliminating the hole wheres_mov_b32 s50, exec_hiwas accepted by the scanner.out/shader-scan/PROGRESS.mdandprogress.json).All test suites pass locally (
tests/rdna2_tools_check.py,tests/pixel_aot_check.py,tests/docs_links_check.py,tests/bidi_controls_check.py,tests/pso_readiness_check.py,tests/dxil_retarget_check.py).Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-22T23:23:09Z.
Validated on
c5a6503— all four points holdctest --preset dev --no-tests=error -R "^pixel_aot_|^rdna2_"gives 23/23 on RDNA4 (RX 9070 XT, driver 32.0.32029.2010, MSVC 19.44.35230, DXC 1.9.2602.17). Each of the four points, re-measured on this head:The legitimate upper bound still passes, so the fix is not over-broad — that was the thing I most expected to break.
The mono-register spelling is now symmetric, and the scanner agrees on all three.
Load-bearing, not cosmetic
With the
sgpr_pairvalidation neutralised (if False:on the bounds check), 6 of 23 tests fail —pixel_aot_hardware,pixel_aot_buffer_color_hardware,pixel_aot_three_way_hardwareand their_warpcounterparts. So the negative controls you added actually pin the behaviour rather than merely existing.One residual, non-blocking
s_mov_b64 s[49:50], execstill reportsscanner=Truewhile the translator rejects it, because the scanner checks the mnemonic and not operand alignment. That is a different class from the original bug — one instruction in the counter, not a shader wrongly counted as supported — but it is the same family, and a sentence in the scanner's docstring saying alignment is out of scope would close it honestly.Nothing blocking left from my side.
AI-assisted; runs executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-23T09:20:33Z.
Updated against
main(325fe1e) addressing both review points:Full-width restore tied to both saved halves:
tools/pixel_aot.py, 64-bit restores (s_and_b64ands_mov_b64) using mono-register shorthandsNnow validate even register alignment (n % 2 == 0 and n + 1 <= 105) and check that both saved halves remain intact:[scalar.get(sN), scalar.get(s{N+1})] == [("entry", 0), ("entry", 1)].tests/pixel_aot_check.pyandtests/rdna2_tools_check.pyasserting rejection when the high SGPR (s51) has been clobbered prior to restore acrosss_mov_b64 exec, s50,s_and_b64 exec, exec, s50, ands_and_b64 exec, exec, s[50:51].Rejection of mixed-width restore streams:
tools/pixel_aot.pytracks the WQM expansion width (wqm_widthof 64 vs 32).s_and_b32ands_mov_b32) now require an established wave32 precondition (wqm_width == 32andscalar.get(reg) == ("entry", "w32")).s_wqm_b64) followed by a 32-bit low-only restore without this precondition is rejected. A 32-bit WQM expansion followed by a 64-bit restore is likewise rejected.tests/pixel_aot_check.pyandtests/rdna2_tools_check.py.Native Wave32 canonical shader test:
test_accepted_full_shader_wave32_b32_lifecycleintests/rdna2_tools_check.pycovering an end-to-end pixel shader with native 32-bit save, WQM, and restore (s_mov_b32,s_wqm_b32,s_and_b32).Verification
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T09:30:12Z.
The new controls at
30fd925cover the clobbered high half and the mixed-width pairs. One point remains:wqm_widthrecords which instruction was parsed.s_wqm_b32sets it to 32 unconditionally, ands_mov_b32records("entry", "w32")from operand width alone. Neither value checks a guest wave-size declaration. On the current API the same b32 sequence lowers with no profile or metadata establishing wave32. Please tie the low-only path to a validated guest wave32 profile, with a control that the same instruction sequence is rejected when the profile is absent or wave64. The full-width save/restore checks can stay independent.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-23T09:43:19Z.
Updated the low-only execution mask path to require a validated guest wave32 profile, and added negative controls for absent and wave64 profiles:
Guest Wave Profile Requirement:
wave_sizeandwave_profilekeyword arguments topixel_aot.lower()(and forwarded throughscan_unsupported_shaders.analyze_shader_instructions).32,64,"wave32","wave64", orNone); invalid values raiseValueError.s_mov_b32save ofexec_lo,s_wqm_b32 exec_lo, exec_lo, ands_and_b32/s_mov_b32restore) now require a validated guest wave32 profile (wave_size=32orwave_profile="wave32"), raisingValueErrorwhen absent or set to wave64.s_mov_b64,s_wqm_b64,s_and_b64) remain independent of the profile declaration.Negative Controls and Parity Verification:
tests/pixel_aot_check.py:s_mov_b32+s_wqm_b32+s_and_b32/s_mov_b32sequences lower to bit-exact HLSL parity against the canonical wave64 lowering whenwave_size=32orwave_profile="wave32".must_rejectwhen the profile is absent (None), wave64 (wave_size=64,wave_profile="wave64"), or invalid (wave_size=16,wave_profile="wave16").tests/rdna2_tools_check.py:test_accepted_full_shader_wave32_b32_lifecycleandtest_exec_mask_scanner_translator_agreementto verify translator acceptance withwave_size=32and assert rejection when the profile is absent or wave64.Test Results:
python -B tests/rdna2_tools_check.py:Ran 70 tests in 1.369s, OK (skipped=1)python -B tests/pixel_aot_check.py:Self-test passed.python -B tests/bidi_controls_check.py:Checked 675 tracked source, script and build/CI files: no bidirectional controls.python -B tests/docs_links_check.py:Checked 13 Markdown files and 158 links.python -B tests/pso_readiness_check.py:PSO census, evidence states, and native hash control passedpython -B tests/form_coverage_check.py:form coverage checks passedImported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T09:50:14Z.
ebea4efnow rejects the low-only stream with an absent or wave64 profile, and keeps the full-width checks. I found one API ambiguity to fix before merging: passingwave_size=64, wave_profile="wave32"silently selects wave32, although the caller also supplied contradictory metadata. Please keep one explicit guest-wave-size argument and document its provenance requirement at the entry point, or reject contradictory arguments with a control. Keep scanner and lowerer on the same rule.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-23T09:56:32Z.
Updated in
1956565:Single Explicit
wave_sizeArgument:wave_profileargument completely, leaving a single explicitwave_size: int | None = Noneparameter across bothpixel_aot.lower()andscan_unsupported_shaders.analyze_shader_instructions.wave_size in (32, 64)when provided, raisingValueErroron any other value or type (e.g.16or"wave32"), and disallows any conflicting keyword arguments.Entry-Point Provenance Documentation:
lower()andanalyze_shader_instructions():Updated Controls & Consistency:
tests/pixel_aot_check.py:must_rejecton invalid wave sizes (wave_size=16,wave_size="wave32").tests/rdna2_tools_check.py:ValueErroron invalid wave sizes (wave_size=16,wave_size="wave32") andTypeErroron unexpectedwave_profilekeyword arguments.res_invalid["lower_error"] == "Invalid guest wave size: 16").Verification
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T10:30:46Z.
Thanks for making
wave_sizethe only profile argument. I resolved the conflict with the texture-offset change and pushedefd5461. The short-width save now checks the SGPR range, and the width argument must be an integer. The new LLVM 15 test assembles both low-half restore forms for gfx1013 wave32, decodes them, checks that they produce the reference HLSL, and rejects the same instructions under the wave64 profile. The full pixel binary checks and Python controls passed locally. The result covers encoding and lowering; we have no new native console capture.Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-23T15:34:58Z.
Post-merge check of
87dd090: the mask tracking holds, and one SCC path stays stale. Translation probes, plus what I could and could not run.What ran, and what did not
87dd090checked out on this host:python3 -B tests/rdna2_tools_check.py→ 71 tests OK, 1 skipped (test_llvm_comparison, nolibLLVMhere), the four new wave32 acceptance tests included.check_controlsalso passes.check_wave32_mask_binaryneedsllvm-mc-15/llvm-objcopy-15/libLLVM-15.so.1; this host has neither, so I did not re-run the binary comparison — CI runs it on Ubuntu.lower()/translate()on hand-built programs.The mask tracking behaves
Probed at
87dd090:s_mov_b32 s14, exec_lois refused without a declared profile (32-bit execution mask save requires a validated wave32 guest profile) and accepted withwave_size=32; the b64 forms onexec_lowork with or without one; restore without save, double restore, a save taken inside the quad region, and mismatched save/restore widths all raiseUnsupported execution mask; odd pairs raiseInvalid 64-bit scalar register pair. Thes_wqm_b32gate is covered by the tests themselves (tests/rdna2_tools_check.py:2044, withwave_sizeabsent,64and16cases beside it).One silent-wrong-code path
The three save branches (
tools/pixel_aot.py:1987,:1993,:2005) do not resetscc, while every other mask branch does (:2013,:2020,:2027,:2037,:2046,:2053,:2063,:2072). On hardwares_mov_b64writes SCC. So thisis accepted and lowers to
i.e. the
s_cselect_b64runs on the SCC left by the earliers_and_b64, not on the exec mask thes_mov_b64would have written. Wrong code, no diagnostic. The gap predates this PR for the bracketed form (s_mov_b64 s[a:b], exechad the same omission), but the two new save shapes replicate it, and thescc is Nonerejection fors_cselect(:2094) already exists to catch an untracked condition.Smaller notes
exec_lo(:1987) is accepted without a declared wave size, while the b32 save is gated onwave_size=32(:2006). One of the two orders is wrong; which one is a design call.wave_size=32, a b64 save followed by a b32 restore is refused (Unsupported execution mask) because the half is labelled("entry", 0)rather than("entry", "w32"). That refuses a legal wave32 sequence rather than miscompiling it.AI-assisted; probes executed locally. The SCC path and the line references come from a separate review pass and were reproduced here at
87dd090.