Skip to content

shader: lower multi-DWORD GLOBAL loads in direct Compute - #3164

Merged
pigalot merged 2 commits into
R0Y00:mainfrom
RonLogic:shader/native-global-vector-load
Nov 27, 2026
Merged

pigalot merged 2 commits into
R0Y00:mainfrom
RonLogic:shader/native-global-vector-load

Conversation

@RonLogic

Copy link
Copy Markdown
Contributor

Change

Fixes #3163. Refs #2935 and #2962. The direct Compute frontend now lowers global_load_dwordx2, global_load_dwordx3, and global_load_dwordx4 through a proven root SRV address. At 88cddb09, all three source-built requests stopped at guest +0x38 on the scalar-only decoder restriction.

The lowering reuses the existing DWORD alignment and signed immediate contract. It reads the address before writing the tuple, covers the full transfer width in the view size and range guard, and writes consecutive VGPRs under EXEC. Unsupported segments, pointers and destination tuples still give named refusals. This is the scalar-address GLOBAL form. #3143 is the separate raw MUBUF task.

Verification

Tested 90fe9b5cdf869d66a8ac2873017bbee1f27ebf34 on 88cddb0919fd4044ff45211c0919c3aefda73c35. Windows 11 26300.10075, Visual Studio 2026 18.12.1, SDK 10.0.26100, DXC 1.9.2602.17, RTX 4070 32.0.16.2124. Native replay used the default D3D12 device and its normal configuration without the debug layer.

$tests = '^native_(global_load_hardware|scalar_lds_hardware|adjacent_srv_hardware|mtbuf_hardware|indexed_atomic_hardware|bytewin_store_(controls|hardware)|frexp_f(16|32)_(controls|hardware))$'
foreach ($preset in 'release', 'dev') {
    cmake --build --preset $preset --target compile_dxil native_store_replay
    ctest --preset $preset --no-tests=error -j 1 -R $tests -V
}
  • Debug and Release 11/11 each, with no skips. The original scalar load and adjacent byte-window, root/address, LDS, MTBUF and atomic regressions passed.
  • Each width matched all 2,064 words per alias, tail, sparse EXEC and address-wrap replay, including guard words. The tail cases kept the in-range prefix at the end of the 64-word view. Reversing the component order changed 128 words for x2 and x3 and 256 for x4.
  • Compile controls rejected register tuples that extend past v255 and confirmed that the minimum view size grows with the transfer width. Documentation links and bidi checks passed.

Evidence and follow-up

The experiment note documents the source-built fixture and the public ISA references. The native replay requires wave32, which the local WARP adapter does not expose. Guest accesses outside the bound root view remain subject to the documented root-view limit.

I used Codex to prepare the change and ran verification locally.

@KelboLive

Copy link
Copy Markdown
Contributor

LGTM! The multi-DWORD GLOBAL load lowering is solid:

Key improvements:

  • global_load_dwordx2/x3/x4 now properly compute the address once before writing any destination VGPRs, even when destinations alias VADDR.
  • Correctly handles edge cases: aliasing (dst overlaps vaddr), tail bounds (offset + width exceeds view), sparse EXEC (inactive lanes get sentinel values), and wrap-around guards.
  • View sizing accounts for full transfer width (min_size = offset + width * 4).
  • Tests verify all four widths across multiple cases with proper readback validation.

Minor note: The test fixture wide_program correctly reverses destination ordering when testing aliasing, which matches the hardware behavior where consecutive VGPRs are written in order. This is important for games that use overlapping register allocations.

This significantly expands direct compute coverage for games using large global memory loads.

@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 reviewed 72141fd0 (the main merge on top of 90fe9b5c) merged over main c45bf9ab. The merge is clean (tree 94b6afed) and git diff --cached --check is clean. The source change is the same as in 90fe9b5c.

What I traced.

  • Opcodes: GFX10 FLAT/GLOBAL opcodes 12..15 are global_load_dword, dwordx2, dwordx4 and dwordx3 (gfx1013_isa_tables.inl:713). widths[]{1, 2, 4, 3} matches, and i.name now comes from the table.
  • Address: the address is computed once from vaddr before any destination write, so an alias of VADDR (the alias case) reads the original address. The low two bits are dropped as before.
  • Wrap guards: the lower guard is unchanged. The upper guard now uses the last DWORD's offset, so the whole tuple reads zero if any DWORD would cross 2^32. A negative offset is now an add of a negative constant, the same modulo 2^32 as the old sub.
  • View size: the minimum view size grows by count * 4.
  • Destinations: a tuple that would run past v255 is refused, and each result goes through vector_write under EXEC.
  • Other users of the name: the only other global_load_dword match in src/ is in #3161's clear_vector_spills (merged as c45bf9ab). It still clears one register and only for the exact global_load_dword name. That is safe, because DirectCompute::write() refuses any write to a VGPR that holds symbolic lanes before the analysis clear matters. Widening that match is a possible follow-up, not a blocker for this PR.

What I ran. I built compile_dxil native_store_replay 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_(global_load_hardware|scalar_lds_hardware|adjacent_srv_hardware|mtbuf_hardware|indexed_atomic_hardware|bytewin_store_(controls|hardware))$'
  • Results: 7/7 pass in Debug and Release /O2, with no skips. I also ran native_lane_spill_descriptor_hardware in dev; it passes.
  • Coverage: x2, x3 and x4 each match all 2,064 words for the alias, tail, sparse-EXEC and wrap replays. Reversing the components changes 128, 128 and 256 words.
  • Negative control: on main 28e4a025, the PR's version of native_global_load_check.py fails at the first refusal. main still refuses the GLOBAL encodings with "direct global memory supports only global_load_dword with a scalar address pair", and its own test lists dwordx2 among the refusals.

Mutants in src/gfx1013_direct_compute.inl. For each, I rebuilt in dev and ran native_global_load_hardware:

Mutant Result
widths[]{1, 2, 3, 4} (x3 and x4 swapped) killed (v253 x4 range control)
view span ignores the width (+ 4) killed (extent control)
destination range refusal removed killed
guard select applied to component 0 only killed (x2 wrap: words read 0x51aa0001..4 instead of 0)
lower guard removed killed (guard count)
upper guard uses the first DWORD only (last_offset = offset) survives, equivalent on this GPU

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

For the survivor, I added a probe: an x4 load from v2 (0xfffffff0 + 4 * (lane & 3)) at offset 0, so lanes 1..3 cross 2^32 partway through the tuple. On this head every component reads 0. Under the mutant every component also reads 0, because this driver bounds-checks the unwrapped component offsets. So the last-DWORD guard is not observable here. It would matter on a driver that wraps component offsets.

Non-blocking. If you want the last-DWORD guard pinned on every driver, an IR-level assert would do it: check that the x4 module's upper bound is 0xffffffff - (offset + 12), not 0xffffffff - offset.

Verdict: approve on 72141fd0.

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 72141fd0.

This reply was AI-assisted.

@pigalot
pigalot merged commit d474a39 into R0Y00:main Nov 27, 2026
5 checks passed

@tedin7 tedin7 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.

Review of 72141fd (updated with main). Comment only.

The direct GLOBAL path now handles all four GFX10 DWORD load opcodes, 12 to 15 (global_load_dword, _dwordx2, _dwordx4, _dwordx3; the width table {1, 2, 4, 3} matches that opcode order). It still accepts only the saddr form, ADDR = SADDR + zext(VADDR) + sext(OFFSET). The native decode refuses other segments, the LDS bit (bit 13), a null or EXEC_HI saddr (125, 127), and opcodes outside 12 to 15. The destination range is checked against v255. The wrap guard covers both the first DWORD (negative offset) and the last DWORD (positive offset plus the width), and an out-of-range lane reads 0 for every component. The low two address bits are dropped, as buffer_load_dword does in this path.

Coverage note: the only test of this path is native_global_load_hardware, which needs a wave32 adapter and skips on our WARP host and in CI. The multi-DWORD readback therefore rests on the RTX 4070 run in the description. A no-GPU IR check like the native_*_ir tests, for one dwordx3 load with an aliased destination, would keep the address-before-write order covered everywhere.

On cpp-migration: main itself no longer merges cleanly with that branch, since #3140; the conflicting files are ones this PR does not touch. So I applied only this PR's own change onto cpp-migration and ran the native sweep there (comment below).

Commands: git diff origin/main...pull/3164/head (read), git merge-tree --write-tree origin/cpp-migration pull/3164/head, git apply --3way of the PR's own diff onto origin/cpp-migration, plus the Windows commands in the comment below.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Windows Server 2025 verification of 72141fd0b859a07eb6115a769dc6092c3ba14ede (D3D12 WARP, MSVC 14.44.35207):

  • dev: cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump; ctest --preset dev -R <native sweep>: 100% tests passed out of 158 (91 passed, 67 skipped; native_global_load_hardware skips here, it needs a wave32 adapter)
  • release: same targets with --preset release; ctest --preset release -R <native sweep>: 100% tests passed out of 158 (91 passed, 67 skipped)
  • cpp-migration (a0f67731) with only this PR's own change applied, dev and release: 70 of 71 native tests passed or skipped. The one failure, native_sdwa_f16_ir, fails the same way on cpp-migration without this PR, so it is not caused by this change.

<native sweep> = every native_* test except native_startup_request_cache_hardware, which fails on WARP-only hosts with or without this PR.

AI-assisted; commands listed were executed locally.

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.

shader: accept multi-dword GLOBAL loads through root addresses in direct Compute

4 participants