Skip to content

shader: preserve complete native frontend cache results - #3792

Open
Leyukaka wants to merge 1 commit into
R0Y00:mainfrom
Leyukaka:quality/frontend-cache-results
Open

Leyukaka wants to merge 1 commit into
R0Y00:mainfrom
Leyukaka:quality/frontend-cache-results

Conversation

@Leyukaka

@Leyukaka Leyukaka commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Problem

The native frontend cache stored only part of a translated shader. Pixel descriptor metadata, mesh heap metadata and HLSL were not serialized, so a cache hit could return a result that differs from a live translation. The encoder and decoder were separate hand-written field lists, and nothing failed when a cached record gained a member. The graphics cache key also ignored X2W_MESH57_PARTIAL_ZERO, which lowering reads.

Change

  • Encoding, decoding and equality share one field list. A static_assert on the field count fails the build when NativeComputeShader gains a member that the list does not cover.
  • Every field of the translated shader is cached. Decoding keeps the existing range checks and now also rejects trailing data.
  • The frontend format advances to frontend-3. Loose .csir and .pairir entries are regenerated, and prepared compute packs must be rebuilt.
  • The source fingerprint includes three more cache-relevant headers.
  • X2W_MESH57_PARTIAL_ZERO is read once on first use and is part of the graphics frontend key, so lowering and the cache use the same value.

Lowering is not changed; this is serialization and cache keying only.

This conflicts textually with #3522, which changes first-dispatch lookup in the same cache reader. I will rebase after whichever merges first.

Validation

Windows, MSVC, dev preset, at 22f5b1c9e: 8/8 tests passed.

cmake --preset dev
cmake --build --preset dev --target compile_dxil native_direct_cache_check native_compute_pack_check
ctest --preset dev --no-tests=error --output-on-failure -R '^native_(direct_cache(_key)?_controls|direct_(container|mesh)|fixed_graphics_psi1|compute_pack(_parts)?|compile_dxil_rekey)$'

native_direct_cache_controls round-trips a shader with every field populated and checks that malformed payloads are refused. native_direct_cache_key_controls checks that changing the option gives a separate cache entry. The container check compares cached IR payloads and emitted DXIL byte for byte across cold and warm runs, and the pack checks compare complete cached results with live translations.

@Leyukaka

Leyukaka commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto main (0dd65da). main replaced stride_srvs with stride_sources (ComputeStrideSource) and added shift and base to MeshHeapRead. The shared field list now covers both: stride_sources is decoded with a 32-entry limit and a shader_register > 31 check, and MeshHeapRead is written and read with shift and base. Note that the cache on main still does not serialize mesh_heap_reads at all, so the two new fields are lost on a cache hit there along with the rest; this PR covers them. The CTest selection from the description passes again with MSVC on the new head.

@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.

Thanks for rebasing and covering the new stride and heap-read fields. I rebuilt compile_dxil, native_direct_cache_check and native_compute_pack_check at 9a06ec0a. On Windows Debug, ctest --preset dev --no-tests=error -j 2 -R '^native_(direct_cache(_key)?_controls|direct_(container|mesh)|fixed_graphics_psi1|compute_pack(_parts)?|compile_dxil_rekey)$' --output-on-failure passed 8/8. The merge against main e958b8e8 now conflicts in the X2W_NATIVE_SHADER_REVISION input list in CMakeLists.txt. Please retain shader_translation_error.h from #3799 and all three new cache-identity headers from this PR when rebasing, then rerun the cache and compute-pack refusal checks on the combined head.

@Leyukaka
Leyukaka force-pushed the quality/frontend-cache-results branch from 9a06ec0 to 7c4de86 Compare December 2, 2026 06:52
@Leyukaka

Leyukaka commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto main (f365f12) after #3791 and #3799 merged; the only conflict was the shader-revision source list in CMakeLists.txt (both header lists kept). On the new head, eight of the nine tests in the CTest selection from the description ran and passed. The ninth, native_compute_pack_refusals (added by #3799), was not run: its executable was not built in that run.

Heads-up on an interaction with #3821: it adds ComputeViewBinding::dynamic_scalar_load, and this PR's cache visitor names every field of that struct in a structured binding. The two merge cleanly as text, but the second one to merge will not compile until the field is added to the visitor and its fixture; I will push that follow-up as soon as the first one lands.

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.

2 participants