Repository navigation
Conversation
gfx2hlsl.py --pending translated one request at a time. Requests are independent, so a scan with more than one pending request now runs them in parallel processes (X2W_TRANSLATE_JOBS, default the processor count, at most 61 on Windows). Results are byte-identical; 3,513 requests went from 44.0 s to 6.1 s on a 16-thread host. gfx2hlsl.py --watch <dir> [seconds] repeats that scan until stopped, and run.ps1 -Translate (with -Render) starts it beside the debugger and stops it when the debugger returns, so a pipeline created during a run is translated within seconds instead of on the next run. In watch mode a failure is not retried until its request is rewritten. Tests: startup_gfx2hlsl_watch (ready markers, failure retry rule, a live watcher, parallel equals serial) and startup_run_ps1 (-Translate starts the watcher on the cache and stops it; a mutant that leaves it running is detected). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tedin7
left a comment
There was a problem hiding this comment.
Peer review at commit baadbfaea3d968d451781ccd2ac5abf512c75049 (PRODUCTION_REVIEW_ONLY).
Findings
- P2 —
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. - P2 — Unhandled decode/translation exceptions terminate
--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. - Nit —
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). - Nit — Parallel key-pairing check (
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
- Linux checks:
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.
- Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at
baadbfaea3d968d451781ccd2ac5abf512c75049:- Debug (
--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). - Release
/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).
- Debug (
- Local mutation checks (each reverted immediately):
- Disabled
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). - Allowed
.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).
- Disabled
AI-assisted; commands listed were executed locally.
- The runtime writes each request once and never rewrites it, so the watcher's "retry once the request is rewritten" never happened. Its first pass now retries earlier failures once; later passes skip them. - run.ps1 stops the watcher with taskkill /T so its parallel workers and their fxc.exe do not outlive the run. -Translate without -Render warns. - Batches are sized to keep every worker busy (len // (jobs * 4)) instead of a fixed 8, which left most workers idle on small scans. - An unexpected translator error is written to <key>.fail instead of ending the scan and with it the watcher. - An empty or invalid X2W_TRANSLATE_JOBS falls back to the processor count; the Windows cap of 61 is applied in one place and documented. Tests cover each change, and a mutation of each is detected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… scan test The sixteen synthetic requests all failed with the same message, so a parallel scan that printed results against the wrong keys still matched the serial one. Each request is now an RTV variant naming a different missing base request, so every failure names its own base, and the test checks each printed result against its key. A mutant that reverses the key order is detected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review. All four points are addressed. The review was on
Two more changes from a separate review pass, also in
The PR description has the updated verification and timings. AI-assisted (Claude Code). |
R0Y00#1749 adds its check right after startup_gfx2hlsl_capture_check.py in AGENTS.md and the workflow, as this PR did, so whichever merged second conflicted. This entry now sits two lines further down, so the two PRs merge in either order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tedin7
left a comment
There was a problem hiding this comment.
Peer review of head 95d59d2f7a6211708eca110e1d495638eaad9576 (retest after the earlier review at baadbfaea3d968d451781ccd2ac5abf512c75049).
Result: no P1/P2 defects found in the local verification. All four earlier points are addressed.
Earlier points:
- Worker processes left running after the debugger exits (
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). - Unexpected translator exceptions ending
--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'.- Key pairing in the parallel scan: fixed. The check now uses sixteen RTV variants that each name a different missing base, and requires every printed result to name its own base.
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:
- Each request writes only its own
<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. - The
__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.- The Win2025 run used
--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): Debug dev and Release /O2 both gave startup_stubs and startup_stream_request_warp 2/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 failed
Mutations (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.
run.ps1: keep both new switches (-Translate and upstream's -StartupBelow40). docs: take upstream's X2W_D3D12_RENDER row and keep the -Translate pointer in the X2W_SHADER_CACHE row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A pool worker killed from outside (for example out of memory) raised BrokenProcessPool out of pool.map and ended --watch for the rest of the run. watch_pass() reports such a pass as incomplete; the next pass retries its requests. Tested by injecting a BrokenProcessPool; a mutant that drops the catch is detected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for re-checking.
AI-assisted (Claude Code). |
tedin7
left a comment
There was a problem hiding this comment.
Retest at head d4bfa26 (comment only, not an approval). Earlier review was at 95d59d2.
Result: no P1/P2 findings. Both P3 notes of the earlier review are addressed.
- BrokenProcessPool ending --watch: tools/startup/gfx2hlsl.py now has watch_pass(), which catches BrokenProcessPool, reports "translation pass interrupted, retrying", and does not mark the pass as done, so the next pass retries; the watch check covers it. docs/startup-runtime.md describes it.
- Windows coverage of the taskkill path: the Win2025 run below includes tests/startup_run_ps1_check.py and tests/startup_gfx2hlsl_watch_check.py on Windows.
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:
- git diff --check origin/main...HEAD: clean
- tests/docs_links_check.py: passed (18 files, 378 links)
- tests/bidi_controls_check.py: passed (1327 files)
- tests/startup_gfx2hlsl_watch_check.py: passed
- tests/startup_run_ps1_check.py --text-only: 0 failed
- tests/startup_gfx2hlsl_capture_check.py: passed
Mutations (local, each reverted; tree clean afterwards), run against tests/startup_gfx2hlsl_watch_check.py:
- 'except BrokenProcessPool' replaced by 'except KeyError': exits 1 ("a broken process pool escaped watch_pass").
- watch_pass returning False after a successful pass: exits 1 (the check's subprocess hits its timeout, because the first-pass retry never ends). Killed, though by a timeout and not a named assertion.
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.
docs: take upstream's X2W_D3D12_RENDER and X2W_SHADER_CACHE rows and keep the -Translate pointer in the latter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cold -Render runs stay black when pipelines write req_* requests but never get manifests (pipelines translated 0 / missing N). Add gfx2hlsl.py --watch and run.ps1 -Translate so translations publish while the title runs; keep R0Y00#2008 bytecode resume and -TraceCalls. Rebases reviewed R0Y00#1749 onto current main. Refs R0Y00#870. Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
|
Superseded by #2120 (6921dcf), 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. |
…1750) * startup: write shader requests from the shader archive before a run Translation requests were only written when the title created a pipeline, so every new pipeline cost a run before it could be drawn. A traced startup run showed the native programs come from 64-byte aligned zlib streams in the shader archive, byte for byte. tools/startup/archive_requests.py inflates those streams, joins a stream with the one that starts on the next 64-byte boundary, carves programs (36-byte header, s_inst_prefetch, 64-byte blocks on 256-byte steps) and pairs each pixel program with a directly following vertex program. Root signatures are not in the archive, so they come from earlier req_*.root files and every pair is written once per distinct root, with the runtime's key. gfx2hlsl.py --pending then translates them. Measured locally: 4,982 programs, 1,258 pairs, 3,774 requests in 22 s. Eight of the eleven pipelines of a cold run were among them with identical keys and byte-identical translations. Test: startup_archive_requests on a synthetic archive, with controls for unpaired programs, a pair cut off at the end of a stream, a stream off the 64-byte grid, a pair split across two consecutive streams, missing roots and a second run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * startup: address review findings in the archive request writer - "Directly following" is now enforced: a vertex program pairs only when it starts on the 256-byte step right after the pixel program. Before, any vertex program after a pixel program paired, whatever the gap. - A carved program must contain s_endpgm; one cut short by an all-zero block is counted as incomplete and never paired. - The memory map is closed, and the docs use a neutral <shader archive> placeholder. On the local archive both rules leave the result unchanged (1,258 pairs, 0 incomplete, 8 of 11 recorded keys), so every measured pair was already adjacent. The test adds a gap pair and a program without s_endpgm as controls, and a mutation of each rule is detected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * startup: bound archive inflation and harden the archive request tests Review follow-up. - A zlib stream that would inflate past 1 MiB (a measured one inflates to 64 KiB) is counted as oversized and skipped without inflating it in full, and a joined run of consecutive streams stops growing at 64 MiB. Before, a small crafted archive could make the tool allocate gigabytes. - A part that cannot be written leaves no .a and no temporary file and the run exits with an error; an archive without any pair also fails. Root files are read with a context manager. - The test computes the expected keys with its own copy of the runtime's FNV-1a (start value 1469598103934665603, as in d3d12_draw.inl) instead of gfx2hlsl.pipeline_key, parses the summary, and adds controls for an untagged program, a pair at offsets not a multiple of 4, an empty root file, an oversized stream, a blocked .root write and an archive without pairs. All nine mutants (step size, write order, tag check, alignment check, empty roots, inflate limit, temporary file cleanup, and both failure exits) are detected. The local archive gives the same 1,258 pairs and 8 of 11 recorded keys, with 0 oversized streams. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * startup: classify carved programs from export targets, not translator support main now refuses some forms inside gfx2hlsl.decode (v_cndmask_b32_e64 with NEG on an immediate), and gfx2hlsl.classify goes through decode, so 289 carved programs became "undecodable" and 143 pairs were lost. Which programs pair must not depend on whether they can be translated. stage_of() applies the same export-target rule as classify but reads the disassembler directly. The local archive is back to 1,258 pairs with 0 undecodable programs, and 8 of the 11 recorded pipelines, re-keyed with the current revision, are among the offline requests. The test reads the key revision from src/startup_stubs/d3d12_draw.inl (main bumped it to x2w-startup-shader-4) instead of hard-coding it, and one vertex program now contains that refused v_cndmask form; going back to classify() loses the pair and is detected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * startup: list the archive check apart from the watch check #1749 adds its check right after startup_gfx2hlsl_capture_check.py in AGENTS.md and the workflow, as this PR did, so whichever merged second conflicted. This entry now sits two lines further down, so the two PRs merge in either order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * startup: test the 64 MiB cap on joined archive streams 130 consecutive 512 KiB zlib streams (65 MiB inflated, a few KB on disk) must come out as two joined runs. Before, removing the cap still passed the test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Change
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