recomp: support wave32 split execution for console mesh shaders #39

Manually merged
github merged 1 commit from gh-pr/39/head into gh-pr/39/base 2026-11-26 04:05:44 +00:00
Owner

@⁠wrxqed on GitHub · 2026-11-22 19:18 UTC · original
wrxqed:fix/mesh-wave32 → main · +34 −8 · 5 files · 1 commits · merged 2026-11-22 21:33 UTC

Summary

On adapters without native wave64 support (WaveLaneCountMax < 64, e.g. NVIDIA GPUs), console_mesh previously emitted [WaveSize(64)] unconditionally, causing CreateComputePipelineState to fail with E_INVALIDARG (0x80070057):

D3D12 debug layer (error, id 622): ID3D12Device::CreateComputeShader: Shader wants wave lane count of 64 but maximum wave lane count for device is 32.

This adds a mesh_wave32 option (mirroring geometry_wave32) and wires it from geometry_wave32_required(this) in translated_mesh_stream.

Changes

  • crates/xcl/src/gpu/recomp/mod.rs: add Options::mesh_wave32 (default false).
  • crates/xcl/src/gpu/recomp/emit.rs: in Mode::Mesh, when wave64 && mesh_wave32, emit [WaveSize(32)] and set xcl_half = (gi >> 5) & 1u, xcl_logical_wave64 = true, lane_id = WaveGetLaneIndex() + 32u * xcl_half while preserving [numthreads(t, 1, 1)].
  • crates/xcl/src/gpu/recomp/pso.rs & crates/xcl/src/hle/d3d12x/real.rs: pass geometry_wave32_required(this) into console_mesh.
  • crates/xcl/src/gpu/recomp/tests.rs: add unit test mesh_wave32_emits_wave32_logical_wave64.

Note: Like geometry_wave32, this uses xcl_logical_wave64 split-half emulation (cross-half lane ops remain half-local).

Verification (NVIDIA GeForce RTX 5050, 7911 MiB VRAM)

  • cargo test --release --lib mesh_wave32_emits_wave32_logical_wave64: 1 passed, 0 failed
  • cargo test --release --test gpu_pso_e2e -- --test-threads=1 (with XCL_SAMPLE_RPF / XCL_SAMPLE_DLLS): 6 passed, 0 failed (retail_mesh_pipelines_through_the_hook: 7 / 7 MS+PS pipelines; previously 0 / 7).
**@⁠wrxqed** on GitHub · 2026-11-22 19:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/39) `wrxqed:fix/mesh-wave32` → `main` · +34 −8 · 5 files · 1 commits · merged 2026-11-22 21:33 UTC ### Summary On adapters without native wave64 support (`WaveLaneCountMax < 64`, e.g. NVIDIA GPUs), `console_mesh` previously emitted `[WaveSize(64)]` unconditionally, causing `CreateComputePipelineState` to fail with `E_INVALIDARG` (`0x80070057`): > `D3D12 debug layer (error, id 622): ID3D12Device::CreateComputeShader: Shader wants wave lane count of 64 but maximum wave lane count for device is 32.` This adds a `mesh_wave32` option (mirroring `geometry_wave32`) and wires it from `geometry_wave32_required(this)` in `translated_mesh_stream`. ### Changes - `crates/xcl/src/gpu/recomp/mod.rs`: add `Options::mesh_wave32` (default `false`). - `crates/xcl/src/gpu/recomp/emit.rs`: in `Mode::Mesh`, when `wave64 && mesh_wave32`, emit `[WaveSize(32)]` and set `xcl_half = (gi >> 5) & 1u`, `xcl_logical_wave64 = true`, `lane_id = WaveGetLaneIndex() + 32u * xcl_half` while preserving `[numthreads(t, 1, 1)]`. - `crates/xcl/src/gpu/recomp/pso.rs` & `crates/xcl/src/hle/d3d12x/real.rs`: pass `geometry_wave32_required(this)` into `console_mesh`. - `crates/xcl/src/gpu/recomp/tests.rs`: add unit test `mesh_wave32_emits_wave32_logical_wave64`. *Note:* Like `geometry_wave32`, this uses `xcl_logical_wave64` split-half emulation (cross-half lane ops remain half-local). ### Verification (NVIDIA GeForce RTX 5050, 7911 MiB VRAM) - `cargo test --release --lib mesh_wave32_emits_wave32_logical_wave64`: **1 passed, 0 failed** - `cargo test --release --test gpu_pso_e2e -- --test-threads=1` (with `XCL_SAMPLE_RPF` / `XCL_SAMPLE_DLLS`): **6 passed, 0 failed** (`retail_mesh_pipelines_through_the_hook`: **7 / 7** MS+PS pipelines; previously **0 / 7**).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:05:42 +00:00
github manually merged commit 004b3db378 into gh-pr/39/base 2026-11-26 04:05:44 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-22 19:28 UTC · original

Thanks for this! The wiring is clean, it mirrors geometry_wave32 nicely and it changes nothing on adapters with wave64.

One blocker though: the split geometry path only runs on programs that pass geometry_wave32_hazards (translate_geometry rejects anything with cross-half semantics). The mesh path here has no such check, so every program gets split.

In split mode the two halves can't see each other: ballot() returns only the half's own bits, WaveReadLaneAt across halves returns 0, and each half takes its own branches on EXEC / VCC. I ran geometry_wave32_hazards over every NGG program in the retail shaders.rpf (the pack retail_mesh_pipelines_through_the_hook samples):

MS programs: 9282, wave64: 9282, with cross-half hazards: 9282
    9282  cross-half lane exchange
    9282  branch on a whole-wave mask
    3778  branch on a half-local scalar condition
      40  whole-wave mask reduction

So on a 32-lane adapter all of them would now create a pipeline but compute wrong results (culling / compaction, vertex and primitive counts), and where the halves branch differently around an s_barrier the group can hang the GPU. Today those draws are skipped cleanly because pipeline creation fails; with this change they would draw garbage or TDR. The 7 / 7 in gpu_pso_e2e only checks that the pipelines are created and the unit test checks the emitted text, so neither catches it.

What it needs:

  1. Run the same hazard check in console_mesh when mesh_wave32 is set and return an error for programs that have hazards, like translate_geometry does (the check isn't geometry-specific, so a shared name would be nice). On today's pack that turns 7 / 7 back into 0 / 7, but the failure stays clean.
  2. A test for that rejection (a small wave64 MS program with e.g. v_readlane_b32 or s_cbranch_execz must fail to translate with mesh_wave32, and one without them must still translate).

With (1) and (2) this would be safe to merge. Actually running these programs on NVIDIA needs real cross-half emulation (ballot / readlane / permlane / DPP and the mask branches across both halves) rather than a split; that's what the mesh dispatcher work (mesh_wave / mesh_dispatch) is aiming at, so it's worth coordinating with it.

**@⁠ivall** on GitHub · 2026-11-22 19:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/39#issuecomment-7084430997) Thanks for this! The wiring is clean, it mirrors `geometry_wave32` nicely and it changes nothing on adapters with wave64. One blocker though: the split geometry path only runs on programs that pass `geometry_wave32_hazards` (`translate_geometry` rejects anything with cross-half semantics). The mesh path here has no such check, so every program gets split. In split mode the two halves can't see each other: `ballot()` returns only the half's own bits, `WaveReadLaneAt` across halves returns 0, and each half takes its own branches on EXEC / VCC. I ran `geometry_wave32_hazards` over every NGG program in the retail `shaders.rpf` (the pack `retail_mesh_pipelines_through_the_hook` samples): ``` MS programs: 9282, wave64: 9282, with cross-half hazards: 9282 9282 cross-half lane exchange 9282 branch on a whole-wave mask 3778 branch on a half-local scalar condition 40 whole-wave mask reduction ``` So on a 32-lane adapter all of them would now create a pipeline but compute wrong results (culling / compaction, vertex and primitive counts), and where the halves branch differently around an `s_barrier` the group can hang the GPU. Today those draws are skipped cleanly because pipeline creation fails; with this change they would draw garbage or TDR. The 7 / 7 in `gpu_pso_e2e` only checks that the pipelines are created and the unit test checks the emitted text, so neither catches it. What it needs: 1. Run the same hazard check in `console_mesh` when `mesh_wave32` is set and return an error for programs that have hazards, like `translate_geometry` does (the check isn't geometry-specific, so a shared name would be nice). On today's pack that turns 7 / 7 back into 0 / 7, but the failure stays clean. 2. A test for that rejection (a small wave64 MS program with e.g. `v_readlane_b32` or `s_cbranch_execz` must fail to translate with `mesh_wave32`, and one without them must still translate). With (1) and (2) this would be safe to merge. Actually running these programs on NVIDIA needs real cross-half emulation (ballot / readlane / permlane / DPP and the mask branches across both halves) rather than a split; that's what the mesh dispatcher work (`mesh_wave` / `mesh_dispatch`) is aiming at, so it's worth coordinating with it.
Author
Owner

@⁠grahamster2 on GitHub · 2026-11-22 20:38 UTC · original

Tested on an RTX 3080 (D3D12 wave range 32..32, mesh tier 1, driver 610.88), merged onto current main plus #41 to pick the adapter, with XCL_SAMPLE_RPF set to a retail shaders.rpf:

main this PR
cargo test --workspace --release 352 passed, 2 failed 355 passed, 0 failed
retail_mesh_pipelines_through_the_hook 0 / 7 7 / 7
retail_pipelines_built_in_the_background_behind_a_stand_in failed (mesh half) passed
recompiler GPU tests skipped for "no wave64" 40 40

There was no device removal or TDR, but these tests only create the pipelines and never dispatch the 7 programs. On a Radeon RDNA2 iGPU (native wave64, no mesh shaders) nothing changes: 355 passed, and the mesh parts skip.

On @⁠ivall's point that a split computes wrong results: #44 shows it concretely for the geometry split, which uses the same prelude. A v_mbcnt over a v_cmp mask in lanes 32..63 got 0..23 instead of 24..47 on this GPU. That form is not in geometry_wave32_hazards yet; #44 adds it, so the mesh check below picks it up too.

I've pushed the two requested changes on top of this branch as a suggestion. @⁠wrxqed, feel free to take them, or ignore them if you're already on it: https://github.com/wrxqed/xcl/compare/fix/mesh-wave32...grahamster2:xcl:mesh-wave32-hazards (one commit, +34 / -8):

  • translate_mesh(code, ms, wave64, mesh_wave32) in recomp/mod.rs, mirroring translate_geometry, runs geometry_wave32_hazards when the program is wave64 and split, and returns mesh program requires unsupported cross-half wave64 semantics: {..}. console_mesh uses it.
  • mesh_wave32_rejects_cross_half_operations: wave64 programs with v_readfirstlane_b32 and with s_cbranch_execz are refused when split. They still translate natively, and a plain program still splits.

With it, the RTX 3080 is back to 0 / 7 and fails cleanly with the hazard error (cross-half lane exchange, branch on a whole-wave mask, branch on a half-local scalar condition), with no device removal. The background stand-in test then fails as it does on main.

**@⁠grahamster2** on GitHub · 2026-11-22 20:38 UTC · [original](https://github.com/xcl-dev/xcl/pull/39#issuecomment-7085427055) Tested on an RTX 3080 (D3D12 wave range 32..32, mesh tier 1, driver 610.88), merged onto current `main` plus #41 to pick the adapter, with `XCL_SAMPLE_RPF` set to a retail `shaders.rpf`: | | `main` | this PR | |---|---|---| | `cargo test --workspace --release` | 352 passed, 2 failed | 355 passed, 0 failed | | `retail_mesh_pipelines_through_the_hook` | 0 / 7 | 7 / 7 | | `retail_pipelines_built_in_the_background_behind_a_stand_in` | failed (mesh half) | passed | | recompiler GPU tests skipped for "no wave64" | 40 | 40 | There was no device removal or TDR, but these tests only create the pipelines and never dispatch the 7 programs. On a Radeon RDNA2 iGPU (native wave64, no mesh shaders) nothing changes: 355 passed, and the mesh parts skip. On @⁠ivall's point that a split computes wrong results: #44 shows it concretely for the geometry split, which uses the same prelude. A `v_mbcnt` over a `v_cmp` mask in lanes 32..63 got 0..23 instead of 24..47 on this GPU. That form is not in `geometry_wave32_hazards` yet; #44 adds it, so the mesh check below picks it up too. I've pushed the two requested changes on top of this branch as a suggestion. @⁠wrxqed, feel free to take them, or ignore them if you're already on it: https://github.com/wrxqed/xcl/compare/fix/mesh-wave32...grahamster2:xcl:mesh-wave32-hazards (one commit, +34 / -8): - `translate_mesh(code, ms, wave64, mesh_wave32)` in `recomp/mod.rs`, mirroring `translate_geometry`, runs `geometry_wave32_hazards` when the program is wave64 and split, and returns `mesh program requires unsupported cross-half wave64 semantics: {..}`. `console_mesh` uses it. - `mesh_wave32_rejects_cross_half_operations`: wave64 programs with `v_readfirstlane_b32` and with `s_cbranch_execz` are refused when split. They still translate natively, and a plain program still splits. With it, the RTX 3080 is back to 0 / 7 and fails cleanly with the hazard error (cross-half lane exchange, branch on a whole-wave mask, branch on a half-local scalar condition), with no device removal. The background stand-in test then fails as it does on `main`.
Author
Owner

@⁠ivall on GitHub · 2026-11-22 21:33 UTC · original

Merged, together with @⁠grahamster2's hazard check (798ff0d) on top, which is what I asked for above. Thanks to both of you!

On an adapter with wave64 nothing changes: all tests pass on an RX 9070, gpu_pso_e2e with a retail shaders.rpf included. On 32-lane adapters, wave64 mesh programs that need cross-half semantics are now refused cleanly with the hazard list, and programs without such semantics run split. Every program in today's retail pack needs those semantics, so those draws are still skipped. Really running them needs cross-half emulation, not a split.

**@⁠ivall** on GitHub · 2026-11-22 21:33 UTC · [original](https://github.com/xcl-dev/xcl/pull/39#issuecomment-7086138005) Merged, together with @⁠grahamster2's hazard check (798ff0d) on top, which is what I asked for above. Thanks to both of you! On an adapter with wave64 nothing changes: all tests pass on an RX 9070, `gpu_pso_e2e` with a retail `shaders.rpf` included. On 32-lane adapters, wave64 mesh programs that need cross-half semantics are now refused cleanly with the hazard list, and programs without such semantics run split. Every program in today's retail pack needs those semantics, so those draws are still skipped. Really running them needs cross-half emulation, not a split.
This discussion has been locked. Commenting is limited to contributors.
No description provided.