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

Open
Leyukaka wants to merge 2 commits from upstream-pr/3888 into main
Leyukaka commented 2026-12-02 20:39:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T20:39:44Z.


Takes over #3608 (original commits by @Asimmimx kept unchanged). Supersedes #3608. Refs #3545, #3541. 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.

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

Change

Commit Author Content
96ece7ecc Asimmimx #3608'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 #3608 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 #3638, 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 #3608:

    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 #3608 was not repeated here; the cases are synthetic DXIL text dumps.
  • @Asimmimx, if you would rather rebase #3608 yourself, say so and I will close this PR.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5614318044 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3888). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-02T20:39:44Z. --- Takes over #3608 (original commits by @Asimmimx kept unchanged). Supersedes #3608. Refs #3545, #3541. 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. #3608 fixes this but conflicts with `main` since #3638, and two robustness points from its review were still open. ## Change | Commit | Author | Content | |---|---|---| | `96ece7ecc` | Asimmimx | #3608'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 #3608 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 #3638, 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 #3608: 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 #3608 was not repeated here; the cases are synthetic DXIL text dumps. - @Asimmimx, if you would rather rebase #3608 yourself, say so and I will close this PR.
R0Y00 commented 2026-12-02 20:53:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T20:53:00Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6158814728 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3888#pullrequestreview-6158814728). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T20:53:00Z. **Review:** COMMENTED --- 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 commented 2026-12-03 06:32:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T06:32:32Z.


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 #3608 so we keep one PR for this change.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7369951669 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3888#issuecomment-7369951669). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T06:32:32Z. --- 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 #3608 so we keep one PR for this change.
R0Y00 commented 2026-12-03 08:38:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T08:38:51Z.

Review: APPROVED


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 #3608 is still pending Asimmimx's response.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6166251369 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3888#pullrequestreview-6166251369). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T08:38:51Z. **Review:** APPROVED --- 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 #3608 is still pending Asimmimx's response.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3888:upstream-pr/3888'
git switch 'upstream-pr/3888'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3888'
git switch 'upstream-pr/3888'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3888'
git switch 'upstream-pr/3888'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3888'
git switch 'main'
git merge --squash 'upstream-pr/3888'
git switch 'main'
git merge --ff-only 'upstream-pr/3888'
git switch 'main'
git merge 'upstream-pr/3888'
git push origin 'main'
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!3888
No description provided.