shader: accept readfirstlane of a proven wave-uniform VGPR in the mesh frontend #3439

Merged
Leyukaka merged 3 commits from upstream-pr/3439 into main 2026-11-29 12:05:10 +00:00
Leyukaka commented 2026-11-29 09:04:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T09:04:19Z.


Part of #3416

Branch shader-mesh-udiv-uniform (f7b77587, f74eacc8), based on main 41babe6e. git merge-tree with main 184b15db is clean.

What changes

The native mesh frontend refused any v_readfirstlane_b32 whose source was not one of its tracked lane or group values. That blocks the 32-bit unsigned division expansion over root constants: v_cvt_f32_u32, v_rcp_f32, v_mul_f32, v_cvt_u32_f32, then v_readfirstlane_b32 and a scalar refinement.

In src/gfx1013_direct_mesh.inl (line numbers at the branch head):

  • :109-110 records the SGPRs that hold root constants as wave-uniform at entry.

  • :914 adds s_sub_i32 and s_mul_hi_u32 to the scalar ALU list. Both go through the shared alu.arithmetic.

  • :1118-1152, VALU arm: the result is recorded as wave-uniform (:1149-1152) when the write meets all of these (:1142-1144):

    • it runs under full EXEC;
    • its destination is a VGPR;
    • it is not a DPP or SDWA form;
    • every source is an inline constant or a value already proven uniform. VCC, EXEC, SCC and lane or thread values do not count;
    • for v_mac_f32 / v_fmac_f32, the old destination is also uniform;
    • for 64-bit shifts, the high source register is also uniform.

    A later write to the VGPR replaces the value that readfirstlane reads, so the proof no longer applies.

The v_readfirstlane_b32 gate itself (:1031) is unchanged.

Evidence

On this head, release build:

cmake --build out/build/release --target compile_dxil
ctest --test-dir out/build/release -R '^native_direct_mesh$'

Result: native_direct_mesh Passed. src/gfx1013_direct_mesh.inl and tests/native_direct_mesh_check.py are identical on 41babe6e and 184b15db.

Tests: uniform-udiv is accepted. Each of these is refused at the readfirstlane:

  • varying-udiv
  • overwritten-udiv
  • varying-accumulator
  • varying-pair-high
  • sdwa-uniform-source
  • partial-exec-write

Mutation on this head: if (uniform_result) { (:1149) changed to if (false && uniform_result) {. uniform-udiv then fails with native compute +0x28: unsupported mesh instruction or EXEC state: v_readfirstlane_b32. After the revert the test passes.

Mutation on the previous revision (9aa6e57c on main 212d4b5f, same changed lines), not repeated on this head: uniform_result=full_exec && sources changed to uniform_result=sources. partial-exec-write then fails: the read at +0x24 is accepted, and the run stops later with native compute +0x38: unbound numeric SGPR s18.

partial-exec-write writes v6 and reads it inside the s_cbranch_execz block, then restores the saved EXEC at the branch target. It does not widen EXEC inside the block.

Not covered

  • uniform-udiv asserts only that lowering succeeds and the export is present. It does not check the quotient value.
  • For the source, accumulator, pair-high and SDWA conditions, the cases show only that those inputs are refused at the readfirstlane. Those conditions were not mutated.
  • No case covers the DPP condition or the VCC/EXEC operand exclusion.
  • v_ceil_f32 is in the VALU arm but in none of the source-count lists, so its result is never recorded as uniform (by reading).
  • Pre-existing, by reading: the gate (full_exec || exec_skip, :1031) also accepts a read inside a lane-skip block. No case here covers a read after EXEC is widened inside the skip. shader-mesh-exec-widen refuses that widening.

CI

On main 184b15db the pr CTest preset filter does not match native_direct_mesh, so Build and test on Windows does not exercise this change.

Interactions with other open mesh branches

By git merge-tree at the current heads, two textual conflicts:

  1. tests/native_direct_mesh_check.py, end of main(), with tests-mesh-refusal-coverage (0feac9c2). Keep both blocks. This block starts with its own layout.write_text('mesh1 128 3 1 2 128 64\nconstants 21 0 1').
  2. src/gfx1013_direct_mesh.inl, the scalar ALU name list, with shader-mesh-udiv-ops (ddd77faf). That branch adds s_max_u32 and this one adds s_sub_i32 || s_mul_hi_u32. The resolution is the union of both additions.

No textual conflict with shader-mesh-exec-widen, shader-mesh-exchange-nosave or mesh57-profile-mismatch-part. The combinations were not built at the current heads.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5549250017 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3439). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T09:04:19Z. --- Part of #3416 Branch `shader-mesh-udiv-uniform` (f7b77587, f74eacc8), based on main 41babe6e. `git merge-tree` with main 184b15db is clean. ## What changes The native mesh frontend refused any `v_readfirstlane_b32` whose source was not one of its tracked lane or group values. That blocks the 32-bit unsigned division expansion over root constants: `v_cvt_f32_u32`, `v_rcp_f32`, `v_mul_f32`, `v_cvt_u32_f32`, then `v_readfirstlane_b32` and a scalar refinement. In `src/gfx1013_direct_mesh.inl` (line numbers at the branch head): - :109-110 records the SGPRs that hold root constants as wave-uniform at entry. - :914 adds `s_sub_i32` and `s_mul_hi_u32` to the scalar ALU list. Both go through the shared `alu.arithmetic`. - :1118-1152, VALU arm: the result is recorded as wave-uniform (:1149-1152) when the write meets all of these (:1142-1144): - it runs under full EXEC; - its destination is a VGPR; - it is not a DPP or SDWA form; - every source is an inline constant or a value already proven uniform. VCC, EXEC, SCC and lane or thread values do not count; - for `v_mac_f32` / `v_fmac_f32`, the old destination is also uniform; - for 64-bit shifts, the high source register is also uniform. A later write to the VGPR replaces the value that `readfirstlane` reads, so the proof no longer applies. The `v_readfirstlane_b32` gate itself (:1031) is unchanged. ## Evidence On this head, release build: ``` cmake --build out/build/release --target compile_dxil ctest --test-dir out/build/release -R '^native_direct_mesh$' ``` Result: `native_direct_mesh` Passed. `src/gfx1013_direct_mesh.inl` and `tests/native_direct_mesh_check.py` are identical on 41babe6e and 184b15db. Tests: `uniform-udiv` is accepted. Each of these is refused at the `readfirstlane`: - `varying-udiv` - `overwritten-udiv` - `varying-accumulator` - `varying-pair-high` - `sdwa-uniform-source` - `partial-exec-write` Mutation on this head: `if (uniform_result) {` (:1149) changed to `if (false && uniform_result) {`. `uniform-udiv` then fails with `native compute +0x28: unsupported mesh instruction or EXEC state: v_readfirstlane_b32`. After the revert the test passes. Mutation on the previous revision (9aa6e57c on main 212d4b5f, same changed lines), not repeated on this head: `uniform_result=full_exec && sources` changed to `uniform_result=sources`. `partial-exec-write` then fails: the read at +0x24 is accepted, and the run stops later with `native compute +0x38: unbound numeric SGPR s18`. `partial-exec-write` writes v6 and reads it inside the `s_cbranch_execz` block, then restores the saved EXEC at the branch target. It does not widen EXEC inside the block. ## Not covered - `uniform-udiv` asserts only that lowering succeeds and the export is present. It does not check the quotient value. - For the source, accumulator, pair-high and SDWA conditions, the cases show only that those inputs are refused at the `readfirstlane`. Those conditions were not mutated. - No case covers the DPP condition or the VCC/EXEC operand exclusion. - `v_ceil_f32` is in the VALU arm but in none of the source-count lists, so its result is never recorded as uniform (by reading). - Pre-existing, by reading: the gate (`full_exec || exec_skip`, :1031) also accepts a read inside a lane-skip block. No case here covers a read after EXEC is widened inside the skip. `shader-mesh-exec-widen` refuses that widening. ## CI On main 184b15db the `pr` CTest preset filter does not match `native_direct_mesh`, so `Build and test on Windows` does not exercise this change. ## Interactions with other open mesh branches By `git merge-tree` at the current heads, two textual conflicts: 1. `tests/native_direct_mesh_check.py`, end of `main()`, with `tests-mesh-refusal-coverage` (0feac9c2). Keep both blocks. This block starts with its own `layout.write_text('mesh1 128 3 1 2 128 64\nconstants 21 0 1')`. 2. `src/gfx1013_direct_mesh.inl`, the scalar ALU name list, with `shader-mesh-udiv-ops` (ddd77faf). That branch adds `s_max_u32` and this one adds `s_sub_i32 || s_mul_hi_u32`. The resolution is the union of both additions. No textual conflict with `shader-mesh-exec-widen`, `shader-mesh-exchange-nosave` or `mesh57-profile-mismatch-part`. The combinations were not built at the current heads.
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!3439
No description provided.