gpu: reject meshlet max_vertices below 3 #2811

Manually merged
github merged 1 commit from gh-pr/2811/head into gh-pr/2811/base 2026-11-27 01:24:31 +00:00
Owner

@⁠RenzoWit35 on GitHub · 2026-11-26 11:02 UTC · original
RenzoWit35:gpu/meshlet-builder-vertex-limit → main · +46 −2 · 3 files · 1 commits · merged 2026-11-26 11:08 UTC

Change

build_meshlets accepted max_vertices of 1 or 2 but always places the first triangle of a meshlet, so it returned meshlets whose vertex_count was 3 (2 for a triangle that repeats a vertex), above the requested limit. A triangle can need three vertex slots, so the argument check now requires max_vertices in [3, 256] (same std::invalid_argument, message updated). The header comment documents both ranges and that no meshlet exceeds either limit.

With realistic limits (the defaults 64/126, or anything >= 3) the builder is unaffected; this closes the documented range. No caller passes a value below 3: the callers use the defaults, kMaxMeshletVertices, or kHardwareMaxMeshletVertices.

Verification

Before (current origin/main source, scratch probe built with cl):

  • max_vertices 1 and 2 on a triangle list: max vertex_count 3, exceeds the limit.
  • Repeated-vertex triangles: {0,0,0,1,1,2} with max_vertices 1 gives 2 vertices; {0,0,1} with 1 gives 2 vertices.
  • Not affected: max_vertices 3 (max 3), max_primitives 1 (max 1 per meshlet), max_vertices 2 with repeated-vertex triangles that use at most 2 vertices.

After: cmake --build out/build/dev --target meshlet_builder_check, then ctest --test-dir out/build/dev --no-tests=error -R meshlet_builder --timeout 180: 1/1 passed.

Negative control: the new tests/meshlet_builder_check.cpp compiled against origin/main's src/meshlet_builder.cpp fails with meshlet_builder_check failed: max_vertices=1 rejected (exit 1). The new small-limit property tests (3/126, 64/1, 4/2, 256/256, defaults, repeated-vertex triangles) pass on both sources.

Not run: the D3D12 tests that use the builder (mesh_shader_pipeline_draw, offscreen checks); they only pass limits >= 3 and no hardware tests were run.

Evidence and follow-up

The header never promised that the first triangle is always emitted, so enforcing the limit is the documented behavior. Rejecting below 3 also rejects inputs made only of repeated-vertex triangles that would fit in 1 or 2 slots; none exist in the callers. No open PR touches the meshlet builder (gh pr list --search meshlet: only merged #2462 and #1203).

AI-assisted.

**@⁠RenzoWit35** on GitHub · 2026-11-26 11:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2811) `RenzoWit35:gpu/meshlet-builder-vertex-limit` → `main` · +46 −2 · 3 files · 1 commits · merged 2026-11-26 11:08 UTC ## Change `build_meshlets` accepted `max_vertices` of 1 or 2 but always places the first triangle of a meshlet, so it returned meshlets whose `vertex_count` was 3 (2 for a triangle that repeats a vertex), above the requested limit. A triangle can need three vertex slots, so the argument check now requires `max_vertices` in [3, 256] (same `std::invalid_argument`, message updated). The header comment documents both ranges and that no meshlet exceeds either limit. With realistic limits (the defaults 64/126, or anything >= 3) the builder is unaffected; this closes the documented range. No caller passes a value below 3: the callers use the defaults, `kMaxMeshletVertices`, or `kHardwareMaxMeshletVertices`. ## Verification Before (current `origin/main` source, scratch probe built with `cl`): - `max_vertices` 1 and 2 on a triangle list: max `vertex_count` 3, exceeds the limit. - Repeated-vertex triangles: `{0,0,0,1,1,2}` with `max_vertices` 1 gives 2 vertices; `{0,0,1}` with 1 gives 2 vertices. - Not affected: `max_vertices` 3 (max 3), `max_primitives` 1 (max 1 per meshlet), `max_vertices` 2 with repeated-vertex triangles that use at most 2 vertices. After: `cmake --build out/build/dev --target meshlet_builder_check`, then `ctest --test-dir out/build/dev --no-tests=error -R meshlet_builder --timeout 180`: 1/1 passed. Negative control: the new `tests/meshlet_builder_check.cpp` compiled against `origin/main`'s `src/meshlet_builder.cpp` fails with `meshlet_builder_check failed: max_vertices=1 rejected` (exit 1). The new small-limit property tests (3/126, 64/1, 4/2, 256/256, defaults, repeated-vertex triangles) pass on both sources. Not run: the D3D12 tests that use the builder (`mesh_shader_pipeline_draw`, offscreen checks); they only pass limits >= 3 and no hardware tests were run. ## Evidence and follow-up The header never promised that the first triangle is always emitted, so enforcing the limit is the documented behavior. Rejecting below 3 also rejects inputs made only of repeated-vertex triangles that would fit in 1 or 2 slots; none exist in the callers. No open PR touches the meshlet builder (`gh pr list --search meshlet`: only merged #2462 and #1203). AI-assisted.
build_meshlets always places the first triangle of a meshlet, so
max_vertices of 1 or 2 produced meshlets with 3 vertices (2 for
triangles that repeat a vertex), above the requested limit. A
triangle can need three vertex slots, so the valid range is now
[3, 256]. The header comment documents the range and the
no-meshlet-exceeds-a-limit guarantee. The check covers the new
rejections, max_vertices=3, max_primitives=1 and repeated-vertex
triangles under small limits.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:24:28 +00:00
github manually merged commit bee8e7c37e into gh-pr/2811/base 2026-11-27 01:24:31 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 11:07 UTC · original · reviewed

Review of head bee8e7c3.

Checked:

  • src/meshlet_builder.cpp:199: the range check is now [3, 256]. The old check let max_vertices of 1 or 2 through, but the first triangle of a meshlet is always placed, so vertex_count could go above the limit. The new bound closes that.
  • The only other callsite (meshlet_builder.cpp:306) uses kMaxMeshletVertices, so no caller is affected. The header comment matches the code.
  • The new test_small_limits checks vertex and primitive limits for limits 3/126, 64/1, 4/2, 256/256 and the defaults, plus degenerate triangles. The negative controls cover 1, 2 and 257.
  • No other open or merged PR covers this slice (search "meshlet max_vertices").

Commands run locally:

  • git diff --check origin/main...HEAD clean
  • python3 tests/docs_links_check.py OK
  • python3 tests/bidi_controls_check.py OK
  • g++ build of tests/meshlet_builder_check.cpp + src/meshlet_builder.cpp: meshlet_builder_check: PASS
  • Mutation: reverting the check to max_vertices == 0 makes the test fail with max_vertices=1 rejected.

Not a startup-path change. A Windows WARP run follows.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-26 11:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2811#pullrequestreview-6073052039) · **reviewed** Review of head bee8e7c3. Checked: - `src/meshlet_builder.cpp:199`: the range check is now [3, 256]. The old check let max_vertices of 1 or 2 through, but the first triangle of a meshlet is always placed, so vertex_count could go above the limit. The new bound closes that. - The only other callsite (`meshlet_builder.cpp:306`) uses `kMaxMeshletVertices`, so no caller is affected. The header comment matches the code. - The new `test_small_limits` checks vertex and primitive limits for limits 3/126, 64/1, 4/2, 256/256 and the defaults, plus degenerate triangles. The negative controls cover 1, 2 and 257. - No other open or merged PR covers this slice (search "meshlet max_vertices"). Commands run locally: - `git diff --check origin/main...HEAD` clean - `python3 tests/docs_links_check.py` OK - `python3 tests/bidi_controls_check.py` OK - g++ build of `tests/meshlet_builder_check.cpp` + `src/meshlet_builder.cpp`: `meshlet_builder_check: PASS` - Mutation: reverting the check to `max_vertices == 0` makes the test fail with `max_vertices=1 rejected`. Not a startup-path change. A Windows WARP run follows. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 11:07 UTC · original

Win2025 WARP receipt for head bee8e7c3. Test run: meshlet_builder (meshlet_builder_check).
Real-GPU run not available (RunPod stopped).

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit bee8e7c37e405e875a71de4873fb4689aeb2b9b2:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target meshlet_builder_check -- -j 2): 1.32s (configure 2.31s)
    • Test (ctest --preset dev -R 'meshlet_builder' --parallel 3 --no-tests=error --output-on-failure): 1/1 passed (0.17s: meshlet_builder 0.02s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target meshlet_builder_check -- -j 2): 1.58s (configure 2.36s)
    • Test (ctest --preset release -R 'meshlet_builder' --parallel 3 --no-tests=error --output-on-failure): 1/1 passed (0.16s: meshlet_builder 0.01s)
  • sccache: 1/9 hits; wall 13.5s

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-26 11:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2811#issuecomment-7190308011) Win2025 WARP receipt for head bee8e7c3. Test run: meshlet_builder (meshlet_builder_check). Real-GPU run not available (RunPod stopped). Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `bee8e7c37e405e875a71de4873fb4689aeb2b9b2`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target meshlet_builder_check -- -j 2`): `1.32s` (configure `2.31s`) - Test (`ctest --preset dev -R 'meshlet_builder' --parallel 3 --no-tests=error --output-on-failure`): **1/1 passed** (`0.17s`: `meshlet_builder` `0.02s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target meshlet_builder_check -- -j 2`): `1.58s` (configure `2.36s`) - Test (`ctest --preset release -R 'meshlet_builder' --parallel 3 --no-tests=error --output-on-failure`): **1/1 passed** (`0.16s`: `meshlet_builder` `0.01s`) - `sccache`: 1/9 hits; wall `13.5s` AI-assisted; commands listed were executed locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.