Skip to content

D3D12.X: execute two-pass mesh shaders on DispatchMesh and ExecuteIndirect - #724

Open
Cattn wants to merge 1 commit into
xcl-dev:mainfrom
Cattn:two-pass-dispatch-mesh
Open

Cattn wants to merge 1 commit into
xcl-dev:mainfrom
Cattn:two-pass-dispatch-mesh

Conversation

@Cattn

@Cattn Cattn commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Console mesh shaders translated to a two-pass pair (compute + mesh/PS, TwoPassPso) were already built during CreatePipelineState, but there was no execution path for them: DispatchMesh was not hooked on the console command list vtable, and ExecuteIndirect did not run the compute pass or bind the record buffer (u1) before the mesh pass.

What is in it

  • crates/xcl/src/hle/d3d12x/console_list.rs: track the console mesh root-argument layout (inline_ms across 16 SGPRs from s16 with the spill table pointer in s[8:9]) via user_data_ms, and recycle per-allocator two-pass record buffers on allocator_reset.
  • crates/xcl/src/hle/d3d12x/device_x.rs: in create_command_signature_x, create a companion DISPATCH command signature alongside non-root-changing DISPATCH_MESH command signatures and register (sig, companion, byte_stride, mesh_offset).
  • crates/xcl/src/hle/d3d12x/real.rs: hook DispatchMesh at console command list slot 127 (newer layout slot 129) and add list_device helper.
  • crates/xcl/src/hle/d3d12x/bind.rs: implement dispatch_mesh and TwoPassPso handling in execute_indirect: allocate/recycle a DEFAULT-heap UAV record buffer per command list, bind u0 (io), u1 (res), u2..u5 (UMA), run Pass 1 compute -> UAV barrier -> Pass 2 mesh+PS -> UAV barrier, and scale indirect DispatchMesh group counts on the GPU when mesh_groups_per_record > 1.
  • Unit tests: console_list::tests::mesh_arguments_go_in_user_sgprs_from_s16 and bind::tests::dispatch_mesh_signature_tracking_returns_companion_and_layout.

Tested

  • NVIDIA GeForce RTX 4070 12 GB, Windows 11, rustc 1.93.1 (01f6ddf75 2026-02-11), debug for workspace tests, release for regression runs.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 on 2624f00: 703 passed, 0 failed, 41 ignored.
    • SKIPPED (no wave64): gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware.
  • Also verified in a local combined stack on title 7f4b2c91 past loading: 128+ two-pass ExecuteIndirect(DispatchMesh) calls executed cleanly and rendered 3D world geometry (streetlights, gantries, foliage) without device removal.

Regression run

main:

xcl-smoke v1
commit: f4ce27ceb6d1b0576d0c659b713b674778bf1968
gpu: NVIDIA GeForce RTX 4070
title: 7f4b2c91
seconds: 60
exit: 0x0
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 53 60 60
device removals: 0
crashes: 0
peak commit: 15932 MB

PR:

xcl-smoke v1
commit: 2624f00c4e2d8b87aa1828233fb2f60899eb9533
gpu: NVIDIA GeForce RTX 4070
title: 7f4b2c91
seconds: 60
exit: 0x0
frames shown: 1634 (PresentX 1634)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14704 MB

Not tested

  • AMD or Intel GPUs, wave64 hardware, Linux/Wine.
  • Direct DispatchMesh or indirect ExecuteIndirect(DispatchMesh) with mesh_groups_per_record > 1 on a standalone GPU unit test (observed calls on title 7f4b2c91 had split 1).
  • Titles that use root-changing DISPATCH_MESH command signatures (skipped as before).

AI use

  • Antigravity with Gemini 4 Neon implemented the two-pass execution path, unit tests, and this PR description, and ran the workspace tests and regression runs on the hardware above.

…irect

Console mesh shaders translated to a two-pass pair (compute + mesh/PS,
TwoPassPso) were built by CreatePipelineState but had no execution path:
DispatchMesh was not hooked on the console command list vtable, and
ExecuteIndirect did not dispatch the compute pass or bind the record
buffer (u1) before invoking the mesh pass.

Hook DispatchMesh (slot 127, newer layout slot 129) and handle TwoPassPso
in ExecuteIndirect:
- Track console mesh root-argument layout (s[8:9] spill table, inline
  arguments from s16 across 16 SGPRs) in console_list::user_data_ms.
- Create a companion DISPATCH command signature alongside non-root-changing
  DISPATCH_MESH command signatures in device_x::create_command_signature_x.
- Allocate/recycle a DEFAULT-heap UAV record buffer per command list
  (recycled on allocator reset), bind u0 (io), u1 (res), u2..u5 (UMA),
  run the compute pass -> UAV barrier -> mesh pass -> UAV barrier, and
  scale indirect DispatchMesh group counts on the GPU when
  mesh_groups_per_record > 1.

Assisted-by: Antigravity (Gemini 4 Neon)
@lordon1a

Copy link
Copy Markdown

Independent test report on 2624f00:

Tested

  • Hardware: NVIDIA GeForce RTX 3070 Ti Laptop GPU (driver 616.64, wave32, SM 6.6), Intel i7-12700H, Windows 11 Home 26H2 (build 26200), rustc 1.100.0 (x86_64-pc-windows-gnullvm), debug build, DXC 1.9.2609.5 (01b62ad4)
  • Command: cargo test -p xcl --lib hle::d3d12x -- --test-threads=1
  • Result: 107 passed, 0 failed, 1 ignored in 10.65s (including dispatch_mesh_signature_tracking_returns_companion_and_layout and mesh_arguments_go_in_user_sgprs_from_s16)

Not tested

  • AMD / wave64, Intel GPU, retail title (xcl-smoke)

AI use

  • Antigravity (Google DeepMind agent) — fetched 2624f00 in a detached worktree, audited the diff, ran the test suite, and posted this report.

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

Integrates upstream PR ivall#724 on top of subobject-24 console MS
translation:
- Hook console DispatchMesh (slot 127 / newer 129) and pair
  DISPATCH_MESH command signatures with companion DISPATCH signatures.
- Run the compute pass into a recycled per-allocator record buffer,
  barrier, scale indirect arguments when split > 1, and run the mesh
  pass.
@thehollowedone

Copy link
Copy Markdown

Independent GPU readback for the split >1 indirect-argument scaler at 2624f00. Windows 11 build 26300, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, DXC 1.8.2502.11, debug build.

A temporary synthetic fixture called the PR’s make_scaled_args_buffer on 65 records with a 32-byte stride and a 64-byte source offset. With a split factor of 4, only mesh X changed. All 520 output words matched, and all 536 source words were unchanged. Both fresh runs passed (1 passed, 0 failed, 0 ignored, 0 skipped each) with zero D3D12 InfoQueue errors or corruption messages, first with the standard debug layer and again with GPU-based validation enabled.

cargo test --offline --locked -p xcl --lib gpu_scales_padded_mesh_arguments_at_nonzero_offset -- --nocapture --test-threads=1

This covers the argument scaler. End-to-end ExecuteIndirect, rendered output, and retail gameplay were outside this test. AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the fixture and drafted this report.

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

Integrates upstream PR ivall#724 on top of subobject-24 console MS
translation:
- Hook console DispatchMesh (slot 127 / newer 129) and pair
  DISPATCH_MESH command signatures with companion DISPATCH signatures.
- Run the compute pass into a recycled per-allocator record buffer,
  barrier, scale indirect arguments when split > 1, and run the mesh
  pass.
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 2624f00c4e2d8b87aa1828233fb2f60899eb9533 on AMD RDNA4. I merged it onto current main 64b3f35 locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, mesh shaders), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 703 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 662 passed, 0 failed, 21 ignored
  • 0 SKIPPED; gpu_mesh_mode_two_passes, dispatch_mesh_signature_tracking_returns_companion_and_layout and retail_mesh_pipelines_through_the_hook pass; this adapter has mesh shaders, so the two-pass mesh tests ran for real rather than skipping.

Review: The PR adds the missing execution path: DispatchMesh on the console list and ExecuteIndirect now run the compute pass and bind the record buffer before the mesh pass, with per-allocator record buffers recycled on reset. At 471 lines I reviewed the structure, not every line; nothing stood out.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

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

Integrates upstream PR xcl-dev#724 on top of subobject-24 console MS
translation:
- Hook console DispatchMesh (slot 127 / newer 129) and pair
  DISPATCH_MESH command signatures with companion DISPATCH signatures.
- Run the compute pass into a recycled per-allocator record buffer,
  barrier, scale indirect arguments when split > 1, and run the mesh
  pass.
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…irect

Integrates upstream PR ivall#724 on top of subobject-24 console MS
translation:
- Hook console DispatchMesh (slot 127 / newer 129) and pair
  DISPATCH_MESH command signatures with companion DISPATCH signatures.
- Run the compute pass into a recycled per-allocator record buffer,
  barrier, scale indirect arguments when split > 1, and run the mesh
  pass.
@badoomtch

Copy link
Copy Markdown

A retail data point for the ExecuteIndirect argument path on Windows, RTX 5080. These were local builds based on af20b4b38e5a, with code from #630, #304 and parts of this PR, a bounded two-pass implementation and extra resource-state checks. We ran with XCL_INDIRECT_MESH=1 and the slot-24 remap enabled.

The title created one pure mesh-dispatch signature and no mixed or root-changing signatures. In one run, our check withheld 1,450 calls before recording. The argument resource was a coherent console buffer in 1,074 cases and a sparse buffer in 376. In both groups the recording had no known native read state. This is a count from our guard, not a failure count for this PR.

In a separate run, reading from a verified alias of the same coherent backing allowed eight calls to be recorded. At the end, all eight scratch owners were still pending and no readback had retired. We therefore have no measured GPU acceptance, capacity drops or visible geometry from those eight. Reporting calls recorded, readbacks retired and GPU-side rejected records separately would make that distinction visible when testing this path on a title.

AI use: Codex (GPT-6) reviewed the local runtime reports and drafted this comment.

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

Integrates upstream PR ivall#724 on top of subobject-24 console MS
translation:
- Hook console DispatchMesh (slot 127 / newer 129) and pair
  DISPATCH_MESH command signatures with companion DISPATCH signatures.
- Run the compute pass into a recycled per-allocator record buffer,
  barrier, scale indirect arguments when split > 1, and run the mesh
  pass.
@NathanTheophile

Copy link
Copy Markdown

Review of 2624f00, from reading bind.rs and checking two points on the GPU. I'm interested because #529 (drawing the records with a VS on GPUs without mesh shaders) would build on this execution path.

1. The record buffer is not sized to the dispatch, and root UAVs have no bounds check. ensure_res_buffer caps the buffer at 128 MiB (bind.rs:321, .min(128 << 20)), and ExecuteIndirect always asks for 32 MiB (bind.rs:547). The compute pass writes record gid.x with no bound (emit.rs:4301). With the retail transform record of #304 (21 params + clip distance: 11,908 dwords, 47,632 B), 32 MiB holds 704 groups and 128 MiB holds 2,817. To check where the excess goes, I ran the NGG fixture of gpu_mesh_mode_two_passes with its record buffer as a 64 KiB placed resource and a zeroed buffer placed right after it in the same heap. 14 groups fit and left the next buffer untouched. With 20 groups, 101 dwords of the next buffer were overwritten, and the headers of records 15–19 (nv = 3, np = 1) sit exactly where they would fall past the end. In the runtime, that is whatever the driver placed after the record buffer.

2. Indirect arguments with Y or Z > 1 lose groups. The direct path flattens x·y·z (bind.rs:487-499), but the companion DISPATCH at bind.rs:549 runs the title's (x, y, z) as given. The translated program, and the pass-through, index records by gid.x only (emit.rs:4301, :4310 for v5, :4670). Same fixture, compute pass only: with (2,1,1) the two records are group 0 (x0 = -1) and group 1 (x0 = 0). With (1,2,1), record 0 is group 0 and record 1 stays empty (nv = np = 0): the second group wrote record 0 again, as group 0. The mesh pass then draws record 0 y·z times.

3. Not run, from reading only: the 65,535 groups-per-dimension limit. Dispatch(groups, 1, 1) and DispatchMesh(groups · split, 1, 1) put the whole count in X (bind.rs:496, :499), and the indirect scaler multiplies X by the split. A DispatchMesh(256, 256, 1) that is valid on its own becomes Dispatch(65536, 1, 1). With #304's split of 7, any dispatch over 9,362 groups goes past the limit.

I did not check 1 and 2 through the console-list hooks themselves, only with a direct D3D12 harness around this branch's translated compute pass. The probe is a temporary runner function and a test, and I can post it if useful. One possible direction: pass the record capacity (and the dispatch width, for a linear record index) to the compute pass in io, skip groups past the capacity, and count the drops in the log.

Tested: RTX 4060 Laptop GPU (driver 32.0.16.1687), i7-13650HX, Windows 11 25H2 (26200), Rust 1.100.0 MSVC, DXC 1.8.2502.11, debug. 2624f00 plus the temporary probe: cargo test -p xcl --lib -- --exact gpu::recomp::tests::review_probe_724_records --nocapture, 1 passed. The probe was not committed.

AI use: Claude Code (Claude Opus 5.5) read the diff, wrote and ran the probe, and drafted this review. Each point was checked by the user before posting.

@iggyvilla

Copy link
Copy Markdown
Contributor

A test report on 2624f00c4e2d8b87aa1828233fb2f60899eb9533 and a review of the diff, from an AMD RDNA2 (Navi 23) card. The head is still 2624f00. Its merge base with origin/main is f4ce27ceb6d1b0576d0c659b713b674778bf1968 — which is also the "main" commit of the PR's own smoke block — so I ran that base itself for the second half of the regression instead of the dd2ae9a block on file.

Tested

  • AMD Radeon RX 6650 XT (RDNA2, gfx1032), driver 32.0.21045.29003; AMD Ryzen 7 5700X (8C/16T), 31.9 GB RAM, Windows 11 Home 26H2 build 26300.9974; rustc 1.100.0 (0ef1bc386 2026-11-09), cargo 1.100.0; no XCL_SAMPLE_* set.

  • Detached, clean worktrees for head 2624f00 and base f4ce27c; debug for the tests, release -p xcl for the smokes.

  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 2624f00 (debug): 700 passed, 3 failed, 41 ignored, exit 101. This is the same test set as the NVIDIA and RDNA4 reports, which list 703 passed and 41 ignored: here the same 703 tests are 700 passed + 3 failed, with the same 41 ignored. This card's 3 known failures are:

    No other test fails; the PR adds no failure.

  • No SKIPPED lines at this head on this card. The two tests the NVIDIA report lists as skipped (gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware, gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask) run and pass here, as do gpu_mesh_mode_two_passes (including its split=4 pass-through pixel comparison), gpu_mesh_mode_reads_memory_windows, mesh_split_wave64_form, retail_mesh_pipelines_through_the_hook, and the PR's dispatch_mesh_signature_tracking_returns_companion_and_layout and mesh_arguments_go_in_user_sgprs_from_s16.

  • Targeted, --test-threads=1: -p xcl --lib hle::d3d12x 104 passed, 3 failed (the same three), 1 ignored; -p xcl --lib gpu_mesh 2 passed; -p xcl --lib wave32 5 passed.

  • Smoke with XCL_NETWORK=0, scripts/smoke.ps1 -Game C:\games\retail -Seconds 60, head and merge base built release in their own worktrees, two pairs in the order below. All four runs: exit 0x0, 0 device removals, 0 crashes.

pair run frames shown presents per 2 s (last 3) peak commit
1 head 2624f00 (first) 277 0 1 0 11960 MB
1 base f4ce27c (second) 306 1 1 0 11643 MB
2 base f4ce27c (third) 312 0 2 5 11088 MB
2 head 2624f00 (fourth) 308 0 1 3 11414 MB

The 29-frame head/base gap of pair 1 does not reproduce when the order is reversed (4 frames, 1.3 %), so it follows run order/warm-up rather than the commit. All four runs are in the slow state this machine shows (270–320 frames), well below the 700+ of earlier sessions, so only the paired comparison is meaningful; there is no measurable regression and no crash, removal or exit difference.

  • In both 60 s head runs there are 0 "pipeline from the console MS in two passes" lines and 0 "two-pass DispatchMesh" / "two-pass ExecuteIndirect(DispatchMesh)" lines; head and base log the same 40 "mesh pipeline with its MS … in the AS slot – refused" lines (the separate AS-slot limitation). Within 60 s the title reaches the same loading/menu state on both, so this smoke measures no regression at that point — the PR's execution path is not reached in that window.

Head block (pair 1):

xcl-smoke v1
commit: 2624f00c4e2d8b87aa1828233fb2f60899eb9533
gpu: AMD Radeon RX 6650 XT
title: retail
seconds: 60
exit: 0x0
frames shown: 277 (PresentX 279)
presents per 2 s (last 3): 0 1 0
device removals: 0
crashes: 0
peak commit: 11960 MB

Base block (pair 1):

xcl-smoke v1
commit: f4ce27ceb6d1b0576d0c659b713b674778bf1968
gpu: AMD Radeon RX 6650 XT
title: retail
seconds: 60
exit: 0x0
frames shown: 306 (PresentX 311)
presents per 2 s (last 3): 1 1 0
device removals: 0
crashes: 0
peak commit: 11643 MB

Base block (pair 2):

xcl-smoke v1
commit: f4ce27ceb6d1b0576d0c659b713b674778bf1968
gpu: AMD Radeon RX 6650 XT
title: retail
seconds: 60
exit: 0x0
frames shown: 312 (PresentX 318)
presents per 2 s (last 3): 0 2 5
device removals: 0
crashes: 0
peak commit: 11088 MB

Head block (pair 2):

xcl-smoke v1
commit: 2624f00c4e2d8b87aa1828233fb2f60899eb9533
gpu: AMD Radeon RX 6650 XT
title: retail
seconds: 60
exit: 0x0
frames shown: 308 (PresentX 312)
presents per 2 s (last 3): 0 1 3
device removals: 0
crashes: 0
peak commit: 11414 MB

Review
The shape is right: the console mesh root-argument layout is tracked per pipeline, the companion signature replaces only the 12-byte DISPATCH_MESH argument with the 12-byte DISPATCH one so ByteStride is unchanged, both passes use the ABI root signature with its 6 UAV parameters (so writing u0–u5 is in range), UAV barriers bracket the record buffer, and record buffers are held until their allocator resets. Points I would fix before this reaches a title with 8 GB of video memory:

  1. ensure_res_buffer(this, 32 << 20) (bind.rs:547) requests a fixed 32 MB DEFAULT-heap record buffer for every two-pass ExecuteIndirect, while the direct DispatchMesh path sizes from groups * record_dwords * 4 (bind.rs:492). FREE_RES caches up to 16 buffers per device (bind.rs:55), so up to ~512 MB can sit idle on an 8 GB card plus one live buffer per command list. Size the request from max * tp.record.record_dwords() * 4 with the existing 4 MB floor (and a smaller cache); as it stands, max * record_dwords * 4 > 32 MB already loses records (UAV out-of-bounds writes are dropped), and a size-from-max request above the 128 MB cap would too, so clamp or split the call there.
  2. A DISPATCH_MESH signature that also carries a constant/CBV/SRV/UAV argument is root-changing, gets no companion (device_x.rs:1028-1045), and then falls through bind.rs:543-581 to bind.rs:583-602: because a two-pass PSO is in neither TRANSLATED_GRAPHICS nor TRANSLATED_COMPUTE, that is the "PC pipeline" path, so it sets rs_gfx and runs the mesh signature without pass 1 having written res — stale/zero records rather than the "skipped as before" in the description. If two_pass_of(pso).is_some() and the signature is not a known mesh one, skip with a warning instead of pc().
  3. indirect_arg_bytes returns 0 for unknown argument codes (device_x.rs:1001-1012) and only console DispatchX (105) is translated, so any other console code placed before the DISPATCH_MESH argument makes mesh_offset too small; with mesh_groups_per_record > 1 the scaler then multiplies the wrong dword of every record and silently corrupts the following arguments. Make it return an Option and only record the mesh signature when every preceding argument has a known size; otherwise do not scale (or skip with a log).
  4. DISPATCH_MESH_SIGS is keyed by the title's command-signature address, is never pruned, and the companion is never released (bind.rs:250-261, device_x.rs:1044-1045). If the title releases a signature and the runtime hands the same address to a new one, the new signature inherits the old companion/stride/offset (wrong signature executed; the companion also leaks). Release it with the signature, or key it by something stable.
  5. Minor: ensure_res_buffer/make_scaled_args_buffer do a GetDevice + QI + Release per growth/scaled call (bind.rs:326, bind.rs:460) — cache the device in State; scale_indirect_pipeline compiles its HLSL with DXC synchronously on the first use (bind.rs:412), which can hitch the render thread mid-frame once; and the compute pass always assumes the measured MS convention (table pointer in s[8:9], inline from s16, bind.rs:369, console_list.rs:173) with no fallback when layout.inline_ms is 0 while the root signature has parameters — a one-time log there would make a compiler whose user-SGPR count differs visible.

Not tested

  • No gameplay past the loading/menu within 60 s, so the new two-pass execution path, the split>1 indirect-argument scaler and the record buffer's VRAM behaviour were not observed on the title here. The mesh pipelines the title does create in this window are the AS-slot ones refused before this PR.
  • No direct DispatchMesh with a translated two-pass pipeline, and no indirect DispatchMesh with mesh_groups_per_record > 1 on the title; those paths are covered only by the GPU tests above, not end to end.
  • No XCL_SAMPLE_* / real-shader sample runs, no long run (fps/VRAM decline), no Intel or other-vendor GPU, no release-build workspace tests (release was built only for the smokes), and the PR was not merged onto the current origin/main.

AI use
opencode with DeepSeek V4.1 Flash (opencode-go/deepseek-v4.1-flash) built both worktrees, ran the full workspace suite, reran each failing test alone, ran the targeted groups and the two 60 s smoke pairs, and wrote this report and review. It made no code changes; every review point was checked against the diff at 2624f00.

utkarshxdev added a commit to utkarshxdev/xcl that referenced this pull request Nov 24, 2026
…h rendering)

Consolidate critical engine subsystems required to transition from Stage 5
(2D menus presentation loop) to Stage 6 (ingame 3D world loading, streaming,
and gameplay rendering) on Apple Silicon / macOS via D3DMetal:

1. Two-pass mesh shader execution on DispatchMesh and ExecuteIndirect (PR ivall#724):
   - Hook DispatchMesh (slot 127 / newer 129) on console command list vtable.
   - Execute TwoPassPso (Pass 1 compute -> UAV barrier -> Pass 2 mesh+PS -> UAV barrier).
   - Track console mesh root-argument layout (s[8:9] spill table, inline arguments from s16).
   - Create companion DISPATCH command signature alongside DISPATCH_MESH in device_x.
   - Allocate/recycle DEFAULT-heap UAV record buffer per command list (recycled on allocator reset).
   - Scale indirect DispatchMesh group counts on GPU when mesh_groups_per_record > 1.

2. GPU-side root-changing ExecuteIndirect repack (PR ivall#869):
   - Repack root-changing indirect draw and dispatch commands on the GPU.
   - Allow translated pipelines on XCL ABI root signature to consume title root-changing signatures.
   - Retain native count buffer support and track allocator lifetime for indirect argument buffers.

3. DirectStorage BCPack decompression acceptance (XCL_DSTORAGE_BCPACK_ACCEPT=1):
   - Prevent E_DECOMPRESSION (0x89240030) errors when streaming assets.
   - Maintain since_status = S_OK when solid blocks are filled.

4. Watchdog & fatal crash bypass at 0x23cf683 (eh.rs):
   - Prevent GPU hang watchdog ('GPU Loc Sig') and null write at 0x23cf683 from terminating
     the process when compute PSO compilation or decompression stalls >30s.

5. Sparse buffer lock safety:
   - Use try_lock in forget_buffer and drain deferred GONE queue on forget_gone.
   - Eliminates D3DMetal re-entrancy deadlocks during command list reset/execution.

6. Expanded verification suite:
   - 30 host subsystem checks passing in scripts/verify_mac_build.sh.
@upipibi upipibi mentioned this pull request Nov 24, 2026
@raylitebull

Copy link
Copy Markdown
Member

Great progress on two-pass DispatchMesh / ExecuteIndirect, though a few blockers need addressing before merge: (1) bounds/clamping on the record buffer to prevent >32 MiB OOB writes on large indirect dispatches, (2) a shared/capped scratch buffer to avoid unbounded per-allocator VRAM growth, and (3) safe tracked-state transitions on indirect argument buffers.

@oeirughrepuiohg

Copy link
Copy Markdown

Review and test report on 2624f00.

1. The two-pass io block never gets the UMA base. bind_two_pass_stage builds io from user_data_ms / user_data_gfx, resizes it to KERNEL_SGPRS with zeros, and never sets io[IO_UMA_BASE_HI]. The normal binds do (bind.rs io[crate::gpu::recomp::IO_UMA_BASE_HI] = (u.base() >> 32) as u32, and the same in console_list.rs). The translated mesh-mode program loads it in its prologue (xcl_uma_base = io.Load(448u) in a dumped two-pass compute HLSL) and picks the memory window as hi - xcl_uma_base. With 0 there, xcl_w = hi - 0 is 4–7 for every title address when UMA's base is at 16 GiB (base >> 32 = 4 here), so every access falls into the accessors' default arm: the compute pass reads zeros and its stores are dropped, and the mesh pass draws records that were never written. One line fixes it:

    io.resize(crate::gpu::recomp::KERNEL_SGPRS, 0);
    io[crate::gpu::recomp::IO_UMA_BASE_HI] = (u.base() >> 32) as u32;

Tested (Linux, Wine/GE-Proton 11, vkd3d-proton with XCL's patch, RTX 4070 Ti 12 GB, NVIDIA 620.x; x86_64-pc-windows-gnu release build of main 09940bb + this PR + #684 and other open PRs we run; retail title, own copy):

  • Without this PR: GPU device lost at the world load (kernel Xid 13 "SM Warp Exception: MMU Fault" in most runs).
  • With this PR as is: two-pass draws run (2048+ DispatchMesh, 8192+ ExecuteIndirect(DispatchMesh)) and no MMU fault was seen in two runs; both runs still stall at the same point (a queue's 64-bit fence stops advancing), which we also see without this PR and do not attribute to it.
  • With the one-line fix (in our tree since): the compute pass reads and writes the right UMA windows; the world-load stop that remains is the one described in Newer retail title (TitleID 7952987A): reaches world loading, then the title's GPU watchdog ("GPU Loc Sig") after ListX #101 stub #505 (a 100 % GPU phase that follows skipped binds under XCL_PSO_WAIT_MS), not this PR.

Not tested: Windows, AMD, the full test suite (the crate is built for Windows only; we run it under Wine).

AI use: Claude Code, Claude Opus 5.5 - found the missing field while debugging the world-load fault, wrote this comment; the runs are ours.

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

Integrates upstream PR ivall#724 on top of subobject-24 console MS
translation:
- Hook console DispatchMesh (slot 127 / newer 129) and pair
  DISPATCH_MESH command signatures with companion DISPATCH signatures.
- Run the compute pass into a recycled per-allocator record buffer,
  barrier, scale indirect arguments when split > 1, and run the mesh
  pass.
@Rodriguerra

Copy link
Copy Markdown

Two heads-up from testing two-pass Mesh Shaders rebased onto current main (RTX 3060 12 GB):

  1. When rebasing onto main (which added IO_UMA_BASE_HI), make sure bind_two_pass_stage also writes io[crate::gpu::recomp::IO_UMA_BASE_HI] = (u.base() >> 32) as u32; — without it, two-pass MS + attached PS read xcl_uma_base == 0 and return zeros for every UMA read when u.base() != 0.
  2. In translated_mesh_pso, skipping subobject 14 (D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY) avoids 0x80070057 (E_INVALIDARG) rejections on retail MS pipeline streams.

@ivall

ivall commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

This is the piece #541 needs: at main e9e94ce nothing runs a two-pass pipeline. two_pass_of has no caller outside tests and one log line, and bind::execute_indirect sends such a pipeline down the PC branch with the title's root signature, so u1 is not bound. I think that is the cause of the device removals reported on #541 (details there). So this should land before #541.

What is open here, from the reviews above, before it can be merged:

  1. rebase: it conflicts with main;
  2. io[IO_UMA_BASE_HI] in bind_two_pass_stage (@oeirughrepuiohg, @Rodriguerra): without it every unified-memory access of the pair misses its window;
  3. a bound on the record buffer (@NathanTheophile, @raylitebull): with large dispatches the compute pass writes past it;
  4. indirect arguments with Y or Z > 1 (@NathanTheophile): groups are lost;
  5. the state of the indirect argument buffer, and a cap on the per-allocator scratch memory (@raylitebull, @badoomtch).

@Cattn, are you still on it? If not, say so here and someone can take it over with your commits kept. Splitting it would help the review, for example direct DispatchMesh with the bound first and indirect dispatch second.

Not tested: I have not built or run this PR; the list is from its reviews and from reading main.

AI use: Claude Code (Claude Opus 5.5) read the code and the thread and wrote this, on the maintainer's behalf.

@PracticalStudios

Copy link
Copy Markdown

@Cattn are you still on the points @ivall listed above? If not, I can take them: rebase onto main and fix 2–5 as separate commits on top of yours (your authorship kept), tested on an RTX 3090 (wave32, mesh shaders). I'm starting now; if you're already on it, say so and I'll hand you the commits instead.

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

@PracticalStudios

PracticalStudios commented Nov 24, 2026 •

Copy link
Copy Markdown

@Cattn @ivall the points above are done on PracticalStudios/xcl mesh/two-pass-execution: #724's commit rebased onto main 1d027e5 (authorship kept), then one commit per point:

  • d41d2f3 the two-pass io block gets IO_UMA_BASE_HI;
  • ee561d0 groups stay inside the record buffer (ExecuteIndirect args are rewritten with X capped);
  • ccfe5c1 indirect Y / Z > 1 are folded into X;
  • e284043 the args are read through unified memory instead of transitioning the title's buffer; scratch is per-list 1 MiB blocks, 16 MiB per recording, reuse pool capped at 256 MiB;
  • b718955 one more test case;
  • 3442b58 an ExecuteIndirect with max > 1 runs one command at a time (compute, then mesh), so commands no longer overwrite each other's records; commands past a count buffer's count get no groups.

Each fix has a test that fails without it. RTX 3090 (wave32, mesh shaders), Windows 11, debug: cargo test --workspace --no-fail-fast: 966 passed, 1 failed, 43 ignored. The failure (kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory) fails the same way on main here.

Still open: two-pass ExecuteIndirect calls whose arguments are outside unified memory are skipped with a warning. Not tested: a title run.

Cattn, pull it into #724 if you like; otherwise I'll open it as a PR that supersedes this one.

AI use: Claude Code (Claude Opus 5.5, with Claude Sonnet subagents) wrote the code, the tests and this comment.

@veyn-sudo

Copy link
Copy Markdown

Measurements on the mesh shader's user SGPRs, for the rebased branch (PracticalStudios/xcl mesh/two-pass-execution, read at 3442b58), from a retail title's shader pack:

  1. s16 holds. All 9,282 mesh shaders in the pack read only s3 and s16–s24 before writing them. So FIRST_SGPR_MS = 16 is right, and none of them reads the table address that user_data_ms puts in s8/s9.
  2. Heap addresses are missing. For a root signature with flag 0x400 / 0x800, the console passes the 32-bit address of the view heap / sampler heap after the root arguments, view heap first. D3D12.X: shaders that index the heaps themselves get the heaps' addresses #1803 does this for draws and dispatches. In the 40 mesh pipeline layouts I compared, the shaders read exactly the registers this predicts. user_data_ms stops at the arguments, so on this branch those registers are 0 and such a shader reads its descriptors from address 0 on. The pass-through draw's PS has the same gap, through user_data_gfx in two_pass_io.

Once #1803 and this have both landed, it should be a small follow-up: append with_heaps in both cases of two_pass_io. I can send that PR with a test.

Not tested: I only read the branch; I did not build or run it. The layouts are a sample of 40, not all of them. I have not run mesh draws in the title.

AI use: Claude Code (Claude Opus 5.5) made the measurements, read the branch and wrote this.

@cafeoh

cafeoh commented Nov 25, 2026 •

Copy link
Copy Markdown

RTX 2080 Ti (Turing): PracticalStudios/xcl mesh/two-pass-execution at 3442b58 with #541, in a retail title. The mesh draws now run (2 000 to 10 000 draws per 2 s in the world, about 200 without them), but the scene's depth targets stay at their clear value, and the device is removed (0x887a0005) at 155 to 160 s in 3 of 3 runs (and at 152 and 249 s in 2 of 2 runs with #724's own head 2624f00). Appending the heap addresses in two_pass_io, as @veyn-sudo suggests, did not change either (1 run).

Setup: RTX 2080 Ti 11 GB (32-lane waves), driver 617.14, Windows 10 19045, release. Retail 1.0.2.1. Tree: main 689f2db + #684, #1053, #929, #1323, #1766, #640, #1329, #1732, #1405, #1464, #1102, #541 (6bd8f64), then 3442b58; run 123 also #1803 (cb00751) and with_heaps in two_pass_io (MS and PS stage), plus local diagnostics and a local split of very long command lists (my comment in #505). XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_COHERENT_HEAPS=0 XCL_COHERENT_MB=512 XCL_UMA_SHADOW=1 XCL_PSO_WAIT_MS=50. Not a clean tree.

What I looked at: a render-target dump at present (Palmwave's XCL_RT_DUMP, ported locally), frames 930 to 945 of each run, which are in the world (the intro's credits are drawn over them):

run tree world draws per 2 s end
117 + #541 only – device hung (0x887a0006) at 90 s, no dispatch open (XCL_GPU_CULPRIT)
118, 119 + #724 head 2624f00 up to 10 031 0x887a0005 at 249 s / 152 s
120, 122 + 3442b58 instead up to 7 394 0x887a0005 at 155 s / 160 s
123 + #1803 + heaps in two_pass_io similar 0x887a0005 at 157 s

After each removal the title stops at int3 +0x2474606, as in @Ariorh1337's run 51. In run 119 XCL_GPU_CULPRIT named cs 03e5007cf739d41d (1×1×1 groups) as the one dispatch not done; in runs 117, 120 it found none open. XCL_DRED=1 stopped the title at 6 s (6 presents), so I have no fault address.

Not tested: the test suite on this tree (the two-pass GPU tests pass alone, --test-threads=1; with 4 threads one failed and others skipped, which I have not looked into); AMD; a cleaner tree; more than one run per row.

AI use: Claude Code (Claude Opus 5.5) merged the trees, ran the runs on this machine, read the dumps and wrote this comment.

@CharlyRien

Copy link
Copy Markdown

RTX 3090 (Ampere, 32-lane waves), mesh/two-pass-execution at 3442b58 with #541 in a retail title: same picture as @cafeoh above, plus where it stops. The mesh draws run, but in every non-empty record the compute pass has written (vertices, primitives) = (1, 1), occasionally (2, 2), so the pass-through has nothing to rasterise. Most indirect mesh draws also arrive with 0 groups.

Setup

What the title asks for (pipeline streams logged as it passes them): sub-object 24 holds the console container, there is no sub-object 25 and no VS. The container is a single NGG hardware stage with a mesh interface: 128 threads, at most 128 vertices and 128 primitives, 7 vertex outputs. No amplification stage. Without #541 XCL refuses 6 685 distinct ones in a run (the log cap of 40 hides that). The title issues them both ways: direct DispatchMesh (console slots 127 / 129) and ExecuteIndirect with one signature of stride 12; it does not use argument type 107 here.

A/B on the same build, 600 s runs

mesh pipelines refused #541 + #724
two-pass pipelines built 0 (6 685 refused) 267 – 270, no DXC or driver failure
indirect DispatchMesh per world frame 0 2 806 – 6 759, all executed, 0 skipped
main depth target (D32S8, 2560x1440) clear value (at most 230 texels written in 3 frames) clear value (3 texels in 1 frame)
picture flat grey, HUD on top the same flat grey
device removed (0x887a0005) at 199 s at 476 s

Where it stops (one more run, two world frames captured)

frame A frame B
indirect DispatchMesh 2 833 2 144
… with 0 groups 2 572 1 864
… with groups (sum of groups) 261 (941) 280 (1 618)
direct DispatchMesh, all with groups (sum) 789 (3 356) 739 (7 361)
(vertices, primitives) written by the compute pass in non-empty records (1, 1), sometimes (2, 2) same

So two separate things keep the depth empty here:

  1. The compute pass of the two-pass form yields one vertex and one primitive per record for this title's programs, including the direct calls whose groups are real. The PR's tests pass on this card, so the difference is in what the title's programs do: 128 threads (two 64-lane waves, each run in the split form on a 32-lane GPU), and whatever they use to count and compact (the allocation request, a population count over EXEC, a prefix sum across lanes). Not narrowed down yet; that is what I am looking at next.
  2. About 90 % of the indirect mesh draws get 0 groups from the title's GPU-driven culling, the same culling that leaves most ordinary indirect draws with InstanceCount 0 and most indirect dispatches with 0 thread groups in these frames (with or without the mesh pipelines). That is upstream of this PR.

Not tested: AMD, native 64-lane waves, #1984, #1936 / #1937 (no pipeline was rejected at creation here), the GPU time of the two passes (not timed by my markers).

AI use: Claude Code (Claude Fable 5.2 coordinating, Claude Opus 5.5 for the merges, the captures and the runs) did this and drafted the report.

@CharlyRien

Copy link
Copy Markdown

Follow-up on the (1, 1) records from my comment above: it is the SGPR base of the mesh stage's root arguments, not the translation. With the title's most common root signature the arguments land one register too late with FIRST_SGPR_MS = 16, so the program reads the wrong descriptor table. The binding looks per shader, from metadata in the container, rather than a fixed base.

Same setup as above (RTX 3090, main 689f2db + the stack listed there + #541 + this branch at 3442b58 + #1887 + #1803).

What the title's mesh programs compute (three bound programs read from their translated code): the program takes a 32-bit descriptor table from s17; slot 0 of that table is the meshlet buffer; it reads the entry at 16·group + 12 and sends vertices = (entry & 0x7F) + 1, primitives = ((entry >> 7) & 0x7F) + 1 with s_sendmsg GS_ALLOC_REQ, from thread 0 only. No bit count, ballot or compaction is involved (v_mbcnt only appears with −1, as the lane index), and the GS_ALLOC_REQ decode in emit.rs is right. (1, 1) simply means the entry read as 0.

Offline: the real program, run in the split-wave64 compute pass on the GPU with inputs I control, writes exact counts: (64, 100), (32, 50), (128, 128). So the translation and the two-pass compute are fine for it.

In the title

  • A probe at execution shows that the table the program gets in s17 has a 128-byte block of float 1.0 in slot 0: per-draw constants, not the meshlet buffer. 1.0f gives count 0, entry 0, hence (1, 1).
  • Logged root signatures: 54 of 60 binds are [table, table, table, root SRV, 2 constants]. Starting the arguments at s16 puts the second table in s17 and the third table plus the low half of the SRV address in s[18:19], which the program uses as one 64-bit address. Starting at s15 gives s17 = third table and s[18:19] = the SRV address, which is what the code expects. The other 6 binds are [table, table, root SRV, 2 constants] and fit s16.
  • That agrees with @veyn-sudo's measurement above (only s3 and s16–s24 are read): both bases satisfy it, the difference is which root argument lands in s17 and s[18:19].
  • Two programs with identical code carry different metadata records after their code in the console container (tag 0x10904; types 0x300 and 0x302, which I read as table and descriptor; descriptor offsets 0x18 against 0x20). So the mapping of root arguments to SGPRs is probably described per shader there. I have not decoded it.

Tried: FIRST_SGPR_MS = 15 as a blunt experiment (plus a unit test with this layout, and a GPU test that runs the real program through user_data_ms: (1, 1) with 16, real counts with 15). In the title, for the first time records carry real counts (292 records between 1 and 128 in three frames, e.g. (128, 120) ×42, (98, 86), (126, 120)), but (1, 1) is still the majority, and the other layout is now the broken one (136 of 1 200 probed binds get the SRV's high word in s18). So a fixed base cannot be right for both; it needs the per-shader binding.

And one more wall behind it: the root SRVs of these draws point at addresses with high words 0xe, 0x12, 0x13, outside every unified-memory window on this tree (the windows cover high words 1 – 4 here). That is the situation of issue #697 (the title's large 64 KiB-page reservations fall back to plain memory, buffer views there get an empty V#, root views read 0), so the vertex data would not be readable even with the right counts. Nothing reaches depth yet.

Not tested: depth coverage with the experiment (the run ended in a device removal at 134 s, before the dumps; one run, so I cannot say the change caused it), AMD, the 0x10904 decode.

I can post the two tests and the probe if useful.

AI use: Claude Code (Claude Fable 5.2 coordinating, Claude Opus 5.5 for the code reading, the offline reproduction and the runs) did this and drafted the report.

@PracticalStudios

Copy link
Copy Markdown

Opened as #2092 so the branch above can be reviewed and merged: this PR's commit (authorship kept) + the five review points + the shared-heap bind fix, rebased on main, with the suite and a smoke pair. @Cattn, if you'd rather pull the commits into this PR, say so and I'll close #2092. The (1, 1) records @cafeoh and @CharlyRien found are listed there as not fixed.

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

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.