shader, runtime: lower and bind mesh format loads from a descriptor-table V# (Part of #3703) #3770

Merged
mumba17 merged 4 commits from upstream-pr/3770 into main 2026-12-02 03:03:45 +00:00
mumba17 commented 2026-12-01 17:50:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-12-01T17:50:46Z.


Part of #3703. Fixes the wall formatted mesh load lacks an R32_UINT resource heap contract (108 programs in my census on the current stack).

Shape

All 108 are buffer_load_format_x vN, vM, s[N:N+3], 0 idxen whose V# is read whole with s_load_dwordx4 from a bound descriptor table. The mesh frontend only accepted the resource-heap form.

Change

Translator (gfx1013_direct_mesh.inl): a format load whose V# is a table descriptor goes through the shared typed-buffer SRV path (alu.memory), the same one vertex and pixel shaders use. It records a typed_buffer_srv binding and checks the table binding and all four descriptor words. The heap route is unchanged.

Runtime (native_mesh86.inl): without this half, the new binding would compile and then fail at draw setup with unsupported native Mesh86 SRV shape.

  • Slot 86 now accepts a one-dword typed_buffer_srv, from a descriptor table only.
  • It binds it as an R32_UINT buffer view through the same checks a typed heap slot already gets. I moved those checks into one lambda shared by both routes; the heap route behaves as before. A view token must be an R32_UINT buffer view; a raw V# must have the identity component map and a 4-byte stride.
  • A raw V# on either route must address elements linearly: SWIZZLE_ENABLE (word 1 bit 31) and ADD_TID_ENABLE (word 3 bit 23) clear.
  • A raw table V# must also name a 32-bit data format (32_UINT, 32_SINT or 32_FLOAT, word 3 bits 18:12), so the view returns the dword the guest format load would. Anything else is refused at bind time.

The V# word checks live in the new src/startup_stubs/mesh86_typed_vsharp.h.

Tests

  • tests/native_direct_mesh_check.py:
    • typed-table (full EXEC) and typed-table-lane-skip (inactive lanes keep the old value through select and phi).
    • Controls: typed-table-lane-skip-undef, typed-table-xy (multi-channel still refused) and typed-table-no-skip (narrowed EXEC without EXECZ still refused).
  • @timbot103's typed-table-in-skip control from #3720 refused this route under heap tokens. It now checks that the route compiles without a token view (requires_heap_tokens absent). The other #3720 controls are unchanged.
  • tests/mesh86_typed_vsharp_check.cpp with tests/cmake/mesh86_typed_vsharp.cmake:
    • five cases: the component map, the three 32-bit formats, other formats, linear addressing, and the two word-3 values the title synthesizes for its root SRVs (0x11014fac, 0x31016fac);
    • four WILL_FAIL header mutations: a widened format range, a dropped map check, and a dropped swizzle or thread-ID check.
    • The pr preset filter now includes mesh86_typed_vsharp_[a-z_]+, so CI runs them.
  • Removing the translator route fails typed-table with the old refusal.

Validation (Windows 11, MSVC, Windows SDK 10.0.26100)

  • ctest --test-dir out/build/dev -R "native_direct_mesh|mesh": 219/219. That is the existing 210 plus the 9 new unit and mutation tests; the two mesh_two_exits hardware tests skip as usual.
  • d3d12_xs.dll builds with the runtime change.
  • Not run in the game. The slot 86 bind path has no device-free test. The runtime change is fail-closed: a table V# that is not a linear, identity-mapped 32-bit format with a 4-byte stride is refused with a reason, as before. A Mesh86 run with X2W_D3D12_TRACE_DIRECT_MESH would show whether the title's table V#s pass.
  • Census (same capture and method as on #3703) on main + #3708 + #3709 + #3710 + #3729 + #3760 + #3765 + this: 845 of 1,569 translate, up from 837. 8 gained, none lost.
    • The R32_UINT wall is gone. Most of the other 100 now stop at mesh SAVEEXEC then arm depends on EXEC, which rises from 133 to 215 and is partly covered by #3722.
    • Counts only; request bytes stay local.

@lambirou, this touches native_mesh86.inl: the view-kind check in the root builder, a new typed_buffer_srv branch in the bind loop, and the shared typed check. Happy to rebase onto your open changes there.

AI-assisted.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5591291084 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3770). Originally posted by [mumba17](https://github.com/mumba17) on 2026-12-01T17:50:46Z. --- Part of #3703. Fixes the wall `formatted mesh load lacks an R32_UINT resource heap contract` (108 programs in my census on the current stack). ## Shape All 108 are `buffer_load_format_x vN, vM, s[N:N+3], 0 idxen` whose V# is read whole with `s_load_dwordx4` from a bound descriptor table. The mesh frontend only accepted the resource-heap form. ## Change **Translator** (`gfx1013_direct_mesh.inl`): a format load whose V# is a table descriptor goes through the shared typed-buffer SRV path (`alu.memory`), the same one vertex and pixel shaders use. It records a `typed_buffer_srv` binding and checks the table binding and all four descriptor words. The heap route is unchanged. **Runtime** (`native_mesh86.inl`): without this half, the new binding would compile and then fail at draw setup with `unsupported native Mesh86 SRV shape`. - Slot 86 now accepts a one-dword `typed_buffer_srv`, from a descriptor table only. - It binds it as an R32_UINT buffer view through the same checks a typed heap slot already gets. I moved those checks into one lambda shared by both routes; the heap route behaves as before. A view token must be an R32_UINT buffer view; a raw V# must have the identity component map and a 4-byte stride. - A raw V# on either route must address elements linearly: `SWIZZLE_ENABLE` (word 1 bit 31) and `ADD_TID_ENABLE` (word 3 bit 23) clear. - A raw table V# must also name a 32-bit data format (`32_UINT`, `32_SINT` or `32_FLOAT`, word 3 bits 18:12), so the view returns the dword the guest format load would. Anything else is refused at bind time. The V# word checks live in the new `src/startup_stubs/mesh86_typed_vsharp.h`. ## Tests - `tests/native_direct_mesh_check.py`: - `typed-table` (full EXEC) and `typed-table-lane-skip` (inactive lanes keep the old value through `select` and `phi`). - Controls: `typed-table-lane-skip-undef`, `typed-table-xy` (multi-channel still refused) and `typed-table-no-skip` (narrowed EXEC without EXECZ still refused). - @timbot103's `typed-table-in-skip` control from #3720 refused this route under heap tokens. It now checks that the route compiles without a token view (`requires_heap_tokens` absent). The other #3720 controls are unchanged. - `tests/mesh86_typed_vsharp_check.cpp` with `tests/cmake/mesh86_typed_vsharp.cmake`: - five cases: the component map, the three 32-bit formats, other formats, linear addressing, and the two word-3 values the title synthesizes for its root SRVs (`0x11014fac`, `0x31016fac`); - four `WILL_FAIL` header mutations: a widened format range, a dropped map check, and a dropped swizzle or thread-ID check. - The `pr` preset filter now includes `mesh86_typed_vsharp_[a-z_]+`, so CI runs them. - Removing the translator route fails `typed-table` with the old refusal. ## Validation (Windows 11, MSVC, Windows SDK 10.0.26100) - `ctest --test-dir out/build/dev -R "native_direct_mesh|mesh"`: 219/219. That is the existing 210 plus the 9 new unit and mutation tests; the two `mesh_two_exits` hardware tests skip as usual. - `d3d12_xs.dll` builds with the runtime change. - **Not run in the game.** The slot 86 bind path has no device-free test. The runtime change is fail-closed: a table V# that is not a linear, identity-mapped 32-bit format with a 4-byte stride is refused with a reason, as before. A Mesh86 run with `X2W_D3D12_TRACE_DIRECT_MESH` would show whether the title's table V#s pass. - **Census** (same capture and method as on #3703) on `main` + #3708 + #3709 + #3710 + #3729 + #3760 + #3765 + this: **845 of 1,569** translate, up from 837. 8 gained, none lost. - The R32_UINT wall is gone. Most of the other 100 now stop at `mesh SAVEEXEC then arm depends on EXEC`, which rises from 133 to 215 and is partly covered by #3722. - Counts only; request bytes stay local. @lambirou, this touches `native_mesh86.inl`: the view-kind check in the root builder, a new `typed_buffer_srv` branch in the bind loop, and the shared typed check. Happy to rebase onto your open changes there. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
lukaslw-lab commented 2026-12-01 20:09:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-01T20:09:24Z.

Review: APPROVED


Reviewed 8f769c7e by reading the diff; not built or run.

Verdict: approve. The table route lowers to the same U32 typed buffer the heap route uses, and the runtime binds an R32_UINT view only for identity-mapped 32-bit formats with a 4-byte stride. No MUST.

  • SHOULD The raw-V# checks don't cover the two fields that change addressing:

    • ADD_TID_ENABLE (word 3 bit 23);
    • SWIZZLE_ENABLE (word 1 bit 31).

    typed_dword checks word 3's component map and format. indirect_table_buffer (d3d12_draw.inl:2834) then reads only the address, stride and record count. A table V# with either bit set passes and binds a linear R32_UINT view, so lanes read the wrong elements. The heap route had the same gap before this PR, but the description promises fail-closed for the table route. A check in mesh86_typed_vsharp.h (bit 23 clear, word 1 bit 31 clear) would cover both routes. The title's own word 3 values, 0x11014fac and 0x31016fac, have neither bit set, so nothing seen today changes.

  • Checked, no finding:

    • Result type. The table binding is declared Buffer<uint4> (component type 5) and read with bufferLoad.i32, so the R32_UINT view matches. 32_FLOAT and 32_SINT data return the same dword bits.
    • Word 3 constants. Identity DST_SEL 4/5/6/7 packs to 0xfac, and BUF_FMT 20–22 in bits 18:12 are the three 32-bit formats.
    • The refactor. The heap route's checks move unchanged into typed_dword. Only the table route adds the format check.
    • Root and bind time. The root builder requires a descriptor-table source for typed_buffer_srv. The bind loop reads the record from that table and refuses outside it.
    • Translator. Only idxen or no-index forms with zero offset reach the new branch, and partial writes are marked under a lane skip, as in the existing buffer branches.

Tests:

  • typed-table and -lane-skip reach the new branch.
  • -lane-skip-undef, -xy and -no-skip pin the refusals.
  • The header unit and mutation tests cover the word 3 checks.
  • No test reaches the bind loop: the description says so.

CI ran native_direct_mesh (pr preset filter), but not mesh86_typed_vsharp_*, which the filter doesn't match. Those rest on the author's local 216/216. The branch merges cleanly with main 158ef794.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6139192117 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3770#pullrequestreview-6139192117). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-01T20:09:24Z. **Review:** APPROVED --- Reviewed `8f769c7e` by reading the diff; not built or run. **Verdict: approve.** The table route lowers to the same U32 typed buffer the heap route uses, and the runtime binds an R32_UINT view only for identity-mapped 32-bit formats with a 4-byte stride. No MUST. - **SHOULD** The raw-V# checks don't cover the two fields that change addressing: - `ADD_TID_ENABLE` (word 3 bit 23); - `SWIZZLE_ENABLE` (word 1 bit 31). `typed_dword` checks word 3's component map and format. `indirect_table_buffer` (`d3d12_draw.inl:2834`) then reads only the address, stride and record count. A table V# with either bit set passes and binds a linear R32_UINT view, so lanes read the wrong elements. The heap route had the same gap before this PR, but the description promises fail-closed for the table route. A check in `mesh86_typed_vsharp.h` (bit 23 clear, word 1 bit 31 clear) would cover both routes. The title's own word 3 values, `0x11014fac` and `0x31016fac`, have neither bit set, so nothing seen today changes. - Checked, no finding: - **Result type.** The table binding is declared `Buffer<uint4>` (component type 5) and read with `bufferLoad.i32`, so the R32_UINT view matches. 32_FLOAT and 32_SINT data return the same dword bits. - **Word 3 constants.** Identity `DST_SEL` 4/5/6/7 packs to `0xfac`, and `BUF_FMT` 20–22 in bits 18:12 are the three 32-bit formats. - **The refactor.** The heap route's checks move unchanged into `typed_dword`. Only the table route adds the format check. - **Root and bind time.** The root builder requires a descriptor-table source for `typed_buffer_srv`. The bind loop reads the record from that table and refuses outside it. - **Translator.** Only idxen or no-index forms with zero offset reach the new branch, and partial writes are marked under a lane skip, as in the existing buffer branches. Tests: - `typed-table` and `-lane-skip` reach the new branch. - `-lane-skip-undef`, `-xy` and `-no-skip` pin the refusals. - The header unit and mutation tests cover the word 3 checks. - No test reaches the bind loop: the description says so. CI ran `native_direct_mesh` (pr preset filter), but not `mesh86_typed_vsharp_*`, which the filter doesn't match. Those rest on the author's local 216/216. The branch merges cleanly with `main` `158ef794`.
mumba17 commented 2026-12-01 20:23:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-12-01T20:23:27Z.


@lukaslw-lab Thanks. Agreed: the PR promises fail-closed, so a non-linear V# should not bind.

Fixed in b445b8cd:

  • mesh86_typed_linear(word1, word3) in mesh86_typed_vsharp.h requires SWIZZLE_ENABLE (word 1 bit 31) and ADD_TID_ENABLE (word 3 bit 23) clear.
  • typed_dword applies it to every raw V#, on both the heap and the table route, and refuses with native Mesh86 typed buffer descriptor is swizzled or adds the thread ID. View tokens are unchanged.

Tests:

  • New linear_addressing case: it accepts a stride-4 V# and ignores the other bits, and refuses either bit alone. guest_words now also checks that the title's word 3 values add no thread ID.
  • Two new WILL_FAIL header mutations: any_swizzle and any_tid, one for each dropped check.
  • The pr preset filter now includes mesh86_typed_vsharp_[a-z_]+, so CI runs the unit and mutation tests too.

ctest -R "native_direct_mesh|mesh": 219/219 (210 existing, 9 unit and mutation tests; the two mesh_two_exits hardware tests skip as usual). d3d12_xs.dll builds. The translator is unchanged, so the census stays at 845.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7324601637 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3770#issuecomment-7324601637). Originally posted by [mumba17](https://github.com/mumba17) on 2026-12-01T20:23:27Z. --- @lukaslw-lab Thanks. Agreed: the PR promises fail-closed, so a non-linear V# should not bind. Fixed in `b445b8cd`: - `mesh86_typed_linear(word1, word3)` in `mesh86_typed_vsharp.h` requires `SWIZZLE_ENABLE` (word 1 bit 31) and `ADD_TID_ENABLE` (word 3 bit 23) clear. - `typed_dword` applies it to every raw V#, on both the heap and the table route, and refuses with `native Mesh86 typed buffer descriptor is swizzled or adds the thread ID`. View tokens are unchanged. Tests: - New `linear_addressing` case: it accepts a stride-4 V# and ignores the other bits, and refuses either bit alone. `guest_words` now also checks that the title's word 3 values add no thread ID. - Two new `WILL_FAIL` header mutations: `any_swizzle` and `any_tid`, one for each dropped check. - The `pr` preset filter now includes `mesh86_typed_vsharp_[a-z_]+`, so CI runs the unit and mutation tests too. `ctest -R "native_direct_mesh|mesh"`: 219/219 (210 existing, 9 unit and mutation tests; the two `mesh_two_exits` hardware tests skip as usual). `d3d12_xs.dll` builds. The translator is unchanged, so the census stays at 845. AI-assisted.
lukaslw-lab commented 2026-12-01 20:36:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-01T20:36:49Z.

Review: APPROVED


Reviewed 49ec2911 (delta since 8f769c7e: b445b8cd, 49ec2911) by reading the diff; not built or run.

Verdict: approve. Both open points from the last pass are fixed; no new findings.

  • Raw V# addressing: mesh86_typed_linear refuses SWIZZLE_ENABLE (word 1 bit 31) and ADD_TID_ENABLE (word 3 bit 23), the same positions tools/startup/gfx2hlsl.py:179-184 decodes. It sits in typed_dword under words[0] != view_token_magic, so it covers the heap-slot and the table path alike (native_mesh86.inl:413). CACHE_SWIZZLE (bit 30) and INDEX_STRIDE stay unchecked; neither changes which element a linear, non-swizzled load reads, so that is fine.
  • linear_addressing pins both refusals and checks that all other word 1 / word 3 bits are ignored. guest_words adds that the two guest word 3 values have ADD_TID clear.
  • Mutants any_swizzle / any_tid: each anchor occurs once in the header, the FATAL_ERROR guard catches a lost anchor, and each one reaches a refusal in linear_addressing (WILL_FAIL).
  • No MUST, SHOULD or NIT.

Tests: the five mesh86_typed_vsharp_* cases and four _mut controls are now in the pr build targets and the test regex, so the Windows job will run them. That job is still pending at this head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6139690530 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3770#pullrequestreview-6139690530). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-01T20:36:49Z. **Review:** APPROVED --- Reviewed `49ec2911` (delta since `8f769c7e`: `b445b8cd`, `49ec2911`) by reading the diff; not built or run. **Verdict: approve.** Both open points from the last pass are fixed; no new findings. - Raw V# addressing: `mesh86_typed_linear` refuses SWIZZLE_ENABLE (word 1 bit 31) and ADD_TID_ENABLE (word 3 bit 23), the same positions `tools/startup/gfx2hlsl.py:179-184` decodes. It sits in `typed_dword` under `words[0] != view_token_magic`, so it covers the heap-slot and the table path alike (`native_mesh86.inl:413`). CACHE_SWIZZLE (bit 30) and INDEX_STRIDE stay unchecked; neither changes which element a linear, non-swizzled load reads, so that is fine. - `linear_addressing` pins both refusals and checks that all other word 1 / word 3 bits are ignored. `guest_words` adds that the two guest word 3 values have ADD_TID clear. - Mutants `any_swizzle` / `any_tid`: each anchor occurs once in the header, the `FATAL_ERROR` guard catches a lost anchor, and each one reaches a refusal in `linear_addressing` (WILL_FAIL). - No MUST, SHOULD or NIT. Tests: the five `mesh86_typed_vsharp_*` cases and four `_mut` controls are now in the `pr` build targets and the test regex, so the Windows job will run them. That job is still pending at this head.
R0Y00 commented 2026-12-02 02:10:00 +00:00 (Migrated from github.com)

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


The latest reviewed head 49ec2911 has green CI and approval, but GitHub reports a merge conflict. Please rebase while retaining the indexed raw SRV path from #3807 and the EXEC restore fixes from #3765, and rerun the typed V# controls and native mesh fixtures.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7332544528 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3770#issuecomment-7332544528). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T02:10:00Z. --- The latest reviewed head `49ec2911` has green CI and approval, but GitHub reports a merge conflict. Please rebase while retaining the indexed raw SRV path from #3807 and the EXEC restore fixes from #3765, and rerun the typed V# controls and native mesh fixtures.
R0Y00 commented 2026-12-02 02:54:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T02:54:43Z.


Pushed merge resolution 89e6dc03 to this PR's maintainer-editable branch, preserving the original commits. The resolved root check retains both the typed table view and #3807's indexed raw view, including its stride checks. git merge-tree --write-tree review-latest HEAD succeeds against main 2b870868. The isolated MSVC /O2 fixture passed all five V# cases. Integrated CI on the new head is pending.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7333326250 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3770#issuecomment-7333326250). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T02:54:43Z. --- Pushed merge resolution `89e6dc03` to this PR's maintainer-editable branch, preserving the original commits. The resolved root check retains both the typed table view and #3807's indexed raw view, including its stride checks. `git merge-tree --write-tree review-latest HEAD` succeeds against main `2b870868`. The isolated MSVC `/O2` fixture passed all five V# cases. Integrated CI on the new head is pending.
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!3770
No description provided.