shader: add a scan for the pixel input mask location #1662
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1669"
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 RenzoWit35 on 2026-11-24T16:46:10Z.
Change
Adds
tools/startup/ps_input_scan.pyandtests/startup_ps_input_scan_check.py, registered as theCTest
startup_ps_input_scanand in the platform-independent Python list inwindows.yml. Asection in
docs/experiments.mddocuments the command.For every pixel shader (request directory,
--pixel-dirof containers or raw blobs, or a capture)the tool derives, from the disassembly alone, the live-in vector registers, the I/J interpolation
pairs and the registers split into 16-bit halves. It tries every candidate location in the
pipeline's byte regions (raw blob header; FSSM head/tail, XDAT entries and every other container
part; capture description and state blocks; tagged words) and reports which location holds a mask
whose register layout fits every shader.
Two kinds of agreement stay separate:
whose layout is exactly as large as the highest live-in register needs count as "tight"; this
separates a real mask from an all-ones word, which is consistent with everything.
mask predicts for bit 15) is reported on its own line and never votes. It tests the assumed
register widths, not a location, and is not proof of the hardware register order.
Loop-carried registers: a first read inside a loop of a register that is written later in program
order is reported as ambiguous and does not vote (the same test gates the interpolation and
16-bit-half evidence, and aliases do not cross a branch or a branch target). A branch the text does
not resolve, or an indirect branch, makes every such first read ambiguous. A contract no address
mask can satisfy is excluded and counted on its own header line.
The enable/address relation is reported per candidate (equal, subset, other); the layout is taken
from the address mask. Default output is aggregates only;
--listadds pipeline ids and--jsonalways keeps them. It does not changegfx2hlsl.py,pixel_aot.pyorcapture.py.Sources of regions: raw blob header; for a container the FSSM head/tail, XDAT entries and every
non-DXIL part (
ps.part.<TAG>); with--capturethe 96-byte description and, only when the capturealso holds that memory, the two state blocks; and, in a request directory, every other
req_<key>.<ext>file up to 1 MiB asreq.<ext>. The sibling files are the way to scan a recordeddescription or state block without changing the tool.
After the two agreement lines,
full matches that also agree on every packed splitnames the fullmatches that also predict every split register correctly; it does not change ranking or verdict.
How to run on local records
Pipelines are numbered
p000001... in sorted file-name order and file names are never printed.Report only aggregates from stdout: the
pipelines:andinformative contracts:lines, the toptable rows (region, candidate, counts), the
verdict:line, themask agreement:line and thepacked-position agreement:line, theambiguous live-in readsandcontracts no mask can satisfylines and, when present, the packed-split line. Do not post the JSON,
--listoutput or the records.Verification
Commit under test: the PR head.
Negative controls (changed, run, reverted):
WIDTHS[3]3 -> 2 fails the layout assertion; treatingexpoperands as destinations,low & high->low | high, disabling alias tracking andrecording SDWA evidence on compare forms each fail a contract assertion; restoring the linear
first-read rule, keeping aliases across block targets, not excluding unsatisfiable contracts and
counting every full match in the packed line each fail their own control; making the packed rule
vote again fails the vote cross-check and the packed misfire control; dropping
tightfrom theranking fails the all-ones decoy control.
Also run at the same commit, all exit 0:
tests/docs_links_check.py,tests/bidi_controls_check.py,tests/run_checks_parallel_check.py,tests/startup_translator_check.pyandtests/startup_flat_param_check.py(Python 3.14.5, Windows 11). The CMake registration was addedbut not run through CTest locally. No GPU is involved.
Performance (synthetic, 12,000 containers, five regions of about 2 KiB of random bytes each,
default region limit): 14.4 s wall, 167 MB peak working set on the development PC.
Evidence and follow-up
statement about where real pipelines store the masks is made.
real data.
Enabled-but-unread inputs are expected, which is why
tightis a ranking statistic and not apass/fail rule.
cannot discriminate.
--region-limit).Refs #1629
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:00:05Z.
Review: COMMENTED
Peer review of #1669 (
ea6170bf3d0c0a10a6cc4295782ab774fa94d4a5): no defects found (0 P1, 0 P2).Summary
tools/startup/ps_input_scan.py: derives per-shader live-in register contracts (live-in VGPRs,v_interp_p{1,2}_f32I/J pairs, and 16-bit split registers viaand/shift/SDWA/bfe, excluding compare forms and loop-carried ambiguous reads) and ranks candidate locations across request directories,--pixel-dir, and--capturebyte regions without printing file names in default/aggregate output.tests/startup_ps_input_scan_check.py,CMakeLists.txt,.github/workflows/windows.yml,docs/experiments.md: adds unit and end-to-end checks on synthetic shaders/containers/captures, wirestests/startup_ps_input_scan_check.pyinto.github/workflows/windows.ymlandstartup_ps_input_scanintoCMakeLists.txt. Title-neutral andgit diff --checkclean.Verification
python3 -B tests/startup_ps_input_scan_check.py-> PASS (17 shader shapes, 13 destination cases, 9 layout masks, corpora A–F + decoy/loop/packed/container/capture/determinism/457-candidate reference checks)python3 -B tests/docs_links_check.py-> PASS (Checked 16 Markdown files and 350 links.)git diff --check origin/main...HEAD-> PASSx2w_pipe.py win2025 1669):--preset dev):cmake --build --preset dev --target startup_stream_consumer+ctest --preset dev -R '^startup_ps_input_scan$'-> 1/1 passed (9.68s:startup_ps_input_scan9.60s)./O2(--preset release):cmake --build --preset release --target startup_stream_consumer+ctest --preset release -R '^startup_ps_input_scan$'-> 1/1 passed (9.45s:startup_ps_input_scan9.38s).if any(r >= count for r in shader.live_in):->if False:intools/startup/ps_input_scan.py(consistent);python3 -B tests/startup_ps_input_scan_check.pyfailed as expected (AssertionErroronC1 coveragecheck, exit code 1). Restored viagit checkout -- ..AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T17:24:47Z.
The synthetic enable/address and decoy cases pass here. I reproduced a false negative with a branch-skipped definition: a forward conditional jump skips a write to v2, then the join reads v2. The scanner reports neither a live-in nor an ambiguous v2, so a mask that omits v2 can rank as consistent. Please add this source-built diamond and decoy mask. Either intersect the available definitions across incoming edges or keep the affected contract out of the vote.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T18:10:40Z.
Ran it, then tried to break it
At
ea6170bf, no build needed:Five mutations to
tools/startup/ps_input_scan.py, each restored afterwards:WIDTHS[0]2 → 1BYTE_ADDRESS['ena']0x286CC → 0x286C8PACKED_BIT15 → 14PAIR_BITSdrops bit 6CONTEXT_INDEX['ena']0x1B3 → 0x1B4 (same asaddr)The first three say the width table, the byte address and the packed bit are all load-bearing. The last two are the ones
worth a decision before this lands.
The two survivors
PAIR_BITSbit 6. Nothing in the fixture exercises a two-register input at bit 6, so it can be dropped from thetuple while every rule still passes. If a synthetic shader with an I/J pair there is constructible, one case would
close it. If bit 6 cannot occur in a real pipeline, saying so next to the constant is enough — either way the tuple
currently carries an entry the fixture cannot see.
CONTEXT_INDEX['ena']. Making the two entries equal (both 0x1B4) keeps the check green. That is a collision thescan is explicitly meant to distinguish: with one index for both masks, an agreement found at 0x1B4 would be reported
without anything noticing that
enashould be 0x1B3. If the fixture never builds a pipeline where the two masks differ,it also never tests that the two are kept apart.
Neither is a correctness bug in the tool today — both are places where the check would not notice an edit.
What the summary line does well
agreement is evidence about where the masks are stored; it does not prove hardware behaviouris exactly the rightcaveat, and having it printed on every run (not only in the docstring) is better than what most tools here do. The
bit 15split — reported on its own, never voting — is the same kind of honesty, assuming a case pins it; if one doesnot, that is the third thing to add.
Verdict
Reviewed
ea6170bf. The scan runs, its contract rules are counted and pin three of the five constants I tried. The twosurvivors are narrow but they are the two that encode "these two masks are distinct", which is the claim the tool exists
to test. No objection to the change itself.
Notes
Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-25T05:48:11Z.
Review: APPROVED
Verified head
ea6170bfon Windows x64 (Python 3.12).python -B tests/startup_ps_input_scan_check.py-> passed (ps_input_scan checks passed, 457 candidate summaries matched reference, 3PYTHONHASHSEEDdeterminism checks passed)python -B tests/docs_links_check.py-> passed (16 Markdown files, 350 links)Verdict: Approved at
ea6170bf.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:52:58Z.
@RenzoWit35 could you rebase this branch onto current
mainand force-push?GitHub reports head
ea6170bfas conflicting withmain, so it cannot be merged as is.Files that conflict with current
main(4aaea119):.github/workflows/windows.ymlCommands run locally:
Once it is rebased and CI is green it will be re-checked right away.
AI-assisted; commands listed were executed locally.