Skip to content

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

Open
mumba17 wants to merge 2 commits into
R0Y00:mainfrom
mumba17:shader/mesh-uniform-buffer-load
Open

mumba17 wants to merge 2 commits into
R0Y00:mainfrom
mumba17:shader/mesh-uniform-buffer-load

Conversation

@mumba17

@mumba17 mumba17 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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 shader, runtime: lower and bind mesh format loads from a descriptor-table V# (Part of #3703) #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 (shader: broadcast lane-0 value for full-EXEC mesh v_readfirstlane_b32 (Part of #2413, #3416) #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 shader: slot 86 mesh programs set the root SRV stride with s_bitset1_b32, then stop at a scalar loop #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

mumba17 and others added 2 commits December 2, 2026 08:28
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 <noreply@anthropic.com>
Since R0Y00#3793, a v_readfirstlane_b32 of a value that is not uniform under
full EXEC broadcasts lane 0 through groupshared memory instead of being
refused. The uniform buffer load cases now check that READFIRSTLANE reads
the load directly with no broadcast slot, and the OFFEN and per-lane index
cases check that the broadcast is used.

Part of R0Y00#3703.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mumba17
mumba17 force-pushed the shader/mesh-uniform-buffer-load branch from 3e20366 to 0acbcdc Compare December 2, 2026 07:40
@mumba17 mumba17 changed the title shader: treat a mesh buffer load at a uniform address as uniform (Part of #3703, stacked on #3770) shader: treat a mesh buffer load at a uniform address as uniform (Part of #3703) Dec 2, 2026

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants