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

Open
Asimmimx wants to merge 1 commit from upstream-pr/3608 into main
Asimmimx commented 2026-11-30 13:27:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-30T13:27:33Z.


Refs #3545, #3541. Target main.

Problem

tools/startup/mesh86_cache.py (_heap_index_range) only accepted a constant slot or add (UMin(%x, C)), FIRST when proving a published slot 86 --heap-buffer window. Common bounded DXIL heap-index expressions emitted by DXC were refused at publication, including:

  • zero-based min(x, C) (DXC folds + 0, leaving a bare UMin);
  • commuted UMin(C, x);
  • bitmask indexing x & mask and base + (x & mask) (which DXC lowers to and + or when bits are disjoint);
  • two-way select i1 %cond, i32 a, i32 b (emitted for cond ? a : b and base + uint(cond));
  • clamped ranges clamp(x, lo, hi) (UMin(UMax(x, lo), hi) / UMax(UMin(x, hi), lo));
  • zext i1 %cond to i32 added to a base.

Change

  • Replace the two-pattern matcher in tools/startup/mesh86_cache.py with a sound inclusive u32 interval evaluator (_u32_range) over constants, dx.op.binary.i32 UMax (39) / UMin (40), overflow-checked add, and, or, select i1, and zext i1 to i32, with cycle detection.
  • Unbounded values, 32-bit wrapping add, bare UMax, select with an unbounded branch, cyclic SSA definitions, and ranges leaving [first, first + count) remain refused.
  • Extend tests/startup_mesh86_cache_cli_check.py with positive cases for each form and negative controls for out-of-window, unbounded, wrapping, and cyclic expressions.

Verification

Base commit 077bff3a, Windows 11 build 10.0.26300.0, MSVC Debug (dev preset), AMD Radeon RX 6600 (driver 32.0.21045.29003), DXC 10.0.26100.0 (CTest) and Vulkan SDK 1.4.363.0:

powershell .\out\pe-env\Scripts\python.exe -B tests\startup_mesh86_cache_cli_check.py ctest --preset dev --no-tests=error -j1 -R '^(startup_indirect_mesh_cache_heap_|runtime_mesh86_cache_cli_check$)' -V .\out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py

  • runtime_mesh86_cache_cli_check: Passed (5/5, including all 21 heap-buffer window subtests)
  • startup_indirect_mesh_cache_heap_warp: Passed
  • startup_indirect_mesh_cache_heap_hardware (AMD Radeon RX 6600): Passed
  • Real dxc -T ps_6_6 compilation covering min(v.x, 1u), 4u + (v.y & 1u), (v.z != 0u) ? 4u : 5u, clamp(v.w, 4u, 5u), and 4u + uint(v.z != 0u): prove_heap_buffer_window([dump], 0, 6) returned (0, 6)
  • tests/bidi_controls_check.py: Passed (2726 files checked)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5566197855 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3608). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-30T13:27:33Z. --- Refs #3545, #3541. Target `main`. ## Problem `tools/startup/mesh86_cache.py` (`_heap_index_range`) only accepted a constant slot or `add (UMin(%x, C)), FIRST` when proving a published slot 86 `--heap-buffer` window. Common bounded DXIL heap-index expressions emitted by DXC were refused at publication, including: - zero-based `min(x, C)` (DXC folds `+ 0`, leaving a bare `UMin`); - commuted `UMin(C, x)`; - bitmask indexing `x & mask` and `base + (x & mask)` (which DXC lowers to `and` + `or` when bits are disjoint); - two-way `select i1 %cond, i32 a, i32 b` (emitted for `cond ? a : b` and `base + uint(cond)`); - clamped ranges `clamp(x, lo, hi)` (`UMin(UMax(x, lo), hi)` / `UMax(UMin(x, hi), lo)`); - `zext i1 %cond to i32` added to a base. ## Change - Replace the two-pattern matcher in `tools/startup/mesh86_cache.py` with a sound inclusive `u32` interval evaluator (`_u32_range`) over constants, `dx.op.binary.i32` `UMax` (39) / `UMin` (40), overflow-checked `add`, `and`, `or`, `select i1`, and `zext i1 to i32`, with cycle detection. - Unbounded values, 32-bit wrapping `add`, bare `UMax`, `select` with an unbounded branch, cyclic SSA definitions, and ranges leaving `[first, first + count)` remain refused. - Extend `tests/startup_mesh86_cache_cli_check.py` with positive cases for each form and negative controls for out-of-window, unbounded, wrapping, and cyclic expressions. ## Verification Base commit `077bff3a`, Windows 11 build `10.0.26300.0`, MSVC Debug (`dev` preset), AMD Radeon RX 6600 (driver `32.0.21045.29003`), DXC `10.0.26100.0` (CTest) and Vulkan SDK `1.4.363.0`: ``powershell .\out\pe-env\Scripts\python.exe -B tests\startup_mesh86_cache_cli_check.py ctest --preset dev --no-tests=error -j1 -R '^(startup_indirect_mesh_cache_heap_|runtime_mesh86_cache_cli_check$)' -V .\out\pe-env\Scripts\python.exe -B tests\bidi_controls_check.py `` - `runtime_mesh86_cache_cli_check`: Passed (5/5, including all 21 heap-buffer window subtests) - `startup_indirect_mesh_cache_heap_warp`: Passed - `startup_indirect_mesh_cache_heap_hardware` (AMD Radeon RX 6600): Passed - Real `dxc -T ps_6_6` compilation covering `min(v.x, 1u)`, `4u + (v.y & 1u)`, `(v.z != 0u) ? 4u : 5u`, `clamp(v.w, 4u, 5u)`, and `4u + uint(v.z != 0u)`: `prove_heap_buffer_window([dump], 0, 6)` returned `(0, 6)` - `tests/bidi_controls_check.py`: Passed (2726 files checked)
mumba17 commented 2026-11-30 13:47:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-11-30T13:47:38Z.

Review: COMMENTED


Reviewed dc1b0c5b by reading the diff, not run. I wrote the original --heap-buffer proof in #3593.

The interval evaluator looks sound for every form it accepts:

  • UMin/UMax take the min/max of the bounds.
  • add is accepted only when the upper bounds cannot overflow 32 bits.
  • and is bounded by the smaller operand and by the bits both sides can set.
  • or is an exact sum only when the possible bits are disjoint, and is bounded by their union otherwise.
  • select and zext i1 are handled.
  • Unknown instructions, negative constants (\d+ does not match them) and cycles become unbounded and are refused.

Two robustness points, neither a soundness issue:

  1. No memoization in _u32_range. A shared sub-expression is evaluated once per use, so a chain like %2 = add %1, %1; %3 = add %2, %2; … takes exponential time, and about 30 such lines would hang publication. Caching the result per operand fixes it. The result does not depend on seen except for cycles, which already return unbounded.
  2. Deep chains raise RecursionError. main() does not catch it, so the user gets a traceback instead of a refusal. Catching it and refusing, or evaluating iteratively, would fix this.

A small test for each would pin these: a 30-line self-add chain that must finish quickly, and a chain of about 1,500 lines that must be refused cleanly.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6113277204 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3608#pullrequestreview-6113277204). Originally posted by [mumba17](https://github.com/mumba17) on 2026-11-30T13:47:38Z. **Review:** COMMENTED --- Reviewed `dc1b0c5b` by reading the diff, not run. I wrote the original `--heap-buffer` proof in #3593. The interval evaluator looks sound for every form it accepts: - `UMin`/`UMax` take the min/max of the bounds. - `add` is accepted only when the upper bounds cannot overflow 32 bits. - `and` is bounded by the smaller operand and by the bits both sides can set. - `or` is an exact sum only when the possible bits are disjoint, and is bounded by their union otherwise. - `select` and `zext i1` are handled. - Unknown instructions, negative constants (`\d+` does not match them) and cycles become unbounded and are refused. Two robustness points, neither a soundness issue: 1. **No memoization in `_u32_range`.** A shared sub-expression is evaluated once per use, so a chain like `%2 = add %1, %1; %3 = add %2, %2; …` takes exponential time, and about 30 such lines would hang publication. Caching the result per operand fixes it. The result does not depend on `seen` except for cycles, which already return unbounded. 2. **Deep chains raise `RecursionError`.** `main()` does not catch it, so the user gets a traceback instead of a refusal. Catching it and refusing, or evaluating iteratively, would fix this. A small test for each would pin these: a 30-line self-add chain that must finish quickly, and a chain of about 1,500 lines that must be refused cleanly.
R0Y00 commented 2026-11-30 19:33:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-30T19:33:51Z.

Review: COMMENTED


The current head conflicts with main after #3638 in the same cache-producer and CLI-test surface. Please rebase the interval proof while preserving the stage-visibility and constants-only proof for wide legacy heap roots and the separate Texture1D profile. Keep the overflow and out-of-window controls, then rerun runtime_mesh86_cache_cli_check on the revised head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6119155291 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3608#pullrequestreview-6119155291). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-30T19:33:51Z. **Review:** COMMENTED --- The current head conflicts with `main` after #3638 in the same cache-producer and CLI-test surface. Please rebase the interval proof while preserving the stage-visibility and `constants-only` proof for wide legacy heap roots and the separate Texture1D profile. Keep the overflow and out-of-window controls, then rerun `runtime_mesh86_cache_cli_check` on the revised head.
Leyukaka commented 2026-12-02 20:39:58 +00:00 (Migrated from github.com)

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


Thank you for this change, @Asimmimx. #3608 conflicts with main since #3638, so I rebased it in #3888: your commit is carried with its authorship and message unchanged, with one commit on top for the two robustness points from the review. Are you fine with closing #3608 in its favour? If you would rather rebase this one yourself, say so and I will close mine.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7358112649 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3608#issuecomment-7358112649). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-02T20:39:58Z. --- Thank you for this change, @Asimmimx. #3608 conflicts with `main` since #3638, so I rebased it in #3888: your commit is carried with its authorship and message unchanged, with one commit on top for the two robustness points from the review. Are you fine with closing #3608 in its favour? If you would rather rebase this one yourself, say so and I will close mine.
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/3608:upstream-pr/3608'
git switch 'upstream-pr/3608'

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