Skip to content

native: raw buffer loads through heap view tokens (#3023 stage 3, translator) - #3631

Open
JB2WIN wants to merge 12 commits into
R0Y00:mainfrom
JB2WIN:native/heap-token-buffers
Open

JB2WIN wants to merge 12 commits into
R0Y00:mainfrom
JB2WIN:native/heap-token-buffers

Conversation

@JB2WIN

@JB2WIN JB2WIN commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

What

Raw buffer loads from the directly indexed resource heap at a GPU-selected offset, through the same view tokens as #3544 (stage 3 of #3023, translator side).

  • An s_load_dwordx4/s_load_dwordx8 (SMEM op 2/3) that reads a buffer V# through a heap token, followed by MUBUF loads, becomes ResourceDescriptorHeap[baseraw + id] when the token names a raw buffer view (dimension table code 0x20). Otherwise it reads the null raw view (reads zero) and counts one miss per wave with an active lane, as the texture route does.
  • The token words grow from 5 to 7 when a program has buffer loads (baseraw, nullraw). NativeComputeShader::heap_token_word_count (0/5/7) replaces the bool. Manifest: udsrc K heaptok baseraw|nullraw.
  • native_compute_output_revision 2 → 3 (doc: Revision).

Why

The texture route (#3544) leaves buffer reads through the same tokens refused. The census shows them as the next block of heap refusals.

How

  • Eligibility is judged per load. An op-2 candidate that is not eligible keeps today's path and text; it never makes the program ineligible for the texture route. Loads inside a loop are not eligible.
  • If the token words exceed the 32-word compute entry layout, the program is translated again without the buffer route, so the buffer loads keep today's result.
  • The byte address is the unshifted low word. The s_add_u32 high word must be the constant 0 at translation time (no carry map, no runtime carry check; same heap-relative model as the heap_offset path).
  • Dispatch still refuses every heaptok line ("heap token textures are not bound yet"). Binding is the runtime PR (PR 2), which also writes the 0x20 dims entries.

How tested

  • Rig controls (native_heap_token_texture_check.py): 130 assertions. They include loop, mixed loop, the mixed case (eligible texture plus ineligible buffer), a 25/26-stride word budget, mask/high-word/dims/slot mutations, and EXEC none/half from native: translate GPU-selected heap textures through view tokens in compute #3544.
  • Hardware (native_heap_token_texture.cpp, RTX 3080): 83 assertions; rawbuf, rawbuf_waterfall, sbuf modes. They fail with the src reverted.
  • A3: every request the previous compile_dxil compiled gives byte-identical output (revision line aside). Census on a local request set (counts only, no shader data in the repo): compiled 831 → 844, heap refusals 1323 → 1308.
  • ctest after merging main and native: translate GPU-selected heap textures through view tokens in compute #3544: 1076/1077. The one failure, native_direct_mesh, fails the same way on main (077bff3).

Risks / open

  • Design not independently approved: three review rounds did not converge, so the design was frozen with documented owner decisions.
  • A1: words 2 (num_records) and 3 of the title V# are not read; the raw view's range is used. PR 2 must make the two ranges equal.
  • A2 (out-of-bounds raw read returns 0) is an external-spec assumption. Only one GPU was tested; WARP was not.
  • HeapViewContract::none gate unchanged. The EXEC-gated miss count is shared with the texture route (heap_token_slot); no rig mode exercises it on a raw buffer load.
  • Under the opt-in X2W_D3D12_VIEW_CONTENT_TOKENS=1, buffer views are content tokens, which this route treats as misses (null view). PR 2 must refuse or decode them.

Depends on #3544 (this branch contains it; review the last commits). Refs #3023, #3224.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

🤖 Generated with Claude Code

JB2WIN and others added 10 commits November 30, 2026 04:34
…ompute

A compute program that loads a texture with s_load_dwordx8 from the directly indexed
resource heap at an SGPR offset chosen by GPU data is now translated when every use of
the eight words is the T# of a supported image instruction (1D, 2D or 2D-array load,
load_mip, sample_l, sample_lz, 2D gather4_lz, get_resinfo). The shader reads the 32-byte
view token at the guest byte address, checks the magic, the view id range and the
dimension recorded for the id, and samples ResourceDescriptorHeap[base(dimension) + id]
(a null slot otherwise, counting one miss per wave). The manifest names the runtime-
provided views and words (heaptok, heaptokdims, heaptokmiss, five heaptok words); the
runtime reader still refuses them by name, so dispatch behaviour is unchanged.

Not independently design-approved: see the PR description.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n compute

Refs R0Y00#3023 R0Y00#3224. Builds on the heap token textures of R0Y00#3544.

A raw buffer V# loaded with s_load_dwordx4 from the directly indexed resource
heap at a GPU-selected byte offset (an SGPR offset, or an address formed by
s_add_u32) is read through the view token the title keeps at that address,
like the token textures. Reads of that V# in the byte-window form
(buffer_load_dword{,x2,x3,x4} with OFFEN, the s_bfe/s_max/s_mul/s_and/s_or
rewrite) and scalar buffer loads from it are translated; every other use keeps
today's path and refusal text.

- Each s_load_dwordx4 candidate is judged on its own; a candidate that fails is
  dropped and does not take the texture route off the program. An s_add_u32
  heap address that is not an eligible candidate keeps the old rejection.
- The shader checks magic, id range and the dimension table entry 0x20 (raw
  buffer view) on every execution and reads ResourceDescriptorHeap[baseraw +
  id], or the null raw view with one counted miss per wave.
- A program with an eligible buffer load publishes seven token words (baseraw
  and nullraw after the five of the textures): NativeComputeShader::
  heap_token_word_count replaces heap_token_words. Texture-only programs keep
  five words and byte-identical modules and manifests (revision line aside).
- native_compute_output_revision 2 -> 3.
- The dispatch reader names baseraw and nullraw and still refuses every
  heaptok line: programs of this change stay refused at dispatch until the
  runtime binds the views (PR 2).

Tests: native_heap_token_texture_controls (eligible forms, controls with
today's text, address shapes, loop, mixed texture and buffer),
native_heap_token_texture_{warp,hardware} (rawbuf, rawbuf_waterfall, sbuf),
native_compute_manifest_reasons, startup_compute_dispatch_texture.

The design was frozen by the owner without independent approval (see the PR).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review fixes for the heap token buffer route.

- heap_token_buffer_eligible now checks the address the lowering needs, on the
  state at the load: heap pointer high word is the constant 0, imm % 32 == 0,
  proven 32-byte aligned SGPR offset, no offset + imm overflow; on an added
  address imm == 0 and a masked offset. It also compares the V# words symbol
  for symbol as heap_token_buffer does. A candidate that fails is dropped
  (an added address keeps the old program-wide rejection) and keeps today's
  text. The lowering refusals stay as a safeguard.
- When no buffer load is eligible, the textures are judged again on the
  analysis without the byte window, as before the route knew buffers.
- Document the carry assumption of an added address (heap-relative model of
  the existing heap_offset path, no runtime carry check).
- Tests: address-shape controls expect the heap contract text of the dropped
  load; new controls for overflow, a non-constant high word, an unread
  candidate next to a texture, and an accepted wide mask.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…word budget)

Review fixes, round 2.

- A byte window load inside a loop is dropped by the analysis with the same
  query the lowering uses, instead of failing the whole program (textures
  included) at lowering.
- When the seven token words do not fit the 32-word entry layout next to the
  descriptor strides and root constants (the strides are known only while
  lowering), the program is translated again with the buffer route off, so the
  buffer loads keep today's path and text.
- Document that words 2 and 3 of the title's V# are not read and that PR 2 must
  make the raw view's range equal it (A1).
- Tests: loop and texture + loop controls now expect today's text; 25 strides
  compile next to seven token words, 26 are refused with today's text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ments

- The budget retry in translate_program catches HeapTokenWordBudget (thrown by
  prepare_heap_tokens with the same text) instead of matching the message.
- Exact root signature match for the user SGPR count in the test, comments
  wrapped to 120 columns, doc line for the seven-word form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e-only refusal, SGPR reads)

- Count a token miss only when the wave has an active guest lane (ballot of EXEC), not for a
  wave that reaches the instruction with EXEC = 0. The hardware fixture gains two modes: EXEC
  limited to the upper 16 lanes (lane 0 inactive) and EXEC = 0.
- The native-only route refuses a program with token words with the manifest reader's text
  ("heap token textures are not bound yet") instead of "view kind N is not bound". Covered by
  startup_compute_dispatch_native.
- conservative_sgpr_reads: encodings without a case now read every SGPR (control flow, LDS,
  export and interpolation are listed as reading none), and the v_cndmask_b32 lane mask counts
  as a pair. Control in native_heap_token_texture_controls (mask_pair vs. a mask clear of the T#).
- Say why native_compute_output_revision is 2 (header and doc).

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts in src/direct_compute_cache.cpp (token words before the sampler heap line),
tests/native_compute_manifest_reasons.cpp and tests/startup_compute_dispatch_native_check.py:
both sides kept.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Takes the R0Y00#3544 review fixes: the EXEC-gated miss count now applies to the
raw buffer route as well, the native-only refusal reads heap_token_word_count,
the revision comment explains both bumps (2 textures, 3 raw buffers), the
manifest test keeps the seven-word case next to the sampler cases, and the
hardware rig keeps both first_active and scalar modes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed f4cc6a0e by reading the diff (the seven commits on top of #3544 cf0f40be); not built or run.

Verdict: approve. The buffer route is opt-out by construction: candidates are judged per load, ineligible ones keep today's path, the word-budget retry translates without the route, and dispatch still refuses every heaptok line, so nothing changes at runtime until PR 2. No MUST.

  • SHOULD No CI has run at this head (no checks reported; the branch conflicts with main in tests/native_compute_manifest_reasons.cpp, inherited from #3544). After the rebase, native_heap_token_texture_controls needs no GPU but is not in the pr preset filter, so CI still would not run the 130 rig assertions. Adding _controls to the filter makes the eligibility rules (loop, mixed, word budget, mutations) a CI check.
  • SHOULD The dims table compares for equality (gfx1013_direct_compute.inl:1240, == 0x20 at :1303; doc native-heap-token-textures.md:97). #3619 (mesh, translator only) reads typed R32_UINT buffers through the same tokens with kind 16. The codes do not clash, but with one code per id, a title buffer that compute reads raw and a mesh program reads typed would miss in one of the two routes. Both buffer codes are single bits, so testing (dims & 0x20) != 0 here (and & 16 in #3619) lets PR 2 mark one id as both. The doc line should also list 16, so PR 2 writes one table for both translators. I'll change #3619 to match.
  • NIT The pre-pass comment says "raw MUBUF dword-family load" (gfx1013_compute_native.cpp:2000), but the code takes only buffer_load_dword (:2070). x2/x3/x4 loads drop out as ineligible. That is safe, but the comment overstates it.
  • Checked, no finding: the HeapTokenWordBudget text matches refuse() for texture-only programs (rethrown unchanged); the retry cannot recurse (buffers_allowed=false); a cached old heap_token_words value fails decode and is retranslated, not trusted (direct_compute_cache.cpp:380, :542); the s_add high-word-0 assumption is judged identically in the pre-pass and the lowering; the window's byte count is the title V#'s own num_records times stride, so A1 holds if PR 2 builds the view from the same descriptor.

Tests: _controls proves the per-load eligibility, the retry and the manifest words; _hardware (RTX 3080, author) proves rawbuf/sbuf reads and fails with the src reverted. CI ran neither (see above), and _warp skips (77).

lukaslw-lab added a commit to lukaslw-lab/Xbox2Windows that referenced this pull request Nov 30, 2026
The token guard compared the kind word with heap_token_r32_uint_buffer (16).
A view id can carry other kind bits as well, such as the raw-buffer bit from
R0Y00#3631, so test (kind & 16) != 0 instead. The fixture checks the and/icmp ne
pair and that no equality test against 16 remains.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lukaslw-lab added a commit to lukaslw-lab/Xbox2Windows that referenced this pull request Nov 30, 2026
The token guard compared the kind word with heap_token_r32_uint_buffer (16).
A view id can carry other kind bits as well, such as the raw-buffer bit from
R0Y00#3631, so test (kind & 16) != 0 instead. The fixture checks the and/icmp ne
pair and that no equality test against 16 remains.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
JB2WIN and others added 2 commits December 1, 2026 12:45
…extures

Conflicts and how they were resolved: tests/native_compute_manifest_reasons.cpp
kept both new cases (our heap token views and words, upstream's root buffer SRV)
and the summed case count (+9). CMakePresets.json: native_heap_token_texture added
to the pr build preset so the native_.*_controls test filter finds its executable.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts and how they were resolved: tests/native_compute_manifest_reasons.cpp
kept the token-buffer seven-word case and upstream's root buffer SRV case, and
the summed case count (+10). The CI preset line comes in with the textures branch.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Leyukaka

Leyukaka commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Friendly note: this is approved, but it currently conflicts with main after the recent merges; it should be ready again once rebased together with #3544 underneath it.

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.

3 participants