Recompiler: split-form geometry keeps the ES and GS phases apart in programs with branches #1689

Manually merged
github merged 1 commit from gh-pr/1689/head into gh-pr/1689/base 2026-11-26 05:01:41 +00:00
Owner

@⁠bmjask on GitHub · 2026-11-24 19:18 UTC · original
bmjask:recomp/split-geometry-fix → main · +68 −6 · 2 files · 1 commits · merged 2026-11-24 20:03 UTC

In the split wave64 form of geometry mode (GPUs with 32-lane waves only, e.g. NVIDIA), the ES and GS run as two phases of one body on the guarded block chain: pc starts at 0 for the ES and at gs_start for the GS. structured_span could pick a structured stretch that ran across the ES's s_setpc_b64, because term() does not treat it as a branch. So in any geometry program with a branch, the ES phase fell through into the GS code, and the GS phase had no if (pc == gs_start) entry. The GS phase then ran nothing and the records came out empty.

What is in it

  • crates/xcl/src/gpu/recomp/mod.rs: in the split form (phase_split), structured_span now stops at the ES's s_setpc_b64. The ES phase ends there (pc = select(xcl_es_phase, 0xFFFFFFFFu, gs_start)) and the GS phase enters at gs_start. The native wave64 form does not take this path, so its output is unchanged.
  • crates/xcl/src/gpu/recomp/tests.rs: the program from gpu_geometry_mode_es_gs_strip is now built by a helper and has a variant with branches: an ES forward branch, a GS EXEC-zero skip and a GS scalar loop. It keeps the cut and the partial last group (25 triangles = 21 + 4).
    • New gpu_geometry_mode_es_gs_strip_with_branches: on the GPU, checks every record vertex by vertex and the strip triangles.
    • New geometry_split_phases_with_branches_have_entry_and_exit: checks the HLSL shape (each phase's entry and exit) without a GPU, and that the native form still translates completely.

Tested

  • NVIDIA GeForce RTX 4090 (wave32 only, so the split form), Windows 11, rustc 1.100.0, debug test builds, release smoke builds.
  • Before the fix, both new tests fail. The GPU test fails with empty records (group 0: vertices / triangles are 0/0). After the fix both pass, and so does the existing strip test.
  • cargo test -p xcl --lib gpu::recomp: 196 passed, 0 failed, 18 ignored.
  • cargo test --workspace -- --test-threads=4: 807 passed, 4 failed, 22 ignored (SKIPPED GPU tests: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, no wave64).
    • The 4 failures were D3D12.X / DirectStorage tests (title_textures x2, vram::d32s8_targets..., dstorage::a_destination_page_filled_in_after_enqueue) while other cargo jobs were running on the machine.
    • All 4 pass when rerun alone. They don't touch the recompiler.

Regression run

main:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: NVIDIA GeForce RTX 4090
title: game
seconds: 60
exit: 0x0
frames shown: 1585 (PresentX 1585)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15720 MB

PR:

xcl-smoke v1
commit: 87d421b4a966cb01e3f1225ee6d871f03007c408
gpu: NVIDIA GeForce RTX 4090
title: game
seconds: 60
exit: 0x0
frames shown: 1589 (PresentX 1589)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15577 MB

Performance: frames 100.3 % of main, peak commit 99.1 % of main. I expected no change: only split-form geometry programs with branches compile differently.

Not tested

  • The native wave64 form on a GPU with 64-lane waves: only translation and compile checks here (no wave64 hardware).
  • Retail geometry shaders in the split form, beyond the smoke run.

AI use

  • Claude Code (Claude Opus 5.5): found the cause, wrote the fix and the tests, ran the tests and the regression runs, and wrote this description.

🤖 Generated with Claude Code

**@⁠bmjask** on GitHub · 2026-11-24 19:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/1689) `bmjask:recomp/split-geometry-fix` → `main` · +68 −6 · 2 files · 1 commits · merged 2026-11-24 20:03 UTC In the split wave64 form of geometry mode (GPUs with 32-lane waves only, e.g. NVIDIA), the ES and GS run as two phases of one body on the guarded block chain: `pc` starts at 0 for the ES and at `gs_start` for the GS. `structured_span` could pick a structured stretch that ran across the ES's `s_setpc_b64`, because `term()` does not treat it as a branch. So in any geometry program with a branch, the ES phase fell through into the GS code, and the GS phase had no `if (pc == gs_start)` entry. The GS phase then ran nothing and the records came out empty. **What is in it** - `crates/xcl/src/gpu/recomp/mod.rs`: in the split form (`phase_split`), `structured_span` now stops at the ES's `s_setpc_b64`. The ES phase ends there (`pc = select(xcl_es_phase, 0xFFFFFFFFu, gs_start)`) and the GS phase enters at `gs_start`. The native wave64 form does not take this path, so its output is unchanged. - `crates/xcl/src/gpu/recomp/tests.rs`: the program from `gpu_geometry_mode_es_gs_strip` is now built by a helper and has a variant with branches: an ES forward branch, a GS EXEC-zero skip and a GS scalar loop. It keeps the cut and the partial last group (25 triangles = 21 + 4). - New `gpu_geometry_mode_es_gs_strip_with_branches`: on the GPU, checks every record vertex by vertex and the strip triangles. - New `geometry_split_phases_with_branches_have_entry_and_exit`: checks the HLSL shape (each phase's entry and exit) without a GPU, and that the native form still translates completely. **Tested** - NVIDIA GeForce RTX 4090 (wave32 only, so the split form), Windows 11, rustc 1.100.0, debug test builds, release smoke builds. - Before the fix, both new tests fail. The GPU test fails with empty records (`group 0: vertices / triangles` are 0/0). After the fix both pass, and so does the existing strip test. - `cargo test -p xcl --lib gpu::recomp`: 196 passed, 0 failed, 18 ignored. - `cargo test --workspace -- --test-threads=4`: 807 passed, 4 failed, 22 ignored (SKIPPED GPU tests: `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`, no wave64). - The 4 failures were D3D12.X / DirectStorage tests (`title_textures` x2, `vram::d32s8_targets...`, `dstorage::a_destination_page_filled_in_after_enqueue`) while other cargo jobs were running on the machine. - All 4 pass when rerun alone. They don't touch the recompiler. **Regression run** main: ``` xcl-smoke v1 commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0 gpu: NVIDIA GeForce RTX 4090 title: game seconds: 60 exit: 0x0 frames shown: 1585 (PresentX 1585) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15720 MB ``` PR: ``` xcl-smoke v1 commit: 87d421b4a966cb01e3f1225ee6d871f03007c408 gpu: NVIDIA GeForce RTX 4090 title: game seconds: 60 exit: 0x0 frames shown: 1589 (PresentX 1589) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15577 MB ``` Performance: frames 100.3 % of main, peak commit 99.1 % of main. I expected no change: only split-form geometry programs with branches compile differently. **Not tested** - The native wave64 form on a GPU with 64-lane waves: only translation and compile checks here (no wave64 hardware). - Retail geometry shaders in the split form, beyond the smoke run. **AI use** - Claude Code (Claude Opus 5.5): found the cause, wrote the fix and the tests, ran the tests and the regression runs, and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
In the split wave64 form of geometry mode the ES and GS run as two phases of the
same body on the guarded block chain (pc starts at 0 for the ES, at gs_start for
the GS). A structured stretch found by structured_span could run across the ES's
s_setpc (it is not a branch to term()), so with any branch in the program the ES
phase fell through into the GS code and the GS phase found no `if (pc ==
gs_start)` entry: it ran nothing and the records came out empty. Only GPUs with
32-lane waves alone use the split form.

structured_span now stops at the s_setpc in the split form; the native wave64
form is unchanged. Tests: the ES/GS strip test with branches (ES forward branch,
GS EXEC-zero skip and a scalar loop, cut, 21 + 4 partial last group) on the GPU,
and an HLSL shape test for the phases' entry and exit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:01:40 +00:00
github manually merged commit 87d421b4a9 into gh-pr/1689/base 2026-11-26 05:01:41 +00:00
Author
Owner

@⁠Aniseto on GitHub · 2026-11-24 19:30 UTC · original

Ran the geometry tests at 87d421b:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

XCL_ADAPTER=nvidia cargo test -p xcl --lib geometry_
6 passed; 0 failed; 0 ignored      (exit 0)

This adapter has no native wave64, so console ES+GS programs run in the split form; the two new tests are exactly that path and pass here:

  • geometry_split_phases_with_branches_have_entry_and_exit
  • gpu_geometry_mode_es_gs_strip_with_branches

together with the existing geometry tests in the same filter (6 passed).

Not tested: native wave64, RDNA2/RDNA4 and Intel GPUs, Wine, release profile, retail titles.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; no local changes were made.

**@⁠Aniseto** on GitHub · 2026-11-24 19:30 UTC · [original](https://github.com/xcl-dev/xcl/pull/1689#issuecomment-7142201467) Ran the geometry tests at `87d421b`: Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build. ``` XCL_ADAPTER=nvidia cargo test -p xcl --lib geometry_ 6 passed; 0 failed; 0 ignored (exit 0) ``` This adapter has no native wave64, so console ES+GS programs run in the split form; the two new tests are exactly that path and pass here: - `geometry_split_phases_with_branches_have_entry_and_exit` - `gpu_geometry_mode_es_gs_strip_with_branches` together with the existing geometry tests in the same filter (6 passed). Not tested: native wave64, RDNA2/RDNA4 and Intel GPUs, Wine, release profile, retail titles. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash 1017** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; no local changes were made.
Author
Owner

@⁠MatyEjsr on GitHub · 2026-11-24 20:12 UTC · original

Verified PR #1689 at head commit 87d421b4a966cb01e3f1225ee6d871f03007c408 on an NVIDIA wave32-only GPU: the fix works as described and the full workspace test suite passes cleanly with zero failures.

Tested

  • OS: Windows 11 Pro for Workstations (Build 26200)
  • CPU: AMD Ryzen 7 7800X3D (8 cores / 8 threads)
  • GPU: NVIDIA GeForce RTX 3090 24 GB (driver 617.42, wave32 only)
  • RAM: 31.4 GB
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09), debug build, DXC dxcompiler 1.9.2602.17 / dxil 1.9.2602.17
  • cargo build --workspace -j 8: succeeded in 12.25s
  • cargo test -p xcl --lib geometry -j 8 -- --nocapture: 5 passed, 1 SKIPPED (gpu_geometry_wave32_prefix_count_over_a_mask: no wave64), 0 failed, 0 ignored (0.29s); both gpu_geometry_mode_es_gs_strip_with_branches and geometry_split_phases_with_branches_have_entry_and_exit ran and passed on the RTX 3090
  • cargo test -p xcl --lib gpu::recomp -j 8 -- --test-threads=8: 194 passed, 2 SKIPPED (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware: no wave64), 0 failed, 18 ignored (4.05s)
  • cargo test --workspace -j 8 -- --test-threads=8: 857 passed, 3 SKIPPED (gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware: no wave64; heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows), 0 failed, 42 ignored (860 reported passed by cargo; lib suite 14.26s)

Review notes (confirmed on 87d421b)
Two related edge cases in crates/xcl/src/gpu/recomp/mod.rs remain worth considering (either here or as a follow-up):

  1. term() only treats F_TERMINATOR as Term::Other, whereas S_SETPC_B64 has flags = 5 (F_BRANCH | F_INDIRECT, no F_TERMINATOR). As a result, unresolved S_SETPC_B64 still returns Term::Next (despite Term::Other's comment mentioning s_setpc). Because the new break in structured_span is gated on c.phase_split, a native wave64 (split_wave64: false) ES with an early s_setpc_b64 (for example two branches each ending in s_setpc_b64) still merges the first s_setpc_b64 into structured_span and lets that branch fall through into the second ES branch instead of jumping to gs_start. Returning Term::Other for unresolved S_SETPC_B64 in term() would handle both split and native forms without needing the phase_split flag.
  2. In structured_span, entered_inside only checks c.edges (from rdna2::branch_target), which does not include gs_start. If any block without S_SETPC_B64 sits between the ES's s_setpc_b64 and gs_start (confirmed with a synthetic ES ending in s_setpc_b64 followed by s_nop 0 or s_code_end padding before gs_start), structured_span starting at that intervening block still merges across gs_start and omits if (pc == <gs_start>u). Treating gs_start as an entry boundary in structured_span (stopping before gs_start when j > i, or recording it as an entry target) closes this case as well.

Not tested

  • Native wave64 GPU execution (no wave64 hardware), retail title smoke run, release build.

AI use

  • agy with gemini-4-neon-high: checked out the PR head, built and ran the test suite, verified the two edge cases against 87d421b, and drafted this report.
**@⁠MatyEjsr** on GitHub · 2026-11-24 20:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/1689#issuecomment-7143191589) Verified PR #1689 at head commit `87d421b4a966cb01e3f1225ee6d871f03007c408` on an NVIDIA wave32-only GPU: the fix works as described and the full workspace test suite passes cleanly with zero failures. **Tested** - OS: Windows 11 Pro for Workstations (Build 26200) - CPU: AMD Ryzen 7 7800X3D (8 cores / 8 threads) - GPU: NVIDIA GeForce RTX 3090 24 GB (driver 617.42, wave32 only) - RAM: 31.4 GB - Toolchain: `rustc 1.100.0 (0ef1bc386 2026-11-09)`, debug build, DXC `dxcompiler 1.9.2602.17` / `dxil 1.9.2602.17` - `cargo build --workspace -j 8`: succeeded in 12.25s - `cargo test -p xcl --lib geometry -j 8 -- --nocapture`: 5 passed, 1 SKIPPED (`gpu_geometry_wave32_prefix_count_over_a_mask: no wave64`), 0 failed, 0 ignored (0.29s); both `gpu_geometry_mode_es_gs_strip_with_branches` and `geometry_split_phases_with_branches_have_entry_and_exit` ran and passed on the RTX 3090 - `cargo test -p xcl --lib gpu::recomp -j 8 -- --test-threads=8`: 194 passed, 2 SKIPPED (`gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`: no wave64), 0 failed, 18 ignored (4.05s) - `cargo test --workspace -j 8 -- --test-threads=8`: 857 passed, 3 SKIPPED (`gpu_geometry_wave32_prefix_count_over_a_mask` and `gpu_wave32_program_in_wave64_hardware`: no wave64; `heap_window_out_of_memory_falls_back_to_the_switch_form`: no heap windows), 0 failed, 42 ignored (860 reported passed by cargo; lib suite 14.26s) **Review notes (confirmed on `87d421b`)** Two related edge cases in `crates/xcl/src/gpu/recomp/mod.rs` remain worth considering (either here or as a follow-up): 1. `term()` only treats `F_TERMINATOR` as `Term::Other`, whereas `S_SETPC_B64` has `flags = 5` (`F_BRANCH | F_INDIRECT`, no `F_TERMINATOR`). As a result, unresolved `S_SETPC_B64` still returns `Term::Next` (despite `Term::Other`'s comment mentioning `s_setpc`). Because the new break in `structured_span` is gated on `c.phase_split`, a native wave64 (`split_wave64: false`) ES with an early `s_setpc_b64` (for example two branches each ending in `s_setpc_b64`) still merges the first `s_setpc_b64` into `structured_span` and lets that branch fall through into the second ES branch instead of jumping to `gs_start`. Returning `Term::Other` for unresolved `S_SETPC_B64` in `term()` would handle both split and native forms without needing the `phase_split` flag. 2. In `structured_span`, `entered_inside` only checks `c.edges` (from `rdna2::branch_target`), which does not include `gs_start`. If any block without `S_SETPC_B64` sits between the ES's `s_setpc_b64` and `gs_start` (confirmed with a synthetic ES ending in `s_setpc_b64` followed by `s_nop 0` or `s_code_end` padding before `gs_start`), `structured_span` starting at that intervening block still merges across `gs_start` and omits `if (pc == <gs_start>u)`. Treating `gs_start` as an entry boundary in `structured_span` (stopping before `gs_start` when `j > i`, or recording it as an entry target) closes this case as well. **Not tested** - Native wave64 GPU execution (no wave64 hardware), retail title smoke run, release build. **AI use** - agy with gemini-4-neon-high: checked out the PR head, built and ran the test suite, verified the two edge cases against `87d421b`, and drafted this report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 21:47 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 21:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/1689#issuecomment-7145395475) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠bmjask on GitHub · 2026-11-24 22:28 UTC · original

@⁠MatyEjsr thanks for the verification on the RTX 3090 and for the two edge cases. Both were real. In native wave64, an early s_setpc_b64 on one ES branch fell through into the other branch, and padding before gs_start could lose its entry. Both are fixed in #1873 (draft, smoke pair pending), with a regression test for each that fails on main. I made the change in structured_span rather than in term(), so non-geometry programs keep their current lowering. If you can, please re-check your synthetic cases against #1873.

AI use: Claude Code (Claude Opus 5.5) wrote this comment for @⁠bmjask.

**@⁠bmjask** on GitHub · 2026-11-24 22:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/1689#issuecomment-7146278458) @⁠MatyEjsr thanks for the verification on the RTX 3090 and for the two edge cases. Both were real. In native wave64, an early `s_setpc_b64` on one ES branch fell through into the other branch, and padding before `gs_start` could lose its entry. Both are fixed in #1873 (draft, smoke pair pending), with a regression test for each that fails on `main`. I made the change in `structured_span` rather than in `term()`, so non-geometry programs keep their current lowering. If you can, please re-check your synthetic cases against #1873. AI use: Claude Code (Claude Opus 5.5) wrote this comment for @⁠bmjask.
This discussion has been locked. Commenting is limited to contributors.
No description provided.