startup: write shader requests from the shader archive before a run #1743
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1750"
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 NiiRoZz on 2026-11-24T18:06:45Z.
Change
Shader translation requests used to exist only after the title created a pipeline, so every new pipeline cost a run before it could be drawn. This adds
tools/startup/archive_requests.py, which writes runtime-keyed requests from the shader archive, without starting the title:How the format was found:
extract_shaders.pyreads a different record structure in the same file and does not see them.What the tool does:
s_inst_prefetch, padded in 64-byte blocks, starting on a 256-byte step. A program ends at an all-zero block or at the next program's header.s_endpgm. A program cut short by an all-zero block is counted as incomplete and never paired.req_<key>.{a,b,root}with the runtime's key:.band.rootfirst, then.a, each through a temporary file and a rename.What it cannot take from the archive (documented):
req_*.rootfrom earlier runs (by default the cache) and writes each pair once per distinct root. Unused combinations cost translation time and nothing else.Refs #1723 (the translator census this population produced, with a per-pair correction in its comments).
Verification
Branch head
754dd51f(615189afplus two commits addressing review findings: strict adjacency ands_endpgm, then an inflate limit, write-failure handling and independent test keys), onmainata4d17cf5. Windows 11 (26300), Python 3.13.The synthetic test builds an archive from documented encodings:
expands_endpgmwords pluss_inst_prefetch, with no title bytes. Each adjacent pixel/vertex pair must become one request per root, with the key computed by the test's own copy of the runtime's FNV-1a (notgfx2hlsl.pipeline_key) and exact parts. Controls that must write nothing:s_endpgm;--rootspath, and a cache without roots (both refused with a message).A pair split between two consecutive streams must be carved whole, and a second run must write nothing new.
Mutation checks, each run against a temporary edit that was then reverted. Every mutant failed the check:
s_endpgmruleSTEP0x100 → 0x40.awritten before.b/.root.aleft behind a blocked.rootat % 4check dropped…2econtrol)oversizedcount wrong.tmpfoundLocal data, not in the repository. On a Scarlett package's shader archive (the adjacency and
s_endpgmrules left these counts unchanged: 0 incomplete programs) the tool joined 1,079 zlib streams into 800 runs, carved 4,982 programs (2,730 pixel, 2,115 vertex, 137 other) and wrote 3,774 requests for 1,258 pairs and three recorded roots in 22 s. A cold startup run recorded eleven pipelines:<key>.txt, both.hlslfiles and both.csofiles were byte-identical to the run's.Translated on its own, the population gives 104 of 1,171 pairs that translate under at least one root (measured before stream joining). The refusals are tracked in #1723.
Evidence and follow-up
run.ps1 -Translatestill covers anything this misses.Checklist
AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:17:31Z.
Review: COMMENTED
Review of head
615189afda(comment only, not an approval). First review of this PR; the base isa4d17cf5and main is now 10 commits ahead. I read the diff, not the existing comments.Verdict: 0 P1 / 2 P2, plus nits.
P2-1: inflate is unbounded (tools/startup/archive_requests.py,
chunks()andstreams())inflater.decompress(window)has nomax_length, andstreams()keeps every consecutive stream injoineduntil a gap appears. A stream of at most 128 KiB can inflate to about 100 MB.python3 -B tools/startup/archive_requests.py bomb8.bin cache --roots rootswith a 796 KB archive of 8 consecutive zlib streams, each inflating to 100 MiB:/usr/bin/time -vshowsMaximum resident set size 1669384 kB, exit 0.max_lengthcheck (reject above about 1 MiB) and a cap onjoinedare cheap. The archive is the user's own input, hence P2.P2-2: the tests do not guard several behaviours the PR text and docs claim
gfx2hlsl.pipeline_key, the function the tool uses, so a wrong key formula or argument order cannot be seen; it also asserts stdout text such aspairs=4 written=8 streams=3.No finding
'req_%016x' % key, the archive carries no names, and the cache and roots paths come from argv.<name>.<pid>.tmpandos.replaced in the order.b,.root,.a; a concurrent run writes identical bytes, and the.acheck gives idempotence.gfx2hlsl.Unsupported; a truncated stream is skipped; an empty archive returns early. Fixtures are synthetic.Run (worktree at the head)
python3 -B tests/startup_archive_requests_check.py: passed.tests/startup_gfx2hlsl_capture_check.py: passed. docs_links_check (17 files, 365 links), bidi_controls_check (1300 files),git diff --check origin/main...HEAD: clean.git checkout --). Caught: keep a program that reaches the end of its stream; pair a vertex program with any previous program; drop the root dedupe; drop the existing-.askip; swap thepipeline_keyarguments; drop the 64-byte rounding of the stream end; do not join consecutive streams. NOT caught:STEP0x100 -> 0x40; writing.afirst instead of last (the marker order is untested); dropping the header-tag check; dropping theat % 4 == 0check; keeping empty root files.Nits
pipeline_key(vs_code, ps_code, root)is called with(ps, vs); consistent withtranslate_requestbut the parameter names mislead, so a comment would help.read_rootsusesopen().read()without closing; a failed write leaves a.tmpfile; zero streams or zero pairs exits 0, so pointing it at a wrong file looks like success;req_*.rootfiles from older runs are read from the cache by default (documented).req_*.aas the ready marker this PR relies on, and #1641 touches the same area; all three edit the CMake and AGENTS.md test lists, so expect trivial conflicts. I did not check them semantically.Not run: PowerShell,
run.ps1, the real archive, the fxc translation, ctest, YAML parsing of windows.yml (PyYAML missing; the change is one list line). C++, llvm-mc and shader forms do not apply to this diff.Linux limits: no Windows, WARP, DXC or GPU here; LLVM 19 only (CI pins LLVM 15). Anything that needs them was not run.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-24T18:38:46Z.
Thanks for the review. Everything is addressed in
754dd51f. The review was on615189af;c357c8d3had already enforced strict adjacency and requireds_endpgm.P2-1, unbounded inflation.
inflater.decompress(window, MAX_INFLATE)with a 1 MiB limit (a measured stream inflates to 64 KiB). A stream that hits the limit without ending is counted asoversizedand skipped, never inflated in full.oversized=1. Removing the limit is detected.P2-2, test independence and mutants.
fnv_bytes/cached_translationind3d12_draw.inl, not fromgfx2hlsl.pipeline_key. Side note: the runtime's start value is1469598103934665603, one digit short of the standard offset basis14695981039346656037. The test reproduces it as written, because the existing cache keys depend on it.STEP0x100 → 0x40.awritten before.b/.root.root; no.amay exist for that keyat % 4check dropped…2ereq_*.rootin the roots directoryFour more mutants are also detected: the inflate limit removed, a temporary file left after a failed write, a write failure exiting 0, and an archive without pairs exiting 0.
Nits.
pipeline_key(ps, vs)argument order now has a comment: the runtime hashes its first recorded blob first, and only the order matters.read_rootsuseswith..a, and makes the run exit 1.On the local archive the result is unchanged: 1,258 pairs, 0 incomplete, 0 oversized, and 8 of 11 recorded keys.
On the overlap: this PR and #1749 each add one line after
startup_gfx2hlsl_capture_check.pyinAGENTS.mdand the workflow, so whichever lands second gets rebased.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:21:41Z.
Review: COMMENTED
Re-review at head
b3d3ea1368d2d4a3af458408f898b6cb5481dfe2(comment only, not an approval). The earlier review was at615189af; I read the diff against currentmainand the author's replies.Verdict: 0 P1 / 0 P2, two P3. Both P2 findings of the first review are resolved.
Earlier findings
inflater.decompress(window, MAX_INFLATE)caps one stream at 1 MiB andMAX_JOINEDcaps a joined run at 64 MiB. I rebuilt the earlier repro (8 consecutive zlib streams, each inflating to 100 MiB, an 815,593-byte archive): the run now ends in 0.23 s with a maximum resident set of 27 MB (it was 1,669,384 kB), reportsoversizedand exits 1 with "no program pair found".FAILnow:STEP0x100 to 0x40,.awritten before.band.root("no ready marker"), header-tag check dropped,at % 4check dropped, empty roots kept. Also caught: inflate limit removed, pair accepted without adjacency,pipeline_keyarguments swapped,complete()always true. The expected keys now come from the test's own FNV-1a and the revision text fromd3d12_draw.inl, the summary is parsed into a dict.Findings
size + len(data) > MAX_JOINEDreplaced byFalseintools/startup/archive_requests.py(streams());tests/startup_archive_requests_check.pystill passes. The PR text anddocs/startup-runtime.mdstate the cap. A guard needs about 65 consecutive streams of 1 MiB of zeros (a few KB of archive) and a check that the joined run is split.pipeline_key(previous[2], program, root)), whilegfx2hlsl.pipeline_keynames its first parametervs_code, and the runtime hashesstages[0]/words[5]first (d3d12_draw.inl:271,:357). The comment added in this head says only the order matters, and the "8 of 11 recorded keys" in the PR text supports a = pixel, but I could not check it here (no real archive or run). The synthetic test pins only that the tool and the test agree.Other things I checked, no finding
'req_%016x' % key; the archive carries no names..b,.root,.alast, each through<name>.<ext>.<pid>.tmpandos.replace; a blocked.rootleaves no.aand no temporary file and exits 1 (the test covers it).stage_of()reading the disassembler directly instead ofgfx2hlsl.classify) matches the export-target rule it documents; the test has a vertex program with a refusedv_cndmask_b32_e64form to keep pairing independent of translatability.Commands run (Linux, worktree at the head)
python3 -B tests/startup_archive_requests_check.py: passed.python3 -B tests/startup_gfx2hlsl_capture_check.py: passed.tests/docs_links_check.py(17 files, 368 links),tests/bidi_controls_check.py(1313 files),git diff --check origin/main...HEAD: clean.git merge-treeagainst currentmain: no conflicts.archive_requests.pyas listed above, each restored withgit restore;git status --shortclean afterwards.Limits: Linux only. I did not run PowerShell, a real archive, the fxc translation or ctest, and the Windows 2025 runner script could not be used in this session, so nothing in this diff was run on Windows.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-24T19:02:15Z.
Merged current
main(conflict inCMakeLists.txtonly: both new test registrations kept). Merging surfaced one behaviour change, fixed in92f8c6cd:mainnow refusesv_cndmask_b32_e64with NEG on an immediate insidegfx2hlsl.decode, andgfx2hlsl.classifygoes throughdecode. On the local archive, 289 carved programs became "undecodable" and 143 pairs were lost.stage_of()applies the same export-target rule asclassifybut reads the disassembler directly. The result is back to 1,258 pairs with 0 undecodable. The 11 recorded pipelines, re-keyed with the current revision, still give 8 of 11.d3d12_draw.inl(mainbumped it tox2w-startup-shader-4). One synthetic vertex program contains that refusedv_cndmaskform; going back toclassify()loses the pair and is detected.b3d3ea13moves this PR's entry inAGENTS.mdand the workflow two lines further down. #1749 and this PR now merge intomainin either order without conflicts (checked both orders withgit merge-tree), so the rebase I mentioned earlier is no longer needed.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:25:09Z.
Review: COMMENTED
Retest at head
3543b48937(comment only, not an approval). Earlier review was atb3d3ea1368.Result: no P1/P2 findings. The delta is one file, tests/startup_archive_requests_check.py (13 insertions, 1 deletion), and it resolves the earlier P3 about the 64 MiB joined-run cap: the check builds 130 consecutive 512 KiB zero streams (65 MiB inflated) and requires the summary to report streams=2.
Linux checks run locally in a clean worktree at this head:
Mutation (local, reverted, tree clean afterwards): in tools/startup/archive_requests.py, 'size + len(data) > MAX_JOINED' replaced by 'False'. The check exits 1 with "FAIL joined run capped at 64 MiB: got '1', want '2'".
Win2025 (Windows Server 2025 build 26100, WARP, coordinator run, full default target set): Debug dev and Release /O2 builds succeeded; startup_stubs and startup_stream_request_warp 2/2 passed in both (Debug 1.49 s, Release 1.53 s). Windows Python check tests/startup_archive_requests_check.py ok (1.4 s).
Still open from the earlier review (P3, unchanged): the key order (pixel program hashed first) is an empirical claim that this session could not check against a real archive.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-24T20:08:43Z.
Thanks.
MAX_JOINED: covered in3543b489. 130 consecutive 512 KiB streams (65 MiB inflated, a few KB on disk) must come out as two joined runs. Replacing the cap condition withFalsenow fails the test.Key order: the runtime hashes the first recorded blob first (
aincached_translation). In every pipeline this tool covers, that first blob is the pixel program;pipeline_key's first parameter is namedvs_code, but only the order is used. The evidence is the local measurement in the description, re-checked after mergingmain:x2w-startup-shader-4revision);<key>.txt,.hlsland.csofiles were byte-identical to the offline ones.With the pair swapped, none of the 8 would match. I'd leave renaming the
gfx2hlslparameter to a separate change, since this PR doesn't touchgfx2hlsl.py.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:10:30Z.
Review: COMMENTED
Review of head
74a3460c77bcf85645b2ac8360ca054512f0c9ef(comment only).Scope:
tools/startup/archive_requests.py(new),tests/startup_archive_requests_check.py(new), docs/startup-runtime.md, plus CMake/CI/AGENTS.md registration of the new check. Title is neutral. Mergeable. CI: Linux Python checks, gfx1013 fixtures and Windows build/test all pass (the /O2 and chart jobs were skipped).Commands run locally (Linux, worktree at the head SHA):
python3 -B tests/startup_archive_requests_check.py->startup_archive_requests_check passedpython3 tests/docs_links_check.py-> passed (18 files, 396 links)python3 tests/bidi_controls_check.py-> passed (1430 files)git diff --check origin/main...HEAD-> cleanMutations (each reverted with
git checkout -- .):pipeline_key(program, previous[2], root)-> test fails (request keys and downstream checks).at == next_step(...)adjacency condition -> test fails (second runcount 10 vs 8).existingearly-return inwrite_request-> test fails (second runwritten 8 vs 0).All three were killed, so the new logic is well covered.
Findings
archive_requests.py:94: only a zlib header of0x78is accepted. Streams with other CMF/FLG levels (for example0x48) are skipped silently. The docs say "measured archive", so this is fine, but a counter for skipped candidates would make a miss visible.archive_requests.py:96-98:WINDOWis 128 KiB of compressed input. A valid stream longer than that is dropped without a counter (only the inflated-size cap is counted asoversized). Consider counting it.archive_requests.py:35:complete()accepts any 4 bytes matchings_endpgmat a 4-byte offset. This could also match an inline literal. Low risk, because the pair is also gated on stage and position.Not run: Windows/WARP (
win2025). This is an offline Python tool with no shader lowering or C++ change, and Windows CI already passed.AI-assisted; commands listed were executed locally.