Skip to content

Recompiler: direct DXIL makes a pointer to storage again in each block - #2082

Open
Royalflamejlh wants to merge 1 commit into
xcl-dev:mainfrom
Royalflamejlh:linux/direct-gep-per-block
Open

Royalflamejlh wants to merge 1 commit into
xcl-dev:mainfrom
Royalflamejlh:linux/direct-gep-per-block

Conversation

@Royalflamejlh

@Royalflamejlh Royalflamejlh commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

On Linux, vkd3d-proton's dxil-spirv turns five of the retail title's 2,682 direct-DXIL compute programs into SPIR-V that spirv-val rejects: a pointer into groupshared storage is used in a block its definition does not dominate. The direct backend now merges identical getelementptrs within a block only, and all five convert to valid SPIR-V.

Module::optimize merged identical getelementptrs along the dominator tree, so one pointer into the wave64 exchange words or the LDS was used in up to 136 blocks. In the DXIL the definition dominates every use. In the smallest of the five (abeb82838a13d6d9) the pointer is made inside a loop that has two exits and is used after one of them: dxil-spirv routes both exits through one merge block and picks the way on with a flag, so the block inside the loop no longer dominates the code after it. The values made in the loop get a phi there; the pointer does not (my reading of that one output, not of dxil-spirv's code). DXC's DXIL carries such pointers across blocks too and all of it converts validly here, so the merging alone is not a fault: it is avoided because that costs 0.04 % of DXIL.

What is in it

  • crates/xcl/src/gpu/dxil/module/opt.rs: one arm in cse_kind. A getelementptr is merged within its block (Cse::Block) unless it points into a constant global, where loads are still merged along the tree. One unit test, red without the arm.

Tested

  • Retail title 1.0.2.1, xcl shaders shaders.rpf --precompile --only cs --split 1 with XCL_DIRECT_DXIL=1, at main aaa0936 and at 80f5d50 (the tree of this head, 6818f70; only the commit message differs); each program's DXIL through dxil-spirv built natively, with the options vkd3d-proton passes, then spirv-val --target-env vulkan1.3:

    main aaa0936 this commit
    invalid SPIR-V of 2,682, dxil-spirv e084e35c + 061225da + three patches from [OFFICIAL] Looking for PRs with shaders optimization #1269 (0naku's, the split-loop patch and the fourth) 5 0
    the same five through dxil-spirv 34f0ff8 (the one in vkd3d-proton v3.1-90-g30b0eb9b) 5 invalid 0 invalid
    DXIL, all programs 935,669,256 B 936,012,404 B (+0.04 %; 682 programs change)

    The unsplit form of the pack (--split 0, what a card with 64-lane waves gets) is byte-identical with and without the change, all 2,682 programs, and all of its SPIR-V passes spirv-val on main: only the split form's exchange words were reached through a merged pointer.

    The five records: 25b531863bfb0d42, 2a098601171855aa, 8b1f2896e2354d1b, a9f2cd53943d5dc4, abeb82838a13d6d9.

  • Again on today's main, with this commit merged locally (it merges with Recompiler: collapse empty trampolines and merge linear blocks in direct DXIL opt #2194's simplify_cfg without conflict), 1 pass each: on 426a5a7 through 34f0ff8, 5 of 2,682 outputs fail spirv-val on main and 0 with it; on 5478c4a through e084e35c (whose five commits are in dxil-spirv's master since today), 5 and 0.

  • 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, vkd3d-proton v3.1-90-g30b0eb9b with Linux (Wine + vkd3d-proton): a retail game reaches what main reaches on Windows; the obstacle is replaced vtables — proposal: proxies #175's patch in the prefix: 1147 passed, 5 failed, 46 ignored. The same command on main aaa0936: 1146 passed, 5 failed, 46 ignored, the same five (directed_reference_basics, gpu_depth_buffer_created_for_unordered_access_is_placed, stale_blob_cannot_bypass_the_offline_pipeline_cap, test_title_runs_and_game_folder_is_untouched, disk_free_space_ex_reports_pls_quota). SKIPPED: the "no GPU", "no wave64" and "no wave32" tests.

  • RTX 4070 12 GB (driver 615.71.09), the same Wine with vkd3d-proton v3.1-90-g30b0eb9b: cargo test --release -p xcl --lib --target x86_64-pc-windows-gnu -- gpu_ gpu::dxil coverage --test-threads=4: 242 passed, 2 failed, 5 ignored. On main aaa0936: 241 passed, 2 failed, 5 ignored, the same two (directed_reference_basics, gpu_depth_buffer_created_for_unordered_access_is_placed). SKIPPED on both: the two "no wave64" tests.

  • Windows 11 Pro 26300, RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, rustc 1.99.1, debug: cargo test --workspace --no-fail-fast -- gpu::dxil coverage --test-threads=4: 119 passed, 4 failed, 4 ignored. The four are fuzz_validate_and_gpu_0 to _3 (CreateComputePipelineState: Not enough memory resources are available, seeds 70, 545, 1019 and 1507). They fail the same way, with the same seeds, on main 689f2db on that machine, and again here run alone on one thread.

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, the PR's first.

main:

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

PR:

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

Under Wine 11.21 Staging with vkd3d-proton v3.1-90-g30b0eb9b on an RTX 4070 12 GB (driver 615.71.09), main first, 1 run each: 1423 frames on main aaa0936 and 1522 on 6818f70, the last three counts 60 60 60, 0 device removals and 0 crashes in both (under Wine the exit code reads 0x89 and peak commit 0 MB on every tree).

Not tested

  • The title on Linux with the direct backend and this change. No run of ours shows what the five invalid programs did on the card: in earlier runs NVIDIA's compiler took two pipelines of the sizes of two of them without an error (a match by size only).
  • Whether the 682 changed programs compute the same on a GPU beyond what the gpu_ tests cover.
  • AMD and Intel; pixel and vertex programs through the direct backend (--only cs).
  • Compile time in a driver, and dxil-spirv's conversion time: two passes here differed by machine load only.

AI use

  • Two Claude Code sessions (Claude Fable 5.2): one found the cause, wrote the change, the test and this description and ran the conversions, the suite and the Windows runs; the other ran the tests on the Linux card and the run under Wine.
  • Claude Code (Claude Opus 5.5) made the checks on today's main and reran the suite above on that vkd3d-proton build (the same counts).

Module::optimize merged identical getelementptrs along the dominator
tree, so one pointer into the wave64 exchange words or the LDS was used
in up to 136 blocks of a program. dxil-spirv (under vkd3d-proton)
restructures the blocks, and for five programs of the retail title's
pack the block that makes the pointer then no longer dominates a use:
the SPIR-V fails spirv-val ("ID ... defined in block ... does not
dominate its use"). A value gets a phi there; a pointer does not.

A getelementptr is now merged within its block only, unless it points
into a constant global (the lookup tables, whose loads are merged along
the tree).

Direct pack of main aaa0936, compute, split wave64 (2,682 programs),
through dxil-spirv legacy-struct-remove e084e35c and spirv-val
--target-env vulkan1.3: 5 invalid before, 0 after; the same five
through dxil-spirv 34f0ff8 (vkd3d-proton v3.1-90): invalid before,
valid after. DXIL 935,669,256 B before, 936,012,404 B after (+0.04 %);
682 programs change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Royalflamejlh
Royalflamejlh marked this pull request as ready for review November 25, 2026 04:03
@Parakeet-Wheat

Copy link
Copy Markdown

NVIDIA RTX 3070 on native Windows, head 6818f70 on its base aaa0936 (4 commits behind current main): the new test fails without the cse_kind arm and passes with it, the whole suite passes, and the smoke pair is within the limits. The first independent run on this PR.

Tested

  • NVIDIA GeForce RTX 3070 8 GB (driver 610.88, 32-lane waves), Ryzen 5 5600X, 32 GB, Windows 11 26300, Rust 1.95.0 stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11, retail 1.0.2.1. Head 6818f70 (one commit on main aaa0936), checked out clean. Tests in the debug profile, smoke in release.
  • cargo test -p xcl --lib a_pointer_to_storage_is_made_again_in_each_block -- --nocapture --test-threads=1:
    • on aaa0936 with the PR's opt.rs but its cse_kind hunk reverted: 1 failed, left: [1, 0], right: [1, 1] (the second block's pointer is merged into the first's);
    • on 6818f70: 1 passed, 0 failed.
  • .\scripts\test.ps1 (cargo build --workspace, then cargo test --workspace -- --test-threads=4) on 6818f70: 1152 passed, 0 failed, 46 ignored, exit 0. SKIPPED, 25: 20 × no wave64, 3 × per-lane form refused (V_CVT_F16_F32, V_PK_MUL_F16, V_MUL_F16: "its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's"), 1 × no heap windows, 1 × cannot disable the driver cache (Windows Developer Mode required).

Regression run (scripts/smoke.ps1 -Game <folder> -Seconds 60, the same title, back to back, menus, no input; unedited). Base aaa0936:

xcl-smoke v1
commit: aaa093657bd96a146c05c0c1a9b61149fe761453
gpu: NVIDIA GeForce RTX 3070
title: 3d7db37d
seconds: 60
exit: 0x0
frames shown: 1451 (PresentX 1451)
presents per 2 s (last 3): 60 59 18
device removals: 0
crashes: 0
peak commit: 18451 MB

PR head 6818f70:

xcl-smoke v1
commit: 6818f70811ecae3e77d1faff0e5543357a80a11b
gpu: NVIDIA GeForce RTX 3070
title: 3d7db37d
seconds: 60
exit: 0x0
frames shown: 1456 (PresentX 1456)
presents per 2 s (last 3): 60 59 20
device removals: 0
crashes: 0
peak commit: 18537 MB

That is 100 % of the base's frames and 100 % of its peak commit.

Not tested

  • The SPIR-V side the PR is about (dxil-spirv under vkd3d-proton on Linux, spirv-val on the five programs), the --precompile runs on the retail title, a world run, AMD, native wave64 (the 20 no wave64 skips above), the tests on game data (XCL_SAMPLE_* not set).

AI use

  • Claude Code (Claude Sonnet 5.5) ran the tests and wrote this report. The account owner has not reviewed it.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@safesearch77

Copy link
Copy Markdown

Reviewed 6818f70 against main (0829441) and crates/xcl/src/gpu/dxil/module/opt.rs.

  • Merges cleanly onto current main (0829441), including alongside #2194's simplify_cfg pass (simplify_cfg runs after CSE and only merges single-predecessor unconditional edges, so intra-block GEPs cannot regain cross-loop-exit uses before dxil-spirv structurization).
  • Restricting Op::Gep(p, _) if !self.is_const_global_ptr(*p) to Cse::Block cleanly matches Op::Load(p, _) if self.is_const_global_ptr(*p) => Cse::Dom right below it: lookup-table constant globals keep dominator-tree GEP+Load CSE, while mutable TGSM (@xcl_xs / LDS) and alloca pointers stay per-block so dxil-spirv never needs an illegal pointer OpPhi at multi-exit loop merge blocks (+0.04% DXIL size across the 2,682 split compute shaders is negligible).
  • Checked local.clear() on dx.op.discard (opt.rs:471): worst case in a PS with discard is re-emitting an alloca GEP after discard in the same block, which is harmless.

LGTM — clean, minimal fix for NVIDIA Wave32 + vkd3d-proton Direct-DXIL compute pipelines.

AI use: Antigravity (Gemini 4 Carbon) assisted with verifying merge cleanliness and pass interactions in opt.rs; reviewed by me.

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.

4 participants