startup: translate shader requests in parallel and during a run #1749
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!1749
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1749/head"
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?
@NiiRoZz on GitHub · 2026-11-24 18:06 UTC · original
NiiRoZz:startup/shader-translate-watch→main· +351 −11 · 8 files · 6 commits · closed without mergingChange
Two changes to how
tools/startup/gfx2hlsl.pyconsumes the startup shader cache, so translations stop being the slow step between runs.Parallel
--pending. Requests are independent (each writes only its own<key>.*files), so a scan with more than one pending request now translates them in a process pool.X2W_TRANSLATE_JOBSsets the worker count. The default is the processor count, capped at 61 on Windows becauseProcessPoolExecutorrefuses more there.<key>.failinstead of ending the scan.Translation during a run.
gfx2hlsl.py --watch <dir> [seconds]repeats the pending scan (every 2 s by default) until it is stopped.run.ps1 -Render -Translatestarts the watcher on the shader cache beside the debugger, logs to<log>/translate.txt, and stops it, together with its worker processes (taskkill /T), in afinallyblock that still returns the debugger's exit code.--pendingstill retries every failure, as before.Related: #1641 caches the driver's PSO blobs. That is a different layer, and the two compose. A follow-up PR writes requests from the shader archive before any run.
Verification
Branch head
7b4275cb(baadbfaeplus a commit addressing review findings), onmainata4d17cf5. Windows 11 (26300), Python 3.13, x64.Mutation checks, each run against a temporary edit that was then reverted. Every mutant failed the check:
.fail-newer-than-marker rulestartup_gfx2hlsl_watch(3 failures, including a failure rewritten on later passes)startup_gfx2hlsl_watchstartup_gfx2hlsl_watch(no.failwritten)X2W_TRANSLATE_JOBSraisesstartup_gfx2hlsl_watch(ValueError)Stop-Processinstead oftaskkill /T)startup_run_ps1startup_gfx2hlsl_watch(parallel output ≠ serial)run.ps1never stops the watcherstartup_run_ps1("translator left running")Local data, not in the repository. A Scarlett package's 3,513 shader requests (132 translated, 3,381 refused) took 56.9 s with one process and 7.8 s with 16 workers on a 16-thread Ryzen. Every result file (
.txt,.hlsl,.cso,.fail) was byte-identical between the two runs. On this branch the eleven requests recorded by a cold startup run all translate in parallel, and their.csofiles are identical to the sequential ones.A cold-cache startup run with
-Render -Translatetranslated all eleven requests during the run, and the presented surface went from mean level 0 to 87.8/255 in that same run. One pipeline still counted as missing at the end of that run; I did not trace why, so this run is not claimed as evidence for anything beyond the watcher translating during a run.Evidence and follow-up
.band.rootbefore.a, each through a temporary file and a rename (publish_shader_requestind3d12_draw.inl), so.aexisting means the request is complete.docs/startup-runtime.mdgains "Translating shaders during a run", atranslate.txtrow in the log table, and theX2W_SHADER_CACHErow now points to-Translate.Checklist
AI-assisted (Claude Code).
🤖 Generated with Claude Code
@NiiRoZz on GitHub · 2026-11-24 18:38 UTC · original
Thanks for the review. All four points are addressed. The review was on
baadbfae.Stop-Processleaves the pool workers andfxc.exerunningrun.ps1stops the watcher withtaskkill /T /F. Thestartup_run_ps1stub watcher now starts a child process, and the check requires both to be gone; reverting toStop-Process -Forceis detected.7b4275cbpool.mapand stops--watchtranslate_one, which writestranslator error: <type>: <message>to<key>.failand carries on. Tested with an injectedZeroDivisionError.7b4275cbX2W_TRANSLATE_JOBSraisestranslation_jobs()falls back to the processor count for empty, non-numeric or non-positive values, and the Windows cap of 61 is applied there.7b4275cb95d59d2fTwo more changes from a separate review pass, also in
7b4275cb:publish_shader_requestreturns early when the file exists), so "retry once the request is rewritten" could never fire. The watcher's first pass now retries earlier failures once, and later passes skip them.chunksizeis nowlen(keys) // (jobs * 4)instead of a fixed 8, so small scans use every worker.The PR description has the updated verification and timings.
AI-assisted (Claude Code).
@NiiRoZz on GitHub · 2026-11-24 20:08 UTC · original
Thanks for re-checking.
BrokenProcessPool: fixed ind4bfa263. A pass now goes throughwatch_pass(), which reports a broken pool on stderr and returns; the next pass retries those requests, and the watcher keeps running. Tested by injecting aBrokenProcessPool; a mutant that drops the catch is detected.startup_run_ps1(including the child-process andtaskkill /Tmutants) andstartup_gfx2hlsl_watchpass ond4bfa263. The repository's own Windows job also runs both.ead2227amerged currentmain:run.ps1keeps both new switches (-Translate,-StartupBelow40), and the docs take upstream'sX2W_D3D12_RENDERrow. #1750 and this PR still merge intomainin either order.AI-assisted (Claude Code).
@R0Y00 on GitHub · 2026-11-25 01:10 UTC · original
Superseded by #2120 (
6921dcfd), which rebased your watcher and launcher work onto current main while retaining the later bytecode-resume behavior. Thanks for the original implementation and controls. I reran the watcher, translator and PowerShell 5.1/7 process-tree checks at the merged candidate. The original review and contribution remain linked here.@tedin7 on GitHub · 2026-11-24 18:13 UTC · original · reviewed
Peer review at commit
baadbfaea3d968d451781ccd2ac5abf512c75049(PRODUCTION_REVIEW_ONLY).Findings
run.ps1Stop-Processdoes not terminateProcessPoolExecutorchild processes on Windows (tools/startup/run.ps1):Stop-Process -Id $translator.Id -Forcein thefinallyblock only kills the parentpython.exe--watchprocess. If the debugger exits whiletranslate_pendingis running aProcessPoolExecutorbatch, spawned workerpython.exeprocesses (and anyfxc.exechildren) are left running. Usingtaskkill /PID $($translator.Id) /T /F(or a job object) would tear down the process tree.--watch(tools/startup/gfx2hlsl.py):translate_requestcatches(Unsupported, OSError, UnicodeError)andtranslate_tocatchesUnsupported. Any unexpected exception from a malformed request (e.g.struct.error,ValueError,IndexError) propagates out ofpool.mapand stops the--watchloop instead of recording a.failfor that key.X2W_TRANSLATE_JOBS=""(tools/startup/gfx2hlsl.py):int(os.environ.get('X2W_TRANSLATE_JOBS', 0))raisesValueErrorwhenX2W_TRANSLATE_JOBSis set to an empty string (int(os.environ.get('X2W_TRANSLATE_JOBS') or 0)avoids it).tests/startup_gfx2hlsl_watch_check.py): All 8 synthetic RTV requests inpending_runfail with the same message (unsupported: invalid RTV variant request), so swapping keys inpool.map(tested locally withlist(reversed(keys))) is not caught by the check.Verification
python3 -B tests/startup_gfx2hlsl_watch_check.py→startup_gfx2hlsl_watch_check passedpython3 -B tests/startup_run_ps1_check.py --text-only→0 failed (text only: requested)python3 -B tests/startup_gfx2hlsl_capture_check.py→startup_gfx2hlsl_capture_check passedpython3 -B tests/startup_gfx2hlsl_operand_count_check.py→operand count checks: 0 failedpython3 -B tests/docs_links_check.py→Checked 17 Markdown files and 367 links.python3 -B tests/bidi_controls_check.py→Checked 1299 tracked source, script and build/CI files: no bidirectional controls.baadbfaea3d968d451781ccd2ac5abf512c75049:--preset dev):cmake --build --preset dev --target startup_stub_consumer -- -j 8(3.51s),ctest --preset dev -R '^(startup_gfx2hlsl_watch|startup_run_ps1|startup_gfx2hlsl_capture|startup_gfx2hlsl_operand_count|startup_translator)$' --parallel 6 --no-tests=error --output-on-failure→ 5/5 passed (124.66s)./O2(--preset release):cmake --build --preset release --target startup_stub_consumer -- -j 8(1.09s),ctest --preset release -R '^(startup_gfx2hlsl_watch|startup_run_ps1|startup_gfx2hlsl_capture|startup_gfx2hlsl_operand_count|startup_translator)$' --parallel 6 --no-tests=error --output-on-failure→ 5/5 passed (124.74s).skip_failed.failmtime check inpending_keys→ caught bytests/startup_gfx2hlsl_watch_check.py(rc=1:watch pass,failure left unchanged by later passes,watcher output lines)..bas a ready marker inpending_keys(r'req_([0-9a-f]{16})\.(?:a|b|rtv)') → caught bytests/startup_gfx2hlsl_watch_check.py(rc=1:watch pass,one-shot pass).AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-24 19:28 UTC · original · reviewed
Peer review of head
95d59d2f7a6211708eca110e1d495638eaad9576(retest after the earlier review atbaadbfaea3d968d451781ccd2ac5abf512c75049).Result: no P1/P2 defects found in the local verification. All four earlier points are addressed.
Earlier points:
tools/startup/run.ps1): fixed. Thefinallyblock now runstaskkill.exe /T /F /PID $translator.Id, andtests/startup_run_ps1_check.pyhas a stand-in watcher that starts a child process and checks that both are gone, with two mutants (no stop at all, parent-onlyStop-Process).--watch(tools/startup/gfx2hlsl.py): fixed.translate_onerecords anyExceptionas<key>.fail(translator error: ...), and the watch check covers it.X2W_TRANSLATE_JOBS="": fixed.int(os.environ.get(...) or 0)inside atry, and the check covers'','abc','-3'.Read in full: the diff of
tools/startup/gfx2hlsl.py,tools/startup/run.ps1, the two checks, CMake, the workflow list and the docs. Points checked:<key>.*files, and the manifest is published with a temporary file andos.replace(gfx2hlsl.py:1392-1395), so killing the watcher in the middle of a translation cannot leave a half-written.txt.__main__guard is in place forProcessPoolExecutoron Windows (spawn), the 61-worker limit is applied, and an empty pending list gives zero jobs and no pool.pending_keysyields each key once (an.aand an.rtvfor the same key would need an FNV collision).X2W_SHADER_CACHEis set inrun.ps1:53before the watcher starts.Non-blocking notes (P3):
pool.mapcan still raiseBrokenProcessPoolif a worker is killed from outside (for example out of memory), which would end--watch. Catching it in the watch loop and retrying the pass would make the watcher match the new per-request error handling.--regex '^(startup_stream_request_warp|startup_stubs)$', sostartup_run_ps1(the only check that executestaskkill) andstartup_gfx2hlsl_watchdid not run on Windows in that phase. The text-only mode of the run.ps1 check ran here on Linux.Win2025 (coordinator run, Windows Server 2025 build 26100, WARP, target
startup_stream_consumer): Debugdevand Release/O2both gavestartup_stubsandstartup_stream_request_warp2/2 passed (Debug 0.48 s and 1.42 s, Release 0.53 s and 1.45 s).Linux checks run locally in a clean worktree at this head:
git diff --check origin/main...HEAD: cleantests/docs_links_check.py: passed (17 files, 367 links)tests/bidi_controls_check.py: passed (1299 files)tests/startup_gfx2hlsl_watch_check.py: passedtests/startup_run_ps1_check.py --text-only: 0 failedtests/startup_gfx2hlsl_capture_check.py: passedtests/startup_gfx2hlsl_operand_count_check.py: 0 failedMutations (local, each reverted with
git checkout -- .; tree clean):zip(keys, pool.map(...))changed tozip(reversed(keys), pool.map(...)):startup_gfx2hlsl_watch_check.pyexits 1 (sixteen "names its own base" failures).except Exceptionchanged toexcept ValueErrorintranslate_one: the check exits 1 (a translator error escaped translate_pending).AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-24 20:25 UTC · original · reviewed
Retest at head
d4bfa263ea(comment only, not an approval). Earlier review was at95d59d2f7a.Result: no P1/P2 findings. Both P3 notes of the earlier review are addressed.
Read the PR diff against origin/main (8 files) in full for tools/startup/gfx2hlsl.py, tools/startup/run.ps1 and the two checks. The run.ps1 finally block runs taskkill.exe /T /F /PID on the watcher, and the check's stand-in watcher starts a child and requires both to be gone.
Linux checks run locally in a clean worktree at this head:
Mutations (local, each reverted; tree clean afterwards), run against tests/startup_gfx2hlsl_watch_check.py:
Win2025 (Windows Server 2025 build 26100, WARP, coordinator run, target startup_stream_consumer set): Debug dev and Release /O2 builds succeeded; startup_stubs and startup_stream_request_warp 2/2 passed in both (Debug 1.74 s, Release 1.57 s). Windows Python checks: tests/startup_gfx2hlsl_watch_check.py ok (2.6 s), tests/startup_run_ps1_check.py ok (126.9 s).
AI-assisted; commands listed were executed locally.
Pull request closed