shader: lower bounded runtime mesh geometry comparisons #1906

Merged
avt0m4t48 merged 2 commits from upstream-pr/1913 into main 2026-11-24 21:19:52 +00:00
avt0m4t48 commented 2026-11-24 20:58:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by avt0m4t48 on 2026-11-24T20:58:42Z.


Refs #1760. Builds on the source-built mesh fixture from #1889.

The optional mesh_dynamic_aot tool translates a bounded two-wave64 triangle entry to one desktop mesh HLSL shader. A scalar equality against a runtime geometry DWORD divides the input into cases. Replay of the existing wave model proves every case's allocation and exports before the tool emits HLSL. At execution, a raw SRV supplies the words and selects the case. Unsupported arithmetic, bounds, incomplete outputs, backward branches, and more than 32 cases are refused.

Both test adapters use the existing offscreen_check mesh renderer with source-built programs. One generated shader handles triangle, quad, empty, over-limit, invalid-index, and duplicate-primitive inputs. A source compare immediate changed in a second program gives two controls for accepting the new word and refusing the old one.

  • Windows build 26100, Microsoft Basic Render Driver, D3D12 debug layer enabled: cmake --build --preset release --target offscreen_check and ctest --preset release --no-tests=error -R '^mesh_dynamic_aot_(cpu|draw_warp)$' -V passed 2/2. All eight WARP cases matched all 1,024 pixels each. Windows results
  • Linux LLVM 15 reassembly and both portable mesh checks passed. Linux DXC and dxv validated the two unmodified ms_6_5 shaders. A separate Vulkan llvmpipe check matched every pixel, allocation, primitive index and trace guard for both source variants.
  • The physical check is ctest --preset release --no-tests=error -R '^mesh_dynamic_aot_draw_hardware$' -V. Physical execution and routing application mesh pipelines into this tool remain open. The input programs and pixel references are source-built.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6591279865 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1913). Originally posted by [avt0m4t48](https://github.com/avt0m4t48) on 2026-11-24T20:58:42Z. --- Refs #1760. Builds on the source-built mesh fixture from #1889. The optional `mesh_dynamic_aot` tool translates a bounded two-wave64 triangle entry to one desktop mesh HLSL shader. A scalar equality against a runtime geometry DWORD divides the input into cases. Replay of the existing wave model proves every case's allocation and exports before the tool emits HLSL. At execution, a raw SRV supplies the words and selects the case. Unsupported arithmetic, bounds, incomplete outputs, backward branches, and more than 32 cases are refused. Both test adapters use the existing `offscreen_check` mesh renderer with source-built programs. One generated shader handles triangle, quad, empty, over-limit, invalid-index, and duplicate-primitive inputs. A source compare immediate changed in a second program gives two controls for accepting the new word and refusing the old one. - Windows build 26100, Microsoft Basic Render Driver, D3D12 debug layer enabled: `cmake --build --preset release --target offscreen_check` and `ctest --preset release --no-tests=error -R '^mesh_dynamic_aot_(cpu|draw_warp)$' -V` passed 2/2. All eight WARP cases matched all 1,024 pixels each. [Windows results](https://github.com/avt0m4t48/Xbox2Windows/actions/runs/45485816247) - Linux LLVM 15 reassembly and both portable mesh checks passed. Linux DXC and `dxv` validated the two unmodified `ms_6_5` shaders. A separate Vulkan llvmpipe check matched every pixel, allocation, primitive index and trace guard for both source variants. - The physical check is `ctest --preset release --no-tests=error -R '^mesh_dynamic_aot_draw_hardware$' -V`. Physical execution and routing application mesh pipelines into this tool remain open. The input programs and pixel references are source-built.
upstream-sync closed this pull request 2026-11-24 21:27:34 +00:00
tedin7 commented 2026-11-24 21:27:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:15:24Z.

Review: COMMENTED


Review of exact head e6e327d65092d70e1ffcd81e360b25fd3e355b23 (base main). Scope: new tools/mesh_dynamic_aot.py (+232), two new tests, a small refactor of tools/mesh_entry_aot.py (translate split into decode_mesh + lower), CMake/CI registration, docs. Comment only, no approval.

Verdict: no P1/P2 found. The lowering logic reads sound and the Windows lanes pass. There are P3 test-coverage gaps (several guards survive mutation), listed below.

Clean-room / title

  • Title is neutral. The tests reuse the existing synthetic oracle (mesh_dynamic_geometry_check.CASES/CODE), so no vendor bytes are added. Docs-only external reference: see the docs note below.

What I checked in the diff

  • Partitioning (mesh_dynamic_aot.py:enumerate_variants): every split pushes both != and == for the same word/value, so the cases are disjoint and exhaustive. That makes it correct to emit the last case as a bare else in emit_hlsl. A word that is never proven concrete raises (RuntimeWave.scalar/lane_value/vector_op), so no sample value is ever substituted for an unknown word.
  • s_cmp_eq_u32 handling: the excluded branch sets scc = False and a comparison between two runtime words falls through to the base class and is refused via RuntimeWave.scalar (mutation M2 below confirms this path matters).
  • Emitted HLSL: variant/vertexCount/primitiveCount are assigned on every if/else path, the loads are uniform, and exactly one SetMeshOutputCounts is emitted before any output write. Per-variant precise expression blocks are scoped, so names cannot collide.
  • Refactor in mesh_entry_aot.py: translate is behaviour-preserving (same decode arguments, same lower call).

Commands run locally (venv x2w-rev-venv, worktree at the exact SHA, git rev-parse HEAD == headRefOid)

  • git diff --check origin/main...HEAD -> exit 0, no output
  • python -B tests/mesh_dynamic_aot_check.py -> Runtime mesh specializations matched the CPU cases and rejected unproven uses
  • python -B tests/mesh_dynamic_geometry_check.py -> Six mesh inputs matched the CPU allocation and export model
  • python -B tests/mesh_amplification_refusal_check.py -> passes
  • python -B tests/bidi_controls_check.py -> Checked 1334 tracked ... files: no bidirectional controls.
  • python -B tests/docs_links_check.py -> Checked 18 Markdown files and 377 links.
  • Windows Server 2025 (MSVC 14.44.35207, D3D12 WARP), x2w_pipe.py win2025 1913 --targets offscreen_check --regex '^(mesh_dynamic_aot_cpu|mesh_dynamic_aot_draw_warp|mesh_dynamic_geometry_cpu|mesh_pixel_pipeline_warp)$': Debug and Release 4/4 passed, including the new mesh_dynamic_aot_cpu and mesh_dynamic_aot_draw_warp.
  • Refactor regression, same lane with --regex '^(mesh_entry|mesh_indexed|mesh_fallback|mesh_descriptor)': Debug and Release 14/14 passed (WARP and hardware adapter variants).
  • Limit: the other mesh Python checks (mesh_entry_check.py, mesh_indexed_check.py, ...) need DXC and an adapter and cannot run standalone on Linux, so they were only exercised through the Windows lane above. The mutations below were run on Linux against tests/mesh_dynamic_aot_check.py only. mesh_dynamic_aot_draw_check.py was not mutated (Windows-only).

Mutation testing (each applied to tools/mesh_dynamic_aot.py, tests/mesh_dynamic_aot_check.py re-run, then git checkout -- .)

# Mutation Result
M2 excluded-branch self.scc = False -> True killed (ValueError: Unproven runtime geometry word 0 in s15)
M1 cap check + 2 > MAX_VARIANTS -> >= survived
M3 drop & U32 on the compared value survived
M4 HLSL predicate always == (never !=) survived the CPU check
M5 geometry bound key < word_count -> <= survived
M6 drop or second.counts (second wave must not set counts) survived
M7 drop max(triangle) >= nv index-range check survived

P3 (non-blocking) test gaps, from the surviving mutants

  • tests/mesh_dynamic_aot_check.py patches MAX_VARIANTS to 1 only, so the exact boundary (tools/mesh_dynamic_aot.py:149, 32 cases allowed vs 31) is not pinned. Patching it to the real variant count of CASES (and to one less) would pin both sides.
  • mesh_dynamic_aot.py:125 and :117 (triangle index >= vertex count; counts set by the second wave) have no refusal case. A case in the style of the existing expect_refusal calls (edit one decoded instruction) would cover them.
  • mesh_dynamic_aot.py:50: the scalar index bound is unexercised (all reads go through the slice branch, line 47). Either test it or drop the unused branch.
  • M4: the HLSL predicate text is only checked for load lines and counts. The Windows draw test would catch a wrong ==/!= pixel result, but the Linux unit test never looks at the predicates. One substring assertion on a != clause would make the CPU lane catch it.
  • mesh_dynamic_aot.py:228-229: the CLI catches ValueError/KeyError only, so a missing input file (OSError) or geometry[:n] with a None slice bound (TypeError at line 47) would print a traceback. The CLI has no test at all in this PR.

Docs note

  • docs/experiments.md ends the new section with a link to a CI run on a contributor fork (avt0m4t48/Xbox2Windows/actions/runs/...). Two such links already exist in the file, so this follows the current convention; fork runs can disappear, so the numbers in the paragraph (6 inputs + 2 controls, 1,024 pixels each) are worth keeping reproducible by the ctest command printed just above, as they are.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6047531225 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1913#pullrequestreview-6047531225). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T21:15:24Z. **Review:** COMMENTED --- Review of exact head `e6e327d65092d70e1ffcd81e360b25fd3e355b23` (base `main`). Scope: new `tools/mesh_dynamic_aot.py` (+232), two new tests, a small refactor of `tools/mesh_entry_aot.py` (`translate` split into `decode_mesh` + `lower`), CMake/CI registration, docs. Comment only, no approval. **Verdict: no P1/P2 found. The lowering logic reads sound and the Windows lanes pass. There are P3 test-coverage gaps (several guards survive mutation), listed below.** ### Clean-room / title - Title is neutral. The tests reuse the existing synthetic oracle (`mesh_dynamic_geometry_check.CASES/CODE`), so no vendor bytes are added. Docs-only external reference: see the docs note below. ### What I checked in the diff - Partitioning (`mesh_dynamic_aot.py:enumerate_variants`): every split pushes both `!=` and `==` for the same word/value, so the cases are disjoint and exhaustive. That makes it correct to emit the last case as a bare `else` in `emit_hlsl`. A word that is never proven concrete raises (`RuntimeWave.scalar/lane_value/vector_op`), so no sample value is ever substituted for an unknown word. - `s_cmp_eq_u32` handling: the excluded branch sets `scc = False` and a comparison between two runtime words falls through to the base class and is refused via `RuntimeWave.scalar` (mutation M2 below confirms this path matters). - Emitted HLSL: `variant/vertexCount/primitiveCount` are assigned on every if/else path, the loads are uniform, and exactly one `SetMeshOutputCounts` is emitted before any output write. Per-variant `precise` expression blocks are scoped, so names cannot collide. - Refactor in `mesh_entry_aot.py`: `translate` is behaviour-preserving (same `decode` arguments, same `lower` call). ### Commands run locally (venv `x2w-rev-venv`, worktree at the exact SHA, `git rev-parse HEAD` == `headRefOid`) - `git diff --check origin/main...HEAD` -> exit 0, no output - `python -B tests/mesh_dynamic_aot_check.py` -> `Runtime mesh specializations matched the CPU cases and rejected unproven uses` - `python -B tests/mesh_dynamic_geometry_check.py` -> `Six mesh inputs matched the CPU allocation and export model` - `python -B tests/mesh_amplification_refusal_check.py` -> passes - `python -B tests/bidi_controls_check.py` -> `Checked 1334 tracked ... files: no bidirectional controls.` - `python -B tests/docs_links_check.py` -> `Checked 18 Markdown files and 377 links.` - Windows Server 2025 (MSVC 14.44.35207, D3D12 WARP), `x2w_pipe.py win2025 1913 --targets offscreen_check --regex '^(mesh_dynamic_aot_cpu|mesh_dynamic_aot_draw_warp|mesh_dynamic_geometry_cpu|mesh_pixel_pipeline_warp)$'`: Debug and Release **4/4 passed**, including the new `mesh_dynamic_aot_cpu` and `mesh_dynamic_aot_draw_warp`. - Refactor regression, same lane with `--regex '^(mesh_entry|mesh_indexed|mesh_fallback|mesh_descriptor)'`: Debug and Release **14/14 passed** (WARP and hardware adapter variants). - Limit: the other mesh Python checks (`mesh_entry_check.py`, `mesh_indexed_check.py`, ...) need DXC and an adapter and cannot run standalone on Linux, so they were only exercised through the Windows lane above. The mutations below were run on Linux against `tests/mesh_dynamic_aot_check.py` only. `mesh_dynamic_aot_draw_check.py` was not mutated (Windows-only). ### Mutation testing (each applied to `tools/mesh_dynamic_aot.py`, `tests/mesh_dynamic_aot_check.py` re-run, then `git checkout -- .`) | # | Mutation | Result | |---|---|---| | M2 | excluded-branch `self.scc = False` -> `True` | killed (`ValueError: Unproven runtime geometry word 0 in s15`) | | M1 | cap check `+ 2 > MAX_VARIANTS` -> `>=` | **survived** | | M3 | drop `& U32` on the compared value | **survived** | | M4 | HLSL predicate always `==` (never `!=`) | **survived** the CPU check | | M5 | geometry bound `key < word_count` -> `<=` | **survived** | | M6 | drop `or second.counts` (second wave must not set counts) | **survived** | | M7 | drop `max(triangle) >= nv` index-range check | **survived** | ### P3 (non-blocking) test gaps, from the surviving mutants - `tests/mesh_dynamic_aot_check.py` patches `MAX_VARIANTS` to 1 only, so the exact boundary (`tools/mesh_dynamic_aot.py:149`, 32 cases allowed vs 31) is not pinned. Patching it to the real variant count of `CASES` (and to one less) would pin both sides. - `mesh_dynamic_aot.py:125` and `:117` (triangle index >= vertex count; counts set by the second wave) have no refusal case. A case in the style of the existing `expect_refusal` calls (edit one decoded instruction) would cover them. - `mesh_dynamic_aot.py:50`: the scalar index bound is unexercised (all reads go through the slice branch, line 47). Either test it or drop the unused branch. - M4: the HLSL predicate text is only checked for load lines and counts. The Windows draw test would catch a wrong `==`/`!=` pixel result, but the Linux unit test never looks at the predicates. One substring assertion on a `!=` clause would make the CPU lane catch it. - `mesh_dynamic_aot.py:228-229`: the CLI catches `ValueError/KeyError` only, so a missing input file (`OSError`) or `geometry[:n]` with a `None` slice bound (`TypeError` at line 47) would print a traceback. The CLI has no test at all in this PR. ### Docs note - `docs/experiments.md` ends the new section with a link to a CI run on a contributor fork (`avt0m4t48/Xbox2Windows/actions/runs/...`). Two such links already exist in the file, so this follows the current convention; fork runs can disappear, so the numbers in the paragraph (6 inputs + 2 controls, 1,024 pixels each) are worth keeping reproducible by the `ctest` command printed just above, as they are. AI-assisted; commands listed were executed locally.
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!1906
No description provided.