Repository navigation
startup: translate in-process compute programs on worker threads (opt-in) - #3571
JohnConnorNPC wants to merge 4 commits into
Conversation
Under Wine a missing name in the ~274k-entry shader cache costs ~155 ms, and the draw and Dispatch paths probed the cache root with draw_lock held: request parts, the slot 57 base manifest, graphics and compute manifests and the compute .cs.hlsl. These now ask the cache index first and skip the disk for an absent name. The index gains a change feed: one thread queues ReadDirectoryChangesW on the cache, then makes the listing, and adds every created or renamed-to name. req_ names (written only by runtimes) use the listing and this process's own writes. Translator files are answered absent only while the feed is reading and was reading before the listing began; a dropped batch or a feed error sends them back to the disk. These probes never make or wait for the listing, so draw_lock no longer waits for it. A 10 s counter line reports each probe's skipped and on-disk counts, the feed state, records, added names, lookups that found a name added after the listing, and contradictions.
A compute manifest that is absent, stale or unmarked is looked for again on the retry schedule, and each retry re-reads <key>.txt with draw_lock held. With hundreds of such keys those re-reads add up to seconds of draw_lock per 10 s, although nothing in the cache changed. The change feed now also watches last writes and sizes, and numbers every record whose name starts with a cache key. A retry takes a change mark before it looks on disk and keeps it with its miss. The next retry, while no <key>.* name has a record from that mark on, repeats the miss without a file-system call. A created, removed, renamed or rewritten file of the key sends it back to the disk, and so does a feed that is not reading. The cache probes line counts these retries as "compute retry unchanged".
With X2W_NATIVE_SHADERS, the first Dispatch of a compute key translates it in the stand-in while holding draw_lock. One translation takes up to seconds, so a burst of new keys holds draw_lock for nearly all of the wall time and draws and Dispatches on other threads wait behind it. X2W_NATIVE_COMPUTE_WORKERS=<1-8> moves that translation onto worker threads (native_compute_worker.h). Dispatch queues a key once and polls it on later Dispatches without waiting; until a worker has finished, that key's Dispatches are refused with "in-process translation still running". A ready result is moved into the key's entry; a refused key then reads its published manifest, as before. Each worker has its own DXC compiler. Unset, the Dispatch translates as before. A 10 s line reports the workers' queue, results, longest wait, time translating and the Dispatches refused while a key was translating.
|
This overlaps #3506 (which continues #3467). Both move the in-process compute translation off What each one does that the other doesn't:
Your E1/D1 numbers are the case for more than one worker: 36 k refused Dispatches with three workers against 1.0 M with one. #3506's published fallback covers the other side: Dispatches of a pending key that has a published translation are drawn, not refused. #3506 has an approving review. Proposal: rebase this onto #3506 and keep only the multi-worker part, i.e. the per-thread compiler, the worker count and the status line, as a follow-up to it. With the fallback in place, only keys with no published translation are refused while they translate, which shrinks the trade-off that keeps this switch opt-in. #3570 (the index) is independent and can stay as it is. |
The cache index check now runs before the plain-key manifest probe instead of inside it, so the guard tests/startup_gfx2hlsl_ps57in_check.py reads is the same expression as on main. Call order and probe counts are unchanged.
|
Closing this one: it overlaps #3506, which already moves the in-process compute translation off The cache-index change in #3570 is separate and stays open. AI-assisted. |
Stacked on the cache-index PR from the same series: the first two commits here are that PR's. Rebased onto current main; one conflict in the compute dispatch translation (now calls
compile_native_shader) was resolved by hand. This rebase was not rebuilt or re-run; the measurements below were taken before it.Summary
With
X2W_NATIVE_SHADERS, the first Dispatch of a compute key translates it in the stand-in (frontend + DXC) whileholding
draw_lock. A translation takes from milliseconds to several seconds. When a new scene brings hundreds of newkeys,
draw_lockis held for most of the wall time, and draws and Dispatches on other threads wait behind it.X2W_NATIVE_COMPUTE_WORKERS=<1-8>moves that translation onto worker threads (src/startup_stubs/native_compute_worker.h):Dispatches are refused with
in-process translation still running(counted as untranslated).the key reads its published manifest in that Dispatch, as before. The native-first order is kept: no published
manifest is read while a key is still translating.
requests are locked; the D3D12 device is free-threaded; DXC and frontend cache publishes use unique temporary names
and accept an identical winner.
x2w-draw native compute workers <n>: ...every 10 s: queued, translated, refused, waiting, most at once, longestwait, time translating, and Dispatches refused while their key was translating.
0or any other value: unchanged. The Dispatch translates, and its first Dispatch is recorded, asstartup_compute_dispatch_native_checkstep 1 requires. That is why the switch is opt-in.Trade-off
The first Dispatches of a key that would translate are now skipped until a worker has it. Before, they waited (with
the whole stand-in) and then ran. In the measured run below (one worker, the same mechanism):
480-510 s, at 11-14k per second.
(487.8 s). In the first 600 logged keys, the queue wait reached 240 s and a key was adopted on average 95 s after
it was queued.
the 121 that translated, which is 91% of the worker's time.
Ideas to reduce it, not in this PR:
Tests
Wine only (Proton wine 11.0, clang-cl cross build). Windows CI has not run. No device fixture covers the switch
yet. The existing native compute fixtures run unchanged with the switch unset, but were not run locally.
Measured (local game run, one console executable under test, on 26df182 with the commits cherry-picked)
wait was 95 s (D1: 240 s), and the queue was empty about 130 s after the burst began.
0-3 s per 10 s). It matches the title's streaming phase: storage decompression requests rise and then flatten exactly
where frames recover. That is an inference from timing; what bounds that phase was not measured.