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

Merged
JohnConnorNPC merged 4 commits from upstream-pr/2401 into main 2026-11-25 19:45:45 +00:00
JohnConnorNPC commented 2026-11-25 15:21:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-25T15:21:28Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6607825286 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2401). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-25T15:21:28Z. --- 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.
KelboLive commented 2026-11-25 16:05:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-25T15:58:51Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7167484574 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2401#issuecomment-7167484574). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-25T15:58:51Z. --- 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.
upstream-sync closed this pull request 2026-11-25 20:04:07 +00:00
tedin7 commented 2026-11-25 20:04:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:38:38Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6063854583 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2401#pullrequestreview-6063854583). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T19:38:38Z. **Review:** COMMENTED --- 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 commented 2026-11-25 20:04:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:45:29Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7172726896 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2401#issuecomment-7172726896). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T19:45:29Z. --- 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.
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
R0Y00/Xbox2Windows!2393
No description provided.