startup: translate shader requests in parallel and during a run #1742
Closed
NiiRoZz wants to merge 6 commits from
upstream-pr/1749 into main
pull from: upstream-pr/1749
merge into: R0Y00:main
R0Y00:main
R0Y00:codex/indirect-large-backed-views
R0Y00:codex/word3-preflight-check
R0Y00:codex/vertex-table-two-records
R0Y00:codex/live-index-alias
R0Y00:codex/copied-vertex-buffer-srv
R0Y00:codex/windows-stage-test-output
R0Y00:codex/preserve-live-srv-retirement
R0Y00:codex/share-render-target-tracking
R0Y00:codex/sgd5-negative-offset-fixture
R0Y00:coverage-dashboard
R0Y00:codex/mesh-loose-root
R0Y00:codex/mesh86-cache-padding
R0Y00:codex/xmem-scatter-preflight
R0Y00:codex/mesh-depth-ps
R0Y00:codex/indirect-dispatch-refresh
R0Y00:codex/compute-container-index
R0Y00:codex/startup-compute-formatted-load
R0Y00:codex/compute-indirect-producer
R0Y00:codex/compute-atomic-soffset
R0Y00:codex/mesh-dual-handoff
R0Y00:codex/startup-run-sh-watcher-control
R0Y00:codex/queue31-page-alias
R0Y00:codex/indexed-indirect-compute-root
R0Y00:codex/typed-buffer-view-metadata
R0Y00:codex/translated-indexed-address-alias
R0Y00:codex/fixed-mesh-create-result
R0Y00:codex/xmem-section-lease
R0Y00:codex/startup-slot86-mesh-cache
R0Y00:codex/restore-mesh-barrier-iteration
R0Y00:codex/translated-indirect-upload-index
R0Y00:codex/xapu-completion-opt-in
R0Y00:codex/translated-indexed-rect
R0Y00:codex/translated-indexed-indirect
R0Y00:codex/startup-mesh-lds-integration
R0Y00:codex/startup-console-ms24
R0Y00:codex/startup-slot57-mesh-request
R0Y00:codex/indirect-copy-provenance
R0Y00:codex/present-color-producer-trace
R0Y00:codex/compute-dispatch-binding-trace
R0Y00:codex/translated-indirect-table-buffers
R0Y00:codex/indirect-copy-provenance-base
R0Y00:codex/mix-half-literal-source
R0Y00:codex/translated-indirect-draw
R0Y00:codex/xmem-scatter-diagnostics
R0Y00:codex/slot148-recording-upload
R0Y00:codex/slot70-loading-art-verified
R0Y00:codex/command-list-upload-arena
R0Y00:codex/recover-failed-command-list
R0Y00:codex/startup-heap-timing-notes
R0Y00:codex/align-audio-input-timeline
R0Y00:codex/synthetic-depth-export-control
R0Y00:codex/startup-texture1d-on-windows
R0Y00:codex/1629-packed-position-fixture
R0Y00:codex/cpu-srv-refresh
R0Y00:codex/stream-root-srv-draw
R0Y00:codex/audio-mixer-timer
R0Y00:codex/startup-reload-published-shader
R0Y00:codex/priority-integrate-1284
R0Y00:codex/guest-sixteen-page-record
R0Y00:codex/aot-placed-dxr-batch
R0Y00:codex/guest-directory-selection
R0Y00:codex/gamesave-enumerate-read
R0Y00:codex/readme-archive-to-pixels
R0Y00:codex/pe-placed-view-draw
R0Y00:codex/archive-directory-gpu
R0Y00:codex/slot133-dxr-build
R0Y00:codex/materialize-placed-vertex-view
R0Y00:codex/dstorage-directory-offsets
R0Y00:codex/xg-nine-bc-copy
R0Y00:codex/xg-slot10-bc64-arrays
R0Y00:codex/dxr-guest-address-readback
R0Y00:codex/gpu-va-high-bits
R0Y00:codex/clarify-diagnostic-startup-scope
R0Y00:codex/xg-six-levels
R0Y00:codex/typed-derived-blend
R0Y00:codex/english-legal-text-progress
R0Y00:codex/address-bc-4ks
R0Y00:codex/dstorage-bounded-file-read
R0Y00:codex/wide-srv-offsets-menu
R0Y00:codex/startup-memory-srv
R0Y00:codex/bound-view-tail
R0Y00:codex/language-selector-readback
R0Y00:codex/setup-menu-progress
R0Y00:codex/cpu-plane-refresh
R0Y00:codex/startup-ubyte-vertex
R0Y00:codex/presenter-window-selection
R0Y00:codex/startup-uniform-buffer-lane
R0Y00:codex/intro-loop-timing
R0Y00:codex/static-clzero-loops
R0Y00:codex/document-rtx-intro
R0Y00:codex/startup-insertq
R0Y00:codex/nv12-startup-texture
R0Y00:codex/stream-stage-draw
R0Y00:codex/startup-null-uav-format
R0Y00:codex/startup-draw-capture
R0Y00:codex/shorten-windows-checks
R0Y00:codex/dstorage-rfc1950
R0Y00:codex/startup-dump-fence
R0Y00:codex/pr1135-review-base
R0Y00:codex/startup-stream-requests
R0Y00:codex/startup-chroma-view
R0Y00:codex/readme-graphics-pipeline-streams
R0Y00:codex/static-crt-free-tls
R0Y00:codex/arc-140t-rtx-5080-laptop-gpu-reports
R0Y00:codex/main-startup-progress-entry
R0Y00:codex/signed-dxil-catalogue
R0Y00:codex/reloc-free-preferred-base
R0Y00:codex/quad-dpp-bit-mask
R0Y00:codex/raw-srv-bounds
R0Y00:codex/rx9070-31044-hardware-report
R0Y00:codex/gpu-page-source-provenance
R0Y00:codex/runtime-placeholder-interior
R0Y00:codex/gpu-copy-queue-tile-order
R0Y00:codex/pe-pin-external-providers
R0Y00:codex/xmem-placeholder-reservations
R0Y00:codex/xmem-shared-physical-pages
R0Y00:codex/pe-package-startup
R0Y00:codex/xmem-tools-memory-query
R0Y00:codex/cpu-stack-output-import
R0Y00:codex/pe-load-security-cookie
R0Y00:codex/record-three-bvh-retests
R0Y00:codex/cpu-rbp-frame-anchor
R0Y00:codex/xmem-default-startup
R0Y00:codex/record-rtx-3050-ti-9597
R0Y00:codex/docs-readme-start-here
R0Y00:codex/check-compute-mad24-truncation
R0Y00:codex/docs-discord-community
R0Y00:codex/bound-rcx-branch-mutants
R0Y00:codex/rtx5060ti-bvh-62114
R0Y00:codex/837-neutral-readme-disclaimer
R0Y00:codex/record-rtx-3070-ti
R0Y00:codex/title-neutral-public-wording
R0Y00:codex/exe-shadow-frame-submissions
R0Y00:codex/exe-shadow-runtime-chain
R0Y00:codex/readme-polish
R0Y00:codex/gpu-coverage-nov23
R0Y00:codex/spirv-minlod
R0Y00:codex/shadow-shim-device
R0Y00:codex/exe-two-shadow-frames
R0Y00:codex/shim-dispatch-cleanup
R0Y00:codex/fix-spirv-cache-probe
R0Y00:codex/sampler-use
R0Y00:codex/ballot-bit-extract
R0Y00:codex/packed-fma-release
R0Y00:codex/cpu-packed-fma-o2
R0Y00:codex/publish-coverage-dashboard
R0Y00:codex/mesh-cbv-binding-order
R0Y00:codex/spirv-window-fixture
R0Y00:codex/ps-e32-float-uint
R0Y00:codex/ps-cbuffer-reads
R0Y00:codex/fixed-profile-rescan
R0Y00:codex/shim-compute-integration
R0Y00:codex/readme-visible-coverage
R0Y00:codex/readme-research-navigation
R0Y00:codex/integrate-pr-256
R0Y00:codex/indexed-mesh
R0Y00:codex/sampled-coverage
R0Y00:codex/first-ms
R0Y00:codex/dual-ps
R0Y00:codex/ps-attribute
R0Y00:codex/compute-first
R0Y00:codex/ps-export
R0Y00:codex/readme-research-status
R0Y00:codex/ps-layout
R0Y00:codex/blast-window
R0Y00:codex/chart-caption
R0Y00:codex/reviewer-roles
R0Y00:codex/blast-aot
R0Y00:codex/archive-program
R0Y00:codex/crc-stream-program
R0Y00:codex/exe-image-data-chain
R0Y00:codex/local-cpu-fixture-coverage
R0Y00:codex/exe-bound-frame-chain
R0Y00:codex/exe-mapped-comparison
R0Y00:codex/contribution-dependencies
R0Y00:codex/exe-entry-aot
R0Y00:codex/bink-frame-heap-integration
R0Y00:docs/hardware-seven-reports
R0Y00:codex/bink-custom-heap
R0Y00:codex/bink-heap-callers
R0Y00:codex/discussions-entry-points
R0Y00:codex/gpu-community-batch-64
R0Y00:codex/ffx-scratch-writers
R0Y00:codex/generic-project-documentation
R0Y00:codex/ffx-dispatch-rcas
R0Y00:codex/four-windows-gpu-reports
R0Y00:codex/title-neutral-project-wording
R0Y00:codex/community-coverage-provenance
R0Y00:codex/rcas-packed-texels
R0Y00:codex/community-gpu-retests
R0Y00:codex/community-build-and-gpu-reports
R0Y00:codex/ffx-provider-loop
R0Y00:codex/ffx-recurrent-views
R0Y00:codex/ffx-recurrent-resource
R0Y00:codex/amd-wave64-reports
R0Y00:codex/ffx-backend-slots
R0Y00:codex/upscaler-device-init
R0Y00:codex/ffx-context-lifecycle
R0Y00:codex/ffx-version-query
R0Y00:codex/ffx-provider-contract
R0Y00:codex/typed-object-callback
R0Y00:codex/cpu-ordinal-import
R0Y00:codex/chained-cpu-ranges
R0Y00:codex/cpu-import-call
R0Y00:codex/cpu-direct-call
R0Y00:codex/cpu-leaf-aot
R0Y00:codex/community-project-status
R0Y00:codex/script-state-path-replay
R0Y00:codex/script-state-evidence
R0Y00:codex/bc7-resident-tail
R0Y00:codex/bcpack-mip-tail
R0Y00:codex/bc7-texture-draw
R0Y00:codex/asset-ranges
R0Y00:codex/pixel-constants
R0Y00:codex/pixel-aot
R0Y00:codex/pre-exe-workloads
R0Y00:codex/root-signature-device-coverage
R0Y00:engineering/packed-bvh-leaves
R0Y00:engineering/bvh-build-and-update
R0Y00:engineering/intake-root-roundtrip
R0Y00:community/gpu-check-release
R0Y00:community/english-contributor-entry
No reviewers
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
R0Y00/Xbox2Windows!1742
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1749"
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:39Z.
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
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:13:32Z.
Review: COMMENTED
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.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-24T18:38:45Z.
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).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:28:04Z.
Review: COMMENTED
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.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:25:13Z.
Review: COMMENTED
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.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-24T20:08:42Z.
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).
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T01:10:54Z.
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.Pull request closed