Skip to content

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

Merged
R0Y00 merged 12 commits into
R0Y00:mainfrom
JB2WIN:native/heap-token-buffers
Dec 2, 2026
Merged

R0Y00 merged 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 7 commits November 30, 2026 09:49
…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>
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>
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.

…n-buffers

heap_token_word_count replaces heap_token_words in main's cache visitor,
round-trip fixture and validate_shader (0, 5 or 7 words).

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

JB2WIN commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@Leyukaka merged the updated #3544 (with main 46d465d) in 06b0e70. heap_token_word_count (0, 5 or 7) now goes through main's cache visitor, the round-trip fixture and validate_shader.

Local, RTX 3080: ctest -R 'heap_token|manifest|direct_cache|native_compute|startup_compute|triage_run' gives 256/265. The 9 failures are the same ones main 46d465d has without these branches.

AI-assisted.

JB2WIN and others added 2 commits December 2, 2026 20:14
…n-buffers

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

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

# Conflicts:
#	src/direct_compute_cache.cpp
#	src/gfx1013_compute_native.h
#	src/gfx1013_direct_compute.inl
#	tests/native_compute_manifest_reasons.cpp
#	tests/native_direct_cache_check.cpp
@JB2WIN

JB2WIN commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@Leyukaka main moved again, including #3500, which adds its image field words at the same places as the heap token words. Merged in f7a54aa (#3544) and 26d1c53 (this PR). The b0 words are now root constants, stride words, image field words, then heap token words, in the translator, the manifest and the cache visitor. Both branches merge cleanly into main 2398613.

Local, RTX 3080: ctest -R 'heap_token|image_fields|manifest|direct_cache|native_compute|startup_compute|triage_run' gives 259/268 on both. The 9 failures are the same ones main has on its own.

If it conflicts again by the time you check, feel free to resolve it yourselves. We're fine with that, as you offered.

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.

Reviewed the raw-buffer delta from #3544 f7a54aaa to 26d1c531. Independent MSVC Debug on Windows 11 build 26300 passed the heap-token controls, RTX 4060 Laptop hardware readback, manifest reasons and frontend cache round-trip (4 passes). The WARP heap-token fixture skipped with code 77 at the wave32 capability gate. The new manifest bindings still refuse live use until the runtime supplies them. This is ready for the dependency to land first. After #3544 merges, please refresh this branch and verify that the remaining diff is the buffer work.

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

#3544 is now in main. I reviewed 1b193f4d against 75759370; the remaining runtime integration still refuses the heap-token buffer manifest until the follow-up supplies the raw views and dimension table. The raw-buffer lowering, cache and fixture files are unchanged from the previously tested head. Independent MSVC Debug ctest --preset dev --no-tests=error -j 1 -V -R '^(native_heap_token_texture_(controls|warp|hardware)|native_compute_manifest_reasons|native_direct_cache_controls)$' gave four passes and one capability skip on Windows 11 build 26300. The translator rig held 130 assertions and the RTX 4060 Laptop (32.0.16.1656) run held 83. WARP reported wave size 4 and skipped the wave32 fixture with exit 77. The export census also passed all 476 cases and caught six mutations.

@R0Y00
R0Y00 enabled auto-merge (squash) December 2, 2026 20:28
@R0Y00
R0Y00 merged commit e25f864 into R0Y00:main Dec 2, 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