Repository navigation
shader: lower multi-DWORD GLOBAL loads in direct Compute - #3164
Conversation
|
LGTM! The multi-DWORD GLOBAL load lowering is solid: Key improvements:
Minor note: The test fixture This significantly expands direct compute coverage for games using large global memory loads. |
pigalot
left a comment
There was a problem hiding this comment.
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,dwordx4anddwordx3(gfx1013_isa_tables.inl:713).widths[]{1, 2, 4, 3}matches, andi.namenow comes from the table. - Address: the address is computed once from
vaddrbefore any destination write, so an alias of VADDR (thealiascase) 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
addof a negative constant, the same modulo 2^32 as the oldsub. - 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_writeunder EXEC. - Other users of the name: the only other
global_load_dwordmatch insrc/is in #3161'sclear_vector_spills(merged asc45bf9ab). It still clears one register and only for the exactglobal_load_dwordname. That is safe, becauseDirectCompute::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 rannative_lane_spill_descriptor_hardwareindev; 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
main28e4a025, the PR's version ofnative_global_load_check.pyfails at the first refusal.mainstill refuses the GLOBAL encodings with "direct global memory supports only global_load_dword with a scalar address pair", and its own test listsdwordx2among 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.
tedin7
left a comment
There was a problem hiding this comment.
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.
|
Windows Server 2025 verification of
AI-assisted; commands listed were executed locally. |
Change
Fixes #3163. Refs #2935 and #2962. The direct Compute frontend now lowers
global_load_dwordx2,global_load_dwordx3, andglobal_load_dwordx4through a proven root SRV address. At88cddb09, all three source-built requests stopped at guest+0x38on 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
90fe9b5cdf869d66a8ac2873017bbee1f27ebf34on88cddb0919fd4044ff45211c0919c3aefda73c35. Windows 1126300.10075, Visual Studio 2026 18.12.1, SDK 10.0.26100, DXC 1.9.2602.17, RTX 407032.0.16.2124. Native replay used the default D3D12 device and its normal configuration without the debug layer.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.