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

Merged
timbot103 merged 1 commit from upstream-pr/3719 into main 2026-12-02 02:51:24 +00:00
timbot103 commented 2026-12-01 10:52:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-01T10:52:59Z.


Refs #3703.

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5584194407 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3719). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-01T10:52:59Z. --- Refs #3703. ## 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.
lukaslw-lab commented 2026-12-01 19:01:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-01T19:01:45Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6138016095 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3719#pullrequestreview-6138016095). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-01T19:01:45Z. **Review:** APPROVED --- 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.
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!3719
No description provided.