Skip to content

Recompiler: direct DXIL gives every loop head and block one back edge - #1860

Open
Royalflamejlh wants to merge 2 commits into
xcl-dev:mainfrom
Royalflamejlh:linux/direct-single-latch
Open

Royalflamejlh wants to merge 2 commits into
xcl-dev:mainfrom
Royalflamejlh:linux/direct-single-latch

Conversation

@Royalflamejlh

@Royalflamejlh Royalflamejlh commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

On Linux, vkd3d-proton's dxil-spirv segfaults on 77 of the retail title's 2,682 direct-DXIL compute programs in the split wave64 form. The direct backend now gives every loop head and every block one back edge, and dxil-spirv as it is converts all of them. Part of #1805.

dxil-spirv keeps one back edge per loop head. Its main pass merges several first, but the pass it runs for shaders with wave shuffles analyses the CFG before that, and a second back edge then sends its dominator computation into endless recursion. A block with back edges to two loop heads keeps the second among its forward successors, which its loop tracer then follows without end (my reading of the code; not checked per program). The detail is in this comment on #1805.

What is in it

  • crates/xcl/src/gpu/dxil/cfg.rs: single_latch, called from Cfg::build_with after make_reducible. A loop head with several back edges, or one whose back edge leaves a block that has a second, gets a new empty block that jumps to it and takes those edges; the block takes the head's pc, as make_reducible's copies take their original's. Two unit tests.

Tested

  • Head 1160f92: the change is a6e5c0e on main 689f2db (rebased from d812f24 on c4d37be after CfgBlock::pc came in; the only difference is that field), and 1160f92 adds a test by @anes66, from their companion commit b780cdd: latch_blocks_preserve_loop_registers_on_the_gpu runs two loop shapes (two returns to one head; a nested loop with returns to either head) through the direct translator in wave32 and split wave64 and compares the registers with HLSL + DXC and with expected values. On an RTX 5070 Ti (Windows 11, driver 621.24, debug): cargo test --workspace -- latch --test-threads=1, 2 passed, 0 failed, the GPU one among them (1 run). The other half of that commit, a bump of the direct translator's cache version, is not taken: since Recompiler: direct DXIL cache entries change when its sources do #1947 (merged) the cache entries change when the gpu/dxil sources do.
  • No GPU: Ryzen 9 9950X3D, Fedora 44, Wine 11.21 Staging with Mesa lavapipe only, rustc 1.98.0, release, cross-compiled to x86_64-pc-windows-gnu. cargo test --workspace --release --target x86_64-pc-windows-gnu --no-fail-fast -- --test-threads=4 --skip d32s8 --skip reservable_agrees_with_the_driver: 971 passed, 4 failed, 45 ignored. The same command on main 689f2db: 969 passed, 4 failed, 45 ignored. The same 4 fail on both (disk_free_space_ex_reports_pls_quota, gpu_depth_buffer_created_for_unordered_access_is_placed, test_title_runs_and_game_folder_is_untouched, gpu::dxil::round_tests::directed_reference_basics); the 2 more that pass are the new tests. The two tests skipped by name did not finish under Wine in our earlier runs of main. SKIPPED GPU tests: 265 lines on both.
  • RTX 4060 Ti (driver 615.71.09), the same Wine with vkd3d-proton v3.1-90-g30b0eb9b, on d812f24 before the rebase: cargo test --release -p xcl --lib --target x86_64-pc-windows-gnu -- gpu_ gpu::dxil coverage --test-threads=4: 188 passed, 1 failed, 3 ignored; the failure is gpu_depth_buffer_created_for_unordered_access_is_placed, which fails on main under Wine too. SKIPPED: the two "no wave64" tests.
  • Retail title 1.0.2.1, xcl shaders shaders.rpf --precompile --only cs --split 1 with XCL_DIRECT_DXIL=1, at 689f2db and at this commit; each program's DXIL then through dxil-spirv 34f0ff8 (the one in that vkd3d-proton), built natively, with the options vkd3d-proton passes. Before: 77 of 2,682 segfault inside flatten_subgroup_shuffles(). After: 0. One 3.9 MB program is not done in 300 s either way. 79 programs' DXIL changes (those 77 and 2 more), 21,012 bytes more in 907 MB; the other 2,603 are the same bytes. The 77 new SPIR-V outputs pass spirv-val --target-env vulkan1.3. (The dxil-spirv pass was made on the packs of c4d37be and d812f24, which are byte for byte the packs of 689f2db and this commit.)

Regression run

Windows 11 Pro 26300, RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D; the title's first-run screens completed once, no story progress, no input; 1 run each, back to back.

main:

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: NVIDIA GeForce RTX 5070 Ti
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1072 (PresentX 1072)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 18058 MB

PR:

xcl-smoke v1
commit: 1160f92c1480df891561083a9279d3b2ca9b1aa9
gpu: NVIDIA GeForce RTX 5070 Ti
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 1643 (PresentX 1643)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16132 MB

Under Wine on an RTX 4060 Ti 16 GB (driver 615.71.09), before the rebase: 1558 frames on main c4d37be and 1568 on d812f24, 0 device removals and 0 crashes in both.

The title with XCL_DIRECT_DXIL=1 under Wine + vkd3d-proton v3.1-90-g30b0eb9b (its own dxil-spirv, unpatched for this), RTX 4070 12 GB, 120 s, main c4d37be + #684 with and without d812f24: with it 121 and 230 compute pipelines were made by 120 s (2 runs) and Wine logged no stack overflow; without it 23, and one virtual_setup_exception stack overflow line (1 run). Presents stop at about 80 to 93 s either way.

Not tested

AI use

  • Claude Code (Claude Fable 5.2) found the cause, wrote the change, the tests and this description, and ran the tests and the measurements.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

On real hardware: RTX 3070 8 GB (32-lane waves, split wave64), driver 616.56, Windows 11, debug.

It no longer builds on main 689f2db. ee85bc2 added CfgBlock::pc since this PR's base, and the new latch block doesn't set it:

error[E0063]: missing field `pc` in initializer of `cfg::CfgBlock`
   --> crates\xcl\src\gpu\dxil\cfg.rs:246:21

Locally I used the loop head's offset, as main's split copies take their original's (pc: blocks[h].pc).

With that, XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu_ --skip gpu_sparse_vram --test-threads=4:

  • main 689f2db: 110 passed, 0 failed, 1 ignored (2 of 2 runs);
  • this PR: 110 passed, 0 failed, 1 ignored. The two new cfg tests and loop_entered_in_the_middle_is_split pass.

(gpu_sparse_vram_descriptors_buffers_and_xmem was skipped because of the #1727 parallel hang, not this PR.)

AI-assisted (Claude Code). Synthetic tests only.

vkd3d-proton's dxil-spirv keeps one back edge per loop head. Its main
pass merges several first, but flatten_subgroup_shuffles(), which runs
for shaders with wave shuffles (the split wave64 form), analyses the
CFG before that, and a second back edge then sends its dominator
computation into endless recursion: a stack overflow in d3d12core.dll
when the pipeline is made (xcl-dev#1805). The same happens for a block with
back edges to two loop heads.

Cfg::build now adds a block that jumps to the head and takes the back
edges, for a head with several and for one whose back edge leaves a
block that has a second.

Measured on the retail title's shaders.rpf, xcl shaders --precompile
--only cs --split 1 with XCL_DIRECT_DXIL=1, each program then through
dxil-spirv 34f0ff8 natively: 77 of 2,682 programs overflowed its stack
before, none does now. 79 programs change (those 77 and 2 more),
21,012 bytes more DXIL in 907 MB; the other 2,603 are the same bytes.

Part of xcl-dev#1805

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Royalflamejlh
Royalflamejlh force-pushed the linux/direct-single-latch branch from d812f24 to a6e5c0e Compare November 24, 2026 22:35
@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

@upipibi thank you: rebased onto 689f2db, with pc: blocks[h].pc for the latch block as you had it. It builds there, the three cfg tests pass, and the suite under Wine without a card gives 971 passed, 4 failed, 45 ignored against 969 / 4 / 45 on 689f2db, the same 4 failing (1 run each). The 2,682 compute programs it makes with XCL_DIRECT_DXIL=1 are byte for byte those from before the rebase.

Yours is the only run of it on Windows so far. The description has the new counts; the smoke block for the new head is to come.

AI use: Claude Code (Claude Fable 5.2) made the rebase, ran the tests and wrote this.

Posted without review by a person: the account owner was away and reads replies later.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
@itsd-effex

Copy link
Copy Markdown

Tested on a GPU, with the pipelines from #1805: this change alone stops the worker deaths, with dxil-spirv unpatched.

Two builds of the same tree: this PR's head a6e5c0e + #759 dd66d20 (for xcl pipelines), and the same tree with a6e5c0e reverted. Both with vkd3d-proton ec207194 (+ #257's patch) and unpatched dxil-spirv 7c048638, loaded from next to xcl.exe (checked with WINEDEBUG=+loaddll). xcl pipelines with XCL_DIRECT_DXIL=1, 14 workers, empty DXIL and vkd3d-proton caches, a data root of its own. Input: the 21 retail pipelines that each killed their worker on their own in #1805 (on that same unpatched dxil-spirv).

stack overflows result
without this PR 12 14 → 2 live workers within about 60 s, 0 of 21 made (stopped once no worker was busy)
this PR 0 made 21, failed 0, 287 s; the worker count only fell as the last programs finished

The 21: 05a6f7b3c517c29a, 240e0081d6fcbfa3, 241fc505f962313b and 18 more, the killer lines of the classification described in #1805 (comment).

Tested: Linux (CachyOS), Proton Experimental's Wine, RTX 3080 Ti (NVIDIA 620.73.04), i7-11700KF, 32 GB RAM. Retail 1.0.2.1, the title's own journal. Release, cross-built for x86_64-pc-windows-msvc. For the build only, a local commit with a switch to make chosen pipelines (XCL_PIPELINES_ONLY) and a two-line fix that #759 needs to build on this main (#1524 renamed what it uses; reported on #759).

Not tested: the test suite on this head; the title's own runtime compiles; AMD; native Windows; the pack's other ~58,000 pipelines with this change.

AI use

  • Claude Code (Claude Opus 5.5) built the trees, ran the test and wrote this comment.

@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

The goal:world-load label is missing here: this is part of #1805, which carries it (#1833: "If yours is missing, say so here or on the PR").

Posted without review by a person: the account owner was away and reads replies later.

@anes66

anes66 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The latch change needs a direct-translator cache-version bump. Exact head a6e5c0ebe12abfb2fdaa4ee02e719cad10f243e6 changes only gpu/dxil/cfg.rs, which is outside build.rs's source hash, and keeps TRANSLATOR_VERSION=7. A pre-fix disk translation can therefore bypass the new CFG entirely.

Companion patch: b780cdd, directly on that head. It bumps 7 to 8, adds a disk-cache regression, and adds a synthetic GPU output check for the latch rewrite. No competing upstream PR.

Tested

  • Windows 10 Pro 19045, RTX 3060 12 GB / driver 32.0.16.2114, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, DXC 1.9.2602.17, Agility 1.620.2, debug. No XCL_SAMPLE_* inputs.
  • Cache regression before the bump: 0 passed / 1 failed; the old marker was loaded and the translation closure was never called. After: 1/0. It seeds a synthetic v7 entry through the existing cache helpers, requires rebuilding in both direct routing modes, and checks that HLSL still reuses its entry. This is a storage-identity check, not execution of an old retail shader.
  • cargo test --locked -p xcl --lib latch -- --nocapture --test-threads=1: 3/0/0, no skips. The new GPU fixture translates two RDNA2 loop shapes (two returns to one head; a nested loop with returns to either head), asserts the inserted latches, validates DXIL, and compares GPU registers against HLSL+DXC and explicit expected values. Wave32 and split wave64, 0/1/2/5 iterations: 16 input/mode cases, 32 GPU dispatches, all matched. Native wave64 was not run.
  • cargo build --locked --workspace -j 4: passed.
  • Patched workspace, cargo test --locked --workspace --no-fail-fast -j 4 -- --test-threads=1 --show-output: 979 passed / 0 failed / 45 ignored, 23 explicit SKIPPED lines (18 no-native-wave64 cases, three per-lane f16 refusals, the Developer-Mode-dependent PSO measurement, and the heap-window-only case). Skips and sample-gated returns are included in Rust's pass counts.

Parallel limitation
The same patched workspace at --test-threads=4 was 976/3/45, 26 explicit SKIPPED lines. write_buffer_immediate_on_open_existing_heap_visible_to_cpu, rotating_queue_self_deadlock_and_non_monotonic_rescue_do_not_hang, and timestamps_outside_unified_memory_land_after_the_queue failed creating queues with 0x887A0005; subsequent GPU-unavailable skips occurred.

An unmodified exact-head control, cargo test --locked -p xcl --lib -- --test-threads=4 --show-output, was 926/2/25, 23 explicit SKIPPED lines: coherent_buffer_sanitizes_console_flags_and_state and the same write_buffer_immediate_on_open_existing_heap_visible_to_cpu failed. This is a library-only control, not a clean full-workspace comparison. The parallel failures' cause is not established; the serial result does not make the parallel suite green.

Not tested
Wine/vkd3d, AMD/Intel, native wave64, release, title/world-load regression, the 79 changed retail programs, or integration onto newer main. The new GPU fixture calls the direct translator explicitly; the workspace runs used the default backend, not a full XCL_DIRECT_DXIL=1 suite. No proprietary inputs were accessed. A maintainer/title tester still needs the required exact-head regression pair before merging a runtime change.

AI use
Codex (GPT-6; exact variant unavailable) wrote the companion patch and synthetic tests, ran the native checks and controls, and prepared this report. The latch algorithm is the original author's work.

@pablogonz12

Copy link
Copy Markdown
Contributor

Tested on AMD / RADV under Wine: no regression here, but the AMD-side abort is a different failure from #1805 and this change does not touch it.

Not tested: a retail title (no xcl-smoke pair from me); NVIDIA and Windows-native AMD.

…n the GPU

Two loop shapes (two returns to one head; a nested loop with returns to
either head), wave32 and split wave64, against HLSL + DXC and explicit
expected values. The test of anes66's companion commit b780cdd, taken
without its cache-version bump, which xcl-dev#1947 makes unnecessary.
@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

@anes66 thank you: your GPU test is in as your commit (1160f92, the core_tests.rs part of b780cdd). On an RTX 5070 Ti (Windows 11, driver 621.24, debug) cargo test --workspace -- latch --test-threads=1 gives 2 passed, 0 failed, the GPU one among them (1 run), and the description has a new regression block for that head.

I did not take the version bump: #1947, merged since, makes the direct translator's cache entries change when the gpu/dxil sources do, so a translation cached before this change is no longer reused once this is on main. Say if you see a case that still slips through.

AI use: Claude Code (Claude Fable 5.2) made the commit from yours, ran the test and the regression run and wrote this reply.

Posted without review by a person: the account owner was away and reads replies later.

@Royalflamejlh

Copy link
Copy Markdown
Contributor Author

Still needed after #2034: on main aaa0936 vkd3d-proton's own dxil-spirv segfaults on 77 of the 2,682 direct-DXIL compute programs, in the split wave64 form and in the unsplit one, and with 1160f92 merged in (no conflict) on none in either form.

Setup: Fedora 44, Ryzen 9 9950X3D, Wine 11.21 Staging, no GPU. Retail title 1.0.2.1, xcl shaders shaders.rpf --precompile --only cs with XCL_DIRECT_DXIL=1 and --split 1 or --split 0, release builds of aaa0936 and of aaa0936 with 1160f92 merged locally. Each program's DXIL then through dxil-spirv 34f0ff8 (the one in vkd3d-proton v3.1-90-g30b0eb9b, with the one resource-metadata patch our build of it carries), built natively, with the options vkd3d-proton passes on a card with 32-lane waves (--subgroup-size 32 32) for both forms, 4 at a time, 300 s limit. 1 pass each.

2,682 programs main aaa0936 aaa0936 + 1160f92
split form (--split 1, a card with 32-lane waves) 2,604 convert, 77 segfault, 1 not done in 300 s 2,681 convert, 0 segfault, 1 not done in 300 s
unsplit form (--split 0, the form for 64-lane waves) 2,604 convert, 77 segfault, 1 not done in 300 s 2,681 convert, 0 segfault, 1 not done in 300 s
  • The 78 that fail on main are the same programs in both forms, and the 77 are those of the description. 50 of the 77 are the same bytes in both forms, so the unsplit pass is a new test for 27 of them. The description above measured the split form only.
  • The one not done in 300 s is record 95cc13288a27a96e (3.9 MB of DXIL) in all four passes. That is dxil-spirv's conversion time, not the recursion ([OFFICIAL] Looking for PRs with shaders optimization #1269 has patches for it).
  • The merge changes the DXIL of 79 programs in each form, the same 79 as in the description (the 77 and 2 more).

Not tested: the title or a GPU on this merge; whether the 79 changed programs compute the same; the unsplit form with the subgroup sizes a card with 64-lane waves reports; pixel and vertex programs.

AI use: Claude Code (Claude Fable 5.2) built the trees, ran the conversions and wrote this comment.

Posted without review by a person: the account owner was away and reads replies later.

@JJAutoCompare

Copy link
Copy Markdown

Tested

Independent Arc A770 run of open PR #1860 at 1160f92c1480df891561083a9279d3b2ca9b1aa9 on STOR-WINLAB. The test run verified the reused checkout was clean and detached at that SHA before and after.

Windows 11 Enterprise Evaluation x64 26200.9974, AMD Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust and Cargo 1.100.0 MSVC, DXC/DXIL 1.9.2609.5. Used two Cargo jobs with incremental compilation and test debug info disabled.

cargo test --locked -p xcl --lib --no-run
$env:XCL_ADAPTER = 'A770'
$env:XCL_DXC_DIR = Join-Path $env:LOCALAPPDATA 'XclTooling/dxc-1.9.2609/bin/x64'
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
    & 'L:/XclTooling/pr2014-1c971de6/target/debug/build/xcl/77aca8ccb20e299f/out/xcl-77aca8ccb20e299f.exe' gpu::dxil::core_tests::latch_blocks_preserve_loop_registers_on_the_gpu --exact --nocapture --test-threads=1
}

The build completed outside the Arc mutex. The fully captured GPU invocation reported 1 passed, 0 failed, 0 ignored, 0 explicit skips, 953 filtered out, 0.34 s. The wrapper exited 0 and logged lock release. An earlier invocation printed a pass, and PowerShell lost part of its stderr. This report uses the fully captured rerun.

The fixture checked both the two-return and nested loop shapes in wave32 and split wave64, with iteration counts 0, 1, 2, and 5. It validated direct DXIL, compiled the HLSL/DXC reference, and matched registers v1–v3 against expected values and the HLSL/DXC GPU output.

Not tested

Native wave64, other adapters or drivers, additional fixtures, the workspace suite, retail smoke, and performance.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the checked-in fixture and checked the captured logs. The coordinator prepared this summary from the completed run.

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.

7 participants