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

Merged
timbot103 merged 2 commits from upstream-pr/3832 into main 2026-12-03 00:25:52 +00:00
timbot103 commented 2026-12-02 08:00:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T08:00:16Z.


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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5602322357 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3832). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T08:00:16Z. --- 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 commented 2026-12-02 08:06:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T08:06:35Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6146859211 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3832#pullrequestreview-6146859211). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T08:06:35Z. **Review:** APPROVED --- 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.
lukaslw-lab commented 2026-12-02 20:27:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T20:27:28Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6158376343 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3832#pullrequestreview-6158376343). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T20:27:28Z. **Review:** APPROVED --- 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 commented 2026-12-02 23:04:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T23:04:54Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7361538894 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3832#issuecomment-7361538894). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T23:04:54Z. --- 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 commented 2026-12-02 23:47:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T23:47:26Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7362428230 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3832#issuecomment-7362428230). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T23:47:26Z. --- 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 commented 2026-12-03 00:24:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T00:24:43Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6161509803 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3832#pullrequestreview-6161509803). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T00:24:43Z. **Review:** APPROVED --- 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 in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!3832
No description provided.