Skip to content

Recompiler: limit per-region loop budgets to compute and kernel shaders - #2865

Open
Saksukella wants to merge 1 commit into
xcl-dev:amd-devfrom
Saksukella:fix/compute-only-loop-budget
Open

Saksukella wants to merge 1 commit into
xcl-dev:amd-devfrom
Saksukella:fix/compute-only-loop-budget

Conversation

@Saksukella

Copy link
Copy Markdown

Summary

  • Scope per-region loop-budget tracking (budget_regions -> VAR_BUDGET_OWNER / VAR_BUDGET_TOTAL in direct DXIL crates/xcl/src/gpu/dxil/kernel.rs and xcl_bown / xcl_btotal in HLSL crates/xcl/src/gpu/recomp/mod.rs) strictly to compute and kernel shaders (Entry::Compute / Mode::Compute / Mode::Kernel).
  • Non-compute graphics stages (Entry::Mesh, Mode::Mesh, Mode::Pixel, Mode::Vertex, Mode::Geometry) keep the single program-wide loop budget and avoid injecting extra loop-carried PHI/select chains into every loop header.
  • Add regression test per_region_loop_budgets_are_compute_only in crates/xcl/src/gpu/recomp/tests.rs.

Motivation / Root Cause

Commit 287a931b (per-region loop budgets) fixes compute spin-wait passes whose initial spin-wait otherwise exhausts a single shared 65,536 loop budget before the main loop runs, but applied budget_regions unconditionally to all shader stages.

On AMD RDNA 4 (RX 9070 XT, amdxc64.dll), injecting VAR_BUDGET_OWNER / VAR_BUDGET_TOTAL into non-compute stages grew multi-region Entry::Mesh / Stage::Pixel shaders by +3-11 KiB and caused a deterministic 0xc0000005 null-dereference inside amdxc64.dll+0xe3d80a (read at 0x4 / 0x4bfee, vtable amdxc64.dll+0x598bfb0) during CreatePipelineState on a 331,416 B two-pass MS PSO at world entry (3 of 3 runs crashed at t=46-69 s on amd-dev 71b8e6e0).

Limiting per-region loop budgets to compute/kernel shaders preserves 100% of the compute spin-wait fix while restoring crash-free compilation on graphics/mesh pipelines (the same MS PSO compiles in 60-93 ms with 0 crashes across 3 consecutive 180 s world-load runs).

Tested

  • cargo test -p xcl --lib gpu::dxil::compact: 13 passed; 0 failed (including gpu_a_loop_after_a_spin_to_the_budget_still_runs_in_both_forms)
  • cargo test -p xcl --lib per_region_loop_budgets_are_compute_only: 1 passed; 0 failed
  • cargo test -p xcl --lib gpu_a_loop_after_a_spin_to_the_budget_still_runs: 2 passed; 0 failed
  • Offline direct DXIL validation (xcl shaders <pack> --direct --sample 50 --validate, DXC/DXIL 1.9.2609.5): 38/38 (100%) translated & validated (CS 3/3, GS 2/2, MS 11/11, PS 15/15, VS 7/7, 0 validator errors).
  • Extended world-load verification on AMD Radeon RX 9070 XT (XCL_RT_GATE=miss, XCL_DIRECT_DXIL=1, XCL_PER_LANE=1): 0 amdxc64.dll+0xe3d80a crashes and 0 0x887a device removals across three 180 s runs (exit 0x0).

Not tested

  • NVIDIA or Intel GPUs, Linux/Wine, and non-compute shaders that might rely on multiple independent spin-wait loops exceeding 65,536 total iterations.

Regression run
Baseline (main b49be183):

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
seconds: 60
exit: 0x0
frames shown: 1624 (PresentX 1624)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 19700 MB

This PR (2f4b4082):

xcl-smoke v1
commit: 2f4b4082882f2bff2f5932d2a6d45c44bfbc71e0
gpu: AMD Radeon RX 9070 XT
title: b8db18c2
seconds: 60
exit: 0x0
frames shown: 1419 (PresentX 1419)
presents per 2 s (last 3): 60 63 60
device removals: 0
crashes: 0
peak commit: 12968 MB

AI use
AI-assisted using Gemini 2.5 Pro for forensic log/diff analysis, implementation of the compute-only guard and regression test, and local verification on Windows (RX 9070 XT). All code changes, unit tests, offline DXIL validation, and smoke runs were executed and verified locally.

@jessenic

Copy link
Copy Markdown
Contributor

Thanks, @Saksukella. I agree with the scope. The case #2793 fixes is a compute spin-wait, and I know of no graphics or mesh program that needs region budgets. Limiting them to compute and kernel programs also keeps every pixel, vertex, geometry and mesh program's HLSL exactly as on main, so their cached translations and driver blobs stay valid. On the retail title, the guard changed 1,512 of the 2,682 compute programs, and the graphics programs on top of that, which is a large recompile.

If the maintainer prefers one change, I can fold this into #2793 with your test, credited to you; otherwise this one stacks cleanly on it. Either is fine with me.

AI use: Claude Code (Claude Opus 5.5) wrote this comment.

@DarkPanda69

Copy link
Copy Markdown

NVIDIA run (listed as untested), with the RX 9070 XT from the same PC: the new test passes on both, and the PR changes no other result.

Tested: head 2f4b408 applied on its base amd-dev 71b8e6e, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17, card picked with XCL_ADAPTER.
XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: per_region_loop_budgets --test-threads=4 --nocapture, base and PR one after the other on each card:

  • NVIDIA RTX 3060, driver 32.0.16.1088: base 763 passed, 4 failed, 20 SKIPPED; PR 764 passed, 4 failed, 20 SKIPPED.
  • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010: base 761 passed, 6 failed, 4 SKIPPED; PR 762 passed, 6 failed, 4 SKIPPED.

On both cards the only result change is per_region_loop_budgets_are_compute_only, ok. The failures are the same with and without the PR, so they come from amd-dev at 71b8e6e, not from this change:

Not tested: a non-compute shader with more than one spin-wait loop, a title, release, Intel.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@jessenic

Copy link
Copy Markdown
Contributor

A second reason for this scope, from NVIDIA. On the RTX 5070 Ti (driver 610.88, retail title, my integration tree with #2793), the world often ended in a TDR (0x887a0006) with region budgets in every stage. Two 900 s runs that differ only in this PR's scope:

region budgets in run end
all stages (#2793 as is) 900 s TDR 580 s into the world
compute and kernel only (this PR's scope) 900 s no removal, 1,536 presents in the world, 2.05 presents/s

One run each, so read it as a direction. My guess at the mechanism: a graphics loop that really runs away gets up to four budgets instead of one, and on a pixel shader across a full screen that is long enough for the 2 s timeout. A compute spin-wait is the case #2793 was meant for, so I would take this scope into #2793 itself.

AI use: Claude Code (Claude Opus 5.5) ran the runs and wrote this comment.

jessenic added a commit to jessenic/xcl that referenced this pull request Nov 26, 2026
Taken from @Saksukella's xcl-dev#2865. The spin-wait the region budgets are for is
in a compute program. Graphics and mesh stages keep the single budget:
- On AMD (RX 9070 XT), the extra loop-carried values in multi-region mesh
  loop headers crashed the driver's compiler in CreatePipelineState (xcl-dev#2865).
- On NVIDIA (RTX 5070 Ti, retail title), a 900 s run with region budgets in
  every stage hung (0x887a0006) 580 s into the world; the same run with
  this scope ran to the end. One run each. A pixel shader loop that runs
  away got up to four budgets instead of one.

Pixel, vertex, geometry and mesh programs emit exactly the HLSL of main
again, so their cached translations stay valid.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

3 participants