Record a launch's pipelines, rebuild them with the current translator, and warm them from preparation #497

Merged
csj0oe merged 29 commits from upstream-pr/497 into main 2026-11-29 18:04:33 +00:00
csj0oe commented 2026-11-29 17:01:38 +00:00 (Migrated from github.com)

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_recipes by default; TUXBOX_RECORD_PSOS=<dir> chooses another and 0 turns it off). A record holds:

  • the subobject stream exactly as handed to CreatePipelineState, with the offset of every pointer field;
  • the title's own bytecode for each stage the stream points at;
  • the root signature bytes the pipeline is created with, in the descriptor's own precedence: the scene root, the reflected table layout, the sampler layout, or the title's root when the program is bound with that;
  • for a graphics stream, the input layout and the stream-output declaration, with their semantic names and scalar fields, so a replay can rebuild the arrays.

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_TRACE names 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 a wineserver inherits 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.exe fills 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 through MESA_SHADER_CACHE_DIR as 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 through runtime_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 1 and either title bytecode or the translation recorded beside it.

Translator

xshader --root translates a container with a root signature the container does not carry — a DXBC container or a bare RTS0 payload — 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 all now produces the three things a launch loads:

  • the translator, as -p tuxbox-xshader with the host target;
  • the constant-buffer layer, through tools/build_frosty_cbv_layer.sh;
  • the pipeline helper (tuxbox-pipeline-prep, linked as pipeline-prep.exe) with a digest of its sources beside it.

The translator is a workspace member excluded from default-members, so a bare cargo build still builds only the Windows providers. A launch uses TUXBOX_XSHADER when 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() and copy() now wait for in-flight GPU batches whose spans overlap before they retire imports or bind new pages, as pin() and wait() 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):

what number
pipeline compilation, cold launch 233 min
pipeline compilation, warmed launch under 1 min
pipeline creation calls in the warmed launch 81,561 graphics, 2,689 compute
those taking over 100 ms 0
records written after the root fix that create a pipeline 60 of 60
one preparation over this prefix 18,323 records staged, 12,649 replayed
pipelines created by that replay 2,774 compute, 2,929 graphics
driver time for it 22 s

Supporting figures from the recording and warming steps:

what number
distinct pipelines one run creates 2,335
distinct compute programs over 1 s to compile 674
their driver time 172 min
slowest single program 369 s
records in one prefix before these changes 1,283 / 128 MiB, of which 93 MiB translated DXIL
staging that prefix, sixteen jobs vs one 29.1 s vs 124.5 s
the same with the DXIL store warm 4.2 s
records that could not be replayed and were dropped from staging 5,674 of 18,323

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.
  • 667 Python tests pass, including the staging, root, replay-name and translator-choice cases.
  • 11 pso_recipe tests in tuxbox-dxbc pass, pinning the recipe fields a replay rebuilds and the offsets it refuses.
  • Six pso_record tests pass under Proton Wine after cargo xwin test -p tuxbox-d3d12 --no-run, including the byte-budget trim and the stream-hash test that ignores addresses.

Not verified / known limits

  • No NVIDIA card has run this. Every number here comes from one AMD card on RADV. Shared code still needs an NVIDIA run before it can be called done.
  • Graphics records warm only the build that recorded them. The runtime grafts into a raster stage what a command-line translation does not reproduce — a linked pixel program, a stencil redirect, the pixel root from the mesh table, the screen rectangle's generated geometry — so where the rebuild differs, the replay uses the translation recorded beside the title's bytecode. Those records go stale after a translator rebuild. Compute records keep the title's bytecode and its root and do survive one.
  • Records written before the root fix keep the title's root, which does not describe the shader the pipeline is created with, so they cannot warm; vkd3d refuses them with 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.
  • The title still crashes and runs at about 10 fps. Neither is compilation, and neither is caused by this change: the frame rate matches the writeback over-approximation already recorded in docs/FOCUS.md and 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.
  • Open review findings, left for the crash work: retire_range blocks 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. capture also writes its files on the render thread, and apply's exclude parameter is accepted and unused outside the diagnostic log line.
<!-- greyfinch-sync:brcly/TuxBox:issue:5553002702 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/497). Originally posted by [csj0oe](https://github.com/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_recipes` by default; `TUXBOX_RECORD_PSOS=<dir>` chooses another and `0` turns it off). A record holds: - the subobject stream exactly as handed to `CreatePipelineState`, with the offset of every pointer field; - the title's own bytecode for each stage the stream points at; - the root signature bytes the pipeline is created with, in the descriptor's own precedence: the scene root, the reflected table layout, the sampler layout, or the title's root when the program is bound with that; - for a graphics stream, the input layout and the stream-output declaration, with their semantic names and scalar fields, so a replay can rebuild the arrays. 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_TRACE` names 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 a `wineserver` inherits 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.exe` fills 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 through `MESA_SHADER_CACHE_DIR` as 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 through `runtime_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 1` and either title bytecode or the translation recorded beside it. ### Translator `xshader --root` translates a container with a root signature the container does not carry — a DXBC container or a bare `RTS0` payload — 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 all` now produces the three things a launch loads: - the translator, as `-p tuxbox-xshader` with the host target; - the constant-buffer layer, through `tools/build_frosty_cbv_layer.sh`; - the pipeline helper (`tuxbox-pipeline-prep`, linked as `pipeline-prep.exe`) with a digest of its sources beside it. The translator is a workspace member excluded from `default-members`, so a bare `cargo build` still builds only the Windows providers. A launch uses `TUXBOX_XSHADER` when 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()` and `copy()` now wait for in-flight GPU batches whose spans overlap before they retire imports or bind new pages, as `pin()` and `wait()` 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): | what | number | |---|---| | pipeline compilation, cold launch | 233 min | | pipeline compilation, warmed launch | under 1 min | | pipeline creation calls in the warmed launch | 81,561 graphics, 2,689 compute | | those taking over 100 ms | 0 | | records written after the root fix that create a pipeline | 60 of 60 | | one preparation over this prefix | 18,323 records staged, 12,649 replayed | | pipelines created by that replay | 2,774 compute, 2,929 graphics | | driver time for it | 22 s | Supporting figures from the recording and warming steps: | what | number | |---|---| | distinct pipelines one run creates | 2,335 | | distinct compute programs over 1 s to compile | 674 | | their driver time | 172 min | | slowest single program | 369 s | | records in one prefix before these changes | 1,283 / 128 MiB, of which 93 MiB translated DXIL | | staging that prefix, sixteen jobs vs one | 29.1 s vs 124.5 s | | the same with the DXIL store warm | 4.2 s | | records that could not be replayed and were dropped from staging | 5,674 of 18,323 | ## 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. - 667 Python tests pass, including the staging, root, replay-name and translator-choice cases. - 11 `pso_recipe` tests in `tuxbox-dxbc` pass, pinning the recipe fields a replay rebuilds and the offsets it refuses. - Six `pso_record` tests pass under Proton Wine after `cargo xwin test -p tuxbox-d3d12 --no-run`, including the byte-budget trim and the stream-hash test that ignores addresses. ## Not verified / known limits - No NVIDIA card has run this. Every number here comes from one AMD card on RADV. Shared code still needs an NVIDIA run before it can be called done. - Graphics records warm only the build that recorded them. The runtime grafts into a raster stage what a command-line translation does not reproduce — a linked pixel program, a stencil redirect, the pixel root from the mesh table, the screen rectangle's generated geometry — so where the rebuild differs, the replay uses the translation recorded beside the title's bytecode. Those records go stale after a translator rebuild. Compute records keep the title's bytecode and its root and do survive one. - Records written before the root fix keep the title's root, which does not describe the shader the pipeline is created with, so they cannot warm; vkd3d refuses them with `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. - The title still crashes and runs at about 10 fps. Neither is compilation, and neither is caused by this change: the frame rate matches the writeback over-approximation already recorded in `docs/FOCUS.md` and 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. - Open review findings, left for the crash work: `retire_range` blocks 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. `capture` also writes its files on the render thread, and `apply`'s `exclude` parameter is accepted and unused outside the diagnostic log line.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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
brcly/TuxBox!497
No description provided.