Shaders: restore cached-only state after panics #2378

Closed
github-bot wants to merge 1 commit from gh-pr/2378/head into gh-pr/2378/base
Owner

@⁠mokkamokacaffe on GitHub · 2026-11-25 17:27 UTC · original
mokkamokacaffe:shaders/cached-only-panic-guard → main · +67 −4 · 1 files · 1 commits · closed without merging

A panic inside dxc::cached_only() previously bypassed its thread-local cleanup. If an outer caller caught that panic, later shader requests on the same thread remained in cache-only mode and could silently fail as deferred cache misses.

This addresses only the unclaimed TLS-state item from #1896. The mesh/geometry deferral and xcl shaders --direct worker handling are covered separately.

Part of #1896.

What is in it

  • crates/xcl/src/gpu/recomp/dxc.rs: restore the previous CACHED_ONLY and MISSED state through an RAII guard during normal returns and panic unwinding.
  • Preserve nested cache-only probes and propagate an inner deferred miss to its outer probe.
  • Add a regression test covering panic recovery, subsequent clean probes, nested state restoration and nested miss propagation.

Tested

  • cargo check -p xcl --lib --tests --target x86_64-pc-windows-msvc: passed.
  • The Windows-target library and test code compile successfully from Linux.
  • git diff --check: passed.

Regression run

  • Pending paired xcl-smoke runs on current main and this PR’s exact head commit.

Not tested

  • The Windows test binary was not executed.
  • The complete workspace suite and retail-title smoke comparison were not run.
  • Not tested on AMD, NVIDIA or Intel hardware.
  • The separate mesh/geometry deferral and shader-worker timeout items from #1896 are outside this PR.

AI use

  • OpenAI Codex with GPT-5 implemented the scoped TLS guard and regression test, reviewed the resulting diff, compiled the Windows target and drafted this description.
**@⁠mokkamokacaffe** on GitHub · 2026-11-25 17:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/2378) `mokkamokacaffe:shaders/cached-only-panic-guard` → `main` · +67 −4 · 1 files · 1 commits · closed without merging A panic inside `dxc::cached_only()` previously bypassed its thread-local cleanup. If an outer caller caught that panic, later shader requests on the same thread remained in cache-only mode and could silently fail as deferred cache misses. This addresses only the unclaimed TLS-state item from #1896. The mesh/geometry deferral and `xcl shaders --direct` worker handling are covered separately. Part of #1896. **What is in it** - `crates/xcl/src/gpu/recomp/dxc.rs`: restore the previous `CACHED_ONLY` and `MISSED` state through an RAII guard during normal returns and panic unwinding. - Preserve nested cache-only probes and propagate an inner deferred miss to its outer probe. - Add a regression test covering panic recovery, subsequent clean probes, nested state restoration and nested miss propagation. **Tested** - `cargo check -p xcl --lib --tests --target x86_64-pc-windows-msvc`: passed. - The Windows-target library and test code compile successfully from Linux. - `git diff --check`: passed. **Regression run** - Pending paired `xcl-smoke` runs on current `main` and this PR’s exact head commit. **Not tested** - The Windows test binary was not executed. - The complete workspace suite and retail-title smoke comparison were not run. - Not tested on AMD, NVIDIA or Intel hardware. - The separate mesh/geometry deferral and shader-worker timeout items from #1896 are outside this PR. **AI use** - OpenAI Codex with GPT-5 implemented the scoped TLS guard and regression test, reviewed the resulting diff, compiled the Windows target and drafted this description.
A panic caught outside cached_only left its thread-local mode enabled, making later shader requests act like non-blocking cache probes. Restore the prior TLS state with a scoped guard, preserve nested probes, and propagate nested misses to their outer probe.\n\nPart of #1896\n\nAssisted-by: OpenAI Codex (GPT-5)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:29:33 +00:00
github-bot closed this pull request 2026-11-26 05:29:33 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 19:12 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: 1 real failure, deterministic (also fails --test-threads=1, 1219/1):
gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier
  assertion failed: group barriers in the program (lower_dxil.rs:1155)

The lowered program is missing an expected group barrier (or emits one where none is expected). Needs a fix before merge.

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-25 19:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/2378#issuecomment-7171957510) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: **1 real failure**, deterministic (also fails `--test-threads=1`, 1219/1): ``` gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier assertion failed: group barriers in the program (lower_dxil.rs:1155) ``` The lowered program is missing an expected group barrier (or emits one where none is expected). Needs a fix before merge. — Devin
Author
Owner

@⁠pablogonz12 on GitHub · 2026-11-25 19:56 UTC · original

Test report from Linux + Wine on AMD, since "Not tested" says the Windows test binary was not executed. This is the first execution of it that I can see: it runs under Wine here, on AMD RADV hardware. Prepared with AI assistance: DeepSeek V4.1 Flash in OpenCode; the commands were run by it and the output is pasted verbatim.

Setup

  • CachyOS (Arch), kernel 7.3.6-1-cachyos-eevdf, Mesa 26.3.1-5 (RADV GFX1201), AMD Radeon RX 9070 XT 16 GB (native wave64), Ryzen 9 9900X.
  • GE-Proton11-14 wine (Wine 11.0), scratch prefix, WINEDLLOVERRIDES="d3d12,d3d12core,dxgi,d3d11,d3d10core=n,b", VKD3D_CONFIG=ignore_shared_fence, WINEDEBUG=-all, DXC 1.9.2609.5 (01b62ad4).
  • Build: RUSTFLAGS="-C target-feature=+crt-static" cargo xwin test --workspace --release --target x86_64-pc-windows-msvc --no-run; run wine <xcl lib exe> --test-threads=1 <filter>.
  • Base = main 2898511 with this PR merged on top (clean merge, only this PR differs), head = 86c12ba.

Result

filter base 2898511 this PR 86c12ba
dxc ok: 40 passed, 0 failed, 3 ignored (0.82 s) ok: 41 passed, 0 failed, 3 ignored (0.79 s)
gpu::recomp FAILED: 385 passed, 3 failed, 19 ignored FAILED: 386 passed, 3 failed, 19 ignored

The new test passes:

test gpu::recomp::dxc::tests::cached_only_restores_tls_after_panics_and_nested_calls ... ok

The three gpu::recomp failures are main's own on this box and are byte-identical before and after the PR (they are not related to dxc.rs):

gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu
gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu
gpu::recomp::tests::gpu_nonfused_mad_and_mac_prevent_fma_contraction   (tests.rs:8078 base / :8078 here)

Excluded from the counts

  • gpu::recomp::tests::jumps_to_outer_loop_heads_are_structured aborts the test binary on Wine + RADV (exit status 5, #1246) on both trees; skipped on both sides and not counted.

Not tested

  • No game run: this says nothing about cached-only shader state in a title.
  • Windows, NVIDIA, Intel; and the rest of the workspace suite (only dxc and gpu::recomp were run, because further chapters abort on this Wine lane as described above).

AI use

  • DeepSeek V4.1 Flash (OpenCode) built both commits, ran the tests above and wrote this report; no code was written or changed by it.
**@⁠pablogonz12** on GitHub · 2026-11-25 19:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/2378#issuecomment-7172961493) Test report from Linux + Wine on AMD, since "Not tested" says the Windows test binary was not executed. This is the first execution of it that I can see: it runs under Wine here, on AMD RADV hardware. Prepared with AI assistance: DeepSeek V4.1 Flash in OpenCode; the commands were run by it and the output is pasted verbatim. **Setup** - CachyOS (Arch), kernel 7.3.6-1-cachyos-eevdf, Mesa 26.3.1-5 (`RADV GFX1201`), AMD Radeon RX 9070 XT 16 GB (native wave64), Ryzen 9 9900X. - GE-Proton11-14 wine (Wine 11.0), scratch prefix, `WINEDLLOVERRIDES="d3d12,d3d12core,dxgi,d3d11,d3d10core=n,b"`, `VKD3D_CONFIG=ignore_shared_fence`, `WINEDEBUG=-all`, DXC 1.9.2609.5 (01b62ad4). - Build: `RUSTFLAGS="-C target-feature=+crt-static" cargo xwin test --workspace --release --target x86_64-pc-windows-msvc --no-run`; run `wine <xcl lib exe> --test-threads=1 <filter>`. - Base = `main` 2898511 with this PR merged on top (clean merge, only this PR differs), head = 86c12ba. **Result** | filter | base 2898511 | this PR 86c12ba | |---|---|---| | `dxc` | ok: 40 passed, 0 failed, 3 ignored (0.82 s) | ok: 41 passed, 0 failed, 3 ignored (0.79 s) | | `gpu::recomp` | FAILED: 385 passed, 3 failed, 19 ignored | FAILED: 386 passed, 3 failed, 19 ignored | The new test passes: ``` test gpu::recomp::dxc::tests::cached_only_restores_tls_after_panics_and_nested_calls ... ok ``` The three `gpu::recomp` failures are main's own on this box and are byte-identical before and after the PR (they are not related to `dxc.rs`): ``` gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu gpu::recomp::tests::gpu_nonfused_mad_and_mac_prevent_fma_contraction (tests.rs:8078 base / :8078 here) ``` **Excluded from the counts** - `gpu::recomp::tests::jumps_to_outer_loop_heads_are_structured` aborts the test binary on Wine + RADV (exit status 5, #1246) on both trees; skipped on both sides and not counted. **Not tested** - No game run: this says nothing about cached-only shader state in a title. - Windows, NVIDIA, Intel; and the rest of the workspace suite (only `dxc` and `gpu::recomp` were run, because further chapters abort on this Wine lane as described above). **AI use** - DeepSeek V4.1 Flash (OpenCode) built both commits, ran the tests above and wrote this report; no code was written or changed by it.
Author
Owner

@⁠CalvyPZ on GitHub · 2026-11-25 22:44 UTC · original

This PR has been marked as a duplicate and closed after multiple agreeing checks in #1607. If you believe this is incorrect please re-open with why.

**@⁠CalvyPZ** on GitHub · 2026-11-25 22:44 UTC · [original](https://github.com/xcl-dev/xcl/pull/2378#issuecomment-7176722539) This PR has been marked as a duplicate and closed after multiple agreeing checks in #1607. If you believe this is incorrect please re-open with why.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.