Recompiler: an enormous program's HLSL fallback follows the direct translator in the translated cache #3230

Closed
CharlyRien wants to merge 1 commit from upstream-pr/3230 into main
CharlyRien commented 2026-11-28 23:27:34 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CharlyRien on 2026-11-28T23:27:34Z.


Update: #3243 (merged on main after this PR's base 7db2f39) makes direct DXIL the default. With it, the enormous-program route is skipped and the cache identity already follows the direct translator, so the trap described here remains only with XCL_DIRECT_DXIL=0. This PR has not been rebased onto it yet; it still merges without conflict.

A compute program whose HLSL DXC would compile unoptimised (pso::enormous, over 8 MiB of HLSL) goes to the direct DXIL translator, even without XCL_DIRECT_DXIL. What that translator makes is kept in the translated cache under rerouted_identity, which follows the direct translator's version and sources. When the direct translator fails on such a program, its HLSL fallback was kept under the HLSL path's identity instead, and that identity does not follow the direct translator.

translated::cached_rerouted looks under the HLSL path's identity first. So once a build has stored such a fallback, every later build is served that fallback, even one whose direct translator can now translate the program. The program is never tried again.

This PR keeps that fallback under rerouted_identity too. A new direct translator version then misses it and translates the program again.

What is in it

  • crates/xcl/src/gpu/recomp/pso.rs:
    • compile_console_shader: when the enormous-program route's direct translation fails, the HLSL result it falls back to is marked as following the direct translator (the bool that already sends the direct translator's own output to rerouted_identity).
    • Doc comments of compile_console_shader and translated::cached say so; the cache-hit note reads "direct DXIL (its HLSL is enormous), or its HLSL fallback".
  • Kept where they were: programs the HLSL path takes for any other reason, and everything under XCL_DIRECT_DXIL (whose identity already carries the direct translator's version).
  • Test shader_cache_tests::an_enormous_programs_fallback_is_retried_by_a_new_direct_translator:
    • the fallback is a hit for the same direct translator version;
    • a new version misses it and keeps its own DXIL;
    • an old-style entry under the HLSL path's identity is still served to a new version (the case this PR stops creating).
  • +53 / −7 in one file, about 35 of the added lines the test. pso.rs is one of PREPARATION_LAYOUT_SOURCES, so XCL_PIPELINE_LAYOUT_ID changes, as with any edit of pso.rs. The translator identity (XCL_TRANSLATOR_SOURCE_ID) does not change.

Why (what we hit)

  • Measured (posted on #3154, comment): one enormous compute program of the retail title. On main e429936c the direct translator failed on it, and main stored its 9,370,880-byte HLSL fallback. A build of #3154 translates that program directly (1,214,602 bytes). Its first run, on a copy of the cache from the main run, was served main's fallback, unchanged.
  • Read: in cached_rerouted the HLSL path's identity is looked up first, then rerouted_identity. Only the direct translator's own output was stored under rerouted_identity.
  • Deduced: swapping the lookup order alone would not help. A new direct translator has a new rerouted_identity, which misses, and the lookup then still finds the old fallback under the HLSL path's identity. The fallback itself has to follow the direct translator.

Tested

  • Head on main 7db2f39 (it merges with main 227d2cb without conflict; not tested there). RTX 3090 24 GB (Resizable BAR off), driver 616.56, Ryzen 9 5950X, 32 GB RAM, Windows 11 22631, Rust 1.100.0, release tests (cargo test --release -p xcl --lib), XCL_REQUIRE_GPU=mesh.
  • gpu::recomp::pso::shader_cache_tests::: 31 passed, 0 failed, the new test and the two existing rerouted-cache tests (rerouted_disk_entries_follow_the_direct_translator, ..._follow_compact_nesting_policy) among them.
  • The build has the same 18 compiler warnings as main 7db2f39 (no new one).

Regression run
Not run yet: no scripts/smoke.ps1 pair (main and this head) has been made for this PR, so there is no xcl-smoke block. That is why it stays a draft. The change only decides under which identity a fallback is stored, for enormous compute programs whose direct translation fails.

Not tested

  • A title run with this change, and the #3154 program through this exact path (a unit test cannot hold an 8 MiB HLSL program and a failing direct translation; the test drives cached_rerouted with the flag compile_console_shader now sets).
  • Entries stored before this change stay under the HLSL path's identity and are still served: such a fallback goes away only when its file is removed or the cache is new. Bumping TRANSLATION_GLUE_REVISION would clear them, but also every other translation, so this PR does not.
  • AMD and Intel GPUs (nothing here is GPU-specific).
  • #2540 also edits cached_rerouted (container validation); the two should merge without overlap, not checked.

AI use

  • Claude Code with Claude Opus 5.5 found the cache trap while testing #3154, wrote this change and its test, ran the tests on this machine and wrote this description. The person running these tests asked for this PR.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5545619157 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3230). Originally posted by [CharlyRien](https://github.com/CharlyRien) on 2026-11-28T23:27:34Z. --- **Update:** #3243 (merged on `main` after this PR's base `7db2f39`) makes direct DXIL the default. With it, the enormous-program route is skipped and the cache identity already follows the direct translator, so the trap described here remains only with `XCL_DIRECT_DXIL=0`. This PR has not been rebased onto it yet; it still merges without conflict. A compute program whose HLSL DXC would compile unoptimised (`pso::enormous`, over 8 MiB of HLSL) goes to the direct DXIL translator, even without `XCL_DIRECT_DXIL`. What that translator makes is kept in the translated cache under `rerouted_identity`, which follows the direct translator's version and sources. When the direct translator fails on such a program, its HLSL fallback was kept under the HLSL path's identity instead, and that identity does not follow the direct translator. `translated::cached_rerouted` looks under the HLSL path's identity first. So once a build has stored such a fallback, every later build is served that fallback, even one whose direct translator can now translate the program. The program is never tried again. This PR keeps that fallback under `rerouted_identity` too. A new direct translator version then misses it and translates the program again. **What is in it** - `crates/xcl/src/gpu/recomp/pso.rs`: - `compile_console_shader`: when the enormous-program route's direct translation fails, the HLSL result it falls back to is marked as following the direct translator (the `bool` that already sends the direct translator's own output to `rerouted_identity`). - Doc comments of `compile_console_shader` and `translated::cached` say so; the cache-hit note reads "direct DXIL (its HLSL is enormous), or its HLSL fallback". - Kept where they were: programs the HLSL path takes for any other reason, and everything under `XCL_DIRECT_DXIL` (whose identity already carries the direct translator's version). - Test `shader_cache_tests::an_enormous_programs_fallback_is_retried_by_a_new_direct_translator`: - the fallback is a hit for the same direct translator version; - a new version misses it and keeps its own DXIL; - an old-style entry under the HLSL path's identity is still served to a new version (the case this PR stops creating). - +53 / −7 in one file, about 35 of the added lines the test. `pso.rs` is one of `PREPARATION_LAYOUT_SOURCES`, so `XCL_PIPELINE_LAYOUT_ID` changes, as with any edit of `pso.rs`. The translator identity (`XCL_TRANSLATOR_SOURCE_ID`) does not change. **Why (what we hit)** - Measured (posted on #3154, [comment](https://github.com/xcl-dev/xcl/pull/3154#issuecomment-7242721036)): one enormous compute program of the retail title. On `main` `e429936c` the direct translator failed on it, and `main` stored its 9,370,880-byte HLSL fallback. A build of #3154 translates that program directly (1,214,602 bytes). Its first run, on a copy of the cache from the `main` run, was served `main`'s fallback, unchanged. - Read: in `cached_rerouted` the HLSL path's identity is looked up first, then `rerouted_identity`. Only the direct translator's own output was stored under `rerouted_identity`. - Deduced: swapping the lookup order alone would not help. A new direct translator has a new `rerouted_identity`, which misses, and the lookup then still finds the old fallback under the HLSL path's identity. The fallback itself has to follow the direct translator. **Tested** - Head on `main` `7db2f39` (it merges with `main` `227d2cb` without conflict; not tested there). RTX 3090 24 GB (Resizable BAR off), driver 616.56, Ryzen 9 5950X, 32 GB RAM, Windows 11 22631, Rust 1.100.0, release tests (`cargo test --release -p xcl --lib`), `XCL_REQUIRE_GPU=mesh`. - `gpu::recomp::pso::shader_cache_tests::`: **31 passed, 0 failed**, the new test and the two existing rerouted-cache tests (`rerouted_disk_entries_follow_the_direct_translator`, `..._follow_compact_nesting_policy`) among them. - The build has the same 18 compiler warnings as `main` `7db2f39` (no new one). **Regression run** Not run yet: no `scripts/smoke.ps1` pair (main and this head) has been made for this PR, so there is no `xcl-smoke` block. That is why it stays a draft. The change only decides under which identity a fallback is stored, for enormous compute programs whose direct translation fails. **Not tested** - A title run with this change, and the #3154 program through this exact path (a unit test cannot hold an 8 MiB HLSL program and a failing direct translation; the test drives `cached_rerouted` with the flag `compile_console_shader` now sets). - Entries stored before this change stay under the HLSL path's identity and are still served: such a fallback goes away only when its file is removed or the cache is new. Bumping `TRANSLATION_GLUE_REVISION` would clear them, but also every other translation, so this PR does not. - AMD and Intel GPUs (nothing here is GPU-specific). - #2540 also edits `cached_rerouted` (container validation); the two should merge without overlap, not checked. **AI use** - Claude Code with Claude Opus 5.5 found the cache trap while testing #3154, wrote this change and its test, ran the tests on this machine and wrote this description. The person running these tests asked for this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
CharlyRien commented 2026-11-28 23:58:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CharlyRien on 2026-11-28T23:58:40Z.


The red "Build and test" on 4835af9 is 4 tests outside this PR: shaders::pipeline_library::tests::{builder_deduplicates_names_and_atomically_replaces_output, graphics_pipeline_round_trips_through_serialized_library, mesh_pipeline_round_trips_through_serialized_library} and shaders::warm_library::tests::cold_publish_makes_an_unchanged_corpus_reusable. The first fails on an entry count (3 against 2); the other three then fail on the poisoned lock.

This PR only changes gpu/recomp/pso.rs (the translated cache). The same 4 tests passed on #3231 and #3232, opened from the same main 7db2f39 at the same time. This looks like the shared library-builder state that #3221 and #3183 address (and #3180 lists). We cannot rerun the job from here.

AI use: Claude Code with Claude Opus 5.5 read the CI log and wrote this.

<!-- greyfinch-sync:ivall/xcl:comment:7247787760 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3230#issuecomment-7247787760). Originally posted by [CharlyRien](https://github.com/CharlyRien) on 2026-11-28T23:58:40Z. --- The red "Build and test" on `4835af9` is 4 tests outside this PR: `shaders::pipeline_library::tests::{builder_deduplicates_names_and_atomically_replaces_output, graphics_pipeline_round_trips_through_serialized_library, mesh_pipeline_round_trips_through_serialized_library}` and `shaders::warm_library::tests::cold_publish_makes_an_unchanged_corpus_reusable`. The first fails on an entry count (3 against 2); the other three then fail on the poisoned lock. This PR only changes `gpu/recomp/pso.rs` (the translated cache). The same 4 tests passed on #3231 and #3232, opened from the same `main` `7db2f39` at the same time. This looks like the shared library-builder state that #3221 and #3183 address (and #3180 lists). We cannot rerun the job from here. AI use: Claude Code with Claude Opus 5.5 read the CI log and wrote this.
CharlyRien commented 2026-11-29 13:25:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CharlyRien on 2026-11-29T13:25:15Z.


Closing: since #3243 made direct DXIL the default, the enormous-program route this PR fixes is only reached with XCL_DIRECT_DXIL=0, so the trap no longer affects the default path. Happy to reopen if the HLSL-only route matters to someone.

AI use: closed with Claude Code (Claude Opus 5.5), decided by me.

<!-- greyfinch-sync:ivall/xcl:comment:7256524459 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3230#issuecomment-7256524459). Originally posted by [CharlyRien](https://github.com/CharlyRien) on 2026-11-29T13:25:15Z. --- Closing: since #3243 made direct DXIL the default, the enormous-program route this PR fixes is only reached with `XCL_DIRECT_DXIL=0`, so the trap no longer affects the default path. Happy to reopen if the HLSL-only route matters to someone. AI use: closed with Claude Code (Claude Opus 5.5), decided by me.

Pull request closed

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
xcl-dev/xcl!3230
No description provided.