Repository navigation
shader: translate mesh allocations with several vertices and triangles - #1779
Conversation
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
left a comment
There was a problem hiding this comment.
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: cleantests/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.
|
Thanks for catching this: the check required the debug-layer summary even on hosts where
AI-assisted. |
tedin7
left a comment
There was a problem hiding this comment.
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 requiresdebug_errors=0 debug_warnings=0only when the output contains the exact linebackend=<adapter> debug_layer=enabled, the same rule the sibling mesh checks use. The three call sites indraw()passadapter. 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.cppandtests/pso_readiness_check.pystill hold.
Commands run locally at 2de7fe7
git diff --check origin/main...HEAD: exit 0tests/docs_links_check.py: 17 files, 366 links OKtests/bidi_controls_check.py: 1304 files OKtests/form_coverage_check.py: passedtests/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 behindmain, 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/O23/3 passed, includingmesh_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.
Change
Refs #730. Limit 3 from my comment there:
tools/mesh_entry_aot.pyaccepted only a(3, 1)allocation, so a scene had to issue oneDispatchMeshper triangle.The translator now lowers any
MSG_GS_ALLOC_REQcounts 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-multimode (MeshDrawMode::multi_primitiveintests/desktop_gpu.h) that takes the export trace size from the fixture, 80 to 3,600 bytes.tests/pso_readiness_check.pyexpected 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.pyandCMakeLists.txt). Againstmain,git merge-treeshows that this branch adds no conflicting file. No open PR touchestools/mesh_entry_aot.py.Verification
Windows 11 26200.9974, MSVC 19.44,
devpreset, D3D12 debug layer on, branch rebased onmainatfc2f1ebb.mesh_multi_draw_hardwarepassed on NVIDIA GeForce RTX 3070 (driver 32.0.16.2101), andmesh_multi_draw_warppassed on WARP 10.0.26100.9818. There were no capability skips, every run printeddebug_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.TRACE_EXPORTSmesh DXIL match the reference on all 1,024 pixels and every trace byte (320, 400 and 481 covered pixels).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. Withmain's translator, the test fails at the first translation (the quad) withExpected a single three-vertex triangle.python -B tests/mesh_multi_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1is 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-fallbackand PSV0 bounds of (11, 10) on the command line. Locally the assembler is the clang 15 integrated assembler behind anllvm-mcwrapper, 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.ctest --preset dev --no-tests=error -R "^(mesh_|compute_mesh_texture_|offscreen_)" -Vpassed 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.releasepreset, 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.mddescribes 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
AI-assisted.