Record a launch's pipelines, rebuild them with the current translator, and warm them from preparation #497
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/497"
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 brcly/TuxBox. Originally posted by csj0oe on 2026-11-29T17:01:38Z.
Summary
A title creates its pipelines every launch, and the driver compiles them again whenever their translated shaders change. This branch makes the provider keep a record of the pipelines a run created, has preparation rebuild each record with the current translator and replay it through the host's own D3D12, so the next launch reads a warm vkd3d-proton and driver cache instead of waiting. It also moves the translator, the constant-buffer layer and the pipeline helper out of the launch and into
python build.py all, so no step of a launch needs Rust, a C compiler or the Windows linker.Measured on the card below: pipeline compilation in the cold launch took 233 minutes. In the warmed launch it took under a minute, across 81,561 graphics and 2,689 compute creation calls, none of them over 100 ms.
Records are written by default, capped at 4096 per kind and 1 GiB per run, and the folder is trimmed to its newest 1 GiB.
What changes
Recording
The provider writes each created pipeline into a folder in the guest's temp directory (
tuxbox_pipeline_recipesby default;TUXBOX_RECORD_PSOS=<dir>chooses another and0turns it off). A record holds:CreatePipelineState, with the offset of every pointer field;Pointer fields are zeroed before hashing, so records dedupe across runs instead of one copy per launch, and a record is named after the title's bytecode. The budget is bytes because one large compute record is about a hundred times a small one (15 KiB median, 1.6 MiB seen). The root signature cache is kept under
roots/and is still trimmed only by its own records.Replay
d3d12-pso-replay.exe(built with the D3D12 guest) recreates recorded compute and graphics pipelines on the host device through D3D12, which is what fills the driver's caches. It runs on a 64 MiB stack, matching the provider, because the driver's shader parser overflowed the default stack on an 870 KiB DXIL.TUXBOX_REPLAY_TRACEnames each record before and after it for a device that goes away with the process. Its receipt is read from the report it writes when stdout is empty, and the guest's output goes to a file rather than a pipe, since awineserverinherits the pipe and never closes it.Preparation runs the replay as a copy named after the executable the launcher was given: vkd3d-proton keys its pipeline cache by that name, so a helper called
d3d12-pso-replay.exefills a file no launch reads. The name comes from the invocation; none is written into the project. Mesa's cache, where the driver compiles live, is shared throughMESA_SHADER_CACHE_DIRas before.Rebuilding
A record survives a translator rebuild because it keeps the title's bytecode. Preparation translates each record's stages again with the current translator and the root the pipeline declares (
xshader --root), then compiles throughruntime_shaders.compile_dxil— the runtime's own entry point — with the shader-cache key the provider recorded. The flags, the slow markers and the -O0 fallback are therefore the decisions a launch would take, not a guess, and a DXIL store hit is reused before anything is compiled. The step reports each record as built for this translator, reused from the store, kept as recorded, or dropped.Staging happens beside the records, on the prefix's own disk, and a record is tested before it is copied: a compute record needs its title bytecode, a graphics record needs
replayable 1and either title bytecode or the translation recorded beside it.Translator
xshader --roottranslates a container with a root signature the container does not carry — a DXBC container or a bareRTS0payload — because a record keeps the title's bytecode and its root apart. On one recorded pair the same vertex program named registers t7, t9, t71, t72 and t75 from PSV without the root, and t67, t73, t74, t76 and t78–t80 with the root that declares them.Build
python build.py allnow produces the three things a launch loads:-p tuxbox-xshaderwith the host target;tools/build_frosty_cbv_layer.sh;tuxbox-pipeline-prep, linked aspipeline-prep.exe) with a digest of its sources beside it.The translator is a workspace member excluded from
default-members, so a barecargo buildstill builds only the Windows providers. A launch usesTUXBOX_XSHADERwhen set, otherwise the binary this checkout built, and refuses with the build command when there is none; a binary older than its sources is reported rather than silently rebuilt.The page-remap gate
retire_range()andcopy()now wait for in-flight GPU batches whose spans overlap before they retire imports or bind new pages, aspin()andwait()already did. A page remap can no longer replace pages a queued batch is still reading.Measurements
Taken with caches cleared, on one AMD card (RADV, GE-Proton):
Supporting figures from the recording and warming steps:
Verification
python tuxbox.py check --proton <dir> --prefix <prefix> --windows-dxc <dir>: all eleven gates pass, including Lanes on the GPU, the D3D12 regression controls and the shader translator on the GPU. The translator gate compares against the reference output, not merely a successful compile.pso_recipetests intuxbox-dxbcpass, pinning the recipe fields a replay rebuilds and the offsets it refuses.pso_recordtests pass under Proton Wine aftercargo xwin test -p tuxbox-d3d12 --no-run, including the byte-budget trim and the stream-hash test that ignores addresses.Not verified / known limits
dxil-spirv: Failed to remap. The next recording launch writes the pair that matches, so this needs a provider rebuild and one recording run to show the failure count fall.docs/FOCUS.mdand tracked as issue #215, and the crash is a GPU-side hang in which RADV reports a hard recovery followed by GPUVM permission faults, preceded in every case by five-second label waits. Both are present in runs from before this branch.retire_rangeblocks on a GPU fence from inside the XMem retire callback. XMem holds no lock the fence needs, so it is not a lock-order deadlock; the risk is narrower and real — the page-mapping worker registers its batch before applying it, so a fault on that worker inside the apply path would wait on a fence only that thread can signal.capturealso writes its files on the render thread, andapply'sexcludeparameter is accepted and unused outside the diagnostic log line.