Skip to content

GPU: number bounded indirect mesh groups consecutively - #2996

Open
andrewpozdnakov7-jpg wants to merge 2 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex1/indirect-mesh-grid
Open

andrewpozdnakov7-jpg wants to merge 2 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex1/indirect-mesh-grid

Conversation

@andrewpozdnakov7-jpg

@andrewpozdnakov7-jpg andrewpozdnakov7-jpg commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Indirect mesh commands carry three group counts. VIctory's translated mesh input MeshGroup reads the host's SV_GroupID.x and applies the shader's stride. Flattening every record to its original X count loses work. Passing the full grid through leaves X repeated across Y and Z.

The clamp now uses [x*y*z, 1, 1] for grids within the existing 65,535-group per-record ceiling. This gives each translated group its own index. Oversized records keep the original bounded fallback. The list budget still uses the work charged to each record.

  • Same synthetic translated mesh shader on the earlier PR head 9a851cd, through the ordinary State::execute_indirect path: an atomic counter for each MeshGroup records eight hits in each of the first three slots and zero in the remaining 21.
  • On 5385cc6, each of the 24 slots receives one hit. Six paired WARP runs agreed. The argument-buffer test covers empty and oversized inputs plus list budget exhaustion.
  • Full GPU suite on WARP: 248 passed and one ignored in each run. Strict GPU Clippy and the asset policy passed.

This covers VIctory's translated indirect mesh path. #2624 covers direct mesh calls, whose translated group-index behavior needs its own check. #2472's batched clamp needs the same indirect rule if combined.

Coordination · D3D12 mesh indirect argument specification

If you move the patch, please keep its Git author. If you combine it with another commit, please include:

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

AI-assisted with Codex. Synthetic GPU inputs.

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM — the fallback min(g, uint3(65535,1,1)) is elementwise, so oversized grids collapse to (x,1,1) not (65535,1,1) — the test's (257,256,1)→(257,1,1) and (u32::MAX,2,3)→(65535,1,1) both confirm. Overflow analysis holds: the per-axis check makes the product check unreachable when x or y exceeds 65535, so g.xg.y ≤ 65535² fits u32; dividing the ceiling by z avoids xyz overflow. Kept grids charge xyz128 — same 65535-group ceiling, so the budget semantics are preserved exactly (the test's 65532-group records → 16 of 18 run). The clamped_words refactor asserting fields <= per keeps the read-back honest.

@steven-seagull27

Copy link
Copy Markdown

Confirmed the missing groups at execution time on both RTX 5080 and Microsoft WARP. I ran a mesh shader that increments a separate counter for each SV_GroupID. I compared native DispatchMesh with the production clamp followed by ExecuteIndirect, then checked all 64 coordinate counters against CPU enumeration. The largest grid dimension was four.

Input records Direct groups Indirect on 63bcca43 Indirect on 9a851cd3
One (3,2,4), 12-byte stride 24 3 24
(2,3,1) and (1,1,2), 16-byte stride 8 3 8
66 small grids crossing the clamp's 64-record boundary, 20-byte stride 512 132 512

Both adapters gave the same results. At the PR head, every coordinate matched direct dispatch, including both visits to the origin in the two-record case. The input argument buffers also remained byte-identical.

@oni-swr

oni-swr commented Nov 26, 2026

Copy link
Copy Markdown

Independent Windows WARP test run of 9a851cd3c00d94fcf13b9825d1b98673a1de0cf5, compared with its exact parent 63bcca43c6a00a758510398fa43096ce7e4f7df0. This reports test results only, not a review verdict.

Setup. Software only. VICTORY_D3D12_WARP=1 and VICTORY_WARP=1, built with --features diagnostics (WARP selection in victory-gpu is behind that feature). VICTORY_DXIL pointed at the Windows SDK 10.0.26100.0 x64 dxil.dll, but the victory-gpu lib tests never loaded it: a probe found no dxil.dll module in the process. Before any dispatch, each probe checked that the host device's adapter LUID matches EnumWarpAdapter: Microsoft Basic Render Driver, vendor 0x1414, device 0x8c, software flag set. No hardware GPU was used. No game files, dumps or shader data, only synthetic arguments.

Command. cargo test --locked -j 4 -p victory-gpu --features diagnostics --lib -- --test-threads=1, plus filtered runs (probe_attest, probe_, indirect::).

Local probes (not pushed). They run the production clamp through bound/done and read back all three words of every mesh record:

Probe Parent 63bcca4 Head 9a851cd3
Grids within the 65,535-group ceiling keep x/y/z: [5,7,9], [2,2,2], [255,257,1] (exactly 65,535), [1,1,65535] and [3,5,4369] (the z-division edge), [0,9,9], [65535,65535,0]. Over-ceiling or over-axis grids fall back: [256,256,1]→[256,1,1], [2,1,65535]→[2,1,1], [1,1,65536]→[1,1,1], [70000,2,2] and u32::MAX³→[65535,1,1] fails: every y/z becomes 1 ([5,1,1], …, [65535,1,0]) passes
40 records of [32,32,32] (32,768 groups each) against the 2^20-group list budget: exactly 32 run, 8 run empty fails: 40 run as [32,1,1] passes: 32 run
Budget shared across two clamp calls in one list, 20 × [64,64,8]: the second call has 12 left fails: 20 run passes: 12 run
Control: 17 × [65535,2,1] charged at the fallback size, 16 run passes passes

Counts.

  • indirect:: on the head: 11 passed (the 7 module tests, including mesh_clamp_keeps_group_grid_and_charges_all_axes, plus the 4 probes).
  • Full victory-gpu lib suite on the head: 247 of the tree's 248 tests passed, 1 ignored (benchmark_private_data_release). The suite total also included the WARP attestation probe and 4 unrelated local ClearState probes for GPU: implement ClearState on command lists #2984, which fail here as they do on the parent.
  • Parent: 246 passed, 1 ignored. The 3 grid/budget probes failed as shown above. The fallback control passed.

AI-assisted: Claude Code (Claude Opus 5.5), coordinated by Codex (gpt-6.2-sol).

@fuzeofficlal fuzeofficlal 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.

Code review on 9a851cd3 (static source inspection; no runtime GPU execution):

  • High — Multi-axis indirect mesh grids alias SV_GroupID.x across all Y/Z slices (crates/victory-gpu/src/indirect.rs, crates/victory-shader/src/emit/lower.rs:1498-1504):
    • Keeping all three grid axes (x, y, z) in the clamped argument buffer passes multi-axis grids directly to ExecuteIndirect (draw.rs:1811).
    • However, emit/lower.rs:1498-1504 still lowers Input::MeshGroup strictly as groupId.i32(0) * mesh_stride (SV_GroupID.x * mesh_stride), ignoring SV_GroupID.y and SV_GroupID.z.
    • For a grid like (3, 2, 4), the host launches 24 threadgroups, but every (y, z) slice receives the same three MeshGroup indices (0, 1, 2 × mesh_stride), processing the first three meshlets 8 times instead of 24 distinct groups. The new unit test reads back only the clamped argument buffer and does not execute a mesh shader consuming Input::MeshGroup.
    • Please verify the console's multi-axis mesh group numbering and either lower Input::MeshGroup across (x, y, z) or linearize the grid before launching multi-axis DispatchMesh grids (with a mesh-shader execution test consuming Input::MeshGroup).

@andrewpozdnakov7-jpg andrewpozdnakov7-jpg changed the title GPU: keep the group grid in bounded indirect mesh dispatches GPU: number bounded indirect mesh groups consecutively Nov 26, 2026
@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

I reproduced the repeated indices from your review using a translated mesh program that reads Input::MeshGroup and atomically adds to a counter for that group. The program runs through VIctory's normal indirect execution path. The same 3×2×4 record touches only the first three counters, eight times each, on 9a851cd.

5385cc6 gives one hit to each of the 24 counters by dispatching the bounded count along X. The test verifies the supported VIctory scalar input path. Console hardware numbering for multidimensional calls remains unverified. The oversized fallback and work limits are covered separately by GPU argument-buffer readback tests.

Six paired WARP runs agreed. Full GPU suite 248 passed and one ignored, both strict GPU Clippy configurations and policy passed. The branch also merges cleanly with #2624 and current main.

Please preserve the Git author if you cherry-pick this follow-up, or add this trailer if the fix or fixture is folded into another commit.

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

AI-assisted with Codex.

@steven-seagull27

Copy link
Copy Markdown

@andrewpozdnakov7-jpg I verified 5385cc6 with the batch path from #2472. Inline handed a translated (3,2,4) mesh 24 distinct scalar group indices. Our previous batch integration still repeated three indices eight times each. I carried your normalization into the batch kernel and retained your original commit and authorship. RTX 5080 and WARP now agree on all 64 counters for each of the three record sets, including 66 records across the batch boundary. Full results and combined branch

Marvisak commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Verdict: needs work. The change is in the mesh arm of the clamp shader in crates/victory-gpu/src/indirect.rs. In-budget records now become [x*y*z, 1, 1] instead of [min(x, 65535), 1, 1]. Oversized records keep the old fallback, and the list budget is charged for every axis. The new test indirect_mesh_visits_each_translated_group_index (pipeline/host.rs) shows each translated MeshGroup index visited once for a (3,2,4) record. The HLSL looks right: x*y can't overflow once each axis is at most 65,535, and the total is checked by dividing by z.

What's missing is evidence about the console. The comment this replaces on main says the console's mesh dispatches are one-dimensional. If that holds, y = z = 1 and this PR changes nothing for the title. If it doesn't, the result depends on how the console numbers the groups of a multi-dimensional dispatch. Your own follow-up says that numbering is unverified. Row-major linearisation is a guess the test can't confirm, because the test only checks that VIctory's own scalar index is unique.

To change the verdict, show one of:

  • that the title issues indirect mesh records with y or z above 1, for example from VICTORY_DUMP_ARGUMENTS-style logging or the frame trace;
  • a hardware or documentation reference for how the console derives the mesh group index from a 3D grid.

With either, this is a clear fix. The budget accounting part is independently sound.

CI: passing (check).


Generated by Claude Code

@wwwwwwww3333333

Copy link
Copy Markdown
Contributor

AMD hardware run of 5385cc6 (on main 63bcca4). RX 6750 XT (RDNA2), driver 32.0.21045.29003, Windows 11, Rust 1.98.1.

cargo test -p victory-gpu --lib -- pipeline::host::tests::indirect_mesh_visits_each_translated_group_index --exact, hardware adapter, three runs:

  • run 1: the test process died with STATUS_STACK_BUFFER_OVERRUN (0xC0000409);
  • run 2: it returned after 26.5 s with 24 zeros where the test expects 24 ones;
  • run 3: the same 0xC0000409 as run 1.

The display went black for a moment during the first runs and came back. The same test passes on WARP (three runs out of three). The other four tests of that module pass on the hardware adapter without it.

I have not separated whether this comes from the change or from indirect mesh dispatch on this driver, because I did not run the same test on main. The test is new, so main has nothing to compare with. I'd treat it as "unverified on RDNA2" and not as a regression.

Unit tests only, no game files.

@fuzeofficlal fuzeofficlal 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.

5385cc62 cleanly addresses the Input::MeshGroup aliasing issue from the earlier review on 9a851cd3:

  • Bounded multi-axis indirect mesh grids are now linearized to [g.x * g.y * g.z, 1, 1] in crates/victory-gpu/src/indirect.rs, giving each translated MeshGroup a distinct consecutive index while preserving overflow-safe bounds checks (g.x * g.y fits in u32 once g <= 65535, zero axes yield [0, 1, 1] with cost 0, oversized grids keep the existing fallback, and the list budget charges 128 per group).
  • pipeline::host::tests::indirect_mesh_visits_each_translated_group_index executes a translated GFX10 mesh shader reading Input::MeshGroup through State::execute_indirect and verifies all 24 slots for a (3, 2, 4) grid receive exactly one hit.

Verified locally on Windows 11 (RTX 5090 + WARP + D3D12 Debug Layer):

  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --all-features): clean
  • RTX 5090: indirect:: 7/7 passed; indirect_mesh_visits_each_translated_group_index 3/3 passed
  • RTX 5090 + VICTORY_D3D12_DEBUG=1 (--features diagnostics): indirect_mesh_visits_each_translated_group_index 1/1 passed
  • WARP + VICTORY_D3D12_DEBUG=1 (--features diagnostics, VICTORY_D3D12_WARP=1): indirect:: + indirect_mesh_visits_each_translated_group_index 8/8 passed
  • cargo xtask policy: 191 files ok

(Note for maintainers: while RTX 5090 and WARP pass cleanly here including under the D3D12 Debug Layer, see the AMD RX 6750 XT report above on the new mesh test in case AMD drivers dislike a pixel-shader-less / outputs: [] mesh test pipeline.)

LGTM.

@wwwwwwww3333333

Copy link
Copy Markdown
Contributor

A note on the approval above, in case it was written from the WARP/NVIDIA result: the AMD run in my earlier comment is still the open item for 5385cc6. On the RX 6750 XT (driver 32.0.21045.29003) indirect_mesh_visits_each_translated_group_index on the hardware adapter ended with STATUS_STACK_BUFFER_OVERRUN (0xC0000409) in two of three runs and returned 24 zeros instead of 24 ones in the third, while WARP passed three out of three. I have not found the cause and I am not claiming the linearization is wrong. It is the one result I have that disagrees with the passing runs, so it may be worth another AMD or non-NVIDIA run before merging. Happy to rerun any build you want me to try.

@steven-seagull27

Copy link
Copy Markdown

@wwwwwwww3333333, thanks for offering to rerun this on the RX 6750 XT. I adapted Andrew’s translated mesh fixture so you can test the same shader, pipeline, UAV and readback on upstream 63bcca43 and this PR’s 5385cc62. Each command runs one fresh process and prints all 24 counters before releasing the resources. Test commit · Download patch

RTX 5080 and Windows WARP agreed in two runs per case on each revision (24 processes total).

Dispatch Upstream base PR head
Direct (24,1,1) All 24 counters hit once All 24 hit once
Indirect (24,1,1) All 24 hit once All 24 hit once
Indirect (3,2,4) Counters 0–2 hit once, 3–23 stayed zero All 24 hit once

From your VIctory checkout in PowerShell, prepare both worktrees.

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2996-rdna2-mesh-controls
git worktree add --detach ..\mesh2996-head 338064395afd7609b894d703510f3d61230a72c6
git worktree add --detach ..\mesh2996-base 63bcca43c6a00a758510398fa43096ce7e4f7df0
git -C ..\mesh2996-base cherry-pick --no-commit 338064395afd7609b894d703510f3d61230a72c6

In the same shell, run this with $tree = 'base', then with 'head'. Hardware uses VICTORY_D3D12_WARP=0. Set it to 1 for the WARP comparison.

$tree = 'base'
$env:MESH2996_EXPECT_X_ONLY = if ($tree -eq 'base') { '1' } else { '0' }
$env:VICTORY_D3D12_WARP = '0'
$env:VICTORY_D3D12_DEBUG = '1'
foreach ($case in 'direct_24x1x1', 'indirect_24x1x1', 'indirect_3x2x4') {
    cargo test --manifest-path "..\mesh2996-$tree\Cargo.toml" --locked -p victory-gpu --features diagnostics --lib "pipeline::host::mesh2996::$case" -- --exact --nocapture --test-threads=1
    if ($LASTEXITCODE -ne 0) { break }
}

Could you share the revision, first failing case, last MESH_ line and exit code, or the three readbacks if they pass? A failure on direct dispatch would reproduce the problem without the indirect clamp. If direct passes, the one-dimensional indirect control distinguishes a general indirect failure from one specific to the three-dimensional record.

AI-assisted with Codex. Synthetic inputs only.

@wwwwwwww3333333

Copy link
Copy Markdown
Contributor

@steven-seagull27 thanks for the fixture. I ran it on the RX 6750 XT (RDNA2, driver 32.0.21045.29003, Windows 11) with VICTORY_D3D12_WARP=0; MESH_DEVICE reported the RX 6750 XT in the runs below.

Upstream 63bcca4 + test commit 3380643: direct_24x1x1 run 1 died with 0xC0000409 right after MESH_SUBMIT, run 2 read back all 24 counters as 0; indirect_24x1x1 the same (0xC0000409, then all zeros); indirect_3x2x4 run 1 all zeros.

PR head 5385cc6 + the same test commit, after a reboot: direct_24x1x1 died with 0xC0000409 right after MESH_SUBMIT (the script stopped there, so the other two cases were not run on the head).

So the direct dispatch already fails on this GPU on both revisions, without the indirect clamp involved. I do not know the cause. After the first failures on the base, a few runs came up on the Microsoft Basic Render Driver after the display driver reset (the display went black a few times), so I am not reporting those.

@Calvix2k

Copy link
Copy Markdown
Contributor

Supporting measurement for the direction: in the prologue's heavy view the card is ~40% of the frame (94-113 ms on an RX 7800 XT), and 350-600 draws a frame are still dropped without a host pipeline. The published Kelvaroq patch series measures 58-94 ms of card time for 4,500-6,400 indirect mesh draws when each record goes through the per-record clamp (~14 us each) against ~4 us when the group count is known up front (0041, launching through an amplification stage). Numbering the groups consecutively is the cheap half of that win and does not need the new stage.

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

Thanks for rerunning the controls on the RX 6750 XT. With the same fixture, direct (24,1,1) dispatch failed on both 63bcca43 and 5385cc6. That control runs without the indirect clamp. The run on 5385cc6 stopped at the direct case, so the indirect cases on that head remain unverified on this adapter. AMD retest

Slay326 added a commit to Slay326/VIctory that referenced this pull request Nov 26, 2026
Regression test for the case reported on Marvisak#3197 together
with Marvisak#2996 (5385cc6).
Slay326 added a commit to Slay326/VIctory that referenced this pull request Nov 26, 2026
The window's pass carried its own copy of the mesh bounds; a change to
the single clamp's rule (Marvisak#2996, 5385cc6) left the window
on the old one and dropped mesh groups (reported on Marvisak#3197). Both shaders
now take the rule from one HLSL function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants