tooling: prove bounded DXIL heap-index expressions in mesh86_cache #3890

Open
github-bot wants to merge 2 commits from github-bot/gh-3888 into main AGit
Owner

@⁠Leyukaka on GitHub · 2026-12-02 20:39 UTC · original
Leyukaka:takeover/3608 → main · +120 −11 · 2 files · 2 commits · open

Takes over #3610 (original commits by @⁠Asimmimx kept unchanged). Supersedes #3610. Refs #3547, #3543. Target main.

Problem

tools/startup/mesh86_cache.py (_heap_index_range) only accepts a constant slot or add (UMin(%x, C)), FIRST when it proves a slot 86 --heap-buffer window. DXC emits other bounded forms, and publication refuses them:

  • a bare UMin (zero base) and the commuted UMin(C, x);
  • x & mask and base + (x & mask), which DXC lowers to and + or when the bits are disjoint;
  • select i1 %cond, i32 a, i32 b;
  • clamp as UMin(UMax(..)) or UMax(UMin(..));
  • zext i1 %cond to i32 added to a base.

#3610 fixes this but conflicts with main since #3640, and two robustness points from its review were still open.

Change

Commit Author Content
96ece7ecc Asimmimx #3610's commit dc1b0c5b, rebased; author, date and message unchanged
9df97999e Leyukaka review follow-up: per-definition cache and depth limit
  • 96ece7ecc replaces the two-pattern matcher with an inclusive u32 interval evaluator (_u32_range) over constants, UMin/UMax, overflow-checked add, and, or, select i1 and zext i1. Unbounded values, a wrapping add, a bare UMax, a select with an unbounded arm, cyclic definitions and ranges outside [first, first + count) are still refused.

  • Rebase. The commit is line-by-line identical to #3610 except for its 14 new test cases, which take the 5-tuple shape main now uses ("f32" for a success, None for a refusal). main's read-type check from #3640, the stage-visibility and constants-only proof for wide legacy heap roots, and the Texture1D profile are unchanged. The overflow (wrap_add) and out-of-window (outside, selected_outside, masked_outside) controls are kept.

  • 9df97999e addresses the two points from mumba17's review of #3610:

    1. Each definition's interval is cached (mesh86_cache.py:178), so a chain that reuses an operand is evaluated in linear time. A definition that is still being evaluated reads as unbounded, so a cycle is refused as before; the cache can only lose precision, never accept an unbounded index.
    2. An expression deeper than 128 definitions (_RANGE_DEPTH_MAX, mesh86_cache.py:161,176) raises ValueError, which main() already reports as a refusal, instead of a RecursionError traceback.

    Four cases pin this: shared operand (accepted as 0..8 in a 9-slot window), shared operand outside (refused in an 8-slot window), shared operand overflow (a 40-line self-add chain, 2**40 evaluations without the cache, refused) and deep chain (1,500 lines, refused with deeper than 128 definitions).

The diff against main is 2 files, +120 -11.

Verification

Windows, MSVC, dev preset, tested at the same content on base 1e2b0d524; the branch was then rebased onto current main, which has not touched either file since. GPU tests run serially.

ctest --preset dev --no-tests=error -j1 -V -R '^(runtime_mesh86_cache_cli_check|startup_indirect_mesh_cache_(heap(_wide)?|texture_map|constants_wide)_(warp|hardware))$'

Result: 9/9 passed.

  • runtime_mesh86_cache_cli_check
  • startup_indirect_mesh_cache_heap_warp, startup_indirect_mesh_cache_heap_hardware
  • startup_indirect_mesh_cache_heap_wide_warp, startup_indirect_mesh_cache_heap_wide_hardware
  • startup_indirect_mesh_cache_texture_map_warp, startup_indirect_mesh_cache_texture_map_hardware
  • startup_indirect_mesh_cache_constants_wide_warp, startup_indirect_mesh_cache_constants_wide_hardware

Notes

  • _heap_index_range(index, defs) keeps its signature and (low, high) return. Only the refusal text changes, to ... neither a constant nor a bounded window expression.
  • Negative constants and any instruction outside the list above stay unbounded and are refused.
  • The real dxc -T ps_6_6 compilation listed in #3610 was not repeated here; the cases are synthetic DXIL text dumps.
  • @⁠Asimmimx, if you would rather rebase #3610 yourself, say so and I will close this PR.
**@⁠Leyukaka** on GitHub · 2026-12-02 20:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3888) `Leyukaka:takeover/3608` → `main` · +120 −11 · 2 files · 2 commits · open Takes over #3610 (original commits by @⁠Asimmimx kept unchanged). Supersedes #3610. Refs #3547, #3543. Target `main`. ## Problem `tools/startup/mesh86_cache.py` (`_heap_index_range`) only accepts a constant slot or `add (UMin(%x, C)), FIRST` when it proves a slot 86 `--heap-buffer` window. DXC emits other bounded forms, and publication refuses them: - a bare `UMin` (zero base) and the commuted `UMin(C, x)`; - `x & mask` and `base + (x & mask)`, which DXC lowers to `and` + `or` when the bits are disjoint; - `select i1 %cond, i32 a, i32 b`; - `clamp` as `UMin(UMax(..))` or `UMax(UMin(..))`; - `zext i1 %cond to i32` added to a base. #3610 fixes this but conflicts with `main` since #3640, and two robustness points from its review were still open. ## Change | Commit | Author | Content | |---|---|---| | `96ece7ecc` | Asimmimx | #3610's commit `dc1b0c5b`, rebased; author, date and message unchanged | | `9df97999e` | Leyukaka | review follow-up: per-definition cache and depth limit | - **`96ece7ecc`** replaces the two-pattern matcher with an inclusive u32 interval evaluator (`_u32_range`) over constants, `UMin`/`UMax`, overflow-checked `add`, `and`, `or`, `select i1` and `zext i1`. Unbounded values, a wrapping `add`, a bare `UMax`, a `select` with an unbounded arm, cyclic definitions and ranges outside `[first, first + count)` are still refused. - **Rebase.** The commit is line-by-line identical to #3610 except for its 14 new test cases, which take the 5-tuple shape `main` now uses (`"f32"` for a success, `None` for a refusal). `main`'s read-type check from #3640, the stage-visibility and `constants-only` proof for wide legacy heap roots, and the Texture1D profile are unchanged. The overflow (`wrap_add`) and out-of-window (`outside`, `selected_outside`, `masked_outside`) controls are kept. - **`9df97999e`** addresses the two points from mumba17's review of #3610: 1. Each definition's interval is cached (`mesh86_cache.py:178`), so a chain that reuses an operand is evaluated in linear time. A definition that is still being evaluated reads as unbounded, so a cycle is refused as before; the cache can only lose precision, never accept an unbounded index. 2. An expression deeper than 128 definitions (`_RANGE_DEPTH_MAX`, `mesh86_cache.py:161,176`) raises `ValueError`, which `main()` already reports as a refusal, instead of a `RecursionError` traceback. Four cases pin this: `shared operand` (accepted as `0..8` in a 9-slot window), `shared operand outside` (refused in an 8-slot window), `shared operand overflow` (a 40-line self-add chain, 2**40 evaluations without the cache, refused) and `deep chain` (1,500 lines, refused with `deeper than 128 definitions`). The diff against `main` is 2 files, +120 -11. ## Verification Windows, MSVC, `dev` preset, tested at the same content on base `1e2b0d524`; the branch was then rebased onto current `main`, which has not touched either file since. GPU tests run serially. ```powershell ctest --preset dev --no-tests=error -j1 -V -R '^(runtime_mesh86_cache_cli_check|startup_indirect_mesh_cache_(heap(_wide)?|texture_map|constants_wide)_(warp|hardware))$' ``` Result: 9/9 passed. - `runtime_mesh86_cache_cli_check` - `startup_indirect_mesh_cache_heap_warp`, `startup_indirect_mesh_cache_heap_hardware` - `startup_indirect_mesh_cache_heap_wide_warp`, `startup_indirect_mesh_cache_heap_wide_hardware` - `startup_indirect_mesh_cache_texture_map_warp`, `startup_indirect_mesh_cache_texture_map_hardware` - `startup_indirect_mesh_cache_constants_wide_warp`, `startup_indirect_mesh_cache_constants_wide_hardware` ## Notes - `_heap_index_range(index, defs)` keeps its signature and `(low, high)` return. Only the refusal text changes, to `... neither a constant nor a bounded window expression`. - Negative constants and any instruction outside the list above stay unbounded and are refused. - The real `dxc -T ps_6_6` compilation listed in #3610 was not repeated here; the cases are synthetic DXIL text dumps. - @⁠Asimmimx, if you would rather rebase #3610 yourself, say so and I will close this PR.
Evaluate each SSA definition once, so a chain that reuses an operand
stays linear, and refuse an index expression deeper than 128
definitions with a ValueError instead of a RecursionError traceback.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 20:40:38 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 20:53 UTC · original · reviewed

Independently reviewed 9df97999. Memoization removes repeated evaluation within one interval proof, and cyclic/deep definitions stay on the refusal path. The unsigned endpoint rules preserve overflow and window checks. MSVC Debug ctest --preset dev --no-tests=error -j 1 --output-on-failure -R '^(runtime_mesh86_cache_cli_check|startup_indirect_mesh_cache_(heap(_wide)?|texture_map|constants_wide)_(warp|hardware))$' passed 9/9 on Windows 11 build 26300, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. The CLI cases cover shared subexpressions, depth, cycles, overflow and a too-small window. The original PR's landing choice with @⁠Asimmimx is pending.

**@⁠R0Y00** on GitHub · 2026-12-02 20:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3888#pullrequestreview-6158814728) · **reviewed** Independently reviewed `9df97999`. Memoization removes repeated evaluation within one interval proof, and cyclic/deep definitions stay on the refusal path. The unsigned endpoint rules preserve overflow and window checks. MSVC Debug `ctest --preset dev --no-tests=error -j 1 --output-on-failure -R '^(runtime_mesh86_cache_cli_check|startup_indirect_mesh_cache_(heap(_wide)?|texture_map|constants_wide)_(warp|hardware))$'` passed 9/9 on Windows 11 build 26300, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. The CLI cases cover shared subexpressions, depth, cycles, overflow and a too-small window. The original PR's landing choice with @⁠Asimmimx is pending.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-03 06:32 UTC · original

I reviewed 9df97999e and ran python -B tests/startup_mesh86_cache_cli_check.py on that exact head. All six CLI tests passed, including the shared-operand window boundaries, wrapping addition, and the 1,500-definition depth refusal. The branch also merges cleanly with main at 09ff8edec, and the three required CI jobs passed. I’ll leave the takeover pending Asimmimx’s reply on #3610 so we keep one PR for this change.

**@⁠R0Y00** on GitHub · 2026-12-03 06:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3888#issuecomment-7369951669) I reviewed `9df97999e` and ran `python -B tests/startup_mesh86_cache_cli_check.py` on that exact head. All six CLI tests passed, including the shared-operand window boundaries, wrapping addition, and the 1,500-definition depth refusal. The branch also merges cleanly with `main` at `09ff8edec`, and the three required CI jobs passed. I’ll leave the takeover pending Asimmimx’s reply on #3610 so we keep one PR for this change.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-03 08:38 UTC · original · approved these changes

Technical approval for 9df97999e. The exact-head startup_mesh86_cache_cli_check.py passed all six tests, including overflow refusal, the shared operand at a window boundary, and the oversized definition chain. The memo stores conservative unsigned intervals and rejects out-of-window ranges; required CI passed. The landing choice with the original #3610 is still pending Asimmimx's response.

**@⁠R0Y00** on GitHub · 2026-12-03 08:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3888#pullrequestreview-6166251369) · **approved these changes** Technical approval for 9df97999e. The exact-head startup_mesh86_cache_cli_check.py passed all six tests, including overflow refusal, the shared operand at a window boundary, and the oversized definition chain. The memo stores conservative unsigned intervals and rejects out-of-window ranges; required CI passed. The landing choice with the original #3610 is still pending Asimmimx's response.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3890/head:github-bot/gh-3888'
git switch 'github-bot/gh-3888'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3888'
git switch 'github-bot/gh-3888'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3888'
git switch 'github-bot/gh-3888'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3888'
git switch 'main'
git merge --squash 'github-bot/gh-3888'
git switch 'main'
git merge --ff-only 'github-bot/gh-3888'
git switch 'main'
git merge 'github-bot/gh-3888'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.