shader: prove packed root selectors for mesh heap reads (Part of #3703) #3721

Manually merged
github merged 1 commit from github-bot/gh-3719 into gh-pr/3719/base 2026-12-02 02:51:54 +00:00 AGit
Owner

@⁠timbot103 on GitHub · 2026-12-01 10:52 UTC · original
timbot103:shader/mesh-heap-slot-masked-root-provenance → main · +183 −35 · 6 files · 1 commits · merged 2026-12-02 02:51 UTC

Refs #3705.

Summary

Extends root-constant provenance tracking for directly indexed R32_UINT resource-heap reads in the C++ mesh frontend (src/gfx1013_direct_mesh.inl), runtime binder (src/startup_stubs/native_mesh86.inl, src/startup_stubs/native_mesh57.inl), and CLI diagnostics (tools/startup/compile_dxil.cpp):

  • Packed root selectors: s_bfe_u32 and s_lshr_b32 combined with s_and_b32 (with immediate in either operand position for commutative ops) now prove bounded packed root fields; scaling requires << 5 (s_lshl_b32) or * 32 (s_mul_i32).
  • Provenance propagation & constant base offsets: s_mov_b32 and proven-uniform v_readfirstlane_b32 preserve reaching SSA provenance (overwriting discards it); 32-byte-aligned s_add_u32 (checked against 32-bit wrap) and disjoint-bit s_or_b32 (with zero prior base) add a bounded slot base.
  • Shared formula & runtime bounds: Both DXIL emission and native_mesh86.inl compute ((root_word >> shift) & mask) + base and check base + mask < 1024. native_mesh57.inl continues to require shift == 0 && base == 0.
  • Fail-closed controls: Unmasked shifts, wide/dynamic masks or s_bfe_u32, non-32-byte scales, unaligned adds, overlapping s_or_b32, wrapping adds, overwritten copies, and token-without-contract paths stay strictly refused.

Verification

Windows 11 (26200), MSVC 19.44, Ninja, Windows SDK 10.0.26100, NVIDIA GeForce RTX 5080 (driver 32.0.16.2140) + WARP (10.0.26100.9818). D3D12 debug layer unavailable on this host (D3D12GetDebugInterface=0x887a002d). Source-built tests only; 10 new positive DXIL/metadata cases and 16 refusal cases in tests/native_direct_mesh_check.py.

  • Debug (dev preset):
    • ctest --preset dev --no-tests=error -R '^native_direct_|^startup_mesh57_real_shape$' -V -> 3/3 passed (native_direct_container, native_direct_mesh, startup_mesh57_real_shape)
    • Built d3d12_xs_shim + startup_indirect_draw_indexed; ctest --preset dev --no-tests=error -R '^native_fixed_mesh57_uint_heap_(warp|hardware)$' -V -> 2/2 passed (WARP + RTX 5080)
    • ctest --preset dev --no-tests=error -R 'mesh86' -V -> 2/2 passed (startup_mesh86_srv_proof, runtime_mesh86_cache_cli_check)
  • Release (release preset):
    • Built compile_dxil + d3d12_xs_shim; ctest --preset release --no-tests=error -R '^native_direct_|^startup_mesh57_real_shape$' -V -> 3/3 passed
  • git diff --check HEAD^ HEAD clean.

AI-assisted.

**@⁠timbot103** on GitHub · 2026-12-01 10:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3719) `timbot103:shader/mesh-heap-slot-masked-root-provenance` → `main` · +183 −35 · 6 files · 1 commits · merged 2026-12-02 02:51 UTC Refs #3705. ## Summary Extends root-constant provenance tracking for directly indexed `R32_UINT` resource-heap reads in the C++ mesh frontend (`src/gfx1013_direct_mesh.inl`), runtime binder (`src/startup_stubs/native_mesh86.inl`, `src/startup_stubs/native_mesh57.inl`), and CLI diagnostics (`tools/startup/compile_dxil.cpp`): - **Packed root selectors:** `s_bfe_u32` and `s_lshr_b32` combined with `s_and_b32` (with immediate in either operand position for commutative ops) now prove bounded packed root fields; scaling requires `<< 5` (`s_lshl_b32`) or `* 32` (`s_mul_i32`). - **Provenance propagation & constant base offsets:** `s_mov_b32` and proven-uniform `v_readfirstlane_b32` preserve reaching SSA provenance (overwriting discards it); 32-byte-aligned `s_add_u32` (checked against 32-bit wrap) and disjoint-bit `s_or_b32` (with zero prior base) add a bounded slot base. - **Shared formula & runtime bounds:** Both DXIL emission and `native_mesh86.inl` compute `((root_word >> shift) & mask) + base` and check `base + mask < 1024`. `native_mesh57.inl` continues to require `shift == 0 && base == 0`. - **Fail-closed controls:** Unmasked shifts, wide/dynamic masks or `s_bfe_u32`, non-32-byte scales, unaligned adds, overlapping `s_or_b32`, wrapping adds, overwritten copies, and token-without-contract paths stay strictly refused. ## Verification Windows 11 (26200), MSVC 19.44, Ninja, Windows SDK 10.0.26100, NVIDIA GeForce RTX 5080 (driver `32.0.16.2140`) + WARP (`10.0.26100.9818`). D3D12 debug layer unavailable on this host (`D3D12GetDebugInterface=0x887a002d`). Source-built tests only; 10 new positive DXIL/metadata cases and 16 refusal cases in `tests/native_direct_mesh_check.py`. - **Debug (`dev` preset):** - `ctest --preset dev --no-tests=error -R '^native_direct_|^startup_mesh57_real_shape$' -V` -> **3/3 passed** (`native_direct_container`, `native_direct_mesh`, `startup_mesh57_real_shape`) - Built `d3d12_xs_shim` + `startup_indirect_draw_indexed`; `ctest --preset dev --no-tests=error -R '^native_fixed_mesh57_uint_heap_(warp|hardware)$' -V` -> **2/2 passed** (WARP + RTX 5080) - `ctest --preset dev --no-tests=error -R 'mesh86' -V` -> **2/2 passed** (`startup_mesh86_srv_proof`, `runtime_mesh86_cache_cli_check`) - **Release (`release` preset):** - Built `compile_dxil` + `d3d12_xs_shim`; `ctest --preset release --no-tests=error -R '^native_direct_|^startup_mesh57_real_shape$' -V` -> **3/3 passed** - `git diff --check HEAD^ HEAD` clean. AI-assisted.
Carry the root word, right shift, mask and bounded slot base through
SSA values for constant s_bfe_u32, s_lshr_b32, s_and_b32, s_mul_i32,
s_lshl_b32, s_add_u32, s_or_b32, s_mov_b32, and proven-uniform
v_readfirstlane_b32. Use the same selector formula
((root_word >> shift) & mask) + base when lowering the typed DXIL read
and validating its runtime descriptor in Mesh86 (keeping Mesh57 strict
to shift=0, base=0).

AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 10:53:38 +00:00
github-bot force-pushed github-bot/gh-3719 from 7d30203d2e to 6daa78d105 2026-12-01 13:31:44 +00:00 Compare
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-01 19:01 UTC · original · approved these changes

Reviewed 6daa78d1 by reading the diff; not built or run.

Verdict: approve. Each accepted step keeps the slot equal to ((root >> shift) & mask) + base, and everything outside those steps returns no proof, so the heap read is refused as before. No MUST.

  • SHOULD The runtime half (native_mesh86.inl, slot = ((word >> shift) & mask) + base and base + mask < 1024) has no test with a nonzero shift or base. The new cases stop at the requires_heap_r32_uint report and the DXIL. The two native_fixed_mesh57_uint_heap_* runs go through Mesh57, which still requires shift == 0 && base == 0, and they are not in the pr preset filter. One Mesh86 bind case with shift=6 base=1 would pin the binder against the DXIL formula.
  • Checked, no finding:
    • Shift and extract. s_lshr_b32 with an immediate above 31 is refused, not wrapped the way the hardware wraps it. That is fail-closed. s_bfe_u32 takes offset [4:0] and width [22:16], and clips the mask by the accumulated shift (~0u >> selector.shift), so a field running past bit 31 is handled.
    • Scaling and base. Only << 5 / * 32 scale, and only with mask <= 2^27 - 1, so mask << 5 cannot wrap. After scaling, only 32-aligned s_add_u32/s_or_b32 are accepted. OR needs a zero prior base and a base disjoint from the mask, so it equals the add.
    • Copies. Provenance is keyed by SSA name, so s_mov_b32 and a uniform v_readfirstlane_b32 keep it, and an overwrite drops it (overwritten-copy).
    • Gating root_values on validate_uint_heap_reads. The only consumer, the heap-fetch branch, already requires that flag. Mesh86 sets it (translate_mesh_container(..., true, true)), and Mesh57 sets it in its own layout.

Tests: the 10 positives follow the DXIL from createHandleFromHeap back through add/and/lshr to dword 1 of root parameter 2. The 15 refusals cover each excluded step. native_direct_mesh is in the pr preset filter, and CI ran it green at this head.

**@⁠lukaslw-lab** on GitHub · 2026-12-01 19:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3719#pullrequestreview-6138016095) · **approved these changes** Reviewed `6daa78d1` by reading the diff; not built or run. **Verdict: approve.** Each accepted step keeps the slot equal to `((root >> shift) & mask) + base`, and everything outside those steps returns no proof, so the heap read is refused as before. No MUST. - **SHOULD** The runtime half (`native_mesh86.inl`, `slot = ((word >> shift) & mask) + base` and `base + mask < 1024`) has no test with a nonzero `shift` or `base`. The new cases stop at the `requires_heap_r32_uint` report and the DXIL. The two `native_fixed_mesh57_uint_heap_*` runs go through Mesh57, which still requires `shift == 0 && base == 0`, and they are not in the `pr` preset filter. One Mesh86 bind case with `shift=6 base=1` would pin the binder against the DXIL formula. - Checked, no finding: - **Shift and extract.** `s_lshr_b32` with an immediate above 31 is refused, not wrapped the way the hardware wraps it. That is fail-closed. `s_bfe_u32` takes offset `[4:0]` and width `[22:16]`, and clips the mask by the accumulated shift (`~0u >> selector.shift`), so a field running past bit 31 is handled. - **Scaling and base.** Only `<< 5` / `* 32` scale, and only with `mask <= 2^27 - 1`, so `mask << 5` cannot wrap. After scaling, only 32-aligned `s_add_u32`/`s_or_b32` are accepted. OR needs a zero prior base and a base disjoint from the mask, so it equals the add. - **Copies.** Provenance is keyed by SSA name, so `s_mov_b32` and a uniform `v_readfirstlane_b32` keep it, and an overwrite drops it (`overwritten-copy`). - **Gating `root_values` on `validate_uint_heap_reads`.** The only consumer, the heap-fetch branch, already requires that flag. Mesh86 sets it (`translate_mesh_container(..., true, true)`), and Mesh57 sets it in its own layout. Tests: the 10 positives follow the DXIL from `createHandleFromHeap` back through `add`/`and`/`lshr` to dword 1 of root parameter 2. The 15 refusals cover each excluded step. `native_direct_mesh` is in the `pr` preset filter, and CI ran it green at this head.
github-bot changed target branch from main to gh-pr/3719/base 2026-12-02 02:51:47 +00:00
github manually merged commit 6daa78d105 into gh-pr/3719/base 2026-12-02 02:51:50 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.