Skip to content

shader: support defined numeric M0 in direct compute - #3205

Merged
pigalot merged 1 commit into
R0Y00:mainfrom
xiaoqi72665:native/phase3bc-probe
Nov 27, 2026
Merged

pigalot merged 1 commit into
R0Y00:mainfrom
xiaoqi72665:native/phase3bc-probe

Conversation

@xiaoqi72665

Copy link
Copy Markdown
Contributor

Fixes #3202. Refs #2935, #3143 and #3172.

Change

Support defined numeric M0 (RDNA2 scalar encoding 124) in the direct compute frontend. Reuse the existing per-wave register storage, numeric state analysis and CFG joins. Allow the 32-bit scalar move destination and explicit numeric operand reads; keep M0 unbound on entry. This adds eight production lines and removes four. No new state structure or memory-addressing support.

The raw-buffer-load decoder is unchanged: #3172 owns the off/offen and nonzero SGPR-offset work, and still explicitly excludes M0. M0 buffer offsets remain refused. This is a separate register-support prerequisite, not a claim to implement implicit LDS, relative VGPR indexing, interpolation, or all M0 instruction forms. The existing 64-bit pair restrictions remain.

Actual verification

Base 673a9f2, candidate 6307e67.

  • Original source-built baseline at d99e0ae rejected s_mov_b32 m0,4 and subsequent read. On the candidate, both compile via native_cpp; raw loads with M0 still hit the same decoder refusal.
  • New fixture uses two full physical wave32 groups, group-dependent scalar values, carry/SCC selection, overwrite, both sides of a branch, loop, and scalar write with guest EXEC zero. Exact 2064-DWORD buffer including 20 output words and all 2044 untouched/guard words. Six named refusals: uninitialized M0, partially defined CFG join, symbolic descriptor, invalid 64-bit pair source/destination and M0 raw-store offset.
  • Debug and Release registered CTest: 6 passed, 1 capability skip (stock replay, SM6.5). Conversion IR/controls, native SAD, SALU64 and signed-forms controls included. Existing Python scalar-M0 controls also pass.
  • Actual local GPU runs using the same candidate compiler and ignored diagnostic replay with app-local Agility DLLs: RX 7900 XT Debug/Release and WARP Debug/Release all passed, 8,256 DWORD comparisons exact. Local SDK/device initialization is not part of this patch. Full physical waves avoid the known partial-wave WARP anomaly (native compute: run wave32 direct modules on WARP (proposal, stage 1 claimed) #3160).
  • Windows 10 build 19045, RX 7900 XT 32.0.32029.2010, WARP 1.0.22.0, Agility 1.620.2 DLL-only, Windows SDK 10.0.26100.0, MSVC 19.44. Debug layer unavailable. No retail execution or wave64 hardware claim.
foreach ($preset in 'dev', 'release') {
    cmake --build --preset $preset --target compile_dxil native_store_replay native_compute_ir_dump
    ctest --preset $preset --no-tests=error -j 1 -R '^(native_m0_|native_salu64_controls$|native_cvt_f16_i16_(ir|controls)$|native_signed_forms_controls$|native_sad_controls$)' -V
}
python -B tests/startup_gfx2hlsl_scalar_m0_check.py controls

Public source-generated fixtures only. AI-assisted; locally tested by Buhe (@xiaoqi72665).

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I tried to review 6307e672 over current main 6cc46a3c. The trial merge conflicts in both source files, and the conflicts are semantic, not just textual. Three PRs landed after this PR's base 673a9f2c and changed the same three spots:

  1. Emit::require_numeric (src/gfx1013_compute_native.cpp): #3180 (63fd6ea8) gave it a limit parameter (reg < limit, default 106), and operand32 now passes sgpr_limit. This PR's reg <= 105 || reg == 124 has to be folded into that form, for example (reg < limit || reg == 124). If the conflict is resolved by keeping main's side, reads of M0 would skip the numeric check entirely, since 124 is above every limit. Your undefined and partial_join controls should catch that, so please make sure they still run after the rebase.
  2. operand32 (src/gfx1013_direct_compute.inl): the same require_numeric(i, n, sgpr_limit) call. The numeric_m0 condition itself merges unchanged.
  3. The s_mov_b32 / s_mov_b64 destination guard: #3192 (2b7ebf18) replaced !(wave64 && i.dst == 127) with an exec_hi flag that also covers wave32 s_mov_b32 exec_hi. Both clauses need to stay: !exec_hi && !(compute && i.dst == 124 && n == "s_mov_b32").

Reading of the change itself, from the diff only, not run:

  • M0 entry state: it starts unbound, so a read before any write refuses.
  • Raw loads: M0 is still refused as a raw-load soffset after #3172, whose decoder admits SGPRs 0 to 105 only.
  • Other memory operands: operand32 excludes MUBUF/MTBUF/GLOBAL (all Encoding::Mubuf) and SMEM, so M0 cannot become a memory offset through that path either.

I found nothing else to change there. I stopped at the conflict, so I have not built or run this head.

Requested: rebase onto current main with the three resolutions above, then re-run native_m0_controls / native_m0_hardware. I'll retest the new head.

Environment: Windows 11 25H2 build 26200.9974; Git trial merge only.
CI: Build and test on Windows passes on 6307e672 against its own base.

This reply was AI-assisted.

@xiaoqi72665
xiaoqi72665 force-pushed the native/phase3bc-probe branch from 6307e67 to 906d027 Compare November 27, 2026 22:04
@xiaoqi72665

Copy link
Copy Markdown
Contributor Author

Thanks for the precise conflict analysis. Rebased #3205 onto a5c02db as 906d027, preserving all three semantics: numeric M0 with the caller's SGPR limit, the sgpr_limit call, and the upstream EXEC_HI exception alongside the M0 s_mov_b32 exception. Both Debug and Release native_m0_controls passed, including undefined and partial_join. The stock native_m0_hardware fixture skips on this host; relinking the freshly built replay objects with the existing app-local Agility 1.620.2 export and using the upstream --direct-warp mode gave exact 2064-DWORD readbacks on RX 7900 XT and WARP in both builds (4/4, 8256 DWORDs). No changes to the test oracle or M0 scope. The prior commit is retained locally. Debug layer unavailable. Buhe; AI-assisted.

@R0Y00 R0Y00 left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I reapplied exact head 906d0271 over main 886a5a28 (trial tree 382502fb) without a conflict. I checked the three areas called out on the prior head: the caller's SGPR bound is preserved, the numeric M0 read still receives that bound, and the wave32 EXEC_HI and M0 s_mov_b32 destination exceptions coexist. MUBUF/SMEM still exclude M0. Debug and Release /O2 each passed native_direct_container, native_m0_controls, and native_salu_shift64_controls from a source build, with no skips. These are compiler/validation results; the GPU-vendor results above are the author's. @pigalot, the rebase addresses the conflicts you identified on 6307e672; could you update your review for the new head?

Follow-up on the same trial tree: the stock native_m0_hardware fixture passed in both Debug and Release /O2 on RTX 4060 Laptop (32.0.16.1656, Windows 11 26200.9974), with an exact 2,064-DWORD comparison per run and no capability skip. The standalone compute replay does not enable the D3D12 debug layer.

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I retested 906d0271 merged over main c1de64a5. The merge is clean (tree 6af2f070) and git diff --cached --check is clean. This supersedes the changes-requested review on 6307e672.

Earlier findings. All three are addressed at this head:

  1. Emit::require_numeric: the check is now (reg < limit || reg == 124). A caller's lower limit is kept, and M0 is always checked.
  2. operand32: it still passes sgpr_limit to require_numeric for the numeric M0 read.
  3. s_mov_b32 / s_mov_b64 destination guard: #3192's exec_hi exception and the new compute && i.dst == 124 && s_mov_b32 exception are separate clauses. A wave64 s_mov_b64 into M0 stays refused.

What I traced.

  • Analysis: M0 starts unbound, so a read before a defining write is refused, and a join of defined and undefined stays refused.
  • Exclusions: MUBUF and SMEM still exclude M0 as an operand, so this change doesn't touch M0 memory addressing (#3172's scope).

What I ran. I built compile_dxil native_store_replay native_compute_ir_dump in dev and release, then ran

python .agentic\scripts\with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(native_m0_(controls|hardware)|native_salu[a-z0-9_]*|native_direct_container|native_permlane_(controls|hardware)|native_scalar_lds_hardware|native_readlane[a-z0-9_]*|native_lane[a-z0-9_]*)$'
  • Results: 22 pass and 1 skips, in both Debug and Release /O2. The skip (77) is native_lane_spill_descriptor_warp, an existing WARP test this PR doesn't touch.
  • Hardware coverage: native_m0_hardware ran here, with no skip, and matched the 20 value words and all 2,044 guard and untouched words for both groups. native_m0_controls gives the expected refusal for undefined, partial_join, descriptor, pair_source, pair_destination and memory_offset.
  • Negative control: on main d6912f58, the PR's native_m0_check.py fails in both modes. controls is refused at numeric with +0x1c: direct scalar move destination, and the hardware replay compile fails.

Mutants. For each, I rebuilt in dev and ran native_m0_(controls|hardware):

Mutant Result
require_numeric without reg == 124 killed (undefined compiles)
M0 not initialised unbound killed (undefined compiles)
numeric M0 also accepted in MUBUF killed (memory_offset)
scalar move destination refusal disabled killed (pair_destination)
M0 destination exception widened to s_mov_b64 killed (pair_destination)

Restored and rebuilt afterwards; git diff --quiet is clean.

Verdict: approve on 906d0271.

Environment: NVIDIA GeForce RTX 5090 driver 610.88, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10, wave32, debug layer off.
CI: Build and test on Windows passes on 906d0271.

This reply was AI-assisted.

@pigalot
pigalot merged commit e9d1d6a into R0Y00:main Nov 27, 2026
5 checks passed
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.

direct compute: support defined numeric M0 register values

3 participants