tooling: stage shader patches from a patch manifest #3878

Open
github-bot wants to merge 1 commit from github-bot/gh-3876 into main AGit
Owner

@⁠Ammmae0x on GitHub · 2026-12-02 17:07 UTC · original
Ammmae0x:tooling/shader-patch-stage → main · +797 −0 · 5 files · 1 commits · open

Per-key shader-cache override consumer for kind = "shader" manifests (docs/experiments/patch-manifests.md).

What landed — single commit on tooling/shader-patch-stage, off origin/main 8121ca99, pushed to the fork with no force-push. 5 new files only, +0/-0 elsewhere:

  • tools/shader_patch.py — CLI (manifest, input, cache_dir, --report, --runtime-root) + library API (runtime_revisions(root), stage(...)). Reuses patch_manifest.load for the manifest schema and [target] input_sha256 gate. Reads the runtime's current key revisions from the runtime sources, refuses a patch whose revision is not the current one, and validates every shader patch completely (revision + every replacement file's SHA-256, over the bytes read in memory and staged verbatim, never re-read) before writing a single file. Memory patches in a combined manifest are left untouched; a manifest with no shader patches is refused. Staged files are written atomically (tempfile in cache_dir + os.replace) as cache_dir/<key><ext>, blobs first and the manifest marker (.txt / .mesh86.txt) last, matching the runtime cache publication order. Symlink cache_dir, symlink destinations and symlink/non-regular replacement files are refused. Report is {manifest_sha256, input_sha256, patch_ids, staged_files} to --report or stdout; validation/IO failures exit 1 with a concise shader patch: ... message and no traceback.
  • tests/shader_patch_check.py (14 tests), tests/cmake/shader_patch.cmake (shader_patch_controls), tests/checks/python-linux/shader_patch.txt, docs/experiments/shader-patches.md.
  • tools/patch_manifest.py, tools/exe_aot.py and tools/cpu_stdio_exe_aot.py are untouched, so this stays disjoint from the memory-patch work on exe_aot.

Spec note (flagged, not silently followed): the task text said the compute revision comes from src/startup_stubs/d3d12_compute_dispatch.inl. It does not: that file contains no revision literal at all (and no mention of compute_revision). It consumes tr.key, seeded in src/startup_stubs/d3d12_draw.inl from shader_cache::compute_revision (fnv_bytes(shader_cache::compute_revision, ...)), which is where the compute literal lives, beside the graphics one. The tool reads both files (refusing a dispatch literal that disagrees with draw's) and the check pins this, so a future move of the literal is caught instead of silently reading a stale value. Current revisions on this checkout: graphics x2w-startup-shader-29, compute x2w-startup-shader-29cs, mesh86 x2w-startup-mesh-86-1.

Tests — all three pipelines with and without their optional file (graphics ±.gs.cso, compute ±.cs.hlsl, mesh86 ±.ps.cso) using the real current revisions; combined memory+shader manifest stages only the shader override; wrong input/file hashes with no partial apply (bad 2nd patch leaves the cache completely empty); stale revisions; missing/symlinked replacement files; symlink destination/cache_dir; memory-only manifest refused; CLI report to stdout and to --report; two mutations (revision guard dropped, SHA-256 guard dropped) each let their bad input through, proving the refusal tests pin the guards.

Linux (this host, /tmp/pe-env/bin/python, Python 3.12.3, pefile 2024.8.26):

  • tests/shader_patch_check.py: 14 tests, all passed
  • tests/patch_manifest_check.py: 9 tests, all passed
  • tests/form_coverage_check.py: passed
  • tests/docs_links_check.py: 252 Markdown files, 961 links, passed
  • tests/bidi_controls_check.py: 2992 tracked files, no bidirectional controls
  • git diff --check origin/main...HEAD: clean
  • git merge-tree --write-tree origin/main HEAD: exits 0

Full-repo Python suite not run locally per instructions; GitHub Actions runs it on push. No mingw/MSVC on this host, so no Windows compile check; Windows execution awaits WIN-VERIFY.

Refs #3037, #3119.

Windows verification (MSVC dev + release on 98809240):

  • ctest --preset dev --no-tests=error -R '^(shader_patch|patch_manifest)' -V: 2/2 passed (patch_manifest_controls 9/9, shader_patch_controls 14/14, 2.76s)
  • ctest --preset release --no-tests=error -R '^(shader_patch|patch_manifest)' -V: 2/2 passed (patch_manifest_controls 9/9, shader_patch_controls 14/14, 2.61s)
  • tests/form_coverage_check.py, tests/docs_links_check.py (252 files, 961 links), tests/bidi_controls_check.py (2992 files), git diff --check upstream/main...HEAD: passed

WIN-VERIFY: passed | sha=9880924080031b2a0c319d588592f52c746250ef | ctest=^(shader_patch|patch_manifest) | release=true

AI-assisted.

**@⁠Ammmae0x** on GitHub · 2026-12-02 17:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3876) `Ammmae0x:tooling/shader-patch-stage` → `main` · +797 −0 · 5 files · 1 commits · open Per-key shader-cache override consumer for `kind = "shader"` manifests (docs/experiments/patch-manifests.md). **What landed** — single commit on `tooling/shader-patch-stage`, off `origin/main` `8121ca99`, pushed to the fork with no force-push. 5 new files only, +0/-0 elsewhere: - `tools/shader_patch.py` — CLI (`manifest`, `input`, `cache_dir`, `--report`, `--runtime-root`) + library API (`runtime_revisions(root)`, `stage(...)`). Reuses `patch_manifest.load` for the manifest schema and `[target] input_sha256` gate. Reads the runtime's current key revisions from the runtime sources, refuses a patch whose revision is not the current one, and validates every shader patch completely (revision + every replacement file's SHA-256, over the bytes read in memory and staged verbatim, never re-read) before writing a single file. Memory patches in a combined manifest are left untouched; a manifest with no shader patches is refused. Staged files are written atomically (tempfile in `cache_dir` + `os.replace`) as `cache_dir/<key><ext>`, blobs first and the manifest marker (`.txt` / `.mesh86.txt`) last, matching the runtime cache publication order. Symlink `cache_dir`, symlink destinations and symlink/non-regular replacement files are refused. Report is `{manifest_sha256, input_sha256, patch_ids, staged_files}` to `--report` or stdout; validation/IO failures exit 1 with a concise `shader patch: ...` message and no traceback. - `tests/shader_patch_check.py` (14 tests), `tests/cmake/shader_patch.cmake` (`shader_patch_controls`), `tests/checks/python-linux/shader_patch.txt`, `docs/experiments/shader-patches.md`. - `tools/patch_manifest.py`, `tools/exe_aot.py` and `tools/cpu_stdio_exe_aot.py` are untouched, so this stays disjoint from the memory-patch work on `exe_aot`. **Spec note (flagged, not silently followed):** the task text said the compute revision comes from `src/startup_stubs/d3d12_compute_dispatch.inl`. It does not: that file contains no revision literal at all (and no mention of `compute_revision`). It consumes `tr.key`, seeded in `src/startup_stubs/d3d12_draw.inl` from `shader_cache::compute_revision` (`fnv_bytes(shader_cache::compute_revision, ...)`), which is where the compute literal lives, beside the graphics one. The tool reads both files (refusing a dispatch literal that disagrees with draw's) and the check pins this, so a future move of the literal is caught instead of silently reading a stale value. Current revisions on this checkout: graphics `x2w-startup-shader-29`, compute `x2w-startup-shader-29cs`, mesh86 `x2w-startup-mesh-86-1`. **Tests** — all three pipelines with and without their optional file (graphics ±`.gs.cso`, compute ±`.cs.hlsl`, mesh86 ±`.ps.cso`) using the real current revisions; combined memory+shader manifest stages only the shader override; wrong input/file hashes with no partial apply (bad 2nd patch leaves the cache completely empty); stale revisions; missing/symlinked replacement files; symlink destination/cache_dir; memory-only manifest refused; CLI report to stdout and to `--report`; two mutations (revision guard dropped, SHA-256 guard dropped) each let their bad input through, proving the refusal tests pin the guards. Linux (this host, `/tmp/pe-env/bin/python`, Python 3.12.3, pefile 2024.8.26): - `tests/shader_patch_check.py`: 14 tests, all passed - `tests/patch_manifest_check.py`: 9 tests, all passed - `tests/form_coverage_check.py`: passed - `tests/docs_links_check.py`: 252 Markdown files, 961 links, passed - `tests/bidi_controls_check.py`: 2992 tracked files, no bidirectional controls - `git diff --check origin/main...HEAD`: clean - `git merge-tree --write-tree origin/main HEAD`: exits 0 Full-repo Python suite not run locally per instructions; GitHub Actions runs it on push. No mingw/MSVC on this host, so no Windows compile check; Windows execution awaits WIN-VERIFY. Refs #3037, #3119. Windows verification (MSVC `dev` + `release` on `98809240`): - `ctest --preset dev --no-tests=error -R '^(shader_patch|patch_manifest)' -V`: 2/2 passed (`patch_manifest_controls` 9/9, `shader_patch_controls` 14/14, 2.76s) - `ctest --preset release --no-tests=error -R '^(shader_patch|patch_manifest)' -V`: 2/2 passed (`patch_manifest_controls` 9/9, `shader_patch_controls` 14/14, 2.61s) - `tests/form_coverage_check.py`, `tests/docs_links_check.py` (252 files, 961 links), `tests/bidi_controls_check.py` (2992 files), `git diff --check upstream/main...HEAD`: passed WIN-VERIFY: passed | sha=9880924080031b2a0c319d588592f52c746250ef | ctest=^(shader_patch|patch_manifest) | release=true AI-assisted.
Add tools/shader_patch.py, the per-key shader-cache override
consumer for kind = "shader" manifests (docs/experiments/
patch-manifests.md). It reuses patch_manifest.load for the
manifest schema and [target] input_sha256 gate, reads the
runtime's current key revisions from the runtime sources
(graphics/compute from src/startup_stubs/d3d12_draw.inl,
mesh86 from src/startup_stubs/mesh86_cache.inl), refuses a
patch whose revision is not the current one, and validates
every patch (revision and every replacement file's SHA-256,
over the bytes read in memory) before writing a single file.
Memory patches in a combined manifest are left untouched;
a manifest with no shader patches is refused. Staged files
are written atomically (tempfile + os.replace) into
cache_dir/<key><ext>, blobs first and the manifest marker
(.txt / .mesh86.txt) last, matching the runtime cache
publication order. Symlink cache_dir, symlink destinations
and symlink/non-regular replacement files are refused.
The provenance report (manifest_sha256, input_sha256,
patch_ids, staged_files) goes to --report or stdout, and
validation/IO failures exit 1 with a concise
'shader patch: ...' message and no traceback.

Spec note: the compute revision literal lives in
d3d12_draw.inl (shader_cache::compute_revision), not in
d3d12_compute_dispatch.inl, which contains no revision
literal and consumes tr.key seeded from that definition;
the tool reads both files and the check pins this.

Tests: tests/shader_patch_check.py (14 tests) covers all
three pipelines with and without their optional file using
the real current revisions, a combined memory+shader
manifest, wrong input/file hashes with no partial apply,
stale revisions, missing/symlinked replacement files,
symlink destination/cache_dir, memory-only manifests, the
CLI and its report, and two mutations (revision guard and
SHA-256 guard dropped) that each let their bad input
through. Also tests/cmake/shader_patch.cmake,
tests/checks/python-linux/shader_patch.txt and
docs/experiments/shader-patches.md. tools/patch_manifest.py,
tools/exe_aot.py and tools/cpu_stdio_exe_aot.py are untouched.

Refs #3037, #3119.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 19:11:23 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 22:30 UTC · original · requested changes

On 98809240, both Python suites passed independently on Windows (tests/shader_patch_check.py 14/14 and tests/patch_manifest_check.py 9/9). I also tested replacing a populated cache using the existing synthetic graphics fixture. With a write failure injected at .ps.cso, stage returned an error after changing .vs.cso. The cache was left with the old .txt marker, the new VS, and the old PS. Since a marker was already present, writing the new marker last does not prevent a reader from seeing a mixed pair. Please define and enforce the populated-cache contract. Refusing replacement before writes and directing callers to stage into a fresh cache would be one small way to keep the published pair intact. If in-place replacement is required, protect the old pair through the failure path and add a seeded-cache I/O failure control.

**@⁠R0Y00** on GitHub · 2026-12-02 22:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3876#pullrequestreview-6160188324) · **requested changes** On `98809240`, both Python suites passed independently on Windows (`tests/shader_patch_check.py` 14/14 and `tests/patch_manifest_check.py` 9/9). I also tested replacing a populated cache using the existing synthetic graphics fixture. With a write failure injected at `.ps.cso`, `stage` returned an error after changing `.vs.cso`. The cache was left with the old `.txt` marker, the new VS, and the old PS. Since a marker was already present, writing the new marker last does not prevent a reader from seeing a mixed pair. Please define and enforce the populated-cache contract. Refusing replacement before writes and directing callers to stage into a fresh cache would be one small way to keep the published pair intact. If in-place replacement is required, protect the old pair through the failure path and add a seeded-cache I/O failure control.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3878/head:github-bot/gh-3876'
git switch 'github-bot/gh-3876'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3876'
git switch 'github-bot/gh-3876'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3876'
git switch 'github-bot/gh-3876'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3876'
git switch 'main'
git merge --squash 'github-bot/gh-3876'
git switch 'main'
git merge --ff-only 'github-bot/gh-3876'
git switch 'main'
git merge 'github-bot/gh-3876'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.