startup: re-key saved shader requests after a cache revision change #2401

Manually merged
github merged 4 commits from gh-pr/2401/head into gh-pr/2401/base 2026-11-27 00:48:47 +00:00
Owner

@⁠JohnConnorNPC on GitHub · 2026-11-25 15:21 UTC · original
JohnConnorNPC:tools/shader-cache-rekey → main · +434 −0 · 6 files · 4 commits · merged 2026-11-25 19:45 UTC

The startup shader cache key hashes a translation revision string (x2w-startup-shader-N in pipeline_key /
compute_key and in the runtime). After a revision bump the runtime asks for new keys, so a kept cache is cold
and every pipeline has to be requested again by a running title before gfx2hlsl.py --pending can translate it.

tools/startup/shader_cache_rekey.py <old cache> <new dir> recomputes the key of every graphics request, RTV
variant and slot 67 compute request with the gfx2hlsl.py next to it and copies the request files under the new
names. --pending <new dir> then translates them offline, and the results are merged into the cache without
overwriting (robocopy /XC /XN /XO, or cp -rn).

  • It only reads the old cache and writes only req_* request files, never results or .fail. Files that already
    exist are kept.
  • It reads every request before writing. A missing or unreadable part, a malformed RTV variant or one that names a
    missing base makes it print the count, write nothing and exit 1. A destination equal to the source exits 2.
  • Slot 57 and slot 86 mesh requests have their own key strings, so they are counted but not re-keyed.
  • X2W_TRANSLATE_JOBS sets the number of hashing processes, as for --pending.

Docs: docs/startup-runtime.md, "Keep the shader cache between runs".

Test

python -B tests/startup_shader_cache_rekey_check.py -> 24 ok, all checks passed, exit 0. The check is pure Python
on synthetic byte strings, with no game data, Wine or DXC. Its older and newer revisions come from gfx2hlsl's source
with the revision number changed. It is registered in CMake (startup_shader_cache_rekey), the Linux Python job and
AGENTS.md.
python -B tools/run_checks_parallel.py <python-linux list> -> all 135 checks passed (Linux, Python 3.13.5).
The check has three negative controls: a missing .root, a truncated RTV variant and an RTV variant whose base
request is missing. Each exits 1 with its reason and creates nothing. Every one of these mutations of the tool makes
the check fail: key not recomputed, .ia dropped, RTV base kept, errors ignored, overwrite, source touched,
compute key altered, RTV self-hash check removed, missing RTV base accepted.

Measured vs not

  • Measured: on synthetic requests, the names the tool writes equal pipeline_key / compute_key of the current
    revision, and the properties listed above hold.
  • Not measured here: a Windows run of the check (there the multi-process path uses spawn).
  • Re-keying recovers requests, not translations. Some re-keyed pipelines can still fail to translate, which is
    separate from the cache key. Nothing here claims that a title runs.

Evidence from a running title

One local A/B with a single unmodified build of upstream main, on a Linux host running the title under Wine/Proton
(16 cores, X2W_TRANSLATE_JOBS=16). Each run had a 150 s cap and its own cache directory, with a --pending
watcher on that directory:

  • Cold cache (control): the title never reached its first gamepad poll, the point where it starts reading input, in
    150 s. It wrote several thousand new pipeline requests during the run.
  • Prewarmed cache: requests from an older cache were re-keyed to the current revision and translated offline with
    --pending before the run. Two runs, each from its own copy of that cache, reached the first gamepad poll at
    about 18 s. Neither created a new request file.
  • One prewarmed run stopped at an access violation after about 49 s. That crash is a separate known issue that
    does not involve the cache. The other prewarmed run and the cold run reached the 150 s cap.

Caveats: this is one run per arm on one machine, so it is not a statistic. The prewarmed cache was built with an
earlier prototype of this tool that makes the same pipeline_key / compute_key calls but does not yet have the
all-or-nothing checks above. This exact file was not used for that run.

AI-assisted.

**@⁠JohnConnorNPC** on GitHub · 2026-11-25 15:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2401) `JohnConnorNPC:tools/shader-cache-rekey` → `main` · +434 −0 · 6 files · 4 commits · merged 2026-11-25 19:45 UTC The startup shader cache key hashes a translation revision string (`x2w-startup-shader-N` in `pipeline_key` / `compute_key` and in the runtime). After a revision bump the runtime asks for new keys, so a kept cache is cold and every pipeline has to be requested again by a running title before `gfx2hlsl.py --pending` can translate it. `tools/startup/shader_cache_rekey.py <old cache> <new dir>` recomputes the key of every graphics request, RTV variant and slot 67 compute request with the `gfx2hlsl.py` next to it and copies the request files under the new names. `--pending <new dir>` then translates them offline, and the results are merged into the cache without overwriting (`robocopy /XC /XN /XO`, or `cp -rn`). - It only reads the old cache and writes only `req_*` request files, never results or `.fail`. Files that already exist are kept. - It reads every request before writing. A missing or unreadable part, a malformed RTV variant or one that names a missing base makes it print the count, write nothing and exit 1. A destination equal to the source exits 2. - Slot 57 and slot 86 mesh requests have their own key strings, so they are counted but not re-keyed. - `X2W_TRANSLATE_JOBS` sets the number of hashing processes, as for `--pending`. Docs: `docs/startup-runtime.md`, "Keep the shader cache between runs". ### Test `python -B tests/startup_shader_cache_rekey_check.py` -> 24 ok, `all checks passed`, exit 0. The check is pure Python on synthetic byte strings, with no game data, Wine or DXC. Its older and newer revisions come from gfx2hlsl's source with the revision number changed. It is registered in CMake (`startup_shader_cache_rekey`), the Linux Python job and AGENTS.md. `python -B tools/run_checks_parallel.py <python-linux list>` -> `all 135 checks passed` (Linux, Python 3.13.5). The check has three negative controls: a missing `.root`, a truncated RTV variant and an RTV variant whose base request is missing. Each exits 1 with its reason and creates nothing. Every one of these mutations of the tool makes the check fail: key not recomputed, `.ia` dropped, RTV base kept, errors ignored, overwrite, source touched, compute key altered, RTV self-hash check removed, missing RTV base accepted. ### Measured vs not - Measured: on synthetic requests, the names the tool writes equal `pipeline_key` / `compute_key` of the current revision, and the properties listed above hold. - Not measured here: a Windows run of the check (there the multi-process path uses spawn). - Re-keying recovers requests, not translations. Some re-keyed pipelines can still fail to translate, which is separate from the cache key. Nothing here claims that a title runs. ### Evidence from a running title One local A/B with a single unmodified build of upstream main, on a Linux host running the title under Wine/Proton (16 cores, `X2W_TRANSLATE_JOBS=16`). Each run had a 150 s cap and its own cache directory, with a `--pending` watcher on that directory: - Cold cache (control): the title never reached its first gamepad poll, the point where it starts reading input, in 150 s. It wrote several thousand new pipeline requests during the run. - Prewarmed cache: requests from an older cache were re-keyed to the current revision and translated offline with `--pending` before the run. Two runs, each from its own copy of that cache, reached the first gamepad poll at about 18 s. Neither created a new request file. - One prewarmed run stopped at an access violation after about 49 s. That crash is a separate known issue that does not involve the cache. The other prewarmed run and the cold run reached the 150 s cap. Caveats: this is one run per arm on one machine, so it is not a statistic. The prewarmed cache was built with an earlier prototype of this tool that makes the same `pipeline_key` / `compute_key` calls but does not yet have the all-or-nothing checks above. This exact file was not used for that run. AI-assisted.
shader_cache_rekey.py copies the graphics, RTV variant and slot 67 compute
requests of an older cache under the keys of the current cache revision,
using gfx2hlsl's own pipeline_key and compute_key, so --pending can fill
the new cache without a running title. It only reads the old cache, writes
request files only and writes nothing when a request is incomplete.
Requests of an older revision (from a copy of gfx2hlsl with the revision
number changed) are re-keyed to pipeline_key and compute_key of the current
one, RTV variants follow their new base, a second run writes nothing,
current requests keep their names, a missing part, a truncated RTV variant
or an RTV variant without its base request exits 1 and writes nothing, and
the old cache is unchanged. Registered in CMake, the Linux Python job and
AGENTS.md.
Re-key, translate offline and merge without overwriting (robocopy on
Windows, cp -rn on Linux), what the re-key tool refuses and what its check
covers.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:48:46 +00:00
github manually merged commit 6bd46d89f3 into gh-pr/2401/base 2026-11-27 00:48:47 +00:00
Author
Owner

@⁠KelboLive on GitHub · 2026-11-25 15:58 UTC · original

APPROVED: Shader cache re-keying tool. All-or-nothing, atomic writes, multi-process hashing, RTV re-linking. 180-line tool + 235-line test with 24 cases.

**@⁠KelboLive** on GitHub · 2026-11-25 15:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2401#issuecomment-7167484574) APPROVED: Shader cache re-keying tool. All-or-nothing, atomic writes, multi-process hashing, RTV re-linking. 180-line tool + 235-line test with 24 cases.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 19:38 UTC · original · reviewed

Review of head 6bd46d89 (after updating with main). Offline tooling only: no game claim, no runtime or startup path touched.

What I checked:

  • tools/startup/shader_cache_rekey.py recomputes keys with the same pipeline_key / compute_key the runtime uses (imported from the adjacent gfx2hlsl.py), reads everything before writing, writes temp-then-rename with the ready marker last, never overwrites, refuses dst == src.
  • Siblings: slot 57 / 86 are counted but not re-keyed (own key strings), documented. CMake test, Linux Python job, windows.yml list and AGENTS.md all list the new check. No other open or merged PR covers this slice.
  • The windows.yml change is one extra test path in an existing list; the check is pure Python.

Commands run (Linux, worktree at this head):

  • python3 -B tests/startup_shader_cache_rekey_check.py -> all checks passed
  • python3 tests/docs_links_check.py -> ok (19 files, 475 links)
  • python3 tests/bidi_controls_check.py -> ok
  • git diff --check origin/main...HEAD -> clean
  • Mutation 1: pipeline_key(...) replaced by the old key -> check fails (8 failed)
  • Mutation 2: the "keep existing file" guard disabled -> check fails (2 failed)

No blocking findings. Win2025 run follows separately.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 19:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2401#pullrequestreview-6063854583) · **reviewed** Review of head 6bd46d89 (after updating with main). Offline tooling only: no game claim, no runtime or startup path touched. What I checked: - `tools/startup/shader_cache_rekey.py` recomputes keys with the same `pipeline_key` / `compute_key` the runtime uses (imported from the adjacent `gfx2hlsl.py`), reads everything before writing, writes temp-then-rename with the ready marker last, never overwrites, refuses dst == src. - Siblings: slot 57 / 86 are counted but not re-keyed (own key strings), documented. CMake test, Linux Python job, `windows.yml` list and AGENTS.md all list the new check. No other open or merged PR covers this slice. - The windows.yml change is one extra test path in an existing list; the check is pure Python. Commands run (Linux, worktree at this head): - `python3 -B tests/startup_shader_cache_rekey_check.py` -> all checks passed - `python3 tests/docs_links_check.py` -> ok (19 files, 475 links) - `python3 tests/bidi_controls_check.py` -> ok - `git diff --check origin/main...HEAD` -> clean - Mutation 1: `pipeline_key(...)` replaced by the old key -> check fails (8 failed) - Mutation 2: the "keep existing file" guard disabled -> check fails (2 failed) No blocking findings. Win2025 run follows separately. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 19:45 UTC · original

Win2025 WARP receipt for head 6bd46d89 after updating with main.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 6bd46d89f34a7005cea167ca5e97ea0556a12689:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 2): 85.57s (configure 2.00s)
    • Test (ctest --preset dev -R 'startup_shader_cache_rekey' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (1.95s: startup_shader_cache_rekey 1.85s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 2): 114.56s (configure 1.75s)
    • Test (ctest --preset release -R 'startup_shader_cache_rekey' --parallel 2 --no-tests=error --output-on-failure): 1/1 passed (1.73s: startup_shader_cache_rekey 1.63s)
  • Windows Python checks: tests/startup_shader_cache_rekey_check.py ok (1.9s)
  • sccache: 611/649 hits; wall 214.4s

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 19:45 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2401#issuecomment-7172726896) Win2025 WARP receipt for head 6bd46d89 after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `6bd46d89f34a7005cea167ca5e97ea0556a12689`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev -- -j 2`): `85.57s` (configure `2.00s`) - Test (`ctest --preset dev -R 'startup_shader_cache_rekey' --parallel 2 --no-tests=error --output-on-failure`): **1/1 passed** (`1.95s`: `startup_shader_cache_rekey` `1.85s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release -- -j 2`): `114.56s` (configure `1.75s`) - Test (`ctest --preset release -R 'startup_shader_cache_rekey' --parallel 2 --no-tests=error --output-on-failure`): **1/1 passed** (`1.73s`: `startup_shader_cache_rekey` `1.63s`) - **Windows Python checks**: `tests/startup_shader_cache_rekey_check.py` ok (`1.9s`) - `sccache`: 611/649 hits; wall `214.4s` AI-assisted; commands listed were executed locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.