shader: preserve complete native frontend cache results #3792

Merged
Leyukaka merged 1 commit from upstream-pr/3792 into main 2026-12-02 09:00:13 +00:00
Leyukaka commented 2026-12-01 22:54:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-01T22:54:21Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5596119845 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3792). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-01T22:54:21Z. --- ## 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. ```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.
Leyukaka commented 2026-12-02 04:13:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T04:13:41Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7334691343 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3792#issuecomment-7334691343). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-02T04:13:41Z. --- 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.
R0Y00 commented 2026-12-02 05:26:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T05:26:44Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6145243086 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3792#pullrequestreview-6145243086). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T05:26:44Z. **Review:** COMMENTED --- 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 commented 2026-12-02 06:53:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T06:53:32Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7337526605 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3792#issuecomment-7337526605). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-02T06:53:32Z. --- Rebased onto `main` (f365f125b) 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.
R0Y00 commented 2026-12-02 08:59:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T08:59:14Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6147558122 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3792#pullrequestreview-6147558122). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T08:59:14Z. **Review:** APPROVED --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!3792
No description provided.