shader: treat a mesh buffer load at a uniform address as uniform (Part of #3703) #3792

Manually merged
github merged 2 commits from github-bot/gh-3790 into gh-pr/3790/base 2026-12-02 20:46:36 +00:00 AGit
Owner

@⁠mumba17 on GitHub · 2026-12-01 22:37 UTC · original
mumba17:shader/mesh-uniform-buffer-load → main · +53 −0 · 2 files · 2 commits · merged 2026-12-02 20:45 UTC

Part of #3705. Lets v_readfirstlane_b32 read a buffer load at a uniform address directly, where it was refused or, since #3795, broadcast through groupshared memory.

Rebased on current main (f365f125), now that #3772 has merged. It is no longer stacked.

Shape

The programs read the first lane of a buffer load whose address is the same in every lane:

  • buffer_load_format_x vN, vM, s[..], 0 idxen from a descriptor-table V#, with vM copied from a uniform SGPR;
  • buffer_load_dword vN, off, s[..], 0 offset:20, then a second buffer_load_dword vN, vN, s[..], 0 idxen indexed by the first result.

The frontend only treated heap typed loads at a uniform index as uniform.

#3795 now broadcasts lane 0 for any full-EXEC v_readfirstlane_b32. That broadcast costs a groupshared slot and a barrier, and it needs group-uniform control flow. Its result is also not marked uniform. On current main, 167 programs still stop at v_readfirstlane_b32.

Change (gfx1013_direct_mesh.inl)

  • uniform_buffer_address holds for a MUBUF load that meets all of these, until the shader stores to memory:
    • no OFFEN;
    • an IDXEN index, if any, that is uniform;
    • a SOFFSET that is constant or uniform.
  • It is checked before the load, because a load may overwrite its own index register (buffer_load_dword v1, v1, ...).
  • mark_uniform_buffer_load then marks the loaded dwords uniform, under the same conditions as the existing heap typed load:
    • uniform_values under full EXEC;
    • active_uniform under whole-wave execution outside a diamond.
  • Both are applied to buffer_load_dword, after main's OFFEN raw path, and to the table buffer_load_format_x route from #3772.

Tests (tests/native_direct_mesh_check.py)

  • Read directly. Each case checks two things: the v_readfirstlane_b32 result is the load's own extractvalue, converted with uitofp for the export, and no @meshReadFirstLane slot is declared.
    • uniform-load-off, uniform-load-root-soffset: unindexed raw loads, with a constant and a root-constant SOFFSET;
    • typed-table-uniform-index: a table load at index s21;
    • typed-table-uniform-index-in-place: the load overwrites its own index register.
  • Broadcast (#3795's path).
    • uniform-load-offen: OFFEN, even from a uniform VGPR;
    • typed-table-lane-index-readfirstlane: index v0.
  • Mutations. Each one fails the suite:
    • never marking a load uniform (re-run on this head; uniform-load-off fails);
    • run on the first version, against the earlier refusal tests:
      • checking the address after the load (in-place case);
      • dropping the table hook;
      • accepting any index.
  • Not covered by a fixture:
    • an indexed raw load, which needs a reflected container with table records (none of the mesh tests build one);
    • an SOFFSET SGPR that is bound but not uniform, which this frontend does not produce. The check mirrors the scalar-load one and is defensive.

Validation (Windows 11, MSVC, Windows SDK 10.0.26100)

  • ctest --test-dir out/build/dev -R native_direct_mesh: passes on this head.
  • Census (same capture and method as on #3705), main f365f125 vs main + this: 532 of 1,569 both ways; none gained, none lost.
    • Of the 167 programs that stop at v_readfirstlane_b32 on main, 18 now get past it and stop at:
      • ds_swizzle_b32: 10;
      • mesh scalar memory needs a verified guest root mapping (the read lane feeds an s_load_dwordx4 address): 6;
      • mesh VCC branch lacks a proven guest whole-wave mask: 2.
    • So the gain shows once those walls fall. Counts only; request bytes stay local.
  • Not run in the game.

AI-assisted.

🤖 Generated with Claude Code

**@⁠mumba17** on GitHub · 2026-12-01 22:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3790) `mumba17:shader/mesh-uniform-buffer-load` → `main` · +53 −0 · 2 files · 2 commits · merged 2026-12-02 20:45 UTC Part of #3705. Lets `v_readfirstlane_b32` read a buffer load at a uniform address directly, where it was refused or, since #3795, broadcast through groupshared memory. Rebased on current `main` (`f365f125`), now that #3772 has merged. It is no longer stacked. ## Shape The programs read the first lane of a buffer load whose address is the same in every lane: - `buffer_load_format_x vN, vM, s[..], 0 idxen` from a descriptor-table V#, with `vM` copied from a uniform SGPR; - `buffer_load_dword vN, off, s[..], 0 offset:20`, then a second `buffer_load_dword vN, vN, s[..], 0 idxen` indexed by the first result. The frontend only treated heap typed loads at a uniform index as uniform. #3795 now broadcasts lane 0 for any full-EXEC `v_readfirstlane_b32`. That broadcast costs a groupshared slot and a barrier, and it needs group-uniform control flow. Its result is also not marked uniform. On current `main`, 167 programs still stop at `v_readfirstlane_b32`. ## Change (`gfx1013_direct_mesh.inl`) - `uniform_buffer_address` holds for a MUBUF load that meets all of these, until the shader stores to memory: - no OFFEN; - an IDXEN index, if any, that is uniform; - a SOFFSET that is constant or uniform. - It is checked **before** the load, because a load may overwrite its own index register (`buffer_load_dword v1, v1, ...`). - `mark_uniform_buffer_load` then marks the loaded dwords uniform, under the same conditions as the existing heap typed load: - `uniform_values` under full EXEC; - `active_uniform` under whole-wave execution outside a diamond. - Both are applied to `buffer_load_dword`, after `main`'s OFFEN raw path, and to the table `buffer_load_format_x` route from #3772. ## Tests (`tests/native_direct_mesh_check.py`) - **Read directly.** Each case checks two things: the `v_readfirstlane_b32` result is the load's own `extractvalue`, converted with `uitofp` for the export, and no `@meshReadFirstLane` slot is declared. - `uniform-load-off`, `uniform-load-root-soffset`: unindexed raw loads, with a constant and a root-constant SOFFSET; - `typed-table-uniform-index`: a table load at index `s21`; - `typed-table-uniform-index-in-place`: the load overwrites its own index register. - **Broadcast (#3795's path).** - `uniform-load-offen`: OFFEN, even from a uniform VGPR; - `typed-table-lane-index-readfirstlane`: index `v0`. - **Mutations.** Each one fails the suite: - never marking a load uniform (re-run on this head; `uniform-load-off` fails); - run on the first version, against the earlier refusal tests: - checking the address after the load (in-place case); - dropping the table hook; - accepting any index. - **Not covered by a fixture:** - an indexed **raw** load, which needs a reflected container with table records (none of the mesh tests build one); - an SOFFSET SGPR that is bound but not uniform, which this frontend does not produce. The check mirrors the scalar-load one and is defensive. ## Validation (Windows 11, MSVC, Windows SDK 10.0.26100) - `ctest --test-dir out/build/dev -R native_direct_mesh`: passes on this head. - **Census** (same capture and method as on #3705), `main` `f365f125` vs `main` + this: 532 of 1,569 both ways; none gained, none lost. - Of the 167 programs that stop at `v_readfirstlane_b32` on `main`, 18 now get past it and stop at: - `ds_swizzle_b32`: 10; - `mesh scalar memory needs a verified guest root mapping` (the read lane feeds an `s_load_dwordx4` address): 6; - `mesh VCC branch lacks a proven guest whole-wave mask`: 2. - So the gain shows once those walls fall. Counts only; request bytes stay local. - Not run in the game. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The mesh frontend accepted buffer_load_format_x only from a resource heap
slot. Skinned slot 86 programs read the V# whole from a bound descriptor
table instead and were refused with "formatted mesh load lacks an
R32_UINT resource heap contract".

Translator: a format load whose V# comes from a bound table goes through
the shared typed-buffer SRV path, as in vertex and pixel shaders, which
checks the table binding and all four descriptor words. The #3720
control that kept this route refused under heap tokens now checks that
it compiles without a token view.

Runtime: slot 86 accepts a one-dword typed_buffer_srv from a descriptor
table and binds it as an R32_UINT buffer view through the same checks as
a typed heap slot (R32_UINT token view, or a raw V# with the identity
component map and a 4-byte stride). A raw table V# must also name a
32-bit format (32_UINT, 32_SINT or 32_FLOAT), so the view returns the
dword the guest load would. Those word 3 checks live in
mesh86_typed_vsharp.h with unit tests and two mutation controls.

Part of #3703.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A raw V# with SWIZZLE_ENABLE (word 1 bit 31) or ADD_TID_ENABLE (word 3
bit 23) set addresses elements differently from the linear R32_UINT view
slot 86 binds, so refuse it on both the heap and the table route. Add a
linear_addressing unit case with two header mutation controls, and run
the mesh86_typed_vsharp tests in the pr preset.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pr test filter runs mesh86_typed_vsharp_*, but the pr build preset
only builds its listed targets, so CI reported the tests as not run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A buffer_load_dword, or a buffer_load_format_x from a descriptor-table
V#, without OFFEN, with a uniform IDXEN index if any and a constant or
uniform SOFFSET, reads the same address in every lane. Until the shader
stores to memory it returns the same dwords in every lane, so mark them
uniform under the same conditions as the heap typed load and let a
following v_readfirstlane read them. The address is checked before the
load, whose destination may be its own index register.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 22:37:57 +00:00
github-bot force-pushed github-bot/gh-3790 from 3e20366373 to 0acbcdcd28 2026-12-02 07:40:58 +00:00 Compare
github-bot changed title from shader: treat a mesh buffer load at a uniform address as uniform (Part of #3703, stacked on #3770) to shader: treat a mesh buffer load at a uniform address as uniform (Part of #3703) 2026-12-02 07:46:51 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-02 07:43 UTC · original · approved these changes

Reviewed 0acbcdcd by reading the diff; not built or run.

Verdict: approve. The uniform-address rule is sound and reuses the existing uniformity conditions. No MUST.

  • NIT The indexed raw buffer_load_dword (IDXEN with no OFFEN) is accepted with no fixture, as the body says. It goes through the same uniform_buffer_address / mark_uniform_buffer_load pair as the covered cases, so this is a coverage gap, not a suspected bug.
  • Checked, no finding:
    • uniform_buffer_address (gfx1013_direct_mesh.inl:851) tests OFFEN (bit 12) and IDXEN (bit 13) in the right words, and reads VADDR as 256+(i.b&255). It runs before alu.memory, so buffer_load_dword v1, v1, … is judged on the old index, and typed-table-uniform-index-in-place pins that.
    • memory_stored and uniform() are the same rules main uses for scalar loads and the heap typed load (:1514, :1522), so a store before the load or a value uniform only in another lane set is not marked.
    • mark_uniform_buffer_load adds to uniform_values only under full EXEC, and to active_uniform only under whole-wave execution outside a branch, as the heap typed load does. A partial-EXEC load keeps its partial_writes entry either way.
    • SOFFSET at or above 106 is refused unless it is an inline constant or a literal, so M0 and the other special registers stay out.

Tests: the four direct-read cases check that v_readfirstlane_b32 uses the load's own extractvalue and that no @meshReadFirstLane slot is declared. The two broadcast controls (OFFEN, a lane index) keep #3795's path. All of these are in native_direct_mesh, which the pr filter runs. CI for this head was still running at review time. The census result (no gain yet; 18 programs move to the next wall) matches what a uniformity-only change should do.

**@⁠lukaslw-lab** on GitHub · 2026-12-02 07:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3790#pullrequestreview-6146568932) · **approved these changes** Reviewed `0acbcdcd` by reading the diff; not built or run. **Verdict: approve.** The uniform-address rule is sound and reuses the existing uniformity conditions. No MUST. - **NIT** The indexed **raw** `buffer_load_dword` (IDXEN with no OFFEN) is accepted with no fixture, as the body says. It goes through the same `uniform_buffer_address` / `mark_uniform_buffer_load` pair as the covered cases, so this is a coverage gap, not a suspected bug. - Checked, no finding: - `uniform_buffer_address` (`gfx1013_direct_mesh.inl:851`) tests OFFEN (bit 12) and IDXEN (bit 13) in the right words, and reads VADDR as `256+(i.b&255)`. It runs before `alu.memory`, so `buffer_load_dword v1, v1, …` is judged on the old index, and `typed-table-uniform-index-in-place` pins that. - `memory_stored` and `uniform()` are the same rules main uses for scalar loads and the heap typed load (`:1514`, `:1522`), so a store before the load or a value uniform only in another lane set is not marked. - `mark_uniform_buffer_load` adds to `uniform_values` only under full EXEC, and to `active_uniform` only under whole-wave execution outside a branch, as the heap typed load does. A partial-EXEC load keeps its `partial_writes` entry either way. - SOFFSET at or above 106 is refused unless it is an inline constant or a literal, so M0 and the other special registers stay out. Tests: the four direct-read cases check that `v_readfirstlane_b32` uses the load's own `extractvalue` and that no `@meshReadFirstLane` slot is declared. The two broadcast controls (OFFEN, a lane index) keep #3795's path. All of these are in `native_direct_mesh`, which the `pr` filter runs. CI for this head was still running at review time. The census result (no gain yet; 18 programs move to the next wall) matches what a uniformity-only change should do.
github-bot force-pushed github-bot/gh-3790 from 0acbcdcd28 to d431e1fae7 2026-12-02 09:38:44 +00:00 Compare
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-02 09:35 UTC · original · approved these changes

Reviewed d431e1fa by git range-diff against 0acbcdcd; not built or run.

Verdict: approve. This is a rebase onto 45c809ab. The two load branches now carry #3808's vector_exec condition in context. mark_uniform_buffer_load still marks words only under full EXEC, or under whole-wave execution outside a branch, so loads inside a masked diamond are not marked uniform. The test commit is identical. No MUST.

**@⁠lukaslw-lab** on GitHub · 2026-12-02 09:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3790#pullrequestreview-6148173766) · **approved these changes** Reviewed `d431e1fa` by `git range-diff` against `0acbcdcd`; not built or run. **Verdict: approve.** This is a rebase onto `45c809ab`. The two load branches now carry #3808's `vector_exec` condition in context. `mark_uniform_buffer_load` still marks words only under full EXEC, or under whole-wave execution outside a branch, so loads inside a masked diamond are not marked uniform. The test commit is identical. No MUST.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 10:10 UTC · original · reviewed

The Windows job fails in the same mainline integer-row fixture as #3823, with +0x34: unmapped graphics export. I reproduced it on plain main and opened #3853 to isolate that fixture. On d431e1fa plus only the fixture patch from #3853, the full native_direct_mesh check passes. Please sync after #3853 lands to refresh the required Windows check.

**@⁠R0Y00** on GitHub · 2026-12-02 10:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3790#pullrequestreview-6148748299) · **reviewed** The Windows job fails in the same mainline integer-row fixture as #3823, with `+0x34: unmapped graphics export`. I reproduced it on plain main and opened #3853 to isolate that fixture. On `d431e1fa` plus only the fixture patch from #3853, the full `native_direct_mesh` check passes. Please sync after #3853 lands to refresh the required Windows check.
github-bot force-pushed github-bot/gh-3790 from d431e1fae7 to 089765d4d0 2026-12-02 20:16:09 +00:00 Compare
Author
Owner

@⁠mumba17 on GitHub · 2026-12-02 20:13 UTC · original

Synced. #3853 now conflicts with main, and #3863 (merged 15:19Z) already restored the dropped attribute count in the same native_direct_mesh fixture, so I rebased onto main 1cd972cd without waiting for it. Same for the stack #3712 (43791423) → #3762 (42ce2c27); this PR is now a1097fa1 + 089765d4. All three rebased without conflicts.

Local check on each tip: Windows 11 26300, MSVC, cmake --build --preset pr then ctest --preset pr -j 4, failures re-run with -j 1. 289/291 pass on each branch, including native_direct_mesh and the mesh _ir/_dxil/_controls tests. The 2 failures are the same on every branch: native_compute_implicit_lod_controls and native_wave_virtual_derivative_controls stop at this host's SDK validator (Validator version in metadata (1.8) is not supported; maximum: (1.7)). They are compute tests, untouched here, and should pass on CI's validator.

AI-assisted (Claude Code).

**@⁠mumba17** on GitHub · 2026-12-02 20:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3790#issuecomment-7357415155) Synced. #3853 now conflicts with `main`, and #3863 (merged 15:19Z) already restored the dropped attribute count in the same `native_direct_mesh` fixture, so I rebased onto `main` `1cd972cd` without waiting for it. Same for the stack #3712 (`43791423`) → #3762 (`42ce2c27`); this PR is now `a1097fa1` + `089765d4`. All three rebased without conflicts. Local check on each tip: Windows 11 26300, MSVC, `cmake --build --preset pr` then `ctest --preset pr -j 4`, failures re-run with `-j 1`. 289/291 pass on each branch, including `native_direct_mesh` and the mesh `_ir`/`_dxil`/`_controls` tests. The 2 failures are the same on every branch: `native_compute_implicit_lod_controls` and `native_wave_virtual_derivative_controls` stop at this host's SDK validator (`Validator version in metadata (1.8) is not supported; maximum: (1.7)`). They are compute tests, untouched here, and should pass on CI's validator. AI-assisted (Claude Code).
github-bot changed target branch from main to gh-pr/3790/base 2026-12-02 20:46:35 +00:00
github manually merged commit 089765d4d0 into gh-pr/3790/base 2026-12-02 20:46:36 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 20:44 UTC · original · approved these changes

Reviewed 089765d4. The load's index and scalar offset are checked before destination writes, and unproven addresses retain the lane-0 broadcast path if it is available. Independent Windows 11 build 26300, MSVC Debug cmake --build --preset dev --target compile_dxil and ctest --preset dev --no-tests=error -j 1 --output-on-failure -R '^native_direct_mesh$' passed. The fixture covers the in-place typed load and keeps broadcast controls for offen and a lane-varying typed index.

**@⁠R0Y00** on GitHub · 2026-12-02 20:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3790#pullrequestreview-6158677643) · **approved these changes** Reviewed `089765d4`. The load's index and scalar offset are checked before destination writes, and unproven addresses retain the lane-0 broadcast path if it is available. Independent Windows 11 build 26300, MSVC Debug `cmake --build --preset dev --target compile_dxil` and `ctest --preset dev --no-tests=error -j 1 --output-on-failure -R '^native_direct_mesh$'` passed. The fixture covers the in-place typed load and keeps broadcast controls for `offen` and a lane-varying typed index.
This discussion has been locked. Commenting is limited to contributors.
No description provided.