shader: bound OFFEN-only raw loads in the mesh frontend (Part of #3703) #3721

Merged
timbot103 merged 2 commits from upstream-pr/3721 into main 2026-12-02 03:10:24 +00:00
timbot103 commented 2026-12-01 10:53:05 +00:00 (Migrated from github.com)

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


Refs #3703.

Summary

Lowers offen-only (idxen clear) raw buffer loads (buffer_load_dword, dwordx2, dwordx3, dwordx4) in the C++ mesh frontend (src/gfx1013_direct_mesh.inl, sharing the root-descriptor predicate helper with src/gfx1013_direct_compute.inl):

  • Supported descriptors: Accepts proven table SRVs (raw_vector_srv), rewritten byte windows (byte_window_srv), and the three existing unbounded root-SRV descriptor forms (root_buffer_srv), all of which native_mesh86.inl already binds as bounded desktop raw SRVs.
  • Address & per-DWORD bounds: Combines the VGPR byte offset, 12-bit immediate offset, and inline zero or numeric SGPR soffset with unsigned 32-bit wrap checks, aligns down to 4 bytes, queries getDimensions for the raw SRV byte length, and checks bounds per DWORD so reads straddling the view end keep each in-range DWORD and zero-fill out-of-range components.
  • EXEC skip handling: Preserves inactive destination lanes via partial_writes inside open EXECZ skips (including when vaddr aliases a destination VGPR).
  • Fail-closed controls: Keeps unproven/clobbered descriptors, finite synthesized root bounds, wrong root high words, idxen on root SRVs, literal/symbolic soffset, LDS, TFE, and VGPR overflow strictly refused.

Verification

Windows 11 (26200), MSVC 19.44, Ninja, Windows SDK 10.0.26100. Source-built tests only; added 42 positive cases (dword..dwordx4, all 5 descriptor variants, zero & unaligned immediate offsets, SGPR soffset inside a lane skip) and 10 refusal controls 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)
  • Release (release preset):
    • 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:5584195993 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3721). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-01T10:53:05Z. --- Refs #3703. ## Summary Lowers `offen`-only (`idxen` clear) raw buffer loads (`buffer_load_dword`, `dwordx2`, `dwordx3`, `dwordx4`) in the C++ mesh frontend (`src/gfx1013_direct_mesh.inl`, sharing the root-descriptor predicate helper with `src/gfx1013_direct_compute.inl`): - **Supported descriptors:** Accepts proven table SRVs (`raw_vector_srv`), rewritten byte windows (`byte_window_srv`), and the three existing unbounded root-SRV descriptor forms (`root_buffer_srv`), all of which `native_mesh86.inl` already binds as bounded desktop raw SRVs. - **Address & per-DWORD bounds:** Combines the VGPR byte offset, 12-bit immediate offset, and inline zero or numeric SGPR `soffset` with unsigned 32-bit wrap checks, aligns down to 4 bytes, queries `getDimensions` for the raw SRV byte length, and checks bounds per DWORD so reads straddling the view end keep each in-range DWORD and zero-fill out-of-range components. - **EXEC skip handling:** Preserves inactive destination lanes via `partial_writes` inside open `EXECZ` skips (including when `vaddr` aliases a destination VGPR). - **Fail-closed controls:** Keeps unproven/clobbered descriptors, finite synthesized root bounds, wrong root high words, `idxen` on root SRVs, literal/symbolic `soffset`, LDS, TFE, and VGPR overflow strictly refused. ## Verification Windows 11 (26200), MSVC 19.44, Ninja, Windows SDK 10.0.26100. Source-built tests only; added 42 positive cases (`dword`..`dwordx4`, all 5 descriptor variants, zero & unaligned immediate offsets, SGPR `soffset` inside a lane skip) and 10 refusal controls 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`) - **Release (`release` preset):** - `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:03:05 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed e443d01a by reading the diff; not built or run.

Verdict: approve. The offen-only load computes the guest byte address with wrap guards, then checks each DWORD against the view's getDimensions length. Every descriptor it accepts is one that Mesh86 already binds as a sized table view. No MUST.

  • Checked, no finding:
    • raw_root_descriptor refactor. It accepts exactly the three forms the compute path accepted before: stride-one high with 0x11014fac or 0x31016fac, and root-address high with 0x31016fac. It still requires NUM_RECORDS = 0xffffffff and no address offset, so the compute path is unchanged.
    • Modifiers. LDS, TFE, GLC/SLC/DLC and literal or non-zero inline soffset never reach mesh_offen_raw_load. The graphics branch of the raw-load decoder refuses them first (gfx1013_compute_native.cpp:281). The lds, tfe and literal-soffset controls pin that.
    • getDimensions on a root SRV. native_mesh86.inl:70 creates root_buffer_srv as a table view (root SRV/CBV source, zero byte offset), not as a root descriptor, so the dimension query is defined. The 4-byte span (compute asks 4*n) is covered by the per-DWORD check, as the comment says.
    • Bounds arithmetic. available = bytes - aligned is taken only where aligned < bytes, and available >= 4*(j+1) cannot wrap. An invalid address loads at bytes, which reads 0, and every component is then zeroed by its own predicate.
    • Opcode and count. MUBUF 0x0c/0x0d/0x0f/0x0e map to 1/2/3/4 DWORDs through counts[op & 3], and dst + count > 256 refuses overflow.
    • Inside a lane skip. The written VGPRs enter partial_writes. The *-scalar-exec cases check the mesh_empty phi, including vaddr aliasing v1.

Tests: 40 positives across five descriptor forms, four widths and two immediate offsets each pin the DXIL bound sequence (and -4, ult, sub, per-component uge plus select 0). The two lane-skip cases add a numeric SGPR soffset. The 10 controls cover the descriptor and modifier refusals. native_direct_mesh is in the pr preset filter, and CI ran it green at this head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6138038355 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3721#pullrequestreview-6138038355). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-01T19:03:05Z. **Review:** APPROVED --- Reviewed `e443d01a` by reading the diff; not built or run. **Verdict: approve.** The `offen`-only load computes the guest byte address with wrap guards, then checks each DWORD against the view's `getDimensions` length. Every descriptor it accepts is one that Mesh86 already binds as a sized table view. No MUST. - Checked, no finding: - **`raw_root_descriptor` refactor.** It accepts exactly the three forms the compute path accepted before: stride-one high with `0x11014fac` or `0x31016fac`, and root-address high with `0x31016fac`. It still requires `NUM_RECORDS = 0xffffffff` and no address offset, so the compute path is unchanged. - **Modifiers.** LDS, TFE, GLC/SLC/DLC and literal or non-zero inline `soffset` never reach `mesh_offen_raw_load`. The graphics branch of the raw-load decoder refuses them first (`gfx1013_compute_native.cpp:281`). The `lds`, `tfe` and `literal-soffset` controls pin that. - **`getDimensions` on a root SRV.** `native_mesh86.inl:70` creates `root_buffer_srv` as a table view (root SRV/CBV source, zero byte offset), not as a root descriptor, so the dimension query is defined. The `4`-byte span (compute asks `4*n`) is covered by the per-DWORD check, as the comment says. - **Bounds arithmetic.** `available = bytes - aligned` is taken only where `aligned < bytes`, and `available >= 4*(j+1)` cannot wrap. An invalid address loads at `bytes`, which reads 0, and every component is then zeroed by its own predicate. - **Opcode and count.** MUBUF `0x0c/0x0d/0x0f/0x0e` map to 1/2/3/4 DWORDs through `counts[op & 3]`, and `dst + count > 256` refuses overflow. - **Inside a lane skip.** The written VGPRs enter `partial_writes`. The `*-scalar-exec` cases check the `mesh_empty` phi, including `vaddr` aliasing `v1`. Tests: 40 positives across five descriptor forms, four widths and two immediate offsets each pin the DXIL bound sequence (`and -4`, `ult`, `sub`, per-component `uge` plus `select 0`). The two lane-skip cases add a numeric SGPR `soffset`. The 10 controls cover the descriptor and modifier refusals. `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!3721
No description provided.