Skip to content

shader: invalidate watch manifests when sidecar content changes with an older mtime - #3138

Merged
JohnConnorNPC merged 1 commit into
R0Y00:codex/native-shader-modulesfrom
legacy-code-archaeologist:shader/watch-sidecar-content-invalidation
Nov 28, 2026
Merged

JohnConnorNPC merged 1 commit into
R0Y00:codex/native-shader-modulesfrom
legacy-code-archaeologist:shader/watch-sidecar-content-invalidation

Conversation

@legacy-code-archaeologist

Copy link
Copy Markdown
Contributor

Fixes #3133 (Refs #3091).
Base: codex/native-shader-modules at a48d39dc; commit 4a7e2542.

Root Cause

In tools/startup/compile_dxil.cpp, is_watch_request_pending() only invalidated a published graphics manifest when max(mtime(.psin), mtime(.ps57in)) > mtime(<key>.txt) or when both sidecars disappeared while <key>.psdep existed. Adding a contradictory .ps57in with an older timestamp (<= mtime(<key>.txt)) or changing .psin/.ps57in content while preserving an older timestamp left the stale <key>.txt manifest on disk.

Summary

  • Extract read_pixel_inputs() in src/shader_compute_request.cpp and expose x2w::read_pixel_input_description() in src/shader_compute_request.h so the watcher and request loader share exact .psin/.ps57in parsing and conflict rules.
  • Update is_watch_request_pending() in tools/startup/compile_dxil.cpp to compare canonical current sidecar content from read_pixel_input_description() against published <key>.psdep (marking any mismatch, new sidecar, conflict, or invalid sidecar as sidecar_changed regardless of timestamp).
  • Extend tests/native_compile_dxil_watch_check.py with unchanged-input cache-hit controls (both .psin and indexed reflected .ps57in), older- vs newer-mtime contradictory .ps57in equivalence (withdrawing <key>.txt with identical stdout/.fail), preserved-older-mtime .psin and .ps57in content changes, and base+.rtv variant invalidation when base gains an older-mtime .ps57in.

Verification

  • cmake --build --preset dev --target compile_dxil native_compute_pack_check native_frozen_request_check native_pixel_ir_dump native_compute_ir_dump: built cleanly.
  • ctest --preset dev --no-tests=error -R '^(native_compile_dxil_watch|native_startup_request_cache_controls|native_rtv_variant_controls|native_direct_container|native_frozen_request)$' -V: 5/5 passed (native_compile_dxil_watch 3.47s, native_direct_container 24.45s, native_rtv_variant_controls 2.29s, native_startup_request_cache_controls 1.60s, native_frozen_request 0.01s).
  • ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' -j 4 --output-on-failure: 26/26 passed (18.69s).
  • tests/docs_links_check.py: passed (79 Markdown files, 586 links).

AI-assisted.

@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 reviewed 4a7e2542 merged over current codex/native-shader-modules a48d39dc, the PR's base. The merge is clean and git diff --cached --check is clean. #3137 fixes the same issue (#3133) a different way, so I ran each PR's new regressions against the other's build (below).

What I traced.

  • Shared parsing: read_pixel_inputs is a straight extraction of the .psin / .ps57in block from read_graphics_request, so the watcher and the request loader now apply the same parse and conflict rules.
  • What the watcher compares: it compares the canonical description with <key>.psdep, and both compile paths write .psdep from the same input.pixel_input_description. So the comparison is against what the manifest was actually compiled from, not against the sidecar bytes as they are on disk at publish time.
  • The 256-byte cap: a .psin description is psin1 <key> ena= addr= text (parse_pixel_inputs caps the source at 128 bytes), and a .ps57in description is 12 bytes, so the cap can't refuse a real .psdep.
  • RTV variants: the watcher reads the base's sidecars through graphics_psin_path and replace_extension(L".a"), so a variant checks its base's .psin / .ps57in.

What I ran. I built compile_dxil native_compute_pack_check native_frozen_request_check native_pixel_ir_dump native_compute_ir_dump in dev and release, then ran

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(native_compile_dxil_watch|native_startup_request_cache_controls|native_rtv_variant_controls|native_direct_container|native_frozen_request)$'

5/5 pass in both presets.

Cross-check with #3137.

  • #3137's regressions on this build: I ran #3137's tests/native_startup_request_cache_check.py against this build, with only its .psinh-file existence assert removed. native_startup_request_cache_controls passes, so this PR also covers #3137's four cases.
  • This PR's regressions on #3137's build: run the other way, this PR's native_compile_dxil_watch_check.py fails on #3137. The RTV variant keeps its stale manifest when the base gains an older-mtime .ps57in.

Mutants in tools/startup/compile_dxil.cpp. For each, I rebuilt compile_dxil in dev and ran the watch, cache and RTV tests:

Mutant Result
sidecar_changed = current_dep != published_dep; → false killed (1 of 3 fails)
invalid or conflicting sidecar (catch) → sidecar_changed = false killed
unreadable or empty .psdep branch → sidecar_changed = false survives

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

Non-blocking.

  1. The unreadable-.psdep branch isn't pinned. A 0-byte <key>.psdep next to a published manifest with a valid .psin would pin it. Today that should withdraw the manifest, and the mutant serves it.
  2. The batch path can leave a stale .psdep. It writes .psdep only when the description is non-empty and never removes an old one; the watch path does remove it. If the sidecars disappear between two batch runs, the next watch poll sees "" != published_dep and retranslates once. That converges, but removing it in the batch path as well would avoid the extra compile.

Verdict: approve on 4a7e2542. Of the two fixes for #3133, this is the one I'd take. It needs no new cache file, it compares with what the manifest was compiled from, and it covers RTV variants. This targets codex/native-shader-modules, so I'm leaving the merge to the branch owner.

Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10. These are CPU-only checks.
CI: none on this PR (the workflow runs only for main and cpp-migration).

This reply was AI-assisted.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Independently reviewed 4a7e2542 on the exact a48d39dc compiler stack. The watcher resolves an RTV request to the base sidecar and compares canonical parsed content to .psdep, which was produced from the same input as the published stages. That avoids both a second digest file and a fresh read at publish time. The stale-manifest controls cover the base and its RTV variant.

Built compile_dxil native_compute_pack_check native_frozen_request_check native_pixel_ir_dump in dev and release. ctest --test-dir <build> --no-tests=error -j 1 -V -R '^(native_compile_dxil_watch|native_startup_request_cache_controls|native_rtv_variant_controls|native_frozen_request)$' passed 4/4 in both builds, zero skips. The preserved-mtime conflicts withdraw both manifests, unchanged sidecars remain cache hits and the regular watch retry/skip controls pass. Windows 26200.9974, SDK/DXC 10.0.26100.0. Please coordinate this with #3137 and carry a single watcher fix into the #3091 compiler integration, then repeat on the final main base.

@KelboLive

Copy link
Copy Markdown
Contributor

Agree with both APPROVED reviews: extracting read_pixel_inputs() so the watcher and request loader share exact .psin/.ps57in parsing is the right approach. Comparing canonical parsed content against .psdep (what the manifest was compiled from) avoids a second digest file and fresh read at publish time. RTV variant coverage is correct — reads base sidecars through graphics_psin_path.

Extract read_pixel_input_description() so watch/request paths share exact .psin/.ps57in parsing and conflict detection, compare canonical pixel-input descriptions against <key>.psdep, remove stale .psdep in batch compile_job when pixel inputs are empty, and verify stale preserved-mtime base/RTV sidecars and 0-byte .psdep retranslation in native_compile_dxil_watch_check.py.

Refs R0Y00#3133

AI-assisted.
@legacy-code-archaeologist

Copy link
Copy Markdown
Contributor Author

Rebased onto codex/native-shader-modules (247530b0, preserving read_pixel_input_description() and canonical .psdep comparison in needs_compile()) and also addressed @pigalot's two non-blocking notes:

  1. Batch-path stale .psdep cleanup: compile_job in tools/startup/compile_dxil.cpp now removes <key>.psdep when input.pixel_input_description.empty(), matching the watch path.
  2. 0-byte .psdep regression check: Added a check in tests/native_compile_dxil_watch_check.py truncating <key>.psdep to 0 bytes next to a published manifest and valid .psin, verifying compile_dxil --once retranslates and restores .psdep.

Local verification (dev and release presets, Windows 10.0.26100):

  • cmake --build --preset dev --target compile_dxil native_compute_pack_check native_frozen_request_check native_pixel_ir_dump native_compute_ir_dump: passed
  • cmake --build --preset release --target compile_dxil native_compute_pack_check native_frozen_request_check native_pixel_ir_dump native_compute_ir_dump: passed
  • ctest --preset dev --no-tests=error -j 1 -V -R '^(native_compile_dxil_watch|native_startup_request_cache_controls|native_rtv_variant_controls|native_direct_container|native_frozen_request)$': 5/5 passed (39.04s, 0 skips)
  • ctest --preset release --no-tests=error -j 1 -V -R '^(native_compile_dxil_watch|native_startup_request_cache_controls|native_rtv_variant_controls|native_direct_container|native_frozen_request)$': 5/5 passed (35.52s, 0 skips)
  • python -B tests/docs_links_check.py: passed (127 Markdown files, 626 links)

AI-assisted.

@legacy-code-archaeologist
legacy-code-archaeologist force-pushed the shader/watch-sidecar-content-invalidation branch from 4a7e254 to e31ffc6 Compare November 28, 2026 00:38
@R0Y00

R0Y00 commented Nov 28, 2026

Copy link
Copy Markdown
Owner

The compiler base #3091 now points to 247530b and this PR conflicts in compile_dxil.cpp. The base has a small guard for older-timestamp slot-57 files and the mixed-sidecar case. Your shared parser and canonical comparison cover the remaining timestamp-preserved stream changes and RTV variants. Please update this PR on the current base, use the shared comparison in place of the narrower watcher guard, and keep the unchanged-cache and old-timestamp controls. This is the follow-up we should carry forward for #3133.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Reviewed e31ffc6 on compiler base 247530b. The watcher and request reader use the same canonical parser and compare the actual sidecar content to the dependency saved at publication. The controls cover preserved older timestamps for stream and slot-57 inputs, the derived RTV requests, unchanged cache hits and an empty dependency file. Batch and watch now both clear an obsolete dependency.

Debug and Release /O2 each passed five source-built tests: native_compile_dxil_watch, native_startup_request_cache_controls, native_rtv_variant_controls, native_compute_pack and native_frozen_request. Windows 11 26200.9974, SDK 10.0.26100. This approval covers the current stack head. Once the compiler stack is integrated, rerun the required checks on the eventual main target.

@JohnConnorNPC
JohnConnorNPC merged commit 0b505c1 into R0Y00:codex/native-shader-modules Nov 28, 2026
lambirou added a commit to lambirou/Xbox2Windows that referenced this pull request Nov 28, 2026
Keep R0Y00#3138's sidecar_changed invalidation and the branch's compute dependency_changed/lost checks in the watch request gate.
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.

5 participants