shader: preserve complete native frontend cache results #3794

Manually merged
github merged 1 commit from github-bot/gh-3792 into gh-pr/3792/base 2026-12-02 09:03:51 +00:00 AGit
Owner

@⁠Leyukaka on GitHub · 2026-12-01 22:54 UTC · original
Leyukaka:quality/frontend-cache-results → main · +364 −129 · 13 files · 1 commits · merged 2026-12-02 09:00 UTC

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 #3524, 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** on GitHub · 2026-12-01 22:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3792) `Leyukaka:quality/frontend-cache-results` → `main` · +364 −129 · 13 files · 1 commits · merged 2026-12-02 09:00 UTC ## 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 #3524, 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. ```powershell 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 22:55:29 +00:00
github-bot force-pushed github-bot/gh-3792 from 22f5b1c9e4 to 9a06ec0a00 2026-12-02 04:17:29 +00:00 Compare
Author
Owner

@⁠Leyukaka on GitHub · 2026-12-02 04:13 UTC · original

Rebased onto main (0dd65da11). 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.

**@⁠Leyukaka** on GitHub · 2026-12-02 04:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3792#issuecomment-7334691343) Rebased onto `main` (0dd65da11). `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.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 05:26 UTC · original · reviewed

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 #3801 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.

**@⁠R0Y00** on GitHub · 2026-12-02 05:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3792#pullrequestreview-6145243086) · **reviewed** 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 #3801 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.
github-bot force-pushed github-bot/gh-3792 from 9a06ec0a00 to 7c4de869a5 2026-12-02 06:53:49 +00:00 Compare
Author
Owner

@⁠Leyukaka on GitHub · 2026-12-02 06:53 UTC · original

Rebased onto main (f365f125b) after #3793 and #3801 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 #3801), was not run: its executable was not built in that run.

Heads-up on an interaction with #3823: 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.

**@⁠Leyukaka** on GitHub · 2026-12-02 06:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3792#issuecomment-7337526605) Rebased onto `main` (f365f125b) after #3793 and #3801 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 #3801), was not run: its executable was not built in that run. Heads-up on an interaction with #3823: 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.
github-bot changed target branch from main to gh-pr/3792/base 2026-12-02 09:03:49 +00:00
github manually merged commit 7c4de869a5 into gh-pr/3792/base 2026-12-02 09:03:51 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 08:59 UTC · original · approved these changes

Confirmed the rebased head keeps shader_translation_error.h and the three additional cache-identity headers. On 7c4de869, Windows Debug, ctest --preset dev --no-tests=error -j 1 -R '^native_(direct_cache(_key)?_controls|direct_(container|mesh)|fixed_graphics_psi1|compute_pack(_parts|_refusals)?|compile_dxil_rekey)$' --output-on-failure passed 9/9, including the compute-pack refusal test added on main.

**@⁠R0Y00** on GitHub · 2026-12-02 08:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3792#pullrequestreview-6147558122) · **approved these changes** Confirmed the rebased head keeps `shader_translation_error.h` and the three additional cache-identity headers. On `7c4de869`, Windows Debug, `ctest --preset dev --no-tests=error -j 1 -R '^native_(direct_cache(_key)?_controls|direct_(container|mesh)|fixed_graphics_psi1|compute_pack(_parts|_refusals)?|compile_dxil_rekey)$' --output-on-failure` passed 9/9, including the compute-pack refusal test added on main.
This discussion has been locked. Commenting is limited to contributors.
No description provided.