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

Merged
JB2WIN merged 12 commits from upstream-pr/3631 into main 2026-12-02 20:33:15 +00:00
JB2WIN commented 2026-11-30 18:17:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-30T18:17:34Z.


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 #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 #3544: 1076/1077. The one failure, native_direct_mesh, fails the same way on main (077bff3a).

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 [email protected]

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5571113241 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3631). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-30T18:17:34Z. --- ## 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 #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 #3544: 1076/1077. The one failure, `native_direct_mesh`, fails the same way on main (077bff3a). ## 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 <[email protected]> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
lukaslw-lab commented 2026-11-30 18:46:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T18:46:52Z.

Review: APPROVED


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6118333693 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3631#pullrequestreview-6118333693). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T18:46:52Z. **Review:** APPROVED --- 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).
Leyukaka commented 2026-12-02 07:13:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-02T07:13:29Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7337924189 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3631#issuecomment-7337924189). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-02T07:13:29Z. --- 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.
JB2WIN commented 2026-12-02 18:58:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-12-02T18:58:04Z.


@Leyukaka merged the updated #3544 (with main 46d465d9) in 06b0e709. 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 46d465d9 has without these branches.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7355422750 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3631#issuecomment-7355422750). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-12-02T18:58:04Z. --- @Leyukaka merged the updated #3544 (with `main` 46d465d9) in 06b0e709. `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` 46d465d9 has without these branches. AI-assisted.
JB2WIN commented 2026-12-02 19:37:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-12-02T19:37:48Z.


@Leyukaka main moved again, including #3500, which adds its image field words at the same places as the heap token words. Merged in f7a54aaa (#3544) and 26d1c531 (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 23986134.

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7356475829 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3631#issuecomment-7356475829). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-12-02T19:37:48Z. --- @Leyukaka main moved again, including #3500, which adds its image field words at the same places as the heap token words. Merged in f7a54aaa (#3544) and 26d1c531 (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` 23986134. 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 commented 2026-12-02 19:45:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T19:45:37Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6157717733 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3631#pullrequestreview-6157717733). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T19:45:37Z. **Review:** COMMENTED --- 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 commented 2026-12-02 20:28:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T20:28:25Z.

Review: APPROVED


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6158392709 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3631#pullrequestreview-6158392709). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T20:28:25Z. **Review:** APPROVED --- #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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!3631
No description provided.