Skip to content

Recompiler: shadow v_writelane spill slots in split-wave64 - #917

Open
zondy1i wants to merge 1 commit into
xcl-dev:mainfrom
zondy1i:recomp/x64-writelane-shadows
Open

zondy1i wants to merge 1 commit into
xcl-dev:mainfrom
zondy1i:recomp/x64-writelane-shadows

Conversation

@zondy1i

@zondy1i zondy1i commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

��In split-wave64 mode (two hardware wave32 halves per console wave64), SGPR spill reloads (v_writelane_b32 �! v_readlane_b32 with a constant lane) previously went through xcl_x_rla_uniform and emitted a full cross-half exchange (bounded spin loop, barriers, and atomics), even though both halves already hold identical SGPRs (x64_masks keeps v_writelane_b32's scalar source whole-live).

This adds a conservative forward must-analysis (upper_lanes::analyze_spills) for split-wave64 Kernel, Compute, and Mesh programs so constant-lane spill reloads read a scalar shadow xcl_sh<v>_<l> directly without exchanging across halves, reducing DXIL size and NVIDIA driver (nvgpucomp64.dll) pipeline compile time. Native wave64 HLSL is unchanged.

What is in it

  • crates/xcl/src/gpu/recomp/upper_lanes.rs: add analyze_spills (tracks constant-lane v_writelane_b32 slots 0..63 across the CFG; invalidates on any VGPR write, dynamic-lane v_writelane_b32, v_movrel/v_swaprel, LOOP_GUARD exits, or indirect jumps) + unit tests.
  • crates/xcl/src/gpu/recomp/mod.rs: run analyze_spills for split-wave64 Kernel/Compute/Mesh programs.
  • crates/xcl/src/gpu/recomp/emit.rs: emit direct xcl_sh<v>_<l> reads for shadowed v_readlane_b32 in x64() mode without declaring VS/PS-only xcl_hw32.
  • crates/xcl/src/gpu/recomp/tests.rs: add gpu_split_wave64_writelane_spill_shadows GPU test covering lower- and upper-half spill reloads alongside a non-spill cross-half read.

Measured on three spill-heavy retail wave64 compute shaders (RTX 3060 Ti, DXC 1.9.2609.5, before �! after):

Tested

  • Hardware: NVIDIA GeForce RTX 3060 Ti 8 GB (driver 32.0.16.2101), Ryzen 5 7500F, 64 GB RAM, Windows 11 Build 26300, DXC 1.9.2609.5, Rust 1.100.0 (x86_64-pc-windows-msvc), debug + release.
  • cargo test --workspace -- --test-threads=1: 718 passed, 0 failed, 41 ignored (2 SKIPPED GPU tests: gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)).
  • Note: under --test-threads=4 on commit 1ec4c98, pre-existing hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels failed intermittently (cascading 2 PoisonErrors in unrelated d3d12x tests); all recomp tests pass under both --test-threads=4 and --test-threads=1.

Regression run

main:

xcl-smoke v1
commit: 80f4819098e921f2e1ab371144d4832f68ffedd6
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1622 (PresentX 1622)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16539 MB

PR:

xcl-smoke v1
commit: 709abd7fe1a546668c8631b2e691e58d71e3e233
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1614 (PresentX 1615)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15644 MB

Not tested

  • Native wave64 GPU (AMD RDNA): hardware not available here (split_wave64 is false there so emitted HLSL is unchanged).
  • Retail gameplay past menus (smoke run covers boot through menus; world-loading compute shaders were benchmarked offline via DXC + CreateComputePipelineState).

AI use

  • Antigravity (Gemini 4 Neon): analyzed DXIL/corpus spill patterns, wrote the implementation, unit/GPU tests, and PR description; all tests, benchmarks, and smoke runs were executed locally on the hardware above and the diff was reviewed line by line.

@Diskuss

Diskuss commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Tested on AMD Radeon RX 9070 XT (RDNA4) at 32976332072567e6fe9a7cc621e9cedce509ea2f

Hardware: RX 9070 XT (RDNA4, driver 32.0.32015.7029), Ryzen 7 5700X3D, 32 GB RAM, Windows 11 Pro build 26300.9974, Rust 1.100.0 x86_64-pc-windows-msvc, DXC 1.9.2602.17, debug build.

Tested

  • cargo build --workspace: succeeded (1 existing warning in the xcl lib).
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 718 passed, 0 failed, 41 ignored (summed over all test result: lines).
  • The PR's three named tests all ran and passed in that run:
    • gpu_split_wave64_writelane_spill_shadows: ok
    • spills_follow_writelane_for_both_halves: ok
    • spills_stay_conservative_across_overwrites_branches_and_loops: ok
  • SKIPPED lines: 0
  • Device removal: none
  • Compared with main (1ec4c98: 715 passed, 0 failed, 41 ignored, 0 SKIPPED): +3 passed, which matches the 3 new tests; failed and ignored are unchanged.

Not tested: retail title / scripts/smoke.ps1 (no game files), release build, wave32-only GPUs.

Report written by Claude Code (Claude Sonnet 5.5) from a real run on this machine.

Correction (hidden skips): "0 SKIPPED" above means no SKIPPED line appeared in the normal run. A later -- --nocapture run on this machine shows that two tests skip silently, because the D3D12 debug layer is not installed (no Graphics Tools / d3d12SDKLayers.dll). libtest captures their output, so they show as ok: e2e::test_title_draws_with_a_root_signature_under_the_debug_layer and texture_states::uploads_start_from_each_subresources_state. Neither is related to this change, and all other GPU tests ran on the RX 9070 XT.

@IvyNotFound

Copy link
Copy Markdown

Tested on NVIDIA RTX 5080 (Blackwell, wave32) at 32976332072567e6fe9a7cc621e9cedce509ea2f

Tested

  • GPU: NVIDIA GeForce RTX 5080 16 GB, driver 621.24 (32.0.16.2124), split wave64 path; CPU: AMD Ryzen 7 7800X3D
  • Windows 11 25H2 (build 26200.9974), rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100.0), debug build
  • Game data: XCL_SAMPLE_RPF (retail shaders.rpf), XCL_SAMPLE_DLLS, XCL_SAMPLE_TTPF, XCL_SAMPLE_BVH4
  • cargo build --workspace: succeeded (the existing fetch_update deprecation warning only)
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 715 passed, 3 failed, 41 ignored; SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware
  • The PR's tests pass: gpu_split_wave64_writelane_spill_shadows (ran, no SKIPPED line), upper_lanes::tests::spill_slots_come_from_their_shadow, spills_follow_writelane_for_both_halves, spills_stay_conservative_across_overwrites_branches_and_loops; the existing gpu_wave64_vs_spill_slots_and_identity and gpu_wave64_ps_spill_slots pass too
  • gpu_pso_e2e with the pack: 7 passed (including retail_es_gs_voxelize_geometry_mode and the retail mesh / GS pipelines)
  • The 3 failures are the Tests: placed_title_textures_share_vram_and_preserve_pixels fails now and then at its cubemap reuse check (main 9ce2070) #718 flake you note in the description: placed_title_textures_share_vram_and_preserve_pixels (cubemap extra_pages must be reused at same va), then transitions_apply_when_their_list_is_submitted and d32s8_targets_take_their_own_size_of_video_memory on the PoisonError. The same three failed the same way on main 09940bb on this machine. cargo test -p xcl --lib -- --test-threads=4 title_textures::tests vram::tests at this head, three runs: 20 passed, 0 failed each time.

Not tested

  • scripts/smoke.ps1 / the retail title, and the compile-time or DXIL-size numbers (not measured here)
  • release build; native wave64 (AMD)

AI use

  • Claude Code, Claude Opus 5.5: ran the build and the tests and wrote this report. The numbers come from that run.

@DarkPanda69

DarkPanda69 commented Nov 24, 2026 •

Copy link
Copy Markdown

AMD run with native 64-lane waves, plus NVIDIA. Updated for head 709abd7 (first run was on 3297633, same result).

Tested: pass, head 709abd7 applied on main aaa0936, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17.
cargo test -p xcl --lib -- gpu:: --test-threads=4:

  • AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010, native wave64: 587 passed, 2 failed, 22 ignored. gpu_split_wave64_writelane_spill_shadows ok. The 2 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 and _3, which fail the same way on main without this PR on this card.
  • NVIDIA RTX 3060, driver 32.0.16.1088, split wave64: 589 passed, 0 failed, 22 ignored. gpu_split_wave64_writelane_spill_shadows ok.

Not tested: retail gameplay.

Note: these runs check that the translated HLSL matches the test's reference model, in 64-lane and in 32-lane waves. They cannot show that the model matches the hardware.

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

@SlopTart

Copy link
Copy Markdown

Linux / AMD RDNA3 datapoint.

Merged state: head 3297633 onto main 6efdabc, clean merge.

Full suite, cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 723 passed, 7 failed, 41 ignored; failures are the known Wine-lane set from my #42 rows. writelane spill-slot shadowing in split-wave64 green.

Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile, --test-threads=4. My Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

@pvfreis pvfreis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 3297633 (merge base 1ec4c98; it merges cleanly into current main), by reading the code; nothing was built or run here. I checked that analyze_spills drops a VGPR's shadowed slots on every write rdna2::vgpr_uses lists (VALU, VMEM/DS loads, returning atomics, MIMG data registers), on a dynamic-lane v_writelane and on v_movrel*/v_swaprel*, gives up on indirect jumps, and that both halves still write the real VGPR lane. No defect found.

Questions for the author

  • In the GPU test, the "vector write" case reads v11, which no v_writelane wrote. Could it also spill to a slot, overwrite that VGPR with a VALU op, and read the slot from the upper half? Then a stale shadow would be caught on the GPU, not only by the analysis unit tests.
  • How were the DXC/PSO times and the rla_u counts taken (command, number of runs, cold or warm cache), so someone else can repeat them?

Review by Claude Code (written by Claude Opus 5.5, second read by Claude Fable 5.2); each point checked by a person before posting.

@zondy1i

zondy1i commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the code review! Answering both questions:

  1. Overwriting a previously spilled VGPR in the GPU test: Good point — gpu_split_wave64_writelane_spill_shadows currently tests vector invalidation on v11 (not previously spilled), while VALU overwrite of a spilled VGPR is covered by the analysis unit tests in upper_lanes.rs. I left 3297633 untouched for now to avoid invalidating the existing independent hardware PASS runs on this head, but happy to add a spill-then-VALU-overwrite-then-read case directly to the GPU test if desired.
  2. Measurement methodology:
    • The xcl_x_rla_uniform counts come from a one-off local Rust scan over all 10,490 wave64 CS/MS shaders in a retail shader corpus, calling recomp::translate with split-wave64 options and counting xcl_x_rla_uniform( occurrences before vs. after this PR.
    • The DXC and D3D12 PSO times come from a one-off local Rust benchmark calling recomp::translate -> dxc::compile -> ID3D12Device::CreateComputePipelineState (with recomp::pso::abi_root_signature_with) on a cold DXIL/PSO cache on Windows 11 + RTX 3060 Ti (single cold build per shader for base vs. PR).

AI use: Antigravity (Gemini 4 Neon) helped draft this reply from the code and measurement logs.

@pvfreis

pvfreis commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Thanks. I'd add the spill, VALU overwrite, read case to the GPU test: it is the one way a stale shadow gives a wrong value without failing anything, and the analysis unit tests don't run the emitted HLSL. It changes only the test, so the existing runs stay meaningful for the code.

On the numbers: the scan and the benchmark could live in the tree as an #[ignore] test that reads the shader pack from an XCL_SAMPLE_* variable, as the other game-data tests do (CONTRIBUTING, "Tests on game data"), so others can repeat them on their own GPUs.

Reply by Claude Code (Claude Opus 5.5); checked by a person before posting.

In split-wave64 mode (two hardware wave32 halves per console wave64),
SGPR spill reloads (v_writelane_b32 -> v_readlane_b32 with a constant
lane) previously went through xcl_x_rla_uniform and emitted a full
cross-half exchange (spin-wait loop, barriers, and atomics) even though
both halves already hold identical SGPRs (x64_masks keeps
v_writelane_b32's scalar source whole-live).

Add a conservative forward must-analysis (upper_lanes::analyze_spills)
for split-wave64 Kernel/Compute/Mesh programs that tracks constant-lane
v_writelane_b32 slots across 0..64 without intervening VGPR writes,
dynamic-lane writes, v_movrel/v_swaprel, LOOP_GUARD exits, or indirect
jumps. Shadowed v_readlane_b32 reads take xcl_sh<v>_<l> directly with no
cross-half exchange while v_writelane_b32 still updates the VGPR lane.
Native wave64 HLSL is unchanged.

Measured on RTX 3060 Ti (DXC 1.9.2609.5) across spill-heavy retail
wave64 compute shaders:
- CS_Slod_BatchCull: rla_u 259->9, DXC 9231->4869 ms, DXIL -25.6%, PSO 9118->6334 ms
- CS_Gather_Reference: rla_u 311->17, DXC 14047->7720 ms, DXIL -23.7%, PSO 11848->9305 ms
- CS_TransmissionVolumetricsSubmerged: rla_u 506->323, DXC 30955->24472 ms, PSO 30468->27233 ms

Assisted-by: Antigravity (Gemini 4 Neon)
@zondy1i
zondy1i force-pushed the recomp/x64-writelane-shadows branch from 3297633 to 709abd7 Compare November 25, 2026 01:40
@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent RTX 3080 Ti check of #917 head 709abd7. Windows 11 build 26300, RTX 3080 Ti / driver 621.35, Ryzen 7 9800X3D, rustc 1.99.1, DXC 1.8.2502.11. The PR checkout was clean.

  • cargo test --offline --locked -p xcl --lib gpu_split_wave64_writelane_spill_shadows -- --test-threads=1 --nocapture, with XCL_D3D12_DEBUG=1: 1 passed, 0 failed, no skip. This is the stock GPU regression containing the spill, vector overwrite, and reload case.
  • cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 on the exact head, without the optional debug setting: 1,105 passed, 0 failed, 46 ignored across 20 test binaries; 23 explicit SKIPPED notices (19 no native wave64, 3 unsupported f16 forms, 1 no heap windows). The spill-shadow GPU test ran and passed.

I also made a clean, uncommitted merge of that same head into current main e1d84b7 in a disposable checkout. It merged without conflicts. The focused GPU test again passed 1/0 with no skip under XCL_D3D12_DEBUG=1. The full workspace suite on that merged tree passed 1,426/0/46 across 37 binaries, with 25 explicit SKIPPED notices (21 no native wave64, 3 unsupported f16 forms, 1 no heap windows). The merged-tree counts are integration evidence, not counts from the PR commit itself.

Not tested: retail smoke on this machine, cold DXC/PSO compile-time improvement, or native AMD wave64. AI use: Codex (GPT-6; exact variant unavailable) ran the tests and drafted this report; GPT-6.2 Astra Low reviewed the current diff.

@Prime1997 Prime1997 mentioned this pull request Nov 26, 2026
@JJAutoCompare

Copy link
Copy Markdown

Tested

Independent run at clean PR head 709abd7fe1a546668c8631b2e691e58d71e3e233 on Intel Arc A770 (driver 32.0.101.9175), Ryzen 7 3800X, Windows 11 x64 26200.9974, Rust/Cargo 1.100.0 MSVC, DXC/DXIL 1.9.2609.5, debug test profile.

Prebuilt with cargo test --locked -p xcl --lib --no-run --message-format=json outside the GPU mutex. Ran <test-exe> gpu::recomp::tests::gpu_split_wave64_writelane_spill_shadows --exact --nocapture --test-threads=1 under the Arc mutex with XCL_ADAPTER=A770.

1 passed, 0 failed, 0 ignored and 0 GPU skips (3.71 s). HLSL/DXC split-wave64 readback matched both spill slots (0x11223344 and 0x55667788), the post-overwrite cross-half read (152), and the untouched control lane (0xDEAD0006).

Not tested

Branch-join behavior, native wave64, the workspace suite and retail smoke.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the original verification and summarized the saved results.

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 709abd7

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 6089122
head: 709abd7
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1468 passed, 0 failed, 47 ignored (26 SKIPPED lines); base alone: 1465 passed, 0 failed, 47 ignored
review: none. The spill analysis is a must-analysis (intersection at joins): a slot is dropped on any write to its register, on a dynamic-lane writelane and on movrel / swaprel; loop exits are handled and indirect jumps give up. Lane operands are masked. The case asked for in the thread (spill, overwrite, read) is in the GPU test.
performance: it changes a translator source: every tester re-translates all shaders once. Only split-wave64 programs that use writelane change: fewer cross-half exchanges at run time (reasoned).
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@thehollowedone

thehollowedone commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 2c717a0 (main)
head: 709abd7
merge: clean, uncommitted trial merge
build: cargo build --workspace --locked -> ok
tests: cargo test --workspace --locked --no-fail-fast -- --test-threads=4 -> 1,468 passed, 1 failed, 47 ignored; 25 GPU SKIPPED notices. All three new spill tests passed, including gpu_split_wave64_writelane_spill_shadows on the RTX 3080 Ti without a skip. The only failure, console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk, is the same failure on clean main 2c717a04 with the same command and machine (1,465 passed, 1 failed, 47 ignored, 25 skips; paired baseline report).
review: No actionable finding in the four-file diff. The forward must-analysis intersects spill slots at joins, clears them on ordinary VGPR writes or dynamic-lane writes, and accounts for loop exits and indirect control flow. Only a proven constant-lane v_readlane_b32 uses the scalar shadow; the overwritten VGPR case still takes the cross-half exchange. The GPU test checks both halves and the overwritten case by readback.
performance: Proven spill reloads avoid a cross-half exchange in split wave64. The PR's three-shader timings suggest smaller DXIL and faster compile/PSO creation, but I did not repeat those measurements. The new analysis runs during translation; its CPU cost was not measured. Native wave64 lowering is unchanged.
verdict: safe to merge
hardware / tool and model: Windows 11 build 26300; RTX 3080 Ti 12 GB, NVIDIA 621.35; Ryzen 7 9800X3D; Rust 1.99.1 MSVC; DXC 1.8.2502.11. Codex (GPT-6.2 Sol) ran the merge, build and full GPU suite, reviewed the diff and wrote this report; Codex (GPT-6.2 Astra) independently traced the spill analysis and emitter. I did not run a retail smoke on this head.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 709abd7

No open or merged PR makes the same change: main's spill-slot shadows (4d64749, upper_lanes::analyze) cover wave64 VS / PS only, #3380 is wave32 graphics, and #944 batches exchanges instead of removing them. analyze_spills gives split-wave64 compute / mesh the shadows. The PR conflicts with main: emit.rs now declares xcl_hw32 and xcl_present for any upper and reads upper-lane shadows through xcl_present, so the self.x64() branches need to be redone against that code when rebasing.

Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

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

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.