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

Merged
mumba17 merged 2 commits from upstream-pr/3790 into main 2026-12-02 20:45:41 +00:00
mumba17 commented 2026-12-01 22:37:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-12-01T22:37:40Z.


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

Rebased on current main (f365f125), now that #3770 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.

#3793 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 #3770.

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 (#3793'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 #3703), 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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5595881044 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3790). Originally posted by [mumba17](https://github.com/mumba17) on 2026-12-01T22:37:40Z. --- Part of #3703. Lets `v_readfirstlane_b32` read a buffer load at a uniform address directly, where it was refused or, since #3793, broadcast through groupshared memory. Rebased on current `main` (`f365f125`), now that #3770 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. #3793 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 #3770. ## 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 (#3793'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 #3703), `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)
lukaslw-lab commented 2026-12-02 07:43:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T07:43:13Z.

Review: APPROVED


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 #3793'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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6146568932 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3790#pullrequestreview-6146568932). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T07:43:13Z. **Review:** APPROVED --- 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 #3793'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 commented 2026-12-02 09:35:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T09:35:54Z.

Review: APPROVED


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 #3806'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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6148173766 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3790#pullrequestreview-6148173766). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T09:35:54Z. **Review:** APPROVED --- 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 #3806'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.
R0Y00 commented 2026-12-02 10:10:25 +00:00 (Migrated from github.com)

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

Review: COMMENTED


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6148748299 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3790#pullrequestreview-6148748299). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T10:10:25Z. **Review:** COMMENTED --- The Windows job fails in the same mainline integer-row fixture as #3821, with `+0x34: unmapped graphics export`. I reproduced it on plain main and opened #3851 to isolate that fixture. On `d431e1fa` plus only the fixture patch from #3851, the full `native_direct_mesh` check passes. Please sync after #3851 lands to refresh the required Windows check.
mumba17 commented 2026-12-02 20:13:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-12-02T20:13:43Z.


Synced. #3851 now conflicts with main, and #3861 (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 #3710 (43791423) → #3760 (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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7357415155 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3790#issuecomment-7357415155). Originally posted by [mumba17](https://github.com/mumba17) on 2026-12-02T20:13:43Z. --- Synced. #3851 now conflicts with `main`, and #3861 (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 #3710 (`43791423`) → #3760 (`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).
R0Y00 commented 2026-12-02 20:44:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T20:44:53Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6158677643 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3790#pullrequestreview-6158677643). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T20:44:53Z. **Review:** APPROVED --- 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.
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!3790
No description provided.