Skip to content

compute: lower root-UAV global DWORD stores in the direct path - #3333

Merged
JohnConnorNPC merged 6 commits into
R0Y00:mainfrom
SimSalabimse:cursor/direct-global-memory-8fd2
Nov 29, 2026
Merged

JohnConnorNPC merged 6 commits into
R0Y00:mainfrom
SimSalabimse:cursor/direct-global-memory-8fd2

Conversation

@SimSalabimse

Copy link
Copy Markdown
Contributor

Part of #3224: the "direct global memory supports only DWORD loads with a scalar address pair" refusal (9 shaders, 19,528 untranslated dispatches in Not-Saii's census at 8007a539).

What this covers. The census lists only the refusal text, not the opcodes per shader. At 8007a539, global_load_dword through x4 with a scalar address pair already passed the decoder, so my working assumption is that these keys fail on global stores. That is inferred, not checked against the 9 keys. If someone with those requests can rerun the census on this branch, that would confirm how many it actually recovers.

Now lowered (direct compute path)

  • global_store_dword, dwordx2, dwordx3, dwordx4 in the saddr form, when the address is an unadvanced root UAV plus a 32-bit VGPR offset. glc, slc and dlc are accepted, and so is a signed immediate that's a multiple of 4.
  • The same root UAV can be read back with global_load_dword through x4. Out-of-range stores are skipped and out-of-range loads return 0.

Still refused, with a clear reason
The off form (VGPR address pair), FLAT and scratch, an LDS result, byte and short ops, atomics, saddr 127, a store through a root that isn't a UAV, an unaligned immediate, a data range past v255, a mismatched or advanced SGPR pair, and scalar ALU on the root pair.

Tests

  • New: tests/native_global_store_check.py (encodings plus negative controls) and tests/native_store_replay.cpp, registered as native_global_store_encodings / native_global_store_hardware. The native_global_load_hardware fixture now expects the root-SRV store refusal string.
  • Linux: the Python check list passed (254 checks).
  • Windows test PC (NVIDIA, 32-lane waves), at e519c57e, ctest -j 1 with the audio device tests excluded: native_global_store_hardware and native_global_load_hardware passed twice each, native_ passed 351/351 (332 passed, 19 WARP-only skips), and startup_gfx2hlsl_ passed 387/387.

AI-assisted (Cursor)

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

Reviewed e519c57e by its diff. The lowering of the four store widths, the EXEC write mask, the signed 12-bit offset and the refusals (no saddr, lds, flat/scratch, sub-DWORD, atomics) look correct. Three test gaps, a rebase point and a scope note:

  1. Multi-DWORD wrap guard is not exercised. In the store test the only guarded access is a single-DWORD store and load at vaddr 0xfffffff4 offset 16; the wide wrap loads in native_global_load_check.py all have their first DWORD out of range. So const int last_offset = offset; (dropping (count - 1) * 4, diff:284) would pass. Fix: an x4 (or x2) access whose first DWORD passes the guard and whose last would wrap; confirm it fails with the guard narrowed.
  2. No in-range value is read through u0. The only UAV load is the guarded one, stored to LOAD_SLOT and compared to 0; in-range loads are only checked through the root SRV. For example the load's handle class unsigned(uav) (diff:279) is not checked by a readback. Fix: after the stores and s_waitcnt, global_load_dword a DWORD a lane stored and store it to a free slot.
  3. UAV register allocation. Each program has one binding, so const unsigned reg = analysis.srv++; (diff:272) still yields u0. Fix: a fixture with a root SRV and a root UAV, expecting t0 and u0.
  4. Rebase. main added packed_d16_x_uav and indexed_raw_srv after float3_texture_uav, and decode()'s bound is now indexed_raw_srv (src/direct_compute_cache.cpp:138). root_buffer_uav has to go after them, the bound has to follow, and the names list needs packed_d16_x_uav and indexed_raw_srv added before root_buffer_uav, otherwise kind 25 prints as root_buffer_uav and 27 as unknown.
  5. Scope. The compute manifest and the native dispatch path have no case for root_buffer_uav (as for root_buffer_srv), so programs that reach it move to a UAV kind root_buffer_uav refusal rather than run. Worth stating in the body that this is translation only.

Request changes for 1-4.

@cursor
cursor Bot force-pushed the cursor/direct-global-memory-8fd2 branch from e519c57 to 22e7405 Compare November 28, 2026 20:20
@SimSalabimse

Copy link
Copy Markdown
Contributor Author

@Leyukaka Thanks for the review. All three test gaps are covered now, and the branch is rebased onto current main (head a910514a).

  • Multi-DWORD wrap guard: there's an x4 store whose first DWORD is in range and whose last one wraps past 2^32. The address varies per lane (0xffffffe4 + (group << 2) + (lane & 3)) so the compiler can't fold the compare away. The test requires the bound 2^32 - 1 - 28 (or its signed form). If you narrow last_offset to offset, a different constant comes out and the test fails.
  • In-range read through u0: after the stores and s_waitcnt, each lane loads back the DWORD it wrote and stores it to a free slot, so the readback covers the unsigned(uav) load.
  • UAV register allocation: a second program binds two root SRVs and one root UAV, and the test checks that they come out as t0, t1 and u0.

Windows test PC (RTX 4070 Ti plus WARP), ctest -j 1 -R '^native_global_': 4 passed and native_global_srv_heap_replay_warp skipped (77, as expected), ctest exit 0. Linux: python-linux passed 258/258.

AI-Assisted

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

Re-reviewed at a910514a (rebased onto 8ecd30fe) by git range-diff against e519c57e. This replaces my earlier review.

Fixed: 2 (after s_mov_b32 exec_lo, -1 and s_waitcnt, each lane reloads the DWORD at 48N through u0 and stores it to 6400+4N; the UAV load is no longer readonly), 3 (the SRV(t0), SRV(t1), UAV(u0) program must report t0 root=0, t1 root=1, u0 root=2), 4 (enum order, decode bound and names list, src/direct_compute_cache.cpp:138, :897) and 5 (scope stated in docs/experiments/native-direct-global-store.md).

Point 1 is only partly fixed. The x4 store at offset 16 is there, but wide_wrap_bound() searches the whole dxc -dumpbin text for 4294967267|-29|4294967268|-28. X4_BASE = 0xffffffe4 is 4294967268, which is -28 as an i32, one of the accepted values. The v_add_nc_u32 v24, 0xffffffe4, v24 that builds the address is emitted as an add with that constant, so the dump can match on the address add whatever bound the guard compares against, and const int last_offset = offset; may still pass. This is by reading, not measured.

Fix: match only the compare line (for example icmp ule i32 %\S+, -29 or icmp ult i32 %\S+, -28), or use a base that is not an accepted value; add add i32 %a, -28 to the samples that must not match; and post the matching dump line for the head and for the last_offset = offset mutant.

Small: with ule the mutant's bound is 2^32-1-16 = 4294967279, i.e. -17; -16 is its ult form. The comments and the doc say -16.

git merge-tree --write-tree onto origin/main 212d4b5f: clean.

@cursor
cursor Bot force-pushed the cursor/direct-global-memory-8fd2 branch from a910514 to 2da1cc4 Compare November 29, 2026 12:26

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

Head 2da1cc4c, rebased onto main 77d1ba4d. Diff and source reading only, nothing built or run.

git range-diff against a910514a: commits 2-4 are unchanged, commit 1 differs only by the rebase over heap_typed_srv (root_buffer_uav stays last in the enum, the decode bound and the names list, src/direct_compute_cache.cpp:138, :900-901). 2da1cc4c is new (doc and test, +21/-10).

Point 1 is fixed in the code. wide_wrap_bound() (tests/native_global_store_check.py:145-153) now matches only icmp ule i32 %x, -29 or icmp ult i32 %x, -28 (or their unsigned spellings). The samples that must not match (:261-262) include add i32 %a, -28, icmp ule i32 %a, -17, icmp ult i32 %a, -16 and the bare constants. By reading: the guard is emitted as ule against 0xffffffff - last_offset (src/gfx1013_direct_compute.inl:636-638), the x4 at offset 16 is the only access in the program with a last offset of 28, and with last_offset = offset no guard compares against -29.

The -16/-17 wording is corrected in the docstring (:38), the comments and docs/experiments/native-direct-global-store.md:42-44.

Still missing, as asked on a910514a:

  • the matching dxc -dumpbin line for this head and for the last_offset = offset mutant;
  • a run on 2da1cc4c. The last posted run is on a910514a, and PR CI does not run native_global_store_* (not in the pr test filter, no tests/checks/python-linux entry), so the matcher samples in encodings do not run there either. ctest --preset dev -j 1 -R "^native_global_" on this head would cover it.

I will approve once those are posted.

git merge-tree --write-tree onto origin/main 77d1ba4d: clean.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Review of head 2da1cc4c. Read only, nothing built or run.

MUST

  1. This now conflicts with main. compute: publish packed_d16_x_uav runtime manifest (Part of #3224) #3389 merged as af1cab5c. git merge-tree --write-tree --name-only origin/main 2da1cc4c exits 1 with CONFLICT (content): Merge conflict in src/direct_compute_cache.cpp, in one hunk in view_kind_name. main now ends the list with "indexed_raw_srv"}; and adds static_assert(std::size(names) == static_cast<size_t>(ComputeViewKind::indexed_raw_srv) + 1);. To resolve: keep this branch's "indexed_raw_srv", "heap_typed_srv", "root_buffer_uav"}; and point the assert at ComputeViewKind::root_buffer_uav, the last kind here. Drop the stray ponytail: from its comment. Please rebase.
  2. Still held for what was asked on a910514a and again at 12:41: the dxc -dumpbin line for the head and for the last_offset = offset mutant, and a run on this head. I agree with the reading that wide_wrap_bound() now matches only the compare.

SHOULD

  1. The doc names the wrong refusal for the default launcher path. native-direct-global-store.md says a program that reaches the manifest or native dispatch "is refused with UAV kind root_buffer_uav". Only format_compute_runtime_manifest produces that text, and only compile_dxil calls it. Since runtime: default to native shaders and Opus decoding #3449, default runs use the in-process route. There, the binding loop in translate_compute_natively throws "view kind " + std::to_string(...) + " is not bound for a natively translated program" for any kind outside its accepted set, and root_buffer_uav is enum value 28 here (after heap_typed_srv = 27). So in a default run, the 9 census shaders move from direct global memory supports only DWORD loads with a scalar address pair to view kind 28 is not bound for a natively translated program. Please name both reasons, so a census reader can match them.

NIT

  1. Root UAV pairs now carry index_mask = 1 (bind_root_address(..., root_class)). The raw MUBUF byte_bounds test still compares against Symbol{Symbol::Type::root_address,low.value,1} without it. A raw buffer_load_dword through a root UAV is therefore refused as unsupported raw root buffer descriptor or offset. On main it gets compute root descriptor type or visibility. It is refused either way, so only the reason changes. I found this by reading.

AI-assisted.

cursoragent and others added 6 commits November 29, 2026 13:03
Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
Co-authored-by: SimSalabimse <SimSalabimse@users.noreply.github.com>
@cursor
cursor Bot force-pushed the cursor/direct-global-memory-8fd2 branch from 2da1cc4 to 6128c25 Compare November 29, 2026 13:04
@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Re-review of the delta 2da1cc4 → 6128c25, rebased onto main af1cab5 (read-only, on Linux; no build or run here). MUST 1 is resolved. Leyukaka's open request and SHOULD 3 still hold this PR, so I'm not merging it.

Resolved

  • MUST 1 (the conflict): git range-diff shows commits 2–5 unchanged (=). Commit 1 (0425227) changes only as the rebase over compute: publish packed_d16_x_uav runtime manifest (Part of #3224) #3389 requires: "indexed_raw_srv", "heap_typed_srv", "root_buffer_uav"}; ends the list. The new 6128c25 points main's static_assert at ComputeViewKind::root_buffer_uav. git merge-tree --write-tree origin/main 6128c25a exits with rc 0 on current main c04e0dd. CI at 6128c25: Windows, Linux Python and gfx1013 fixtures pass.
  • Correction to my last comment: the // ponytail: comment above that assert comes from main (git grep -c ponytail origin/main -- src/direct_compute_cache.cpp → 1). It is not this branch's, so please ignore my "drop it".

Still open

  1. (MUST) Leyukaka's CHANGES_REQUESTED stands, and the request from a910514 and 12:41 is unanswered. They asked for the dxc -dumpbin line for this head and for the last_offset = offset mutant, and for a run of ctest --preset dev -j 1 -R "^native_global_" on this head. The PR CI still doesn't run native_global_store_*.
  2. (SHOULD) docs/experiments/native-direct-global-store.md still says only that such a program "is refused with UAV kind root_buffer_uav". That text comes from compile_dxil's manifest formatter. On the default in-process route (runtime: default to native shaders and Opus decoding #3449), the refusal is view kind 28 is not bound for a natively translated program. Please name both.

NIT 4 (the reason change for a raw root-UAV buffer_load) is unchanged and not blocking.

This comment was AI-assisted.

@Leyukaka

Copy link
Copy Markdown
Collaborator

Run on head 6128c25a: Windows, a hardware adapter plus WARP, dev preset configured with -DX2W_WITH_OPUS=OFF, full build.

ctest --preset dev --no-tests=error -R '^native_global_', exit 0:

native_global_load_hardware               Passed    13.58 sec
native_global_srv_heap_replay_warp        Skipped    0.79 sec
native_global_srv_heap_replay_hardware    Passed    39.62 sec
native_global_store_encodings             Passed     0.62 sec
native_global_store_hardware              Passed     3.55 sec
100% tests passed, 0 tests failed out of 5

Output of native_global_store_hardware:

encodings: dword, x2, x3 and x4 stores, a UAV load, alias, negative offset and the wrap poison
refused: VGPR address pair, unaligned offset, data past v255, an odd base, saddr 127, a byte store, an atomic, LDS, flat, scratch, a replaced high half, an advanced pointer, an SRV root
module: one root UAV, min_size 48, x4 wrap bound covers the last dword, registers t0 t1 u0
global_store_dword/x2/x3/x4: record, alias, negative offset, sparse EXEC, UAV load wrap guard; poison store absent

native_global_store_encodings prints the first of those lines. The store test has no heap-slot case. In the native_global_srv_heap_replay_hardware output, the window_store case of tests/native_global_srv_heap_replay_check.py reports its expected refusal:

native compute +0x70: a GPU-selected heap slot is read as a raw buffer SRV only

Not covered:

  • No dxc -dumpbin lines, for the head or for the last_offset = offset mutant. I did not produce them and did not run the mutant.
  • WARP: native_global_srv_heap_replay_warp skipped with adapter has no 32-lane waves (4..4), -> exit 77, fixture capability skip (77). The heap replay ran on the hardware adapter only.
  • SHOULD 3 (the doc names only the UAV kind root_buffer_uav refusal) is unchanged at this head.

This answers the head-run part of my request. The dumpbin lines are still open.

@SimSalabimse

Copy link
Copy Markdown
Contributor Author

Windows test PC (--preset dev, -j 1), at 6128c25a49e082178934d487e26930ac52c31d52.

This is the remaining dxc -dumpbin evidence. native_global_store_check.py compiled program() the same way the hardware test does (gfx1013-direct-cs@0), then ran dxc.exe -dumpbin on that .cso.

At this head, unmodified, the compare wide_wrap_bound accepts is:

  %t307 = icmp ule i32 %t306, -29

wide_wrap_bound returns true. That is the only accepted line. The address add of X4_BASE is a different line and is not matched:

  %t154 = add i32 -28, %t153

The same dump also has other icmp ule constants (-17, -5, -13, -25, -45). Those are not the x4 wrap compare. There are no icmp ult lines.

Local mutant, not committed. Only src/gfx1013_direct_compute.inl line 636 changed, from const int last_offset = offset + static_cast<int>((count - 1) * 4); to const int last_offset = offset;. The x4 compare becomes:

  %t307 = icmp ule i32 %t306, -17

wide_wrap_bound returns false. Versus the head dump, the mutant also changes three other compares (-13 to -9, -25 to -17, -45 to -33). The add of -28 is unchanged.

ctest --preset dev -j 1 with -R matching native_global_store_:

  • Head, before the mutant: native_global_store_encodings Passed, native_global_store_hardware Passed, ctest exit 0.
  • Mutant: native_global_store_encodings Passed. native_global_store_hardware Failed with AssertionError: x4 wrap guard does not cover the last dword. ctest exit 8.
  • After restoring the .inl from HEAD: git status and git diff empty, HEAD still 6128c25a49e082178934d487e26930ac52c31d52. Rebuilt. Both store tests Passed again, ctest exit 0.

This does not change SHOULD 3. Nothing was committed or pushed.

AI-Assisted

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

Head 6128c25a, diff only. This replaces my change request.

Delta from 2da1cc4c by git range-diff: commits 2-5 unchanged, commit 1 differs only by the rebase over #3389, and 6128c25a points the static_assert at ComputeViewKind::root_buffer_uav (src/direct_compute_cache.cpp:903).

The dxc -dumpbin lines posted by the author answer my last open point: at the head the matched compare is icmp ule i32 %t306, -29 and the add i32 -28, %t153 is not matched; with last_offset = offset the compare becomes -17 and native_global_store_hardware fails with x4 wrap guard does not cover the last dword. That is the author's measurement, I did not reproduce the dump or the mutant; it is consistent with 0xffffffff - last_offset (-29 = -1 - (16 + 12)).

Still open, not blocking for me: the SHOULD from the other review, docs/experiments/native-direct-global-store.md:22-23 names only UAV kind root_buffer_uav and not the in-process view kind 28 is not bound for a natively translated program.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Re-check at head 6128c25a (unchanged since my 13:24 comment). Read only, on Linux.

Resolved

  • MUST 2: The author posted the dxc -dumpbin evidence at this head. The accepted compare is %t307 = icmp ule i32 %t306, -29. The add i32 -28, %t153 address add is not matched. With last_offset = offset the compare becomes -17, and native_global_store_hardware fails with x4 wrap guard does not cover the last dword. The earlier head run (ctest --preset dev --no-tests=error -R '^native_global_', 5/5, with the WARP heap replay skipped as a 77) covers the run part. Leyukaka's change request is replaced by an approval at 6128c25a, so no review is still requesting changes.
  • git merge-tree --write-tree origin/main 6128c25a exits 0 on current main d3e306a7. CI at the head: Windows, Linux Python and gfx1013 fixtures pass. The /O2 and coverage jobs are skipped, as they are for PRs. The new tests are registered through the tests/cmake/*.cmake glob. The diff changes no launcher, preset or runtime default.

Left as a follow-up (not blocking)

  • SHOULD 3: native-direct-global-store.md still names only UAV kind root_buffer_uav. On the default in-process route, d3d12_compute_dispatch.inl refuses the same program with view kind 28 is not bound for a natively translated program. A one-line doc follow-up that names both reasons would let census readers match them.
  • NIT 4 (the reason for a raw root-UAV buffer_load changes) is unchanged.

With 0 MUSTs, no change request standing and CI green, I'm merging at 6128c25a.

This comment was AI-assisted.

@JohnConnorNPC
JohnConnorNPC merged commit 5b86df1 into R0Y00:main Nov 29, 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.

4 participants