mesh: lower clip and cull distance exports placed by PA_CL_VS_OUT_CNTL #2281
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2289"
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-25T10:13:09Z.
Part of #1998.
Change
Item F, first slice: clip and cull distance exports in the bounded mesh path, placed by an explicit
PA_CL_VS_OUT_CNTLword, as agreed in the claim and the reply above. Reading the word from the slot 57 state stays a separate piece.--pa-cl-vs-out-cntl <word>on the command line oftools/mesh_entry_aot.pyandtools/mesh_dynamic_aot.py,vs_out_cntl=in Python. Without it, the output and the refusals of existing programs are unchanged.tools/mesh_clip_cull.py(new) decodes the word and checks every vertex's position exports against it. Both references are pinned to Mesa commit03ecd8b0a517e528d790a3d252194f7b898d0e8f(tagmesa-24.0.0, MIT):PA_CL_VS_OUT_CNTL:CLIP_DIST_ENA_0..7in bits 0-7,CULL_DIST_ENA_0..7in bits 8-15,VS_OUT_MISC_VEC_ENAin bit 21,VS_OUT_CCDIST0/1_VEC_ENAin bits 22-23. radeonsi writesclipdist_mask | (culldist_mask << 8), so distance component n is component n % 4 of vector CCDIST(n / 4);ac_nir_export_position:pos0, the misc vector when enabled, then each enabled CCDIST vector, numbered without gaps, withdoneon the last position export.pos1and the second ispos2. The output vertex declares only the enabled components, one field per kind and vector (float2 clip0 : SV_ClipDistance0,float cull1 : SV_CullDistance1, ...). A component with both enables, which radeonsi sets for every clip distance (culldist_mask |= clipdist_mask, line 897), is declared as both. Disabled components may beoffor hold any value; they are not declared.Mesh export pos1 needs the PA_CL_VS_OUT_CNTL word), the misc vector (... sets VS_OUT_MISC_VEC_ENA; only clip and cull distance vectors are translated), everyUSE_VTX_*bit andVS_OUT_MISC_SIDE_BUS_ENAby field name, unknown bits, a vector enable without components, components without their vector enable, more than eight components, a value that is not a 32-bit word;Mesh export pos2 is not enabled by PA_CL_VS_OUT_CNTL 0x00400003), an enabled export that is missing (... enables pos2 (CCDIST1), which vertex 0 does not export), an enabled component written asoff, duplicate and reordered exports,doneon another export than the last,pos4and above (Unsupported mesh export);The compute fallback has no room for clip or cull distances.tools/mesh_entry_aot.pythe export parser acceptspos0-pos3and records each position export with itsdoneflag. The check thatdonesits on the last position export moved from the instruction tomesh_clip_cull.vertex_distances(), so apos0withoutdoneand without distances is still refused with the same message.tools/mesh_dynamic_aot.pycarries the decoded word inGeometryand the distances inVariant.Overlap: #2149 also touches
tools/mesh_entry_aot.py.git merge-treeof this branch with its head20c2eb84is clean, and on the merge of the two the CPU checksmesh_clip_cull_check,mesh_dynamic_aot_check,mesh_dynamic_geometry_check,mesh_lane_spill_check,mesh_scc_any_lane_checkandmesh_multi_checkpass.Verification
Windows 11 26200, MSVC 19.44,
devpreset, D3D12 debug layer on, DXC from Windows SDK 10.0.26100.0. Tested commit718e86d5onmainba89d51a. The full set below first ran on the same change onmain77a204d6; after the rebase themesh_clip_cull_*andmesh_two_exits_*tests were run again with the same results.Clipping, separately from culling. Geometry word 1 picks one of two draws of the same program. The clip draw has two partly visible triangles: A loses the pixels left of screen x = 9 to clip distance 0 and B the pixels above y = 7 to clip distance 1 (91 of 1,024 pixels covered). The cull draw has a triangle whose cull distance 4 is -1 on all three vertices, which must disappear, and a neighbour with +1, which must stay whole (78 pixels covered).
Readback.
mesh_clip_cull_draw_hardwarepassed on NVIDIA GeForce RTX 3070 (10de:2484, driver 32.0.16.2101) andmesh_clip_cull_draw_warpon WARP 10.0.26100.9818, with no capability skips. Both draws matched the reference on 1,024 of 1,024 pixels with the static and the runtime translation, withdebug_errors=0 debug_warnings=0. The draw mode also ran three times per adapter, and the three outputs were identical on each.Negative controls. Translator mutants, each drawn on both draws. Each must change exactly the number of pixels the model predicts, and a prediction of 0 must read back unchanged:
pos1read as CCDIST1)The disabled components hold -1.0 or 2.0, so declaring any of them changes the image (last row).
CPU mode. The static translations of both draws and the runtime translation, checked field by field: clip distances 0-1 from
pos1.xy, cull distance 4 frompos2.x, nothing else written. This also catches the clip and cull swap on every adapter. Also checked: Mesa's form withoffin disabled components gives the same HLSL; CCDIST1 enabled alone is carried bypos1; both enables on one component declare both semantics; a word that enables nothing leaves a program without distances unchanged. 20 refusals are checked by message in both lowerers, plus the compute fallback. Each guard ofmesh_clip_cull.pywas then removed in turn (refused bits, unknown bits, export not enabled, enabled export missing, duplicate export, component missing,doneon the last export), and the check failed every time. Three of those mutants are still refused by the order check, with a less precise message, and the check catches the message change.Fail-first. Against
main's lowerers the program stops at its first export, not atpos1as the claim said:Expected completed primitive or position export, becausepos0carries nodonewhen distances follow. Withdoneadded topos0, it stops atpos1withUnsupported mesh export, in both lowerers. The new check cannot import its module there.Binary mode. The 612-byte program reassembles to the embedded bytes, and LLVM's decode equals the Python decoder's. Both command lines produce the same HLSL as
lower, exit 1 without the word (Mesh export pos1 needs the PA_CL_VS_OUT_CNTL word), and exit 2 for an invalid word. I ran this locally with LLVM 15.0.7: the clang 15 integrated assembler stood in forllvm-mc, withllvm-objcopyandLLVM-C.dllfrom the same release, as in #749 and #773. The existing binary modes ofmesh_entry,mesh_dynamic_geometry,mesh_multi,mesh_heap_sampler,mesh_lit,mesh_shadowandmesh_scc_any_lanepass.Wider runs.
ctest --preset dev --no-tests=error -R "^(mesh_|compute_mesh_texture_|offscreen_|startup_sampler_heap)" -Vran 75 tests: 73 passed, andmesh_two_exits_{hardware,warp}skipped withskip: two-exit mesh draw requires LLVM 15 with AMDGPU, because LLVM 15 was not on that run'sPATH. Since that test uses both lowerers, I ranctest --preset dev --no-tests=error -R "^mesh_two_exits_" -Vagain with LLVM 15.0.7 onPATH: both passed, static and runtime. No run reported a debug-layer error.mesh_dynamic_aot_check,mesh_dynamic_geometry_check,mesh_multi_check,mesh_heap_sampler_check,mesh_lane_spill_check,mesh_scc_any_lane_check,mesh_join_descriptor_check,pso_readiness_check,docs_links_check,bidi_controls_checkandgit diff --checkpass. The draw mode also passed on WARP with the debug layer reported as unavailable, reading the pixels only.Not run. The Ubuntu LLVM 15 job and the Linux Python job (the new check is added to both), the
releasepreset, AMD and Intel GPUs, console hardware, reading the word from the slot 57 state, and the misc vector.Evidence and follow-up
The gfx1013 program
tests/mesh_clip_cull.sis original, written for this test, and MIT. No game files. The expected images come from an exact rational model in the test, independent of the translator: coverage of pixel centers (none on an edge), linear interpolation of the clip distances (w = 1), and culling when one cull component is negative on all three vertices. The model also checks that every covered center is at least 1/8 pixel away from each clip plane.Findings:
SV_CullDistanceis negative on some vertices but not all lost the pixels where the interpolated cull distance is negative. That is 57 pixels for the neighbour triangle with cull distances -1, -1, +1. The translated HLSL was the same on both. I report this as an observation, and I did not check a vertex-shader pipeline. The good draws therefore have no mixed signs, and the model checks that they draw the same image either way. The draw mode first runs a calibration draw that accepts only 0 or exactly 57 changed pixels, and the control predictions follow it. With per-pixel culling, clip and cull distances draw alike, so the clip and cull swap changes no pixel on that GPU. WARP and the CPU mode show it. A pixel shader that readsSV_ClipDistanceandSV_CullDistanceback would show it on every adapter; I left that out of this slice.pos0, misc, CCDIST0, CCDIST1 is Mesa's. I have not verified it against console hardware. Because the misc vector is refused, this slice relies on the numbering only for "CCDIST1 ispos1when CCDIST0 is disabled".docs/experiments.mddocuments the input, the references, the refusals and the commands. The new tests are registered in CMake (mesh_clip_cull_cpu,mesh_clip_cull_draw_{hardware,warp}), in the Ubuntu LLVM 15 and Linux Python jobs, and in AGENTS.md.Checklist
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:15:46Z.
Review: COMMENTED
Review of head
718e86d548(mesh: lower clip and cull distance exports placed by PA_CL_VS_OUT_CNTL).Verdict: no blocking findings (P1=0, P2=0). Notes below are nits.
Commands run locally (Linux, in a worktree of the PR head)
git diff --stat origin/main...HEAD: 9 files, +957/-18.python3 -B tests/mesh_clip_cull_check.py: exit 0 (CPU cases, refusal cases, reference-vs-control pixel counts, guard-removal self-checks all pass).python3 -B tests/mesh_dynamic_aot_check.py: "Runtime mesh specializations matched the CPU cases and rejected unproven uses".python3 tests/docs_links_check.py: self-test passed, 18 Markdown files, 436 links.python3 tests/bidi_controls_check.py: 1581 files, no bidirectional controls.git diff --check origin/main...HEAD: clean.gh pr checks: Linux Python checks pass; the Windows jobs were still pending when I looked, so I did not rely on them.Mutations (both reverted with
git checkout -- .)tools/mesh_clip_cull.py:95changed the first CCDIST target frompos1topos2: the test fails withMesh export pos1 is not enabled by PA_CL_VS_OUT_CNTL 0x00c01003. Killed.tools/mesh_clip_cull.py, thevalue is Nonebranch): the test fails. Killed, but see nit 1.Reading of the logic
pos0..pos3, anddoneis only required onprim. Order, duplicates, missing enabled targets anddoneon the last export only are all checked invertex_distances. Without the word, existing programs still get a refusal forpos1+.Nits
TypeError(None formatted as hex) instead of a clean refusal. The guard is correct as written, but the test would be sharper if it asserted the message, not just any failure.tools/mesh_dynamic_aot.pycallsdecode_vs_out_cntltwice (inenumerate_variantsand again inlower). Harmless; one decode passed down would be tidier.Not run
mesh_clip_cull_draw_*): I did not queue the Windows VM. The PR's own Windows CI job covers them and was still pending at review time. Please confirm that job is green before marking Ready.AI-assisted; commands listed were executed locally.