Skip to content

shader: translate mesh allocations with several vertices and triangles - #1779

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
roansystemlabs:mesh/730-multi-primitive
Nov 24, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
roansystemlabs:mesh/730-multi-primitive

Conversation

@roansystemlabs

Copy link
Copy Markdown
Contributor

Change

Refs #730. Limit 3 from my comment there: tools/mesh_entry_aot.py accepted only a (3, 1) allocation, so a scene had to issue one DispatchMesh per triangle.

The translator now lowers any MSG_GS_ALLOC_REQ counts within the PSV0 output bounds. PSV0 may declare up to 256 vertices and primitives; with 128 threads and one export of each kind per thread, an allocation above 128 cannot be covered and is refused (the test checks 129 vertices). The existing coverage rules are unchanged and now carry the whole check: the translation is refused unless every allocated vertex and primitive is exported exactly once, nothing outside the allocation is exported and every index names an allocated vertex. The compute fallback keeps its single-triangle layout and refuses any other allocation by name (The compute fallback translates only a single three-vertex triangle).

The draw runner gains a --mesh-multi mode (MeshDrawMode::multi_primitive in tests/desktop_gpu.h) that takes the export trace size from the fixture, 80 to 3,600 bytes. tests/pso_readiness_check.py expected the old message for an allocation of zero; that program is still rejected, now by the count check, and the expected detail is updated.

Overlap: four open PRs touch files in common (#1568, #1466, #713 and #532, on tests/desktop_gpu.h, tests/offscreen_check.cpp, tests/pso_readiness_check.py and CMakeLists.txt). Against main, git merge-tree shows that this branch adds no conflicting file. No open PR touches tools/mesh_entry_aot.py.

Verification

Windows 11 26200.9974, MSVC 19.44, dev preset, D3D12 debug layer on, branch rebased on main at fc2f1ebb.

ctest --preset dev --no-tests=error -R "^mesh_multi_draw_" -V
  • mesh_multi_draw_hardware passed on NVIDIA GeForce RTX 3070 (driver 32.0.16.2101), and mesh_multi_draw_warp passed on WARP 10.0.26100.9818. There were no capability skips, every run printed debug_errors=0 debug_warnings=0, and the two adapters gave identical result lines. On an earlier base, the same test ran three times per adapter with identical results.
  • Plain and TRACE_EXPORTS mesh DXIL match the reference on all 1,024 pixels and every trace byte (320, 400 and 481 covered pixels).
  • Negative controls run against the correct draw. Each must exit 1 with the pixel count and first trace byte that the reference predicts:
    • Swapped index (the first index of the first primitive traded with the last index of the last one): the quad gives 0 pixels and trace byte 80, because both triangles keep the same vertex sets and only the trace sees the change. The strip gives 64 pixels and byte 208, and the long strip gives 32 pixels and byte 2064.
    • Missing primitive: 156 pixels for the quad, 35 for the strip, and 8 and 15 for the long strip (the last primitive of wave 0 and of wave 1). The trace is unchanged.
    • Count mismatch (one primitive fewer in the counts): trace byte 4, pixels unchanged.
    • A translated program that swaps two indices of every primitive draws the same pixels and fails at trace byte 84, 212 and 2068.
  • python -B tests/mesh_multi_check.py: without a GPU, the translation is refused for a missing primitive, an allocation one vertex larger than the exports, a vertex exported beyond the allocation, an index outside it, counts above the PSV0 bounds, 129 vertices and the compute fallback. With main's translator, the test fails at the first translation (the quad) with Expected a single three-vertex triangle.
  • python -B tests/mesh_multi_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1 is equivalent to the local run, which used LLVM 15.0.7. It assembles 228 bytes, translates each allocation from machine code to the same HLSL as from the source text, and refuses --compute-fallback and PSV0 bounds of (11, 10) on the command line. Locally the assembler is the clang 15 integrated assembler behind an llvm-mc wrapper, as in gpu: light a translated mesh draw with an interpolated normal and N·L #749 and gpu: cast a shadow with a translated depth pass and SampleCmpLevelZero #773.
  • On the previous base, ctest --preset dev --no-tests=error -R "^(mesh_|compute_mesh_texture_|offscreen_)" -V passed 49/49 with no skips. The pure-Python checks listed in AGENTS.md pass. The existing LLVM 15 binary modes (mesh_entry, mesh_indexed, mesh_descriptor_swap, mesh_lit, mesh_shadow) also pass.
  • Not run: the Ubuntu LLVM 15 job was not run on the fork; locally the binary mode ran with LLVM 15.0.7 and the clang 15 assembler (see above). The release preset, AMD and Intel GPUs, PARAM0 attributes on more than three vertices, and performance were not tested.

Evidence and follow-up

The gfx1013 program is original, written for this test, assembled with LLVM 15, MIT. No game files. It reads its allocation word from the geometry binding and exports a skewed strip: vertex i at column i / 2 and row i mod 2, primitive (i, i + 1, i + 2). Three allocations are drawn on a 32×32 target: a quad (4 vertices, 2 triangles), a strip (12, 10) and a strip that spans both waves (128, 126). The reference is an exact rational rasterizer that does not use the translator. Every pixel center stays off every edge, and the last primitive of each wave owns at least one pixel, so the result does not depend on the fill rule.

The new test is in the Ubuntu LLVM 15 job (binary mode) and in CMake as mesh_multi_draw_{hardware,warp}. docs/experiments.md describes the allocation rules and the reproduction commands. Limits 1 and 2 from #730 are not part of this PR (limit 2 is covered by #1702).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

tools/mesh_entry_aot.py accepted only a (3, 1) allocation. It now lowers any
MSG_GS_ALLOC_REQ counts within the PSV0 output bounds, up to 128 vertices and
128 primitives across the two waves, and still refuses the program unless
every allocated vertex and primitive is exported exactly once, nothing outside
the allocation is exported and every index names an allocated vertex. The
compute fallback keeps its single-triangle layout and refuses other counts by
name.

tests/mesh_multi_check.py builds one gfx1013 strip program and draws a quad
(4, 2), a strip (12, 10) and a strip that spans both waves (128, 126) through
the new --mesh-multi runner mode, against an exact rational rasterizer, with
negative controls for a swapped index, a missing primitive and a count
mismatch, translator refusals and an LLVM 15 binary mode.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Peer review of head c197c1881bbe39fc5945e7152c22c107061b0462.

Finding (P2, test robustness): tests/mesh_multi_check.py:258 fails on any adapter run without the D3D12 debug layer.

expect() requires "debug_errors=0 debug_warnings=0" in out on every draw. That line is printed only when the debug layer is enabled (tests/offscreen_check.cpp:1882, report_debug_errors at line 308). With debug_layer=unavailable the draw can be fully correct and the test still fails. The sibling checks accept both cases, for example mesh_fallback_check.py:88-89, mesh_depth_pair_check.py:108-109, mesh_lit_check.py:144-145 and mesh_textured_check.py:103-104 (the debug line is required only when debug_layer=enabled).

Reproduction: on a Windows Server 2025 host (build 26100, WARP, debug_layer=unavailable) with --targets offscreen_check --regex '^(mesh_multi.*_warp|mesh_entry_draw_warp|pso_readiness_check)$', ctest --preset dev gives mesh_multi_draw_warp Failed with AssertionError: quad traced=0 covered=320: unexpected result (exit 0). The renderer output in the same run shows pixels=1024 mismatches=0, so the draw itself matched; only the debug line was missing. offscreen_check was the right target (it built and ran, and mesh_entry_draw_warp passed on the same binary). The PR's own Windows job reports success, which is consistent with a runner where the debug layer is enabled. Suggested fix: require the line only when f"backend={adapter} debug_layer=enabled" is present, as the sibling checks do.

No defect found in the translator change itself. Notes from reading the diff:

  • tools/mesh_entry_aot.py: the count check now applies the single-triangle limit only to the compute fallback. The remaining check (counts within the PSV0 bounds, every slot exported exactly once, no index at or past the vertex count) covers the refusal cases in the test.
  • tests/mesh_entry_draw.cpp: the multi-primitive fixture size is validated (80 to 3600 trace bytes, multiple of 16) before it sets the trace stride.
  • tests/pso_readiness_check.py: the expected refusal text for the empty allocation matches the new check.

Linux checks run locally in a clean worktree at this head:

  • git diff --check origin/main...HEAD: clean
  • tests/docs_links_check.py: passed (17 files, 366 links)
  • tests/bidi_controls_check.py: passed (1304 files)
  • tests/mesh_multi_check.py: passed (3 translations and their refusals)
  • tests/mesh_multi_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so: passed (3 binary translations match the source text; 2 refusals)
  • tests/pso_readiness_check.py: passed

Mutation (local, reverted afterwards): changing max(tri) >= nv to max(tri) > nv in tools/mesh_entry_aot.py made mesh_multi_check.py exit 1 with Invalid multi-primitive mesh accepted. The tree was restored with git checkout -- . and is clean.

Win2025 (coordinator run, WARP, Debug dev): pso_readiness_check passed, mesh_entry_draw_warp passed, mesh_multi_draw_warp failed as described above. The Release /O2 phase did not run because the Debug phase stopped on that failure.

AI-assisted; commands listed were executed locally.

…er on

offscreen_check prints debug_errors/debug_warnings only when the D3D12 debug
layer is enabled. On a host where it reports debug_layer=unavailable, a
matching draw failed expect(). Require the summary only after
"backend=<adapter> debug_layer=enabled", as the sibling mesh checks do.
@roansystemlabs

Copy link
Copy Markdown
Contributor Author

Thanks for catching this: the check required the debug-layer summary even on hosts where offscreen_check reports debug_layer=unavailable.

expect() in tests/mesh_multi_check.py now requires debug_errors=0 debug_warnings=0 only after backend=<adapter> debug_layer=enabled, as mesh_fallback_check.py, mesh_depth_pair_check.py, mesh_lit_check.py and mesh_textured_check.py do (2de7fe7). With the runner's output rewritten to debug_layer=unavailable and the summary removed, the previous version fails on WARP as you saw and this one passes all 19 checks; with the layer on, mesh_multi_draw_{hardware,warp} still pass on an RTX 3070 and WARP.

AI-assisted.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review of head 2de7fe7ffe1f29fdab9f32ba809a424d1410ddd7 (my previous review was at c197c188; one commit added: "require the debug summary in mesh_multi_check only with the layer on"). Comment only, not an approval.

Verdict: 0 P1 / 0 P2. The P2 from the last round (mesh_multi_check.py failed when the D3D12 debug layer is unavailable) is fixed.

What changed and what I checked

  • tests/mesh_multi_check.py:253-263: expect() takes the adapter and requires debug_errors=0 debug_warnings=0 only when the output contains the exact line backend=<adapter> debug_layer=enabled, the same rule the sibling mesh checks use. The three call sites in draw() pass adapter. Matching is by whole line, so the old text "debug_layer=unavailable" cannot satisfy it.
  • No change to the translator; my earlier notes on tools/mesh_entry_aot.py, tests/mesh_entry_draw.cpp and tests/pso_readiness_check.py still hold.

Commands run locally at 2de7fe7

  • git diff --check origin/main...HEAD: exit 0
  • tests/docs_links_check.py: 17 files, 366 links OK
  • tests/bidi_controls_check.py: 1304 files OK
  • tests/form_coverage_check.py: passed
  • tests/mesh_multi_check.py: "3 multi-primitive translations and their refusals checked"
  • tests/pso_readiness_check.py: passed (15 rejected inputs, 2 CLI exits, 1 valid control)
  • git merge-tree --write-tree origin/main HEAD: clean (the branch is far behind main, 293 commits)
  • x2w_pipe.py win2025 1779 --targets offscreen_check --regex '^(mesh_multi.*_warp|mesh_entry_draw_warp|pso_readiness_check)$': Windows Server 2025 (WARP, debug_layer=unavailable) Debug 3/3 passed and Release /O2 3/3 passed, including mesh_multi_draw_warp, the test that failed at the previous head.

Mutations (local, each reverted with git checkout -- .)

All three change tools/mesh_entry_aot.py and are caught by tests/mesh_multi_check.py (exit 1):

  • if compute_fallback and (nv, np) != (3, 1): -> if False and ...: "Invalid multi-primitive mesh accepted"
  • the same line -> if (nv, np) != (3, 1): (old behaviour): ValueError("The compute fallback translates only a single three-vertex triangle")
  • max(tri) >= nv -> max(tri) > nv: "Invalid multi-primitive mesh accepted"

Limit

I did not mutate the new debug-line condition itself: on this host only the translation checks run, and the drawing path is covered by the Windows run above, where the layer is unavailable (the condition that used to fail). A run on a host with the layer enabled would show the other branch; the sibling checks use the identical pattern.

AI-assisted; commands listed were executed locally.

@R0Y00
R0Y00 merged commit 2a27507 into R0Y00:main Nov 24, 2026
5 checks passed
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.

3 participants