Skip to content

startup: warn when the shader cache and the translator come from different revisions - #2820

Merged
pigalot merged 5 commits into
R0Y00:mainfrom
tedin7:x2w-shader-cache-revision
Nov 27, 2026
Merged

pigalot merged 5 commits into
R0Y00:mainfrom
tedin7:x2w-shader-cache-revision

Conversation

@tedin7

@tedin7 tedin7 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #870
Fixes #2815

What this unblocks: a run whose stand-ins and translator come from different revisions now says so in one warning, instead of looking like "nothing translates" (every cached request refused as a key mismatch).

What changed

  • Runtime (src/startup_stubs/d3d12_draw.inl): the three revision strings the request keys start with (graphics x2w-startup-shader-27, compute x2w-startup-shader-27cs, slot 57 mesh x2w-startup-mesh-57-3) move into one shader_cache namespace; the keys are unchanged. Before its first request a process writes them to <X2W_SHADER_CACHE>\revision.txt (graphics ..., compute ..., mesh57 ... lines), through a temporary file and MoveFileExW(..., MOVEFILE_REPLACE_EXISTING). A file that already says the same is not rewritten; a run that publishes no request writes nothing.
  • tools/startup/shader_cache_revision.py (new, standard library only): reads revision.txt and the revision literals of the gfx2hlsl.py it is given (only read; no translation code changes). Silent when they agree or the cache holds no request; one line with both revisions and the two fixes when they differ, or when the cache holds req_* files but no revision.txt. --fresh moves a cache folder that is not empty to <cache>.old-<date>-<time>.
  • run.ps1 / run.sh: with -Render -Translate (--render --translate) the helper runs before the watcher starts and prints the line as a warning. If that was silent, it runs once more after the run, so the first run with an empty cache still warns once its own stand-ins wrote revision.txt. New -FreshShaderCache / --fresh-shader-cache (with -Render) moves the old cache aside first. run.sh runs the helper with the host Python (X2W_HOST_PYTHON, default python3).
  • docs/startup-runtime.md: the shader cache section describes revision.txt, the warning and the switch.

Tests

  • tests/startup_shader_cache_revision_check.py (new, Linux and Windows): same revisions silent; a different revision (also only one kind) warns with both values and both fixes; a garbled revision.txt warns; requests without revision.txt warn; an empty or missing cache is silent; --fresh moves a cache with files aside and leaves an empty or missing one alone; usage errors exit 2; the real gfx2hlsl.py yields all three revisions, compute = graphics + cs.
  • tests/startup_compute_request_check.py (Windows, built stand-in consumer): after the stand-in publishes, revision.txt equals the revisions the gfx2hlsl.py of the same commit spells, the helper is silent for that cache, a stale revision.txt left in the cache is replaced, and a second process does not rewrite it. The request file lists skip revision.txt.
  • tests/startup_run_sh_check.py: four new cases (older revision.txt: one warning with both revisions; requests without revision.txt: one warning; matching cache: no warning; --fresh-shader-cache: cache moved aside, no warning) and two new mutants (warning dropped, fresh cache kept), both detected.
  • tests/startup_run_ps1_check.py: the scratch tree gets the helper; on Windows, a -Translate run on an older cache must print the warning once (compared without whitespace, since PowerShell may wrap it).
  • tests/startup_indirect_draw_indexed.cpp: the slot 57 request count skips revision.txt.

Not covered

  • Caches written only by archive_requests.py or shader_cache_rekey.py have no revision.txt, so they get the "no revision.txt" warning (its text names both tools). A follow-up can have them write the translator's revisions.
  • Slot 86 mesh requests (x2w-startup-mesh-86-1, mesh86_cache.py) are not part of revision.txt.

Source: repository code only: the key seeds of src/startup_stubs/d3d12_draw.inl and pipeline_key / compute_key / mesh57_key in tools/startup/gfx2hlsl.py (#2815); Microsoft Learn, "MoveFileExW function (winbase.h)" (MOVEFILE_REPLACE_EXISTING); PowerShell SDK, "PathIntrinsics.GetUnresolvedProviderPathFromPSPath".

Verification (Linux, head 1bc4a534a; Win2025 dev+release 6/8 each at 1bc4a534a, 2 skipped as expected, see the comment):

  • python3 -B tests/startup_shader_cache_revision_check.py: PASS (16 checks).
  • python3 -B tests/startup_run_sh_check.py: 0 failed (every case and mutant).
  • python3 -B tests/startup_run_ps1_check.py: 0 failed (text only: not a Windows host).
  • Pass unchanged: startup_gfx2hlsl_fract_check, startup_archive_requests_check, startup_gfx2hlsl_export_mask_check, startup_image_load_mip_check, startup_image_sample_a16_check, startup_compute_request_offline_check, startup_shader_cache_rekey_check, startup_shader_cache_key_check (they read the revision constants from the runtime source), docs_links_check, bidi_controls_check, startup_tools_lint_check; git diff --check clean.
  • Win2025 WARP dev+release at d39f65cfc (the revision.txt fix for six draw checks, see the comments): ctest -R '^startup_(logical_view|address_srv|joined_table_pointer|d16_srv|mubuf_descriptor|pixel_uav)_' 16/16 dev and 16/16 release; the same regex at 1bc4a534a failed 14 of 16 (too many values to unpack). An independent second check on d39f65cfc passed (dev and release).

AI-assisted; commands listed were executed locally.

c1 added 3 commits November 26, 2026 12:29
…nt revisions

The runtime writes its graphics, compute and mesh57 key revisions to
<X2W_SHADER_CACHE>/revision.txt before its first request. run.ps1 and run.sh
compare it with the gfx2hlsl.py they start (tools/startup/shader_cache_revision.py)
and print one warning with both revisions and the fixes; a cache with requests
and no revision.txt warns too. -FreshShaderCache / --fresh-shader-cache moves a
cache that is not empty aside. Fixes R0Y00#2815.
…er-cache-revision

# Conflicts:
#	src/startup_stubs/d3d12_draw.inl
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Merged origin/main into the branch (merge commit, no force push): main had raised the cache revision to x2w-startup-shader-28 / 28cs in the same lines this PR moves into shader_cache; the constants are now 28 / 28cs, matching gfx2hlsl.py at the same commit (slot 57 mesh unchanged at x2w-startup-mesh-57-3).

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

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_indirect_draw_indexed -- -j 2): 31.61s (configure 0.00s)
    • Test (ctest --preset dev -R '^(startup_shader_cache_revision|startup_compute_request_warp|startup_compute_request_disabled_control|startup_compute_request_offline|startup_indirect_draw_indexed_.*|startup_run_ps1|startup_run_sh)$' --parallel 3 --no-tests=error --output-on-failure): 6/8 passed (17.95s: startup_shader_cache_revision 0.95s, startup_compute_request_offline 0.85s, startup_compute_request_disabled_control 0.22s, startup_indirect_draw_indexed_warp 0.13s, startup_indirect_draw_indexed_hardware 0.03s, startup_run_sh 0.11s, startup_compute_request_warp 2.53s, startup_run_ps1 17.76s); skipped (capability, not a pass): startup_indirect_draw_indexed_hardware, startup_run_sh
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim startup_indirect_draw_indexed -- -j 2): 73.86s (configure 0.00s)
    • Test (ctest --preset release -R '^(startup_shader_cache_revision|startup_compute_request_warp|startup_compute_request_disabled_control|startup_compute_request_offline|startup_indirect_draw_indexed_.*|startup_run_ps1|startup_run_sh)$' --parallel 3 --no-tests=error --output-on-failure): 6/8 passed (24.96s: startup_compute_request_offline 1.05s, startup_compute_request_disabled_control 0.27s, startup_indirect_draw_indexed_warp 0.12s, startup_indirect_draw_indexed_hardware 0.04s, startup_shader_cache_revision 1.22s, startup_run_sh 0.16s, startup_compute_request_warp 3.62s, startup_run_ps1 24.69s); skipped (capability, not a pass): startup_indirect_draw_indexed_hardware, startup_run_sh
  • Windows Python checks: tests/startup_compute_translate_check.py ok (0.2s), tests/startup_run_ps1_check.py ok (12.7s), tests/startup_run_sh_check.py skipped (0.1s)
  • sccache: 3/18 hits; wall 148.6s

Skipped, as expected: startup_indirect_draw_indexed_hardware (no hardware adapter on the VM) and startup_run_sh (POSIX launcher, runs on Linux). startup_compute_request_warp passed with the new check that the built stand-in's revision.txt equals the revisions of gfx2hlsl.py at this commit; startup_run_ps1 passed with the older-cache case (one warning naming both revisions).

Linux at this head: tests/startup_shader_cache_revision_check.py PASS; the revision-reading checks (startup_gfx2hlsl_fract, archive_requests, export_mask, image_load_mip, image_sample_a16, compute_request_offline, shader_cache_rekey, shader_cache_key), docs_links, bidi_controls, startup_tools_lint pass; the launcher files are unchanged by the merge (startup_run_sh_check.py 0 failed at 421a9c6).

AI-assisted; commands listed were executed locally.

tedin7 pushed a commit to tedin7/Xbox2Windows that referenced this pull request Nov 26, 2026
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Stage-2 gate PASS at 1bc4a534afd710cf0c13788cdd1f23fcf5538b24.

Verification:

  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP), x2w_pipe.py win2025 2820 --host proxmox --force --keep-release --regex 'startup_shader_cache_revision|startup_compute_request|startup_indirect_draw_indexed|startup_run_ps1': dev 7 tests, release 7 tests, all passed except startup_indirect_draw_indexed_hardware (skipped, no hardware adapter). Includes startup_compute_request_warp (revision.txt matches gfx2hlsl at the same commit), startup_shader_cache_revision, startup_run_ps1 (stale-cache case).
  • Mutant, runtime side: the revision.txt compute line written with the previous revision (...-27cs): startup_compute_request_warp FAILS on Win2025 dev, startup_shader_cache_revision still passes. The clean head passes both.
  • Mutant, helper side: the "revisions differ" test weakened so one matching kind silences the warning: startup_shader_cache_revision_check.py exits 1 (Linux). Clean head exits 0.
  • Control: a cache whose revision.txt agrees with the translator prints nothing; a cache with requests and no revision.txt prints the "revision unknown" line (both covered by the check and by startup_run_ps1).
  • Code read: key bytes unchanged (same literals moved into shader_cache::); revision.txt written once per process before the first request, through a temporary file and MoveFileExW(REPLACE_EXISTING); an identical file is not rewritten.
  • Not covered (as stated in the PR body): archive_requests / shader_cache_rekey outputs have no revision.txt (the warning names them), slot 86.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 marked this pull request as ready for review November 26, 2026 12:31
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T12:31:13.531013Z
We couldn’t complete this review. Comment @codex review to try again.
1bc4a53 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

…ader cache

Since R0Y00#2815 the runtime writes revision.txt into X2W_SHADER_CACHE with its first request, so
`manifest, = cache.glob('*.txt')` found two files in the logical view, address SRV, joined table
pointer, d16 SRV, MUBUF descriptor and pixel UAV draw checks.
tedin7 pushed a commit to tedin7/Xbox2Windows that referenced this pull request Nov 26, 2026
tedin7 pushed a commit to tedin7/Xbox2Windows that referenced this pull request Nov 26, 2026
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

New commit d39f65cfc (no force push): six Windows draw checks counted the .txt files in their shader cache and expected exactly one manifest. With this PR the runtime also writes revision.txt there with its first request, so manifest, = cache.glob('*.txt') found two files and the checks failed with ValueError: too many values to unpack. They now skip revision.txt: tests/startup_logical_view_check.py, startup_address_srv_check.py, startup_joined_table_pointer_check.py, startup_d16_srv_check.py, startup_mubuf_descriptor_check.py, startup_pixel_uav_check.py. No runtime or tool change.

Verified on Windows Server 2025 (D3D12 WARP and the hardware adapter variant), ctest -R '^startup_(logical_view|address_srv|joined_table_pointer|d16_srv|mubuf_descriptor|pixel_uav)_':

  • at 1bc4a534a (before): dev 2 of 16 passed, 14 failed (too many values to unpack).
  • at d39f65cfc: dev 16/16 passed, release 16/16 passed.

Linux: python3 -B tests/startup_tools_lint_check.py and tests/startup_joined_table_pointer_check.py (its CPU part) pass; the other five need the Windows build. Still needs the independent second check on this head.

AI-assisted; commands listed were executed locally.

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to review d39f65cf over main 429f11d5, but the trial merge (git merge --no-ff --no-commit) stops with conflicts in three files:

  • src/startup_stubs/d3d12_draw.inl, mostly against #2919 (persisted PSO recipes), which adds pso_recipe_path / read_pso_recipe_text / load_pso_recipes beside read_text. Main now spells the request-key seeds x2w-startup-shader-29 and x2w-startup-shader-29cs. This head's shader_cache namespace still has 28 / 28cs, so the resolution has to take main's values. If it keeps 28, revision.txt would disagree with every key the stand-in writes.
  • tools/startup/run.ps1 and tests/startup_run_ps1_check.py, against #2958 (slot 67 compute requests translated in the stand-in) and #2870 (literal data directory manifest). #2958 changes the -Translate path that the new pre-run and post-run helper calls hook into, so the warning's placement needs re-checking after the merge.

The merge base is 02075500. I have not built or run anything on this head. I'll review the commit that resolves these.

This reply was AI-assisted.

@tedin7

tedin7 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Updated with main: pushed 624bc81f6, a merge commit. The three conflicts are resolved. Request-key seeds and revision.txt now use x2w-startup-shader-29 / 29cs from main, so the revision text agrees with every key the stand-in writes. In run.ps1 the shader-cache warning helpers now sit around the new -Translate flow (slot 67 compute translation, literal data directory manifest); both sides' features are kept.

Not yet run on Windows after the merge: the run.ps1 path.

Commands run locally: 18 Python checks including tests/startup_run_ps1_check.py and the run.sh check, git diff --check, cmake -S . -B <tmp> -DDXC_EXECUTABLE=/bin/true, public_guard.py.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

Verification: head 624bc81f6 after the main merge and the latest fixes.

Environment: Windows Server 2025 (build 26100), MSVC 14.44, D3D12 WARP and the hardware adapter, dev and release legs in parallel.

Commands (the same selection in both legs):

x2w_pipe.py win2025 2820 --force --regex '^(startup_run_(ps1|sh)|startup_shader_cache_revision|startup_compute_request.*|startup_(address_srv|d16_srv|joined_table_pointer|logical_view|mubuf_descriptor|pixel_uav|indirect_draw_indexed).*)$'
  dev:     cmake --build --preset dev --target auto
           ctest --preset dev -R '^(startup_run_(ps1|sh)|startup_shader_cache_revision|startup_compute_request.*|startup_(address_srv|d16_srv|joined_table_pointer|logical_view|mubuf_descriptor|pixel_uav|indirect_draw_indexed).*)$' --no-tests=error --output-on-failure
  release: cmake --build --preset release --target auto
           ctest --preset release -R '^(startup_run_(ps1|sh)|startup_shader_cache_revision|startup_compute_request.*|startup_(address_srv|d16_srv|joined_table_pointer|logical_view|mubuf_descriptor|pixel_uav|indirect_draw_indexed).*)$' --no-tests=error --output-on-failure

Result: 24 selected, no failures in both legs (skips by capability: startup_logical_view_warp, startup_indirect_draw_indexed_hardware, startup_run_sh), including startup_run_ps1 and startup_shader_cache_revision.

AI-assisted; commands listed were executed locally.

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 624bc81f merged over current main c1de64a5. The merge is clean and git diff --cached --check is clean.

The conflicts from my comment on d39f65cf are resolved.

  • Revisions: shader_cache::revision, compute_revision and mesh57_revision are x2w-startup-shader-29, 29cs and x2w-startup-mesh-57-3, the same seeds main uses in d3d12_draw.inl and gfx2hlsl.py. So revision.txt agrees with the keys the stand-in writes.
  • run.ps1 with -Translate: the pre-run check runs just before the watcher starts, and the post-run check runs only if the pre-run one didn't warn.
  • write_cache_revision: it runs once per process from publish_shader_request, and that call covers all four request kinds: graphics, compute, slot 57 and .rtv.

What I ran. I did a full build in dev and release, then ran

ctest --test-dir out/build/<preset> --no-tests=error -j 4 -E '(_hardware$|startup_audio_)' -R '^(startup_shader_cache_revision|startup_shader_cache_rekey.*|runtime_shader_cache_rekey.*|startup_run_ps1.*|startup_run_sh.*|startup_compute_request.*|startup_address_srv.*|startup_d16_srv.*|startup_indirect_draw_indexed.*|startup_joined_table_pointer.*|startup_logical_view.*|startup_mubuf_descriptor.*|startup_pixel_uav.*)$'
# with X2W_TEST_DEBUG_LAYER=1, one at a time
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_address_srv|startup_d16_srv|startup_indirect_draw_indexed|startup_joined_table_pointer|startup_logical_view|startup_mubuf_descriptor|startup_pixel_uav|startup_compute_request).*_hardware$'

The results were the same in both presets:

  • Without _hardware: 16 of 18 pass and 2 skip.
    • startup_logical_view_warp is a capability skip; its _hardware variant passes.
    • startup_run_sh skips because this host has no POSIX shell for it, so I didn't exercise the run.sh side.
  • _hardware: 8/8 pass.

Mutants. For each, I rebuilt where needed and ran the 6 tests startup_shader_cache_revision, startup_run_ps1, startup_run_sh and startup_compute_request*:

Mutant Result
publish_shader_request no longer calls write_cache_revision killed (startup_compute_request_warp)
warning() returns None when no revision kind is shared (shared and dropped) killed (startup_shader_cache_revision)
a cache with requests but no revision.txt gets no warning killed (startup_shader_cache_revision)
--fresh moves an empty cache aside too killed (startup_shader_cache_revision)
warning() compares only the graphics revision survives
run.ps1 skips the post-run check survives

Restored and rebuilt afterwards; git diff --quiet is clean.

Non-blocking.

  1. Compute and mesh57 mismatches are unpinned. No case has a revision.txt whose graphics line matches the translator while its compute or mesh57 line doesn't. Bumping only 29cs (or mesh-57-3) is the case most likely to slip through, so a single case with one stale compute line would pin the comparison.
  2. The post-run warning is unpinned. startup_run_ps1 passes without the if ($watchShaders -and -not $revisionWarned) line. That's the path for a fresh cache, where revision.txt only appears during the run.

Verdict: approve on 624bc81f.

Environment: NVIDIA GeForce RTX 5090, driver 32.0.16.1088; D3D12 WARP; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; debug layer on for the hardware runs.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on 624bc81f.

This reply was AI-assisted.

@pigalot
pigalot merged commit 14d5650 into R0Y00:main Nov 27, 2026
5 checks passed
@pigalot

pigalot commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to my approval: this change broke two tests on main, and I missed them in my review because my test selection didn't include them.

Build and test on Windows on the merge commit 14d56502 (run 46078334414) fails these two:

  • startup_compute_dispatch_native_warp with AssertionError: the native route left ['revision.txt'] in the cache (tests/startup_compute_dispatch_native_check.py:80).
  • native_rtv_variant_warp at tests/native_rtv_variant_check.py:291. This check compares the exact file list of the cache, which now also holds revision.txt.

The cause: publish_shader_request now calls write_cache_revision. So every cache a stand-in writes a request into gets a revision.txt, the native and .rtv routes included. Both checks list the cache and allow only request files (and native).

Reproduced locally on a current-main build (fad97f47 plus an unrelated PR), Debug:

ctest --test-dir out/build/dev --no-tests=error -R '^(startup_compute_dispatch_native_(warp|hardware)|native_rtv_variant_warp)$' --output-on-failure

All three fail. startup_compute_dispatch_native_hardware fails the same way as the WARP one.

The third failure in that run, linear_buffer_backing_copy_warp, passes locally and looks unrelated.

Suggested fix (untested): have both checks ignore revision.txt when they list the cache. That's a test-only change, and the file is part of the cache format now. For example, add and p.name != 'revision.txt' in startup_compute_dispatch_native_check.py, and leave revision.txt out of the listing in native_rtv_variant_check.py.

Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10; D3D12 WARP and NVIDIA GeForce RTX 5090, driver 32.0.16.1088.

This reply was AI-assisted.

Not-Saii added a commit to Not-Saii/Xbox2Windows that referenced this pull request Nov 28, 2026
… texture-output cases

Since R0Y00#2820 the stand-in writes revision.txt into the shader cache with the
first request. R0Y00#3231 allowed it in step 1 of
startup_compute_dispatch_native_check.py; the two exact-set assertions that
close table_views and texture_outputs need the same exception, or the check
fails after its last Dispatch.

Refs R0Y00#3149

AI-assisted.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

startup-tools: warn when the shader cache and the translator come from different revisions

2 participants