native: carry raw and typed heap reads in one program to main (stacked on #3409) #3417

Manually merged
github merged 15 commits from github-bot/gh-3415 into main 2026-11-29 08:33:17 +00:00 AGit
Owner

@⁠JB2WIN on GitHub · 2026-11-28 23:51 UTC · original
JB2WIN:native/main-heap-mixed-raw-typed → main · +974 −121 · 18 files · 15 commits · merged 2026-11-29 08:30 UTC

Carries #3063 (merged into cpp-migration) to main: HeapViewContract::raw_and_typed_dword lets one program read some GPU-selected heap slots raw and others with one-channel typed loads, and .views gains also <slot> <type> lines for further selections of the same dispatch.

#3411 is merged (as a merge commit), so no rebase is needed. This PR adds the commits after 30de88b6:

  • the three #3063 commits, cherry-picked with -x;
  • a doc commit that gives the assertion count on main, the merge of #3411's review fix, and the count update after it.

Conflicts resolved while picking:

  • direct_compute_cache.cpp: the raw_and_typed_dword cache identity, placed in main's cached_compute_ir.
  • gfx1013_compute_native.cpp: heap_window for raw_buffer and raw_and_typed_dword. main's wave64 / narrow-wave64 logic and parse() arguments are unchanged.
  • native_global_srv_heap_replay.cpp: compare_output takes both main's optional EXPECTED_WORDS file and #3063's two reference slots.

This is the translator side only. No runtime code writes .views yet, so a title run still stops at "direct resource-heap load requires the selected GPU slot and its view type" (331 shaders, 4.37 M dispatches in Leyukaka's census). That runtime step is #3023 stage 3, which I'm starting next.

Tests

Windows 11 26200, RTX 3080 (32.0.16.2124), WARP, dev preset, -j1:

  • ^(native_.*|startup_compute_.*|compute_manifest.*|direct_compute.*)$: all pass except the four tests that fail on main without this stack (startup_compute_dispatch_output_{warp,hardware} and startup_compute_half_buffer_uav_{controls,hardware}, see #3355 and #3391). WARP wave32 cases skip with 77.
  • native_global_srv_heap_replay_hardware: 242 assertions pass (234 before #3411's review controls). With the src/, tools/ and fixture changes of the three #3063 commits reverted, it fails at "record mixed select 0+3".

A read-only review of the picks found no blocker. Its nits are carried unchanged from #3063 and left for a follow-up:

  • the other contract refusal text still says only raw reads are translated, though global_srv_contract never returns other;
  • replay with two also lines exits 4 instead of taking the refused path;
  • an invalid REFERENCE_SLOT throws outside the try.

Refs #3063, #3411, #3023, #3226.

AI-assisted.

🤖 Generated with Claude Code

**@⁠JB2WIN** on GitHub · 2026-11-28 23:51 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3415) `JB2WIN:native/main-heap-mixed-raw-typed` → `main` · +974 −121 · 18 files · 15 commits · merged 2026-11-29 08:30 UTC Carries #3063 (merged into `cpp-migration`) to `main`: `HeapViewContract::raw_and_typed_dword` lets one program read some GPU-selected heap slots raw and others with one-channel typed loads, and `.views` gains `also <slot> <type>` lines for further selections of the same dispatch. #3411 is merged (as a merge commit), so no rebase is needed. This PR adds the commits after `30de88b6`: - the three #3063 commits, cherry-picked with `-x`; - a doc commit that gives the assertion count on `main`, the merge of #3411's review fix, and the count update after it. Conflicts resolved while picking: - `direct_compute_cache.cpp`: the `raw_and_typed_dword` cache identity, placed in `main`'s `cached_compute_ir`. - `gfx1013_compute_native.cpp`: `heap_window` for `raw_buffer` and `raw_and_typed_dword`. `main`'s wave64 / narrow-wave64 logic and `parse()` arguments are unchanged. - `native_global_srv_heap_replay.cpp`: `compare_output` takes both `main`'s optional `EXPECTED_WORDS` file and #3063's two reference slots. This is the translator side only. No runtime code writes `.views` yet, so a title run still stops at "direct resource-heap load requires the selected GPU slot and its view type" (331 shaders, 4.37 M dispatches in Leyukaka's census). That runtime step is #3023 stage 3, which I'm starting next. ## Tests Windows 11 26200, RTX 3080 (32.0.16.2124), WARP, dev preset, `-j1`: - `^(native_.*|startup_compute_.*|compute_manifest.*|direct_compute.*)$`: all pass except the four tests that fail on `main` without this stack (`startup_compute_dispatch_output_{warp,hardware}` and `startup_compute_half_buffer_uav_{controls,hardware}`, see #3355 and #3391). WARP wave32 cases skip with 77. - `native_global_srv_heap_replay_hardware`: 242 assertions pass (234 before #3411's review controls). With the `src/`, `tools/` and fixture changes of the three #3063 commits reverted, it fails at "record mixed select 0+3". A read-only review of the picks found no blocker. Its nits are carried unchanged from #3063 and left for a follow-up: - the `other` contract refusal text still says only raw reads are translated, though `global_srv_contract` never returns `other`; - `replay` with two `also` lines exits 4 instead of taking the refused path; - an invalid REFERENCE_SLOT throws outside the `try`. Refs #3063, #3411, #3023, #3226. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
formatted_byte_load asked resource() for raw_vector_srv even when the
descriptor was the byte-address rewrite (stride cleared in word 1), so a
tbuffer_load_format_* through such a window was refused with
"non-contiguous resource descriptor", for a table descriptor and for a
GPU-selected heap descriptor under the raw_buffer contract. It now picks
byte_window_srv by the same rule as the raw MUBUF load. Conversion, the
getDimensions element bound and the raw loads are unchanged.

Tests:
- native_global_srv_heap_replay_check.py: a 32_UINT tbuffer load through
  the heap window is recorded, compiled and replayed for selections 0
  and 1, with the cross-slot mismatch control; the loop guard refuses
  it; an 8_8_8_8_UNORM load through the window compiles.
- native_mtbuf_check.py: the 11-format value check also runs through a
  byte window of its table SRV (native_store_replay accepts the window
  binding as the same raw view).
- native_direct_container_check.py: compute table windows with both
  formats compile; without the byte-count product they are refused.

Refs #3023

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit e67f10177b)
Conflicts resolved:
- indirect_table_buffer: main added `alignment` as the sixth parameter, so the
  compute input call now passes D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT before
  `true, slot.requires_identity_dst_sel` and keeps main's scalar-window fallback.
- formatted_byte_load: a byte window the caller already bound (main's graphics
  path) is used as is; otherwise the zero-stride rewrite selects byte_window_srv.
- native_mtbuf_check.py: main's scalar operand 137 with the byte-window prefix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Accept the one-channel typed heap-view contract in the direct compute compiler and offline replay. Exercise typed slot selection, cache reuse, and malformed metadata refusals with source-built fixtures.

Refs #3023.

(cherry picked from commit a0f6773135)
The typed heap load reads the idxen element index only. offen, an immediate
offset and a nonzero soffset are already refused by the decoder ("formatted
load requires zero or a single linear index"); three negative cases pin that.
The doc now lists the typed_dword contract and the current assertion count.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A program that reads some GPU-selected heap slots raw and others with a
one-channel typed load was refused under both heap view contracts:
raw_buffer refuses the typed load, typed_dword the raw load.
HeapViewContract::raw_and_typed_dword now lets the kind of each heap
load pick its path: buffer_load_format_* (typed_buffer_srv) takes the
typed_dword rules, every other kind (tbuffer included) the raw_buffer
rules, byte windows included. Which heap index feeds which load stays
the caller's guarantee; the comment and the doc say so.

.views gains zero or more "also <slot> <type>" lines: further
selections of the same dispatch, selector word k = selection k. The
decoder refuses a slot named twice. refuse_global_srv_selections checks
every selection; global_srv_contract returns raw_and_typed_dword when
raw and typed selections are both present. compile_dxil and the fixture
map the contract with a switch, and compile_dxil reports also=<slot>:<type>.
The fixture's record takes --also SELECTOR TYPE (selector word 1),
dispatches every selected slot and compares against the sum of the
slot data (N+M in replay).

Tests: native_global_srv_heap_replay_check.py section 11 records,
compiles (fresh frontend cache, then a cache hit) and replays a mixed
program for raw slots 0 and 1 with typed slot 3, checks a cross-slot
mismatch, a refused typed selection, three replay refusals, nine compile
refusals and four compile-only cases (two also lines, byte window,
formatted byte window, plain tbuffer under the mixed contract).

Refs #3023

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 4b0156064f)
The selector word k is selection k, so two words can pick the same slot.
The decoder now accepts a slot named again with the same view type and
refuses only a slot named with two view types, so a file record writes
decodes. An also line with trailing fields is unreadable. A bad --also
selector in the fixture returns 2. Section 11 gains the second-also,
repeated-slot, two-type and trailing-field cases and a raw+raw record,
compile and replay of one slot picked by both words. The stride-read
comment now names all three contracts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 64513f26a8)
Review note on #3063: under raw_and_typed_dword the selection types come from the capture, not from the
shader, so the header comment now matches HeapViewContract and the doc's Limits. Comment only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 2534937a4e)
The typed and mixed steps keep their own counts; the mixed step adds the total
on main (234), where main's raw load and added-address sections run too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 23:56:37 +00:00
Review of #3409 (Leyukaka):
- translate_compute_natively pushed a byte-window slot without
  requires_identity_dst_sel, so with X2W_NATIVE_SHADERS a swapped DST_SEL, a
  non-default slot 18 mapping or a slot 17 CBV token bound without the check.
  The slot now carries the flag. startup_compute_mtbuf_window runs the identity
  and swapped cases on the in-process route too; without the fix the swapped
  case writes the output.
- A Z/W swap with identity X/Y is refused too (catches a check of the low
  DST_SEL fields only).
- global_srv_contract: a two-channel dword line, stride 8, an odd byte count
  and a zero byte count each refuse on their own.
- Doc: the in-process sentence now says what the code does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-29 03:34 UTC · original · approved these changes

Review of e232e475, by reading only, of the part beyond #3411: git diff 30de88b6 e232e475, six commits, 9 files. 30de88b6 is the merge base with #3411.

  1. Contract. Under raw_and_typed_dword, heap_resource takes the typed path only for typed_buffer_srv (src/gfx1013_direct_compute.inl:361-363). A multi-channel typed load is still refused (:366-367), and every other kind keeps the raw_buffer rules (:369-370). heap_window covers both contracts (src/gfx1013_compute_native.cpp:1835-1836), and the cache identity is distinct (src/direct_compute_cache.cpp:377). global_srv_contract returns the mixed contract only when both raw and typed selections are present (src/startup_stubs/native_global_srv.h:240,249). The decoder refuses a slot named with two view types (:180-190), and refuse_global_srv_selections checks every selection in order (:209-216).

  2. Scope. The runtime path still translates without a contract (src/startup_stubs/d3d12_compute_dispatch.inl:325, translate_compute passes HeapViewContract::none). So the refusal "direct resource-heap load requires the selected GPU slot and its view type" is unchanged there. Only compile_dxil with a .views file and the test fixture select the new contract. This matches the description.

  3. Tests. Section 11 has a mismatch control for each positive replay (0+3 against 1+3, and 0+0 against 0+1). It also compiles the same program under raw-only and typed-only metadata as translator-level negatives, and covers a wrong second also. Reading the code, these cases fail if the mixed term is dropped from heap_window, if the kind test is dropped from typed, if the contract always returns typed_dword, or if the also loop is skipped. Two mutations survive, and both are harmless:

    • deleting the /heap-view/raw_and_typed_dword identity (src/direct_compute_cache.cpp:377), which then falls to /heap-view/other (still distinct, and global_srv_contract never produces other);
    • the second refuse_global_srv_selections call at tools/startup/compile_dxil.cpp:151, which repeats the check at :77.
  4. CI. ctest --preset pr does not include native_global_srv_heap_replay_*, and _warp exits 77. So CI does not run the new section, and the evidence for it is the local hardware run in the description.

  5. Description. Two points are out of date after merge 594b2626. The range is now 30de88b6..HEAD (six commits, not four from d4d9af41), and the doc at head gives 242 assertions on main where the description says 234.

Basis: reading of the diff and the CI results on e232e475 (Windows build and test, gfx1013 fixtures, Linux Python checks: pass). I built and ran nothing.

Verdict on e232e475: approve. It should merge after #3411, and it needs a rebase if #3411 is squash-merged.

**@⁠Leyukaka** on GitHub · 2026-11-29 03:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3415#pullrequestreview-6101255140) · **approved these changes** Review of `e232e475`, by reading only, of the part beyond #3411: `git diff 30de88b6 e232e475`, six commits, 9 files. `30de88b6` is the merge base with #3411. 1. **Contract.** Under `raw_and_typed_dword`, `heap_resource` takes the typed path only for `typed_buffer_srv` (`src/gfx1013_direct_compute.inl:361-363`). A multi-channel typed load is still refused (`:366-367`), and every other kind keeps the `raw_buffer` rules (`:369-370`). `heap_window` covers both contracts (`src/gfx1013_compute_native.cpp:1835-1836`), and the cache identity is distinct (`src/direct_compute_cache.cpp:377`). `global_srv_contract` returns the mixed contract only when both raw and typed selections are present (`src/startup_stubs/native_global_srv.h:240,249`). The decoder refuses a slot named with two view types (`:180-190`), and `refuse_global_srv_selections` checks every selection in order (`:209-216`). 2. **Scope.** The runtime path still translates without a contract (`src/startup_stubs/d3d12_compute_dispatch.inl:325`, `translate_compute` passes `HeapViewContract::none`). So the refusal "direct resource-heap load requires the selected GPU slot and its view type" is unchanged there. Only `compile_dxil` with a `.views` file and the test fixture select the new contract. This matches the description. 3. **Tests.** Section 11 has a mismatch control for each positive replay (0+3 against 1+3, and 0+0 against 0+1). It also compiles the same program under raw-only and typed-only metadata as translator-level negatives, and covers a wrong second `also`. Reading the code, these cases fail if the mixed term is dropped from `heap_window`, if the kind test is dropped from `typed`, if the contract always returns `typed_dword`, or if the `also` loop is skipped. Two mutations survive, and both are harmless: - deleting the `/heap-view/raw_and_typed_dword` identity (`src/direct_compute_cache.cpp:377`), which then falls to `/heap-view/other` (still distinct, and `global_srv_contract` never produces `other`); - the second `refuse_global_srv_selections` call at `tools/startup/compile_dxil.cpp:151`, which repeats the check at `:77`. 4. **CI.** `ctest --preset pr` does not include `native_global_srv_heap_replay_*`, and `_warp` exits 77. So CI does not run the new section, and the evidence for it is the local hardware run in the description. 5. **Description.** Two points are out of date after merge `594b2626`. The range is now `30de88b6..HEAD` (six commits, not four from `d4d9af41`), and the doc at head gives 242 assertions on `main` where the description says 234. Basis: reading of the diff and the CI results on `e232e475` (Windows build and test, gfx1013 fixtures, Linux Python checks: pass). I built and ran nothing. Verdict on `e232e475`: approve. It should merge after #3411, and it needs a rebase if #3411 is squash-merged.
Author
Owner

@⁠JB2WIN on GitHub · 2026-11-29 03:36 UTC · original

Thanks. Description updated: the range is 30de88b6..HEAD and the count is 242. I will rebase this on main if #3411 is squash-merged.

AI-assisted.

**@⁠JB2WIN** on GitHub · 2026-11-29 03:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3415#issuecomment-7250147927) Thanks. Description updated: the range is `30de88b6..HEAD` and the count is 242. I will rebase this on `main` if #3411 is squash-merged. AI-assisted.
github manually merged commit 1341bd6b4e into main 2026-11-29 08:33:17 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.