Skip to content

Shaders: XCL_SAFE_BARRIER turns the translation caches off (#1409) - #1413

Open
tiagonogueiraa-bit wants to merge 2 commits into
xcl-dev:mainfrom
tiagonogueiraa-bit:safe-barrier-cache
Open

tiagonogueiraa-bit wants to merge 2 commits into
xcl-dev:mainfrom
tiagonogueiraa-bit:safe-barrier-cache

Conversation

@tiagonogueiraa-bit

@tiagonogueiraa-bit tiagonogueiraa-bit commented Nov 24, 2026 •

Copy link
Copy Markdown

XCL_SAFE_BARRIER=0 changes the HLSL emitted for s_barrier in multi-wave compute programs (emit.rs:553), but the variable was neither in cache_allowed's list nor in the cache key. So a run with it stored those programs' DXIL with the plain group barrier, and later runs without it loaded that DXIL. In the other order, the variable had no effect on programs already cached. Fixes #1409.

What is in it

  • crates/xcl/src/gpu/recomp/pso.rs:
    • cache_allowed: XCL_SAFE_BARRIER joins the list of variables that change the emitted code. As for those, its presence alone turns the caches off.
    • shader_cache_bypasses_debug_overrides checks it, for every stage.
  • crates/xcl/build.rs: TRANSLATION_GLUE_REVISION goes to pso-glue-v2. Entries that a run with the variable set stored under the default key would otherwise stay readable, since pso.rs is outside the source hash; the new revision gives every build a new key (review by @pvfreis).

Tested

  • macOS, Rust stable: cargo check -p xcl --lib --tests --target x86_64-pc-windows-msvc, no errors (C code stubbed, nothing linked).
  • The test's new case fails on main: cache_allowed(Stage::Compute, |v| v == "XCL_SAFE_BARRIER") returns true there, as Shaders: translations made with XCL_SAFE_BARRIER=0 are cached and reused by later runs #1409 shows.
  • @pvfreis, native Windows, RTX 3060, this head merged onto b7aa9f3: cargo test --workspace --locked --no-fail-fast -- --test-threads=4 gives 769 passed, 1 failed, 41 ignored, the same as main b7aa9f3. shader_cache_bypasses_debug_overrides passes. The one failure is the e2e test's swap chain in a non-interactive session, on both. (report)

Regression run
Not run. I have no Windows machine here.

Not tested

  • A cache round trip with the variable set and then unset. @pvfreis's probe on c160d86 showed the stale entry being reused; the revision bump (190c97e) has not been run on Windows.
  • A retail title.

Overlaps
#1284 (XCL_LOOP_BUDGET), #245 (XCL_CS_PAD_ALL, XCL_NO_CS_PAD) and #613 (XCL_DXC_ARGS) add names to the same list and test. Whichever merges later rebases over a one-line conflict.

AI use

  • Claude Code with Claude Opus 5.5. It wrote the change and this description, and ran the macOS check.

🤖 Generated with Claude Code

)

XCL_SAFE_BARRIER=0 changes the HLSL emitted for s_barrier in multi-wave
compute programs (emit.rs), but the variable was neither in
cache_allowed's list nor in the cache key. A run with it stored those
programs' DXIL with the plain group barrier, and later runs without it
loaded that DXIL. In the other order, the variable had no effect on
programs already cached.

It is now in cache_allowed's list, like the other variables that change
the emitted code. As for those, its presence alone turns the caches off.
shader_cache_bypasses_debug_overrides checks it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Integrates 12 additional open upstream PRs on top of upstream/main
(b7aa9f3):
- ivall#1432: GFX10 to DXGI format mappings, depth SRVs, and byte sizing
- ivall#1447: Arena::take overflow/alignment and Uma::free pool validation
- ivall#1441: drop SC_KEYMENU so the window is never frozen in menu mode
- ivall#1431, ivall#1436: TLS directory sizing/alignment and RegisterClassExA checks
- ivall#1430, ivall#1446: XGameSave quota/URL and XAudio2 XMA channel validation
- ivall#1415, ivall#1433: VFS merged-directory sync and CreateFile2 checks
- ivall#1418: XGameRuntime device association synchronization
- ivall#1410, ivall#1413: wave64 form logging and XCL_SAFE_BARRIER cache bypass

Also removes duplicate a_huge_constant_count_has_no_layout test left
from pre-applying ivall#1290 before upstream merged it, and updates README.md.

Verified under GE-Proton11-14 (RX 9060 XT / RADV):
- Release build (x86_64-pc-windows-msvc): ok (22.05s)
- Proton unit test sweep across all merged/touched modules: 209 passed,
  2 failed (known Wine/vkd3d-proton diffs: xma2_source_voice current_buffer_context
  before Start, and vkd3d-proton accepting UNORDERED_ACCESS without UAV flag),
  1 ignored, 0 skipped.
@pvfreis

pvfreis commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Test report for bfaf8c8 (this PR's head) merged onto main b7aa9f3 (clean merge). shader_cache_bypasses_debug_overrides passes with XCL_SAFE_BARRIER added; no regression elsewhere. I opened #1409, and this is the fix it suggested.

Tested

  • RTX 3060 12 GB (driver 617.14), Ryzen 9 5900XT, Windows 11 26H2 (10.0.26300), Rust 1.100.0 stable MSVC, debug
  • cargo build --workspace --locked --offline, then cargo test --workspace --locked --offline --no-fail-fast -- --test-threads=4:
    • main b7aa9f3: 769 passed, 1 failed, 41 ignored
    • this PR merged onto b7aa9f3: 769 passed, 1 failed, 41 ignored (the PR extends an existing test, shader_cache_bypasses_debug_overrides, which passes)
  • SKIPPED on this adapter (both): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64)
  • The 1 failure is the same on both and not from this PR: test_title_runs_and_game_folder_is_untouched (e2e, presents 0), because these runs are in an isolated non-interactive session where CreateSwapChainForHwnd returns 0x887A0022.

Not tested

  • a cache round trip with XCL_SAFE_BARRIER=0 set and unset across two runs
  • AMD, Intel; a retail title (no smoke run here)

Tested and written with Claude Code (Claude Opus 5.5); the runs are real, on the hardware above.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

@tiagonogueiraa-bit
tiagonogueiraa-bit marked this pull request as ready for review November 24, 2026 19:22
@tiagonogueiraa-bit

Copy link
Copy Markdown
Author

Thank you, @pvfreis, and @DavidM1911! The run is in Tested, and the PR is ready for review.

Written with Claude Code (Claude Opus 5.5).

@pvfreis

pvfreis commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

The bypass for runs with XCL_SAFE_BARRIER set looks right. One upgrade case remains.

On stock c160d86, a synthetic s_barrier shader wrote different translated entries under the same cache key with the flag unset and set to 0. I copied just the =0 entry into an empty cache and ran again with the flag unset. XCL reused that entry without writing a lower-level DXIL cache entry.

At bfaf8c8, this patch leaves TRANSLATION_GLUE_REVISION unchanged. build.rs excludes pso.rs from the source hash, so a default run can still read a legacy entry when the hashed sources, DXC and shader settings match. Bumping the translation glue revision would retire those entries. The upgrade path was checked in the code.

Codex (GPT-6.2 Sol) ran the stock probe. Codex (GPT-6.2 Astra) independently checked the evidence and upgrade path.

…_BARRIER bypass

Entries a run with XCL_SAFE_BARRIER=0 or =1 stored under the default key
stay readable after the bypass, since pso.rs is outside the source hash.
Bumping TRANSLATION_GLUE_REVISION gives every build a new key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tiagonogueiraa-bit

Copy link
Copy Markdown
Author

Thanks @pvfreis, you're right: with pso.rs outside the source hash, an entry stored by a run with the variable set stays valid for default runs after this change. 190c97e bumps TRANSLATION_GLUE_REVISION to pso-glue-v2, so every build gets a new key and those entries are retired. Description updated.

@Mischief8713

Copy link
Copy Markdown

GPU run of 190c97e on Windows (NVIDIA GTX 1660 Ti, Turing): 707 passed, 0 failed, 21 ignored

Tested

  • NVIDIA GeForce GTX 1660 Ti 6 GB (Turing, driver 32.0.16.2114), Ryzen 5 2600X, Windows 11 (10.0.26300), rustc 1.100.0, debug build
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4; build exit 0, test exit 0
  • SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64)
  • The head does not contain current main (9039900). It was run as it is.
  • lib: 707 passed, 0 failed, 21 ignored.
  • This is the PR's second commit (bfaf8c8, then 190c97e); the head, not bfaf8c8, was run. The diff touches build.rs and pso.rs, and the suite has no new test name for it, so this shows that nothing else broke.

Not tested

  • No retail title and no scripts/smoke.ps1 run, so no regression run
  • A run with XCL_SAFE_BARRIER set, since that needs a title
  • AMD GPUs; only Turing was run here

AI use

  • Claude Code with Claude Sonnet 5.5 ran the commands and wrote this report. I checked the output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shaders: translations made with XCL_SAFE_BARRIER=0 are cached and reused by later runs

4 participants