Skip to content

Recompiler: read a second atomic operand only where it is used - #1911

Open
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:atomic-operand-use
Open

Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:atomic-operand-use

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1269. The 32-bit buffer, flat and LDS atomic lowering read a second VGPR before selecting the operation. For add, min, max and exchange that register is not one of the instruction's operands, so the per-lane bridge correctly refused the extra read and the whole program fell back to the HLSL form.

What is in it

  • crates/xcl/src/gpu/dxil/lower_mem.rs: the second register is resolved only for compare-exchange and masked OR, the two operations that use it.
  • crates/xcl/src/gpu/recomp/lower_dxil.rs: a GPU test that checks the return values and memory of the per-lane atomics against HLSL.

Tested

  • Ryzen 9 9950X, RTX 5070 Ti (NVIDIA 610.74), Windows 11 build 26200, Rust 1.99.0 (MSVC x64), release, DXC 1.9.2609.5.
  • On the rebased head 39601b4 (base main cbc296a, after Recompiler: take native compute mask branches across the whole wave #1910): cargo test --release -p xcl --lib, unfiltered with GPU tests included, 1,099 passed, 0 failed, 26 ignored, with 23 skip notices (20 for no native wave64, 3 for unsupported wave32 FP). The atomics GPU test and Recompiler: take native compute mask branches across the whole wave #1910's native-wave branch test both ran on the card.
  • Before the rebase, on 8ca5f81: cargo test --offline --release --workspace -- --test-threads=4 gave 960 passed, 0 failed, 43 ignored. A native compute survey with four switch-selected memory windows put 329 of 2,689 programs in the per-lane form, up from 316 on main c4d37be.

Regression run

scripts/smoke.ps1, the same retail title for 60 s each, one after the other on the machine under Tested, release builds from clean trees.

main cbc296a (this PR's base):

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1113 (PresentX 1113)
presents per 2 s (last 3): 0 2 0
device removals: 0
crashes: 0
peak commit: 24774 MB

this PR, 39601b4:

xcl-smoke v1
commit: 39601b4825354e6e262dc20aa51bcd1bb2eb00ae
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1287 (PresentX 1288)
presents per 2 s (last 3): 39 38 40
device removals: 0
crashes: 0
peak commit: 26844 MB

PR vs main: 1287 / 1113 frames (116 %), peak commit 26844 / 24774 MB (108 %); device removals 0 and crashes 0 on the PR run, 0 and 0 on main.

Both runs are on the rebased head and its new base. main's run was still loading over its last 6 s (0, 2 and 0 presents), so the difference in frames is load timing, not this change.

Not tested

  • AMD, native wave64 on hardware, Linux.
  • 64-bit atomics and image atomics, which this change doesn't touch.

AI use

OpenAI Codex (GPT-6.2) wrote the change and the test and ran the suite and the pack count. Claude Code (Claude Opus 5.5) wrote this description and opened the PR.

🤖 Generated with Claude Code

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

@Melow-code Melow-code left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Real bug — VGPR data+1 was read outside the declared operands for add/min/max/swap. The fix is minimal and correct: register index instead of value, resolved only in the cmpxchg and mskor branches. 13 programs unblocked (329→316 refused) is a credible sweep.

@thehollowedone

Copy link
Copy Markdown

Independent split-wave64 check of 14dec7f on an RTX 3080 Ti (621.35), Windows 11 build 26300, Rust 1.99.1 MSVC debug, DXC 1.8.2502.11.

I extended the bundled buffer, global, and LDS atomic fixture to run a 64-lane program on two hardware waves. The shader enabled 21 lanes across both halves. Per-lane DXIL matched the HLSL and CPU expectations for all 128 memory words and 448 destination values. The 43 inactive lanes retained their initial memory and register values, and both EXEC words restored correctly. With only main’s memory lowering restored, per-lane translation refused BUFFER_ATOMIC_ADD because it read a second register that the instruction did not supply.

cargo test --offline --locked -p xcl --lib per_lane_atomics -- --nocapture --test-threads=1: 2 passed (stock wave32 and the split-wave64 extension), zero skips. Synthetic inputs only.

AI-assisted. Codex (GPT-6 family, exact variant unavailable) extended and ran the test and drafted this report.

@raylitebull

Copy link
Copy Markdown
Member

Build and test and PR description are green on b6e884f and the code review is approved.

Remaining before merge: one independent AMD GPU pass on the current head b6e884f (and if possible an NVIDIA sanity check on b6e884f, since prior NVIDIA runs were pre-rebase).

@Kalmarv

Kalmarv commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, @raylitebull. An AMD pass on the current head b6e884f is the one missing piece. We have no AMD card here, so this needs someone who does. @srcamarda and @DarkPanda69, you've run AMD passes on related heads before. If either of you has time:

git fetch https://github.com/xcl-dev/xcl.git pull/1911/head && git checkout FETCH_HEAD
cargo test --release -p xcl --lib -- --test-threads=4

Please post the passed, failed and ignored counts, any SKIPPED lines, and your GPU, driver and DXC version.

We will post the NVIDIA run on b6e884f here as soon as our GPU is free.

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

@Kalmarv

Kalmarv commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

NVIDIA run on the exact head b6e884f (b6e884f88993a6febb6c8fbdd05f00e0374ea6db), from a clean worktree.

  • RTX 5070 Ti, NVIDIA 610.74, Ryzen 9 9950X, Windows 11 26200, DXC and DXIL 1.9.2609.5, rustc 1.99.0, release.
  • cargo test --release -p xcl --lib -- --test-threads=4: 938 passed, 0 failed, 25 ignored. 11 tests printed 21 SKIPPED messages. 18 are native-wave64 subcases, which this card doesn't have, and 3 are per-lane FP subcases unsupported on wave32.
  • The 6 GPU tests this PR touches, rerun on their own: 6 passed, 0 failed, 0 skipped. These include per_lane_atomics_take_their_declared_operands and the shared, buffer and global atomic cases.
  • No XCL_SAMPLE_* variables were set. Both commands exited 0.

The AMD pass is still open; the request is above.

AI use: OpenAI Codex (GPT-6) ran the tests and summarized the logs; Claude Code (Claude Opus 5.5) wrote this comment.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

The 32-bit buffer, flat and LDS lowering read a second VGPR before selecting the atomic operation. For add, min, max and exchange this register is outside the instruction's declared operands. The per-lane bridge correctly rejected that extra read.

Resolve the extra register only for compare-exchange and masked OR. The GPU test checks return values and memory against HLSL. A four-window sweep accepts 329 of 2689 compute programs, up from 316.
@Kalmarv

Kalmarv commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@DavidM1911 Rebased onto main cbc296ab (after #1910) as 39601b4. Thanks for the note.

The one conflict was in the atomic lowering. main's IEEE fcas32 and this PR's integer compare-exchange now each fetch the second operand only in their own arm.

Tested on the rebased head:

  • RTX 5070 Ti, NVIDIA 610.74, Windows 11 build 26200, release, DXC 1.9.2609.5.
  • cargo test --release -p xcl --lib, unfiltered (GPU tests included): 1,099 passed, 0 failed, 26 ignored.
  • 23 SKIPPED messages across 13 tests: 20 for no native wave64, 3 for unsupported wave32 FP.
  • This PR's atomic regression test and Recompiler: take native compute mask branches across the whole wave #1910's native-wave branch test both pass on the card.

Not tested: AMD.

AI use: a Codex (GPT-6.2) helper did the rebase and ran the suite; Claude Code (Claude Opus 5.5) pushed it and wrote this.

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
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.

6 participants