shader: translate mesh allocations with several vertices and triangles #1772
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1779"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-24T18:30:03Z.
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 #749 and #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.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:21:43Z.
Review: COMMENTED
Peer review of head
c197c1881bbe39fc5945e7152c22c107061b0462.Finding (P2, test robustness):
tests/mesh_multi_check.py:258fails on any adapter run without the D3D12 debug layer.expect()requires"debug_errors=0 debug_warnings=0" in outon every draw. That line is printed only when the debug layer is enabled (tests/offscreen_check.cpp:1882,report_debug_errorsat line 308). Withdebug_layer=unavailablethe draw can be fully correct and the test still fails. The sibling checks accept both cases, for examplemesh_fallback_check.py:88-89,mesh_depth_pair_check.py:108-109,mesh_lit_check.py:144-145andmesh_textured_check.py:103-104(the debug line is required only whendebug_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 devgivesmesh_multi_draw_warpFailed withAssertionError: quad traced=0 covered=320: unexpected result (exit 0). The renderer output in the same run showspixels=1024 mismatches=0, so the draw itself matched; only the debug line was missing.offscreen_checkwas the right target (it built and ran, andmesh_entry_draw_warppassed 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 whenf"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: passedMutation (local, reverted afterwards): changing
max(tri) >= nvtomax(tri) > nvintools/mesh_entry_aot.pymademesh_multi_check.pyexit 1 withInvalid multi-primitive mesh accepted. The tree was restored withgit checkout -- .and is clean.Win2025 (coordinator run, WARP, Debug
dev):pso_readiness_checkpassed,mesh_entry_draw_warppassed,mesh_multi_draw_warpfailed as described above. The Release/O2phase did not run because the Debug phase stopped on that failure.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-24T20:38:02Z.
Thanks for catching this: the check required the debug-layer summary even on hosts where
offscreen_checkreportsdebug_layer=unavailable.expect()intests/mesh_multi_check.pynow requiresdebug_errors=0 debug_warnings=0only afterbackend=<adapter> debug_layer=enabled, asmesh_fallback_check.py,mesh_depth_pair_check.py,mesh_lit_check.pyandmesh_textured_check.pydo (2de7fe7f). With the runner's output rewritten todebug_layer=unavailableand 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.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:24:54Z.
Review: COMMENTED
Re-review of head
2de7fe7ffe1f29fdab9f32ba809a424d1410ddd7(my previous review was atc197c188; 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.pyfailed 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.tools/mesh_entry_aot.py,tests/mesh_entry_draw.cppandtests/pso_readiness_check.pystill hold.Commands run locally at
2de7fe7fgit 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.pyand are caught bytests/mesh_multi_check.py(exit 1):if compute_fallback and (nv, np) != (3, 1):->if False and ...: "Invalid multi-primitive mesh accepted"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.