Shaders: restore cached-only state after panics #2368

Closed
mokkamokacaffe wants to merge 1 commit from upstream-pr/2378 into main
mokkamokacaffe commented 2026-11-25 17:27:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by mokkamokacaffe on 2026-11-25T17:27:15Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:6609988905 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2378). Originally posted by [mokkamokacaffe](https://github.com/mokkamokacaffe) on 2026-11-25T17:27:15Z. --- 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.
DavidM1911 commented 2026-11-25 20:08:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T19:12:03Z.


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

<!-- greyfinch-sync:ivall/xcl:comment:7171957510 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2378#issuecomment-7171957510). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T19:12:03Z. --- 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
pablogonz12 commented 2026-11-25 20:08:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by pablogonz12 on 2026-11-25T19:56:05Z.


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.
<!-- greyfinch-sync:ivall/xcl:comment:7172961493 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2378#issuecomment-7172961493). Originally posted by [pablogonz12](https://github.com/pablogonz12) on 2026-11-25T19:56:05Z. --- 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.
bmjask commented 2026-11-25 22:06:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T21:06:45Z.

Review: COMMENTED


No code-level defect found. The TLS RAII guard restores cached-only/miss state through unwind and nesting; focused tests cover panic restoration and miss propagation. Please provide a clean current Windows rerun: PR comments report a deterministic lower-DXIL failure on a rebased branch, apparently outside dxc.rs but needing independent attribution/reproduction. A nested-panic-after-outer-miss case would further pin combined TLS state.

<!-- greyfinch-sync:ivall/xcl:review:6064988104 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2378#pullrequestreview-6064988104). Originally posted by [bmjask](https://github.com/bmjask) on 2026-11-25T21:06:45Z. **Review:** COMMENTED --- No code-level defect found. The TLS RAII guard restores cached-only/miss state through unwind and nesting; focused tests cover panic restoration and miss propagation. Please provide a clean current Windows rerun: PR comments report a deterministic lower-DXIL failure on a rebased branch, apparently outside dxc.rs but needing independent attribution/reproduction. A nested-panic-after-outer-miss case would further pin combined TLS state.
upstream-sync closed this pull request 2026-11-25 23:08:18 +00:00
CalvyPZ commented 2026-11-25 23:09:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by CalvyPZ on 2026-11-25T22:44:00Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7176722539 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2378#issuecomment-7176722539). Originally posted by [CalvyPZ](https://github.com/CalvyPZ) on 2026-11-25T22:44:00Z. --- 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

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!2368
No description provided.