Skip to content

Recompiler: two-pass mesh groups run in whole console waves - #3350

Open
KDenKC wants to merge 1 commit into
xcl-dev:mainfrom
KDenKC:fix/two-pass-mesh-whole-waves
Open

KDenKC wants to merge 1 commit into
xcl-dev:mainfrom
KDenKC:fix/two-pass-mesh-whole-waves

Conversation

@KDenKC

@KDenKC KDenKC commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

The two-pass mesh path launched only the declared thread count. A wave64 mesh program declaring 32 threads therefore had no lanes 32–63, even when its output extents required them; exports from those lanes were lost.

Both the direct-DXIL and HLSL paths launch whole console waves covering max(threads, max_vertices, max_primitives). Entry EXEC still starts at the declared threads. The v5 group-index step uses that rounded launch width for every mesh program, including programs that do not widen EXEC (32 threads/32 outputs on wave64 use a step of 64). GS_ALLOC_REQ writes the per-group header from wave 0 regardless of EXEC: the declared wave may narrow EXEC before the send, and a later wave may widen it.

Related: #3011 (C54, lost triangles), #3484 (main's failing stand-in test). This touches the HLSL mesh entry also changed by #3327; the integration branch keeps the two-pass entry's whole-wave launch and the native branch's separate entry.

What is in it

  • One commit: gpu/recomp/mod.rs defines the whole-wave launch width and group stride; gpu/dxil/kernel.rs, gpu/dxil/lower.rs, and gpu/dxil/lower_mem.rs use them for direct DXIL and wave-0 GS_ALLOC_REQ; gpu/recomp/emit.rs handles the HLSL path.
  • Entry EXEC keeps declared threads active; extra lanes begin inactive and can be enabled only if the shader widens EXEC.
  • gpu/recomp/tests.rs: CPU tests cover output extents and wave rounding. gpu_mesh_mode_two_passes checks the second group's v5 step and retains the four-way split pass-through draw. gpu_mesh_alloc_req_uses_wave0_independent_of_exec checks narrowed wave 0, a widened later wave, and an unguarded negative control through HLSL and direct DXIL.
  • gpu/dxil/robustness_tests.rs: the existing multi-wave barrier survey now uses the launched width.
  • Compute entry-mask generation is unchanged; the mesh entry uses its own EXEC helper.

Tested

  • RTX 3090 VM, driver 621.24, Rust 1.99.1, XCL_NETWORK=0.
  • Head 590f06dbf169e3fd43a4bb606d8a6417bdde7c3f: mesh_group_stride 2/2, gpu_mesh_alloc_req_uses_wave0_independent_of_exec 1/1, and gpu_mesh_mode_two_passes 1/1 passed (no skipped tests). The wave-0 test's unguarded HLSL negative control produced [9, 3]; the guarded HLSL and direct-DXIL paths produced [5, 2].
  • Workspace suite on this head: 2,905 passed, 5 failed, 51 ignored; 0 binaries without a result. The five failures were the four title_textures tests and test_title_runs_and_game_folder_is_untouched, matching main 1c8b5514 on this VM. The suite had 28 capability skips.
  • Earlier 4-thread lib-only runs on this head and main completed without a crash and showed the same four title_textures failures. The earlier intermittent suite access violation was not reproduced in the repeat suite or these isolated runs; this evidence does not attribute it to the PR.
    Regression run
    A 600-second JIT smoke pair on RTX 5090, with held Enter and the same copied cache seed (main-full-d8bd) plus accepted-terms profile (r18-terms) in both arms. Both reached the world; neither crashed or had a device removal. These blocks are verbatim from the run report.

Main 1c8b5514:

xcl-smoke v1
commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 600
exit: 0x0
frames shown: 1724 (PresentX 1725)
presents per 2 s (last 3): 2 1 2
device removals: 0
crashes: 0
peak commit: 47581 MB

Head 590f06db:

xcl-smoke v1
commit: 590f06dbf169e3fd43a4bb606d8a6417bdde7c3f
gpu: NVIDIA GeForce RTX 5090
title: 9cc6a39e
seconds: 600
exit: 0x0
frames shown: 1964 (PresentX 1965)
presents per 2 s (last 3): 2 2 2
device removals: 0
crashes: 0
peak commit: 48740 MB

Not tested

  • Whether retail mesh programs widen EXEC past their declared threads.
  • A capped loop in direct DXIL that ends a lane instead of leaving the loop; exports after it remain a separate issue.
  • Cost of the extra launched lanes and multi-wave barrier work; it remains unmeasured.
  • AMD, Intel, or native wave64 hardware; the 3090 uses split wave64.

AI use

  • An agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen (tools: Claude Code, Codex, Antigravity). The swarm reviewed, implemented, and validated this change.

🤖 Generated with Claude Code
https://claude.ai/code/session_013oPUFCA9W9F8Qb5MPK33bR

@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Nov 29, 2026
@KDenKC
KDenKC force-pushed the fix/two-pass-mesh-whole-waves branch from e741dfc to 664d738 Compare November 29, 2026 10:47
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Nov 29, 2026
@KDenKC
KDenKC marked this pull request as ready for review November 29, 2026 13:31
@KDenKC
KDenKC force-pushed the fix/two-pass-mesh-whole-waves branch from 664d738 to fd2cadf Compare November 30, 2026 01:04
@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 30, 2026
@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 30, 2026
@KDenKC
KDenKC force-pushed the fix/two-pass-mesh-whole-waves branch from fd2cadf to 1e5b298 Compare December 1, 2026 08:33
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Review (head 1e5b298, diff read, not a merge-check; PR description red: its smoke blocks and counts name fd2cadf, not this head):

  • v5 changes for more programs than the description says, and no test sees it. group_stride (gpu/recomp/mod.rs ~380) makes v5 group × max(threads, vertices, primitives) + slot for every program with more vertices or primitives than threads, whether or not it widens EXEC; on main it is group × threads + slot. It is used at gpu/dxil/kernel.rs ~1320 and emit.rs ~5408. The new test draws one group, so the group number is 0 and the stride never shows. All existing mesh GPU tests have at least as many threads as vertices and primitives.
  • The stride isn't rounded to whole waves, but the launch is (launch_threads). With 32 threads, 64 vertices and 126 primitives on wave64, 128 lanes launch with a stride of 126, so lanes 126-127 of group 0 get the same v5 as lanes 0-1 of group 1. Whether the console's v5 counts the launched lanes or the max is the question, and a two-group test would settle it.
  • Unmeasured cost. Extra lanes launch for every such program, even one that never writes EXEC: 32 threads become 128 lanes, four 32-lane hardware waves on NVIDIA instead of one. Those groups also move to the multi-wave barrier (@xcl_bar). The PR's 600 s pair never reached the world, so nothing measured it.
  • Minor:
    • compute_init now emits tid < total where it used a constant true, so compute shaders change too and recompile once.
    • shaders.rs ~603 (the survey) and the test helper at tests.rs ~11678 still use ms.threads (diagnostics only).
    • There are two blank lines after the new test.

Fine: in the split form a wave past the declared threads now gets an empty EXEC instead of wrapping to all lanes, and the other forms ballot slot < threads. Lanes past the record are still blocked by the vertex and primitive bounds checks. Barrier wave counts follow the launched threads on both backends. The group count is unchanged and the launch is capped at 1024. mod.rs and emit.rs are in TRANSLATOR_SOURCES, so no stale DXIL is served. The tests skip through gpu_ready() / mesh_ready() and check both backends' pixels. It will conflict with #3327 (yours) in the HLSL mesh entry.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Triage (#1607) – head d22887e

No open or merged PR makes the same change: launch_threads/group_stride are not on main. #3504, #3052 and #2092 touch other parts of the two-pass mesh path, not the group launch width or entry EXEC. Both backends now launch whole console waves covering max(threads, max_vertices, max_primitives), with EXEC at entry limited to the declared threads, and the GPU test draws through both backends. Note that v5's per-group step is now group_stride(wave64), the launch width (max(threads, max_vertices, max_primitives) rounded up to whole waves), for every two-pass mesh program. So it also changes from threads for programs whose thread count is not a multiple of the wave size, not only for those with more vertices or primitives than threads. The regression run does not show whether the title depends on that.
Recommendation: keep open.

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

KDenKC added a commit to KDenKC/xcl that referenced this pull request Dec 1, 2026
Keep v5 ranges disjoint across every launched wave, including programs whose output extents exceed declared threads. Add CPU tests for the output-extent and wave-rounding cases.

Checked: xcl-dev#3350 review 7306364917, xcl-dev#3327 interaction, REPO-TRACKER.md and search-two-pass-lanes.md.
@KDenKC

KDenKC commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

@Foniass Thanks for the careful review. In d22887e, v5's group stride now uses the same whole-wave launch extent as the two-pass launch. The stride stays broad: guest code can widen EXEC after entry, so lanes beyond the declared thread count may still execute and need a disjoint v5 range; we don't have a complete proof that a program never widens EXEC. The tests cover output extents larger than the declared thread count (including the group-1 boundary that previously aliased slots 126–127) and rounding a 65-thread group to full waves for both wave sizes.

The focused tests passed. The completed workspace suite set XCL_NETWORK=0 for the test processes and had no binaries without results. Its six failures match the VM's known baseline failures: D16 resinfo, placed title textures, the three stream-recheck cases, and the title-folder e2e check.

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 2770 filtered out; finished in 0.00s
env set for the tests: XCL_NETWORK=0
counts: 2880 passed, 6 failed, 51 ignored over the binaries with a result; 0 binaries without a result
  test gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 ... FAILED
  test hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels ... FAILED
  test hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads ... FAILED
  test hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload ... FAILED
  test hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones ... FAILED
  test test_title_runs_and_game_folder_is_untouched ... FAILED

The smoke pair for this head is still pending.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up review (head d22887e, since 1e5b298, diff read, not a merge-check):

  • v5 changes for more programs than the description says, and no test sees it: partly fixed. d22887ec now sets the stride on purpose (group_stride = launch_threads, mod.rs ~379) and adds CPU tests of that function (tests.rs ~11-27), but the third assert there only repeats the first (128 >> 7 is 1), and no test draws a second group, so neither backend's emitted v5 step is checked (kernel.rs ~1320, emit.rs ~5408). The description still does not say v5's step also changes for programs that never widen EXEC (32 threads with 32 vertices on wave64 now get a stride of 64, not 32).
  • The stride is not rounded to whole waves but the launch is: fixed; the stride is the launch width, so lanes past the threads of group 0 no longer alias group 1.
  • Unmeasured cost: still open. The extra lanes and the move to @xcl_bar for programs whose launch exceeds their threads are not measured.
  • Minor points: still open. compute_init emits tid < total instead of a constant true (kernel.rs ~1201, compute DXIL recompiles once); ms.threads stays in the survey and test helper (shaders.rs ~603, tests.rs ~11673); two blank lines after the new GPU test (tests.rs ~4514).

New:

  • Fixup commit not squashed. d22887ec rewrites group_stride, which 1e5b2981 added, so the two are one change; its body points to files not in the repository (REPO-TRACKER.md, search-two-pass-lanes.md), and the description still says "one commit" and does not list the new CPU tests.
  • Failures in Tested not explained. The suite run on d22887ec lists 6 failures (gpu_direct_image_get_resinfo_d16, placed_title_textures_share_vram_and_preserve_pixels, three stream_recheck_*, test_title_runs_and_game_folder_is_untouched) without saying whether they also fail on main.

Fine: the stride and the launch now agree on both backends; EXEC at entry still covers only the declared threads; a group whose launch equals its threads keeps the constant EXEC and the old stride; the smoke blocks name the current head.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

KDenKC added a commit to KDenKC/xcl that referenced this pull request Dec 1, 2026
Launch enough whole console waves to cover max(threads, max_vertices, max_primitives), keep EXEC at entry limited to the declared threads, and use the launched width as v5's per-group step in both backends. Compute programs are unchanged.

Update mesh shader surveys and barrier fixtures to use the launched width. Add CPU coverage for output extents and wave rounding, plus a two-group GPU draw that checks the v5 step and matching records and pixels from HLSL and direct DXIL.

Checked: xcl-dev#3350 review 7325409956, xcl-dev#3011 C54, and xcl-dev#3327 interaction.
@KDenKC
KDenKC force-pushed the fix/two-pass-mesh-whole-waves branch from d22887e to a3f07fa Compare December 1, 2026 22:10
@github-actions github-actions Bot added the area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation label Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head a3f07fa, since d22887e, diff read, not a merge-check; checks red):

  • v5 step untested and under-described: partly fixed. The tests are fixed: tests.rs ~21-23 checks that 32 threads with 32 vertices get a stride of 64 on wave64, and gpu_mesh_mode_two_passes (~4363, ~4412-4420, ~4445-4447) now draws two groups with a launch of 128 and an extent of 126 on both backends, so a wrong step would show in group 1. The description still does not say v5's step also changes for programs that never widen EXEC.
  • Unmeasured cost; failures in Tested not explained: still open.
  • Minor points: partly fixed. The survey (shaders.rs ~603) and the barrier-test helper (tests.rs ~11703) use launch_threads and the blank lines are gone; compute_init still emits tid < total instead of true (kernel.rs ~1201, ~1368).
  • Fixup commit: fixed; one commit with no outside file references. What is in it still names only gpu_mesh_two_pass_widens_exec_past_declared_threads.

New:

  • The split pass-through draw is no longer tested. The shared fixture of gpu_mesh_mode_two_passes went from 128/128/128 to 32/64/126 (tests.rs ~4363), so passthrough_split now returns 1 and the assert changed from 4 to 1 (~4480-4486). mesh_draw_split has no other test caller, so no GPU test draws a record split over several mesh groups any more, though pso.rs ~1436 still takes that path. The split check needs its own MsInterface with 128 vertices.
  • The stride_ms block repeats the first draw. MsInterface { threads: 32, max_vertices: 64, max_primitives: 126, ..ms.clone() } (~4452) is the same as ms, so that block repeats the draws above.
  • Tested and Regression run are for the old head. Both smoke blocks and the suite run name d22887ec, while a3f07fa4 changes shaders.rs and rewrites the GPU test; PR description fails on that.

Fine: stride and launch agree on both backends, EXEC at entry is still the declared threads, and the runtime code in kernel.rs, emit.rs and mod.rs is unchanged since d22887ec.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@KDenKC

KDenKC commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@Foniass thanks for the review. Fixed in one commit, a3f07fa4. The v5 step now uses the whole-wave launch width for every mesh program: on wave64, 32 declared threads with 32 outputs use a stride of 64; output extents that require more lanes are rounded up to whole waves. This avoids lane 126/127 aliasing the next group's first lanes when the launch width is 128.

The CPU tests cover output extents and wave rounding. gpu_mesh_mode_two_passes draws two groups and checks records and pixels through both HLSL and direct DXIL. On the RTX 3090, the focused filters passed (stride 2/2; two-pass 1/1). The workspace suite was 2,880 passed, 6 failed, 51 ignored; the same six failed on main: D16 resinfo, placed title textures, three stream-recheck tests, and the title-folder test. The placed-title test passes alone on main but fails in the suite. Cost of the extra launched lanes and multi-wave barrier work remains unmeasured. A smoke pair for this updated head is pending.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

KDenKC added a commit to KDenKC/xcl that referenced this pull request Dec 1, 2026
Launch enough whole console waves to cover max(threads, max_vertices, max_primitives), keep EXEC at entry limited to the declared threads, and use the launched width as v5's per-group step in both backends. Compute programs are unchanged.

Update mesh shader surveys and barrier fixtures to use the launched width. Add CPU coverage for output extents and wave rounding, plus a two-group GPU draw that checks the v5 step and matching records and pixels from HLSL and direct DXIL.

Checked: xcl-dev#3350 review 7325409956, xcl-dev#3011 C54, and xcl-dev#3327 interaction.
@KDenKC
KDenKC force-pushed the fix/two-pass-mesh-whole-waves branch from a3f07fa to 572f7ea Compare December 1, 2026 22:29
@KDenKC

KDenKC commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Correction: a3f07fa4 also changed partial compute DXIL through the shared entry_exec, despite the description saying compute was unchanged. In 572f7eab, mesh EXEC handling is separate and the compute helper is restored to its previous behavior. The survey and test helper now use the launched mesh width; the redundant blank lines are removed.

On the RTX 3090, both focused mesh filters pass (stride 2/2; two-pass 1/1). The workspace suite is 2,880 passed, 6 failed, 51 ignored, with the same six failures as main. A smoke pair for 572f7eab is still pending.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 572f7ea, since a3f07fa, diff read, not a merge-check; checks red):

  • compute_init emits tid < total instead of true: fixed. Compute keeps main's entry_exec exactly (constant mask on a full wave, the split-wave mask, or ballot(true)), and the declared-threads ballot is now only in the new mesh_entry_exec (gpu/dxil/kernel.rs ~1333-1413), so compute DXIL no longer changes.
  • The split pass-through draw is no longer tested; the stride_ms block repeats the first draw: still open. tests.rs is unchanged since a3f07fa4, so passthrough_split still returns 1 for the shared 32/64/126 fixture (~4363, ~4480) and no GPU test draws a record split over several mesh groups.
  • Tested and Regression run are for an old head: still open. Both smoke blocks and the suite run still name d22887ec, two pushes back; the description still says "One commit" without the CPU tests or the fixture change, and does not say that v5's step also changes for programs that never widen EXEC.

New: none.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@fromthemoonx

fromthemoonx commented Dec 2, 2026 •

Copy link
Copy Markdown

merge-check
base: d71578f
head: 590f06d
merge: conflicts (crates/xcl/src/gpu/dxil/kernel.rs, the Entry::Mesh arm, since b0b44546 landed on main)
build: cargo build --workspace -> not run on this base (conflict); ok merged onto df0cfef6
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> not run on this base; merged onto df0cfef638306f325b208e5adae18d35ab4bf4ed, the main of an hour earlier: 2915 passed, 0 failed, 51 ignored (that base: 2911 passed, 0 failed, 51 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as that base; failing: none
review: read the whole diff (8 files, +284 -36). The code had no blocking problem on the older base; the conflict is what is open.

  • The conflict needs more than keeping both sides. Main now lets a mesh producer run as a dispatch chain when ms.threads is a multiple of 64 (and is 64 if it uses LDS). With this PR the group has launched threads, so that condition probably has to test launched: 64 declared threads with 128 outputs launch two waves. This is from reading, not from a run.
  • My report on 572f7eab missed the header race bmjask found. It is fixed here: both backends store the GS_ALLOC_REQ header from lane 0 of wave 0 only, whatever EXEC is.
  • On the older base: the PR's 3 mesh GPU tests and 2 mesh_group_stride tests with XCL_REQUIRE_GPU=mesh on this wave32 GPU passed 3 of 3 runs, none skipped. Without the wave-0 guard, or with every launched lane active at entry (direct DXIL), the tests aimed at them fail.
  • Not settled by any test here: whether the console's v5 steps by the launch width, whether entry EXEC covers only the declared threads, and a program whose wave 0 skips GS_ALLOC_REQ (bmjask's open points). By the author's census, all 327 title mesh programs seen are 128/128/128, where the v5 step is unchanged, so the smoke pair does not exercise the new step.
  • Nit: the doc comment of gpu_mesh_alloc_req_uses_wave0_independent_of_exec still describes the older empty-EXEC rule.
    performance: extra idle lanes only for programs whose declared threads are below their launch width; not measured. No title was run here.
    verdict: not yet: conflicts with main d71578f8; needs a rebase, then the suite and the smoke run on the new head
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

This replaces the safe to merge I posted here at 13:05 UTC, before main moved.

@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 2, 2026
@fromthemoonx

Copy link
Copy Markdown

@KDenKC merge-check above: the code and tests check out here, but the PR has no xcl-smoke pair on its head 572f7eab (and none on main), which the PR description check also asks for; for a change to every two-pass mesh program's v5 that run is the missing evidence: #3350 (comment)

@KDenKC

KDenKC commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@fromthemoonx thanks for the merge-check. The xcl-smoke pair (main 1c8b5514 and this head 572f7eab) is queued on our RTX 5090, next after the run in progress; the blocks go into the description when it's done.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

@bmjask bmjask 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 572f7eab: 3 finding(s). 2 are inline. These are on lines outside the diff:

crates/xcl/src/gpu/recomp/emit.rs:1372: Not certain about this one: the newly launched waves (EXEC=0 at entry) now run the whole program, including GS_ALLOC_REQ's unconditional if (lane_id == 0u) res.Store(xcl_rec...). For threads=64, max_vertices=128 on wave64, wave 1 has no active lanes and computes M0 from wave-dependent or uninitialized state, then races wave 0 to store the record's vertex/primitive header. A wrong nv/np makes the pass-through drop or garble triangles. The Direct DXIL lowering has the same exposure, and the HLSL mesh entry has no if ((exec_lo|exec_hi)==0u) return; like the compute path.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

sgpr.insert(3, s3);
sgpr.insert(VAR_SCC, zero);
let (lo, hi) = entry_exec(lw, ms.threads, tid);
let (lo, hi) = mesh_entry_exec(lw, ms.threads, launched, tid);

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.

Not certain about this one, because it depends on unverified hardware behaviour: the entry EXEC is still limited to the declared ms.threads. On the console a group launched with launch_threads lanes probably starts with EXEC covering every launched lane, with the guest compiler guarding API threads itself. If so, a mesh program declaring 32 threads with max_vertices=64 that exports from lanes 32..63 without its own s_mov_b64 exec, -1 still starts those lanes inactive in both backends (here and emit.rs:5401 xcl_slot < threads). The vertex exports are dropped, which is the #3011 symptom. The PR says it didn't check whether retail programs widen EXEC, and the only positive test widens it explicitly.

/// The console's v5 per group: each group gets a disjoint range covering every launched
/// lane. Output extents can exceed declared threads, and guest code can widen EXEC later,
/// so this applies to every program, not only ones whose translation proves EXEC widening.
pub fn group_stride(&self, wave64: bool) -> u32 {

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.

Not certain about this one, because it depends on unverified hardware behaviour: group_stride changes v5's per-group step from the declared threads to the rounded launch width for every mesh program where they differ, including ones that worked before. A wave64 program with threads=64, max_vertices=128 that decodes its group as v5 >> 6 used to see group 1 at v5=64, but now sees v5=128 and decodes it as group 2, reading the wrong per-group data. A 32-thread wave64 program now steps by 64 instead of 32. The test fixture decodes v5 >> 7, which matches the new assumption by construction, so it doesn't confirm the console behaves this way.

@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 2, 2026
KDenKC added a commit to KDenKC/xcl that referenced this pull request Dec 2, 2026
Launch enough whole console waves to cover max(threads, max_vertices, max_primitives), keep EXEC at entry limited to the declared threads, and use the launched width as v5's per-group step in both backends. Compute programs are unchanged.

Update mesh shader surveys and barrier fixtures to use the launched width. Add CPU coverage for output extents and wave rounding, plus a two-group GPU draw that checks the v5 step and matching records and pixels from HLSL and direct DXIL.

Checked: xcl-dev#3350 review 7325409956, xcl-dev#3011 C54, and xcl-dev#3327 interaction.
KDenKC added a commit to KDenKC/xcl that referenced this pull request Dec 2, 2026
Checked: xcl-dev#3350 review 6143189220 and the existing two-pass mesh test path before adjusting the regression fixture. The test now has wave 0 write the expected header and gives the empty wave a distinct M0 value, so an overwrite is observable without relying on a seeded output buffer.
@KDenKC
KDenKC force-pushed the fix/two-pass-mesh-whole-waves branch from 572f7ea to 2ed87b0 Compare December 2, 2026 03:19
@KDenKC

KDenKC commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@bmjask thanks for the review. The fixes are pushed: head 2ed87b02, rebased on main 1c8b5514.

  1. The fix keeps the entry EXEC mask limited to the declared mesh threads. The regression makes wave 0 write [5, 2], while the additional empty wave has a distinct [9, 3] allocation request. An unconditional store by that empty wave would change the recorded header. The final fixture skips the whole literal instruction. On the RTX 3090 VM, cargo test -p xcl --lib -- gpu_mesh_ignores_alloc_req_from_empty_wave --nocapture --test-threads=1 passed 1/1, with no skip. (Run on c5ed6994, the same change before the rebase.)
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 2772 filtered out; finished in 1.55s
  1. We keep the entry mask tied to the declared thread count in both generated HLSL and direct DXIL (emit.rs mesh entry; kernel.rs::mesh_entry_exec). Extra launched lanes can contribute only when guest code explicitly widens EXEC. The captured corpus does not contain the proposed smaller-thread/larger-output shape, so it cannot independently confirm that edge case's hardware behavior.

  2. Group stride covers the whole launched wave range (MsInterface::group_stride), preventing adjacent groups from reusing v5 values when output extents exceed the declared threads. The two CPU tests cover output extents and whole-wave rounding; the two-pass GPU test checks multiple groups through both backends. I counted 327 unique program hashes in the push-5 mesh-census lines; every one has wave64, 128 threads, 128 max vertices, 128 max primitives, and reads v5. Thus the changed formula still gives the observed title programs a stride of 128. No captured title program exercises a changed stride; broader hardware semantics remain unmeasured.

Raw census evidence:

[  189.961][12388][INFO ] mesh census: program 2bdc6171bf337731: threads 128, max_vertices 128, max_primitives 128, wave64 true, reads v5 true

The performance cost of launching the additional waves has not been measured. The smoke pair in the description is for 572f7eab; a new pair for 2ed87b02 follows when our RTX 5090 is free.

Current-main validation: all three focused filters passed on 2ed87b02. The first four-thread workspace suite's lib test process crashed with 0xc0000005; the second suite completed with the same five failures as main. Two isolated four-thread lib runs, on the head and on main, both completed without a crash, with the same four title_textures failures; over full suites the head's lib process crashed once in three runs and main's in none of two, so the intermittent access violation is not attributable from this evidence.

unittests src\lib.rs [xcl-081dd78a5d5f7d1b]: NO RESULT (KILLED, exit code 0xc0000005, STATUS_ACCESS_VIOLATION)
counts: 2905 passed, 5 failed, 51 ignored over the binaries with a result; 0 binaries without a result

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 2ed87b0, since 572f7ea, diff read, not a merge-check; checks red):

  • compute_init emits tid < total instead of true: still fixed; eed11c09 is 572f7eab rebased unchanged.
  • The split pass-through draw is no longer tested; the stride_ms block repeats the first draw: still open (tests.rs ~4614-4648 unchanged).
  • Tested and Regression run are for an old head: partly fixed. The description now says v5's step changes for programs that never widen EXEC and lists the CPU tests, but the suite, focused runs and smoke blocks are still for 572f7eab, the new test has no reported run, and "One commit" is now wrong; PR description is red for the missing block on 2ed87b02.

New:

  • The new test is not sure to fail without the fix. In gpu_mesh_ignores_alloc_req_from_empty_wave (tests.rs ~4656-4697), lane 0 of wave 0 and lane 0 of wave 1 both store the header dwords with nothing ordering them, so without the EXEC gate the test still reads [5, 2] whenever wave 0's store lands last.
  • 2ed87b02 fixes a defect eed11c09 adds; it should be squashed into it. On main a mesh group launches only its declared threads, so no wave starts with an empty EXEC; the extra whole waves come from eed11c09 (launch_threads, mod.rs ~367-374; xcl_slot < threads, emit.rs ~5413). At that commit alone an empty wave's GS_ALLOC_REQ can overwrite the header, so the first commit does not stand on its own.
  • Code the fix does not need. runner.rs ~1305-1348 moves mesh_draw_split's body into a new mesh_draw_split_impl with no behaviour change, and mesh_sendmsg (lower_mem.rs ~2656-2665) rebuilds this lane's EXEC bit by hand instead of using self.act() (lower.rs ~940), which also honours guard_override.

Fine: both backends apply the same gate (console lane 0 with its EXEC bit set; exec_lo & 1u in HLSL), and the fixture's wave-index S_BFE of s3 matches the xcl_wave << 24 the mesh entry writes.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@bmjask bmjask 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 2ed87b02: 2 finding(s).

Re-review after the new commit (2ed87b02). Still open from my earlier review: the v5 group_stride change for programs that never needed widening (recomp/mod.rs ~379; e.g. wave64 32/32/32 now steps 64, wave32 48/48/48 steps 64), which nothing has checked against console behaviour. The header race from last time is now gated on EXEC, which raises the two points below. 2 are inline.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

Comment thread crates/xcl/src/gpu/dxil/lower_mem.rs Outdated
let b1 = self.andc(bit, 1);
let live = self.cmpc(Pred::Ne, b1, 0);
let lane0 = self.cmpc(Pred::Eq, lane, 0);
let first = self.land(lane0, live);

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.

GS_ALLOC_REQ now writes the record header only if lane 0's own EXEC bit is set (direct DXIL lane0 && live, HLSL lane_id == 0u && (exec_lo & 1u) at emit.rs:1379). Before, wave 0 wrote it unconditionally, which matches s_sendmsg being a scalar instruction that ignores EXEC. If a declared-thread wave 0 narrows EXEC before s_sendmsg so lane 0 is inactive (v_cmpx / s_and_saveexec on a per-thread condition), the header store is skipped. nv/np stay 0 or stale, and the passthrough drops the meshlet's triangles in programs that worked before.

Comment thread crates/xcl/src/gpu/recomp/emit.rs Outdated
let m0 = self.sreg(124);
self.line(&format!(
"if (lane_id == 0u) {{ res.Store(xcl_rec * 4u, {m0} & 0x3FFu); res.Store(xcl_rec * 4u + 4u, ({m0} >> 12) & 0x7FFu); }}"
"if (lane_id == 0u && (exec_lo & 1u) != 0u) {{ res.Store(xcl_rec * 4u, {m0} & 0x3FFu); res.Store(xcl_rec * 4u + 4u, ({m0} >> 12) & 0x7FFu); }}"

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.

Gating on EXEC only holds while the extra waves keep an empty EXEC, but this PR exists for programs that widen it. A mesh program that does s_mov_b64 exec, -1 early (the case gpu_mesh_two_pass_widens_exec_past_declared_threads covers) and runs GS_ALLOC_REQ in every wave with a wave-dependent M0 has lane 0 live in the extra wave. That wave races wave 0 on the vertex/primitive counts, and the last writer wins. Gating the header on the console wave index (xcl_wave == 0 in HLSL, wave == 0 in mesh_init) handles both this and the lane-0-masked case above.

@KDenKC
KDenKC force-pushed the fix/two-pass-mesh-whole-waves branch from 2ed87b0 to 590f06d Compare December 2, 2026 04:00
@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 2, 2026
@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 590f06d, since 2ed87b0, diff read, not a merge-check):

  • The new test is not sure to fail without the fix: fixed. gpu_mesh_alloc_req_uses_wave0_independent_of_exec (gpu/recomp/tests.rs ~4659) orders the two waves' stores with an S_BARRIER (wave 0 stores before it with an empty EXEC, wave 1 widens EXEC and stores after it), and a negative control without the wave-0 guard reads wave 1's header.
  • The second commit fixed a defect the first one added: fixed; one commit. GS_ALLOC_REQ is now stored by lane 0 of console wave 0 whatever its EXEC (lower_mem.rs ~2655-2660, emit.rs ~1378), on both backends.
  • Code the fix did not need: fixed; mesh_draw_split_impl and the hand-rolled EXEC test are gone.
  • The split pass-through draw is no longer tested: fixed. gpu_mesh_mode_two_passes draws the split pass-through with its own 128/128/128 MsInterface (~4641-4651) and asserts split == 4 again.
  • Tested and Regression run are for an old head: still open; the description says the smoke pair for 590f06db is pending (the reason PR description is red).

New: none. The doc comment of the test (~4654-4656) still describes the old rule ("must not write the record header" from an empty wave).

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@KDenKC

KDenKC commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@bmjask thanks for the follow-up. The fixes are pushed in 590f06db on main 1c8b5514.

  1. GS_ALLOC_REQ is a per-group header write, so wave 0 is the sole sender, independent of EXEC. The direct-DXIL path retains the console wave index in the mesh context; HLSL uses xcl_wave. The GPU fixture narrows EXEC to zero in wave 0 before its send, then widens EXEC in wave 1 before its later send. A group barrier orders those writes. The in-test unguarded HLSL control deterministically leaves [9, 3]; the guarded HLSL and direct-DXIL paths leave [5, 2].

  2. The wave-0 condition handles both cases in one fixture: the declared wave still writes after narrowing EXEC, and the extra wave cannot overwrite the header after widening EXEC. This avoids using EXEC as the sender predicate.

  3. The corpus count is 327 distinct mesh programs: all 327 are wave64 with 128 threads, 128 max vertices and 128 max primitives, and all read v5. Their stride remains 128, so none exercises a changed v5 step. No 32/32/32 program was present in this census; on wave64 that shape now uses stride 64, and its title behavior remains unobserved. The extra-wave performance cost also remains unmeasured.

[  189.961][12388][INFO ] mesh census: program 2bdc6171bf337731: threads 128, max_vertices 128, max_primitives 128, wave64 true, reads v5 true

On the RTX 3090 VM, mesh_group_stride passed 2/2, gpu_mesh_alloc_req_uses_wave0_independent_of_exec passed 1/1, and gpu_mesh_mode_two_passes passed 1/1, with no skips. The workspace suite completed with 2,905 passed, 5 failed and 51 ignored; its five failures were the same four title_textures tests and test_title_runs_and_game_folder_is_untouched seen on main 1c8b5514. No binary crashed.

The existing smoke blocks remain labeled as 572f7eab; a new pair for 590f06db is pending while the 5090 rig is paused.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

@bmjask bmjask 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 590f06db: 1 finding(s).

Re-review at 590f06db. The header is now written by wave 0, which fixes the lane-0 and widening races from my last review. Still open from earlier: entry EXEC is still limited to the declared threads (kernel.rs ~1375 / emit.rs:5412). A program that saves and restores its entry EXEC (s_and_saveexec_b64 ... ; s_or_b64 exec, exec, s[0:1]) rather than setting all lanes still drops exports from lanes >= threads. The group_stride change also has no console reference (recomp/mod.rs ~379). New finding: 1 are inline.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

let lane0 = self.cmpc(Pred::Eq, lane, 0);
let wave = self.mesh.as_ref().expect("mesh").wave;
let wave0 = self.cmpc(Pred::Eq, wave, 0);
let first = self.land(lane0, wave0);

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.

Not certain about this one: with the header written only by wave 0 (also emit.rs:1378), a program whose GS_ALLOC_REQ sits in a block wave 0 skips never writes it. That happens with an execz branch taken because wave 0's lanes are all done, or a capped loop that ends wave 0's lanes early in direct DXIL, which the PR notes as open. Header dwords 0/1 stay zero or hold the previous frame's counts, so the passthrough reads nv/np = 0 or stale. Before, any wave's lane 0 still wrote it. Writing it from the first wave that reaches s_sendmsg (e.g. a per-group flag) would cover both.

@KDenKC

KDenKC commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@bmjask the ISA does not state that GS_ALLOC_REQ must come from wave 0 or be issued in group-uniform control flow. It defines message 0x09 and its vertex/primitive counts; the allocation response is broadcast to the workgroup. NGG lowering sends the request before exports, with a wave-ID argument. Wave 0 as the sole writer is xcl's record-header convention, not an ISA requirement. AMD RDNA 3 ISA, Send Message Types (the RDNA 2 document defines the same message) AMD GPUOpen mesh shader optimization

The 327-program census log records metadata, not disassemblies. I could not map its program IDs to the local target-dump hashes, so I cannot claim a complete branch/loop scan of all 327. In the available best3-retire0 dump set, there are 301 mesh disassembly files (78 distinct MS hashes); each has one s_sendmsg 0x9. A control-flow-range scan found no SCC/VCC branch or loop back-edge enclosing it. Each is under the generated EXEC-zero lane-0 election guard, e.g.:

0000375c: v_cmpx_eq_u32 0, v0
00003760: s_cbranch_execz 0x3798
00003764: s_lshl_b32 s7, s7, 12
00003768: s_andn2_b64 vcc, exec, s[2:3]
0000376c: s_or_b32 s6, s7, s6
00003770: s_mov_b32 m0, s6
00003774: s_sendmsg 0x9

v_cmpx_eq_u32 0, v0 keeps only the lane whose thread ID (v0) is 0, i.e. lane 0 of wave 0, so in these programs the title itself sends GS_ALLOC_REQ from wave 0 only, which is the case the wave-0 rule follows; it is the lane election around the message, not a guest branch or loop that could skip the allocation in wave 0. I found no corpus evidence requiring another code change. The 327-wide claim remains unverified until we have disassemblies keyed to those census records; please treat the current evidence as limited to the 301 dumped files.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

@KDenKC

KDenKC commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@fromthemoonx the xcl-smoke pair is in the description now, for the final head 590f06db (bmjask's and Foniass's points folded in): main 1c8b5514 1724 frames, head 1964 frames, no device removal or crash in either, peak commit 47,581 vs 48,740 MB; PR description is green.

AI use: an agent swarm: Claude Opus 5.5, Claude Sonnet 5.5, GPT-6.2-Sol, Gemini 4 Neon and Gemini 4 Hydrogen.

@fromthemoonx

Copy link
Copy Markdown

@KDenKC thanks for the smoke pair. 590f06db passed here on the main of an hour ago, but main has since moved (b0b44546, mesh producers as dispatch chains) and the PR now conflicts in kernel.rs. When you rebase, main's new ms.threads % 64 condition probably needs your launched thread count instead. Details in the updated report: #3350 (comment)

AI use: Claude Code (Claude Opus 5.5) ran the checks and wrote this.

@github-actions github-actions Bot added the needs-rebase Has merge conflicts with its base branch label Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation area:tests Unit, integration, e2e tests, or testtitle gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs-rebase Has merge conflicts with its base branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants