Skip to content

shader: prove staged mesh vertex export mask coverage (Part of #3703) - #3832

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
timbot103:shader/mesh-output-position-mask
Dec 3, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
timbot103:shader/mesh-output-position-mask

Conversation

@timbot103

Copy link
Copy Markdown
Contributor

Proves staged mesh vertex export mask coverage at shader end rather than requiring every PARAM, CLIP, and packed attribute export to follow POS0 under the exact same lane_active SSA token, clearing "mesh vertex outputs do not share the position mask" (308 mesh programs in #3703).

Part of #3703. Refs #3641.
(Opened as Draft per #3514 until an active review slot frees.)

Summary

  • src/gfx1013_direct_mesh.inl:
    • Records each staged PARAM, CLIP, and packed attribute export's lane_active scope in attribute_scopes and validates at s_endpgm (once POS0 and position_scope are known) that covers_position(mask) holds for every declared attribute.
    • Tracks exact thread < limit count masks (ExportCountMask{limit, wave} via v_cmpx_gt_u32, v_cmpx_lt_u32, lane-linear count guards, and s_and_saveexec_b64 from exact_count_bits) so covers_position proves coverage across:
      • PARAM/CLIP/packed exports before or after POS0 under the same mask,
      • full-EXEC attributes ("") with POS0 under a narrowed mask,
      • separate equivalent count guards referencing the same immutable SSA count value (including v_cmpx_gt_u32 count, tid vs v_cmpx_lt_u32 tid, count and SAVEEXEC),
      • POS0 under a nested child skip of the attribute's mask (mask_parent chain).
    • Extends staged_export_guard() to handle whole-wave EXECZ blocks for exact count masks and intersects lane_active into guarded(...) (export_lane) when !exec_skip->per_lane, so individual lane masks are honored even when EXECZ branched on wave nonemptiness.
    • Refuses narrower attribute masks, different or redefined count values, disjoint nested masks, missing POS0, and duplicate PARAM exports.
  • tests/native_mesh_output_mask_check.py + tests/cmake/native_mesh_output_mask.cmake:
    • native_mesh_output_mask_ir (matches the pr CTest preset): 10 validated DXIL cases (checking @meshPositionWritten, @meshPackedIndices, exact lane-indexed storeVertexOutput counts before emitIndices, and and i1 lane intersection on whole-wave count skips) + 8 fail-closed refusal controls.

Verification

Host: Windows 11 (10.0.26200.9974), MSVC C++20 /W4 (zero warnings on edited lines). Base origin/main f365f125.

  • ctest --preset pr --no-tests=error -R "^native_mesh_output_mask_ir$": 1/1 passed (10 positive + 8 refusals).
  • Debug (dev) & Release (release): 3/3 passed in both configs (native_mesh_output_mask_ir, native_direct_mesh, native_direct_container).
  • tests/bidi_controls_check.py, tests/docs_links_check.py, git diff --check origin/main..HEAD: all clean.

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed 649cfeb7 (draft) by reading the diff; not built or run.

Verdict: approve. Moving the check to s_endpgm is sound: every lane that wrote POS0 must also write each attribute, in either export order. No MUST.

  • SHOULD Run a before/after m86 census on f365f125. Besides the 308 it targets, the export gate changes for staged programs (gfx1013_direct_mesh.inl:1296). An export inside a branch or skip used to pass whenever export_limit was set. Now, with staged indices, it needs staged_export_guard(), because legacy_export_guard only covers the unstaged case. If a program on main reaches that combination, it would now be refused. The census would show that none does.
  • Checked, no finding:
    • covers_position (:409) compares only the count limits. That is exact because every value in linear_threads is the flattened thread ID (built through v_mbcnt or the wave-number v_lshl_add). Masks are recorded only under full EXEC, or from SAVEEXEC with no parent lane, so each one is exactly thread < limit. Walking mask_parent from the position scope is right too: a child mask lies inside its parent.
    • The operand order is right: v_cmpx_lt_u32 tid, N takes src[1], and v_cmpx_gt_u32 N, tid takes src[0].
    • Whole-wave EXECZ skips: guarded now ANDs lane_active (export_lane), so a lane outside EXEC does not store even though the DXIL branch was taken for the whole wave.
    • Attributes under full EXEC ("") cover any POS0 scope. A second POS0 or a duplicate PARAM is still refused.

Tests: native_mesh_output_mask_ir (10 cases, 8 refusals) is in the pr filter. It checks the store counts per lane and the and i1 on whole-wave skips.

@timbot103
timbot103 force-pushed the shader/mesh-output-position-mask branch from a0276f2 to cb62776 Compare December 2, 2026 12:35

@lukaslw-lab lukaslw-lab left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-review on cb627763 (rebased on 5770f14e: clip export now keyed on target 13 with the full clip vector, export lane passed to the position store, s_xor_b64 vcc accepted in the mask forms; the target 13 key and the s_xor_b64 form are main's).

Verdict: approve.

Census, same capture and method as before (6,685 distinct mesh programs), main 5770f14e vs this head:

Programs
Translate, main / with this PR 1,047 / 1,047
Lost / gained 0 / 0
First refusal moved 308: mesh vertex outputs do not share the position mask → unsupported packed vertex export 303, → unproven packed mesh signature rows 5

Same 308 as the earlier head. Checked: the position-mask refusal is gone only where the staged export scratch proves coverage (export_scratch.indices non-empty). The packed-row check still requires position_scope==lane_active without staging. The clip export is recorded only for mesh_clip_control==full_clip_vector.

Update: the first run was on a main that refused 257 programs early (my #3707, #3892; fixed by #3893). I reran main 5770f14e and this head, both with that fix: 308 moved, 0 lost, 0 gained. The numbers above are unchanged.

AI-assisted.

@timbot103

Copy link
Copy Markdown
Contributor Author

Merged main (67862ee4) into this branch. The reviewed commit cb627763 is unchanged, and no follow-up fix was needed.

Tests, Windows 11 26200 with RTX 5080 and WARP. The mesh filter was native_direct_mesh|native_direct_container|native_mesh_ plus this PR's own tests. Every branch passed a full Debug build of every target, including the C++17 native_compute_pack_refusal_check.

  • Debug passed 16/16. Release passed 13/16, and the PR preset passed 1/1.
  • The Release failures are the existing asynchronous WARP allocation fixtures (accepted=1 refused=0). They also fail on a clean 67862ee4, and every one of them passed with X2W_SYNC_MESH_REQUESTS=1.

All six mesh PRs (#3832, #3835, #3838, #3842, #3843 and #3846) were also merged together onto 67862ee4. That combined tree passed 47/47 in Debug and 47/47 in Release, plus 8/8 under the PR preset. All 15 pairs merge cleanly.

@timbot103

Copy link
Copy Markdown
Contributor Author

Marked Ready for review now that #3827 and #3829 have merged, keeping to 5 non-draft PRs per #3514. CI is green at this head. All 17 open PRs from this batch were also merged together onto main c42b7ce3. That combined tree passes a full build, and the only problems it showed were pre-existing main flakes plus one #3833/#3835 fixture issue that does not involve this PR; the #3835 fix is coming.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Independently reviewed this head. The whole-wave shortcut checks the actively intersecting lanes, and only masks whose proven ancestry covers the position export satisfy the staged coverage check.

MSVC x64 Debug (Windows, RTX 4060 Laptop and WARP): built compile_dxil and ran ctest --preset dev --no-tests=error -j 1 --output-on-failure -R '^(native_mesh_output_mask_ir|native_direct_mesh|native_mesh_readfirstlane_(warp|hardware))$'. All 4 passed, including both adapters and the fixture's refusal cases. The trial merge against 0b83a346b was clean.

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