shader: prove mesh VGPRs written under a lane count stay in range at the count export (Part of #2413) #3671
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3671"
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 mumba17 on 2026-11-30T23:38:46Z.
Part of #2413 (claim: https://github.com/R0Y00/Xbox2Windows/issues/2413#issuecomment-7294482863).
Problem
With the open mesh PRs stacked,
graphics register undefined on an incoming path: Nis the first refusal for 152 of the 454 cached slot 57 requests. This is the classX2W_MESH57_PARTIAL_ZERO=1hides by zero-filling. All 152 share one shape:v_cmpx_gt_u32 sV, v0+ EXECZ: the vertex section writes the position sources for threads below V.s_mov_b64 exec, -1, then the count exchange, which sendssG = s_cselect_b32 0, sV(taken whenmin(V, P) == 0).v_cmpx_gt_i32 sG, v0+ EXECZ, thenexp pos0.The full-EXEC reset and the exchange erased every partial VGPR. The export therefore refused, although its lanes are a subset of the writing lanes.
Change (
src/gfx1013_direct_mesh.inl)Keep bounded partials. At
s_mov_b64 exec, -1and at the end of the count exchange, a partial VGPR survives if its value carries the existing skip-close lane-count tag (value_limits). Untagged partials are still erased. Every later read still goes throughcheck_graphics_read. This is the same rule the saved-mask EXEC restore already applies.Group-uniform values. These are values equal in every thread of the group:
v_mov_b32,v_readfirstlane_b32andbuffer_load_format(index form), when all their inputs are group-uniform, including SCC and descriptor symbols. Descriptors from such an SMEM load count too.A merge phi counts only while every scalar branch so far had a group-uniform condition; a VCC branch or a non-uniform SCC clears that for good. EXEC, getreg/setreg, PC and movrel forms are excluded. After any buffer or image store, SMEM and typed loads stop counting.
Unsigned bounds (
at_most):s_cselect_b32with a zero operand is at most its other operand;s_min_u32is at most either source;input_vwheninput_vis group-uniform, because wave zero stored that same value. It is also clamped. The same holds for primitives.check_graphics_readalso accepts a lane count thatat_mostbounds by the defining count. It now also accepts a whole-wave skip onlane_active, not only a per-lane one. The export guard is a whole-wave skip, and in both kinds lanes outsidelane_activehave no effect. Reads at full EXEC, or under any other guard, still refuse withmesh register read outside its proven lane range.Census
454 cached slot 57 requests, #3416 layout, main plus #3635/#3645/#3646/#3655/#3668:
mesh register read outside its proven lane range. Mostly the primitive export reads a VGPR written in the vertex section (thread < V) under the primitive count. Nothing proves that count is at most V, so the refusal is correct.unmapped mesh export target 13.Tests (
tests/native_direct_mesh_check.py)Fixture
bounded-export: V comes from the root constant in s21, a vertex skip writes v10 for threads below V, full EXEC returns, the count exchange sendsselect(V == 0, 0, V), andexp param0 v10runs underv_cmpx_gt_i32 s34, v0.bounded-export, andbounded-export-root-branch(V merged behind an s21 branch).outside its proven lane range: 266:-wave-v(V from the wave index);-select-4(s_cselect 4, V);-full-exec(no count guard);-wave-branch(V merged behind a wave-index branch).count-*-writer-boundrefusals are unchanged.native_direct_mesh:s_cselecttreated as a bound;ctest -R "mesh|compile_dxil": 204/204.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-01T01:19:14Z.
Review: COMMENTED
Reviewed
ce6285f2by reading the diff; not built or run.Verdict: comment. The bound rules and the group-uniform tagging look sound to me. But keeping partials past full EXEC opens one path that, as I read it, gives a wrong value instead of a refusal. No MUST, because compiler output should rarely hit it. I'd approve once it is closed or shown unreachable.
keep_bounded_partialsleaves kept registers inpartial_writes. The merge after a VGPR write (src/gfx1013_direct_mesh.inl, thebefore_partialloop near the end) buildsselect(lane_active, new, old)only when the register was not already partial and the old value is untagged. Before this PR, both were cleared at full EXEC. Now, after the exchange, a kept v10 (tagged V) rewritten inside a whole-wave skip on W gets no select, so the threads outside W in that wave also take the new value. At the skip close,merge_edgesmakesphi(T, y)and carries V's tag from the left side. A later read under a guard bounded by V but not inside W passescheck_graphics_read, while hardware keeps T in those lanes. Refusing a partial write over a kept register would close it. A control:bounded-export, plus a v10 write under the export guard, read again under the vertex guard.at_most:s_cselect_b32with a zero operand,s_min_u32andclamp(input_v)are true unsigned bounds. Signedv_cmpx_gt_i32uses the capped unsigned limit (thread < min(limit, threads)), so a bounded limit gives a subset.input_v. Phis count only in the forward-branch funnel (uniform_join), not at skip or diamond joins.v_cmpANDs withlane_active, andv_readfirstlaneonly takes proven-uniform values.Tests: five fixtures plus six mutations cover the bound, uniformity and guard rules. None rewrites a kept register. CI at this head (23:38 UTC) ran before #3644 put
native_direct_meshinto theprfilter, so only your local run covers them.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-01T03:11:03Z.
Review: APPROVED
Reviewed the lane-count bound and group-uniform provenance. Reads of retained partial VGPRs still require a compatible lane guard after full EXEC is restored.
ctest --test-dir <build> --no-tests=error -j1 -R '^native_direct_mesh$' --output-on-failurepassed in the integration, including the bounded export and the insufficient-bound controls.