cpp-migration: pass captured heap view types into the in-runtime native compute route (#2958) #3023

Open
opened 2026-11-27 06:16:11 +00:00 by JB2WIN · 22 comments
JB2WIN commented 2026-11-27 06:16:11 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-27T06:16:11Z.


Target branch cpp-migration. Follow-up to #2908 (#2972), part of #2935.

Problem. The in-process native compute route of #2958 (X2W_NATIVE_SHADERS, src/startup_stubs/d3d12_compute_dispatch.inl) translates slot 67 requests with x2w::translate_compute(read_compute_request(path), 0, true). That call takes no HeapViewContract, so a request that reads a GPU-selected global SRV heap slot is refused on this route, although #2972 can translate it offline when the view types are known.

Plan.

  1. Record each heap slot's view type when the stand-in creates the SRV (classify_global_srv_view from src/startup_stubs/native_global_srv.h).
  2. At Dispatch, resolve the slots the request can select and build the contract from the recorded types.
  3. Pass the contract into the translation of the slot 67 request (today prepare_direct_compute refuses a contract for non-container requests, and translate_compute has no contract parameter).
  4. Before the Dispatch, check that the live heap still matches the contract; otherwise refuse and keep the gfx2hlsl.py fallback.

Test. A source-built compute workload through the stand-in that reads a buffer, a 2D texture and an empty slot through a GPU-selected index, _warp (capability skip where needed) and _hardware, plus a negative control that indexes one slot off.

I'm taking it; a PR follows. Environment: Windows 11 build 26200, NVIDIA GeForce RTX 3080, plus WARP.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6641161019 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-27T06:16:11Z. --- Target branch `cpp-migration`. Follow-up to #2908 (#2972), part of #2935. **Problem.** The in-process native compute route of #2958 (`X2W_NATIVE_SHADERS`, `src/startup_stubs/d3d12_compute_dispatch.inl`) translates slot 67 requests with `x2w::translate_compute(read_compute_request(path), 0, true)`. That call takes no `HeapViewContract`, so a request that reads a GPU-selected global SRV heap slot is refused on this route, although #2972 can translate it offline when the view types are known. **Plan.** 1. Record each heap slot's view type when the stand-in creates the SRV (`classify_global_srv_view` from `src/startup_stubs/native_global_srv.h`). 2. At Dispatch, resolve the slots the request can select and build the contract from the recorded types. 3. Pass the contract into the translation of the slot 67 request (today `prepare_direct_compute` refuses a contract for non-container requests, and `translate_compute` has no contract parameter). 4. Before the Dispatch, check that the live heap still matches the contract; otherwise refuse and keep the `gfx2hlsl.py` fallback. **Test.** A source-built compute workload through the stand-in that reads a buffer, a 2D texture and an empty slot through a GPU-selected index, `_warp` (capability skip where needed) and `_hardware`, plus a negative control that indexes one slot off. I'm taking it; a PR follows. Environment: Windows 11 build 26200, NVIDIA GeForce RTX 3080, plus WARP. AI-assisted.
JB2WIN commented 2026-11-27 07:24:34 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-27T07:24:34Z.


Update: the first step is #3025.

A census over a local start-up capture (compile_dxil --refusals, 2,689 slot 67 requests, counts only) gives 941 first refusals of this kind. In those programs the heap index is read from buffer data per wave, so the runtime cannot resolve it at Dispatch. Behind the contract there are more walls:

  1. The byte-address rewrite of the loaded heap descriptor (stride, byte count, raw out-of-bounds mode): #3025, compiler only.
  2. Typed loads (buffer_load_format_*) through the heap descriptor. With 1 done in a local prototype, 906 requests stop here.
  3. Runtime: a shader-visible heap with title slot k at desktop index k as raw views, plus a contract check over all selectable slots at Dispatch (one captured slot is not enough for per-wave selection).

I'll continue with 2 next unless someone else is on it.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7212442834 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7212442834). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-27T07:24:34Z. --- Update: the first step is #3025. A census over a local start-up capture (`compile_dxil --refusals`, 2,689 slot 67 requests, counts only) gives 941 first refusals of this kind. In those programs the heap index is read from buffer data per wave, so the runtime cannot resolve it at Dispatch. Behind the contract there are more walls: 1. The byte-address rewrite of the loaded heap descriptor (stride, byte count, raw out-of-bounds mode): #3025, compiler only. 2. Typed loads (`buffer_load_format_*`) through the heap descriptor. With 1 done in a local prototype, 906 requests stop here. 3. Runtime: a shader-visible heap with title slot k at desktop index k as raw views, plus a contract check over all selectable slots at Dispatch (one captured slot is not enough for per-wave selection). I'll continue with 2 next unless someone else is on it. AI-assisted.
JB2WIN commented 2026-11-27 07:47:10 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-27T07:47:10Z.


Runtime acceptance criteria for stage 3 (from R0Y00's review of #3025). Before the runtime supplies a raw-view contract for GPU-selected slots, its fixture must check both of these:

  • a selectable slot whose guest descriptor has a stride above 1 (byte count num_records * stride), read through the byte-address rewrite;
  • a slot whose guest byte count does not match the desktop view: the dispatch must refuse it before the shader runs, not read past or short of the view.

#3025 does not cover either: its descriptor words stay symbolic.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7212816337 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7212816337). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-27T07:47:10Z. --- Runtime acceptance criteria for stage 3 (from R0Y00's review of #3025). Before the runtime supplies a raw-view contract for GPU-selected slots, its fixture must check both of these: - a selectable slot whose guest descriptor has a stride above 1 (byte count `num_records * stride`), read through the byte-address rewrite; - a slot whose guest byte count does not match the desktop view: the dispatch must refuse it before the shader runs, not read past or short of the view. #3025 does not cover either: its descriptor words stay symbolic. AI-assisted.
JB2WIN commented 2026-11-27 09:15:58 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-27T09:15:58Z.


Step 2a is #3034 (builds on #3025): formatted loads (tbuffer_load_format_*) through the byte-address rewritten descriptor, table or GPU-selected heap slot, now read the same raw view as the raw load.

Additions to the stage-3 runtime acceptance criteria from that change:

  • A formatted load bounds its whole element with the desktop raw view's size (getDimensions), not with the guest window's byte count. The runtime must create the raw view for a GPU-selected heap window with exactly the guest window's byte count (num_records * max(stride, 1)). The startup manifest route already sizes a table window that way.
  • The descriptor's DST_SEL (word 3) is not applied; only the identity channel order is translated. The runtime contract should either check identity DST_SEL on every selectable slot or the translator has to apply it.

Typed heap loads (buffer_load_format_*) are the next step and need their own view contract.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7214475868 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7214475868). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-27T09:15:58Z. --- Step 2a is #3034 (builds on #3025): formatted loads (`tbuffer_load_format_*`) through the byte-address rewritten descriptor, table or GPU-selected heap slot, now read the same raw view as the raw load. Additions to the stage-3 runtime acceptance criteria from that change: - A formatted load bounds its whole element with the desktop raw view's size (`getDimensions`), not with the guest window's byte count. The runtime must create the raw view for a GPU-selected heap window with exactly the guest window's byte count (`num_records * max(stride, 1)`). The startup manifest route already sizes a table window that way. - The descriptor's DST_SEL (word 3) is not applied; only the identity channel order is translated. The runtime contract should either check identity DST_SEL on every selectable slot or the translator has to apply it. Typed heap loads (`buffer_load_format_*`) are the next step and need their own view contract. AI-assisted.
JB2WIN commented 2026-11-27 10:27:52 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-27T10:27:52Z.


Typed heap loads: #3042 adds HeapViewContract::typed_dword for one-channel 32-bit typed buffer slots (buffer_load_format_x with an idxen index through the GPU-selected heap descriptor), with .views channel metadata and a fixture section.

On the local capture (counts only) the 906 typed heap loads all have that one-channel shape, but with typed_dword forced, 895 of those programs then stop at a raw read of another heap slot: they read the heap raw and typed through different selectors. Covering them needs more than one captured selection per dispatch (raw and typed contracts per load class), which I plan as the next step before the runtime contract.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7215915139 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7215915139). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-27T10:27:52Z. --- Typed heap loads: #3042 adds `HeapViewContract::typed_dword` for one-channel 32-bit typed buffer slots (`buffer_load_format_x` with an `idxen` index through the GPU-selected heap descriptor), with `.views` channel metadata and a fixture section. On the local capture (counts only) the 906 typed heap loads all have that one-channel shape, but with `typed_dword` forced, 895 of those programs then stop at a raw read of another heap slot: they read the heap raw and typed through different selectors. Covering them needs more than one captured selection per dispatch (raw and typed contracts per load class), which I plan as the next step before the runtime contract. AI-assisted.
JB2WIN commented 2026-11-27 13:22:04 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-27T13:22:04Z.


Translator side of the mixed case is in #3063: HeapViewContract::raw_and_typed_dword lets one program read some GPU-selected heap slots raw and others with one-channel typed loads (the kind of each load picks the path). .views gains also <slot> <type> lines for further selections of the same dispatch (selector word k = selection k).

For stage 3 (runtime), additional acceptance points from this step:

  • the runtime must produce one selection per selector word (also lines), deduplicated; a slot named twice is refused;
  • for every slot a raw load can select the raw_buffer conditions hold, for every slot a typed load can select the typed_dword conditions; the translator cannot check which index feeds which load.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7219390915 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7219390915). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-27T13:22:04Z. --- Translator side of the mixed case is in #3063: `HeapViewContract::raw_and_typed_dword` lets one program read some GPU-selected heap slots raw and others with one-channel typed loads (the kind of each load picks the path). `.views` gains `also <slot> <type>` lines for further selections of the same dispatch (selector word k = selection k). For stage 3 (runtime), additional acceptance points from this step: - the runtime must produce one selection per selector word (`also` lines), deduplicated; a slot named twice is refused; - for every slot a raw load can select the `raw_buffer` conditions hold, for every slot a typed load can select the `typed_dword` conditions; the translator cannot check which index feeds which load. AI-assisted.
RonLogic commented 2026-11-28 00:04:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-28T00:04:54Z.


@JB2WIN I’m checking the ordered compiler prerequisites for retargeting #3063. I’ll start with a narrowly scoped carry of your merged #3034 byte-window MTBUF change onto main, preserving authorship and rerunning its own controls. I found no open main carry in the PR search. The in-process heap contract stays with your existing work here.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7230631607 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7230631607). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-28T00:04:54Z. --- @JB2WIN I’m checking the ordered compiler prerequisites for retargeting #3063. I’ll start with a narrowly scoped carry of your merged #3034 byte-window MTBUF change onto `main`, preserving authorship and rerunning its own controls. I found no open `main` carry in the PR search. The in-process heap contract stays with your existing work here.
RonLogic commented 2026-11-28 00:17:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-28T00:17:19Z.


The first prerequisite is ready for review in #3232. Release and Debug passed the RTX 4070 replay, and the same four tests passed with Agility 1.620.2 and WARP 1.0.22. I have #3042 applied locally on top with its typed-slot replay passing in Release, and will hold its main PR until #3232 lands.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7230795523 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7230795523). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-28T00:17:19Z. --- The first prerequisite is ready for review in #3232. Release and Debug passed the RTX 4070 replay, and the same four tests passed with Agility 1.620.2 and WARP 1.0.22. I have #3042 applied locally on top with its typed-slot replay passing in Release, and will hold its main PR until #3232 lands.
JB2WIN commented 2026-11-28 23:51:15 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-28T23:51:15Z.


Taking stage 3, the runtime side, now that the translator steps are open for main (#3409, #3415). No runtime code writes .views yet, so compile_dxil gets no heap view contract for a title request. That leaves the 331 shaders / 4.37 M dispatches of "direct resource-heap load requires the selected GPU slot and its view type" in Leyukaka's latest census refused.

The aim of stage 3: when the runtime captures a slot 67 request whose program reads the resource heap at a GPU-selected slot, it also records the selected slot(s) and their view types (the .views format of #2972/#3042/#3063). The contract then reaches the published and in-process routes. The acceptance points collected above (stride above 1, byte count mismatch, formatted element bounds, mixed selections) are the bar.

I'll post the design here before building it.

Environment: Windows 11 26200, RTX 3080 (32.0.16.2124), WARP.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7247706828 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7247706828). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-28T23:51:15Z. --- Taking stage 3, the runtime side, now that the translator steps are open for `main` (#3409, #3415). No runtime code writes `.views` yet, so `compile_dxil` gets no heap view contract for a title request. That leaves the 331 shaders / 4.37 M dispatches of "direct resource-heap load requires the selected GPU slot and its view type" in Leyukaka's latest census refused. The aim of stage 3: when the runtime captures a slot 67 request whose program reads the resource heap at a GPU-selected slot, it also records the selected slot(s) and their view types (the `.views` format of #2972/#3042/#3063). The contract then reaches the published and in-process routes. The acceptance points collected above (stride above 1, byte count mismatch, formatted element bounds, mixed selections) are the bar. I'll post the design here before building it. Environment: Windows 11 26200, RTX 3080 (32.0.16.2124), WARP. AI-assisted.
JB2WIN commented 2026-11-29 00:25:31 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-29T00:25:31Z.


Stage 3 design question before I build anything.

What the runtime has today (main + #3409/#3415):

  • Slot 67 requests are published once per key at pipeline creation (publish_compute_request, d3d12_draw.inl, as .c67). Nothing writes .views, and compile_dxil reads .views only for .cdx container requests. So no title request reaches a heap contract.
  • There is no GPU readback before a dispatch. The fixture's record reads the selector back with a fence per dispatch. In a title run that would cost a sync on every dispatch, so I don't plan to copy it.
  • There is a precedent for heap reads in a title run: #2861's resheap N. The translator proves the per-lane heap index is below N, and the dispatch binds heap records 0..N-1 from the title's view heap, refusing by name if any record is not a usable raw buffer (d3d12_compute_dispatch.inl, the heap_srvs loop). The view type is checked for every record the index can reach, not for one captured selection.

Two ways for the C++ direct route:

A. Bounded heap range (the #2861 pattern). The direct translator only accepts a heap read when it can bound the slot index, and publishes the range plus, per load kind, the view type each record in it must have. The dispatch checks every record in the range before it binds, refusing with a name (for example "heap record 5 is a texture, the program reads it raw"). No .views and no readback. It only covers programs whose index is boundable. How many of the 331 that is, I would measure first, before writing the runtime part.

B. Per-dispatch selection. Capture the selected slot(s) per dispatch, either via a readback (expensive) or only where the index is a value the runtime already reads from upload memory or root constants (word_param/root constant cases). Closer to the existing .views contract, but it covers a single dispatch, and a different selection later needs its own check.

I'd start with A: measure how many of the 331 have a boundable index, then build the translator bound and the runtime record check, each as its own PR with a GPU fixture and controls. @R0Y00, since the contract rules are yours: does A fit what you want for #3023, or should the runtime capture selections (B)?

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7248103511 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7248103511). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-29T00:25:31Z. --- Stage 3 design question before I build anything. What the runtime has today (`main` + #3409/#3415): - Slot 67 requests are published once per key at pipeline creation (`publish_compute_request`, `d3d12_draw.inl`, as `.c67`). Nothing writes `.views`, and `compile_dxil` reads `.views` only for `.cdx` container requests. So no title request reaches a heap contract. - There is no GPU readback before a dispatch. The fixture's `record` reads the selector back with a fence per dispatch. In a title run that would cost a sync on every dispatch, so I don't plan to copy it. - There is a precedent for heap reads in a title run: #2861's `resheap N`. The translator proves the per-lane heap index is below N, and the dispatch binds heap records 0..N-1 from the title's view heap, refusing by name if any record is not a usable raw buffer (`d3d12_compute_dispatch.inl`, the `heap_srvs` loop). The view type is checked for every record the index can reach, not for one captured selection. Two ways for the C++ direct route: A. **Bounded heap range (the #2861 pattern).** The direct translator only accepts a heap read when it can bound the slot index, and publishes the range plus, per load kind, the view type each record in it must have. The dispatch checks every record in the range before it binds, refusing with a name (for example "heap record 5 is a texture, the program reads it raw"). No `.views` and no readback. It only covers programs whose index is boundable. How many of the 331 that is, I would measure first, before writing the runtime part. B. **Per-dispatch selection.** Capture the selected slot(s) per dispatch, either via a readback (expensive) or only where the index is a value the runtime already reads from upload memory or root constants (`word_param`/root constant cases). Closer to the existing `.views` contract, but it covers a single dispatch, and a different selection later needs its own check. I'd start with A: measure how many of the 331 have a boundable index, then build the translator bound and the runtime record check, each as its own PR with a GPU fixture and controls. @R0Y00, since the contract rules are yours: does A fit what you want for #3023, or should the runtime capture selections (B)? AI-assisted.
JB2WIN commented 2026-11-29 01:32:29 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-29T01:32:29Z.


Superseded: the provenance numbers below are wrong, see the correction further down (issuecomment-7249057172).

Measurement for the question above. Local cohort of 2,689 slot 67 requests, compile_dxil --refusals on #3415 with temporary, uncommitted diagnostics at the heap refusal. Counts only.

The refusal "direct resource-heap load requires the selected GPU slot and its view type" is the first refusal of 1,073 requests:

  • 1,053: an SGPR offset index whose tracked mask is 0xffffffe0. That mask is only 32-byte alignment, so the bound is 134,217,728 records, which in practice means no bound.
  • 20: an index with no mask at all (11 through a heap-offset add, 9 through an SGPR offset).
  • 0 with a range of 1,024 records or fewer.

So Plan A covers nothing here and I'm dropping it.

Where the index comes from (the last scalar write of the offset SGPR before the descriptor load):

Index Requests
s_lshl_b32 of an SGPR the program never writes: an entry user-data word 603
s_lshl_b32 of s_and_b32 297
s_lshl_b32 of s_mul_hi_u32 / s_add_u32 / s_or_b32 / other scalar ops 153

603 of 1,053 index the heap with entry word << 5. The runtime already has that word at dispatch, as a root constant or a table word that it reads for other bindings (pass.compute_constants, the word_param path). So for those, the exact slot is known on the CPU before the dispatch, with no readback.

Revised proposal (a narrow B): the translator accepts a heap descriptor load whose index is user-data word << 5 (later, maybe, simple scalar functions of user data), and publishes which word it is. At each dispatch the runtime reads that word, takes heap record word, checks its view type against what the program reads (raw / typed, the existing global_srv_contract rules), and binds it as that view. If the record doesn't fit, it refuses by name before the dispatch, the same check the .views route does but per dispatch. The 297 s_and cases come next, once I see what is masked.

@R0Y00 @Leyukaka does this narrow B work for you? I'll start on the translator side under that assumption and won't open a PR before one of you agrees.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7248849647 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7248849647). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-29T01:32:29Z. --- **Superseded:** the provenance numbers below are wrong, see the correction further down (issuecomment-7249057172). Measurement for the question above. Local cohort of 2,689 slot 67 requests, `compile_dxil --refusals` on #3415 with temporary, uncommitted diagnostics at the heap refusal. Counts only. The refusal "direct resource-heap load requires the selected GPU slot and its view type" is the first refusal of **1,073** requests: - **1,053**: an SGPR offset index whose tracked mask is `0xffffffe0`. That mask is only 32-byte alignment, so the bound is 134,217,728 records, which in practice means no bound. - 20: an index with no mask at all (11 through a heap-offset add, 9 through an SGPR offset). - **0** with a range of 1,024 records or fewer. So **Plan A covers nothing here** and I'm dropping it. Where the index comes from (the last scalar write of the offset SGPR before the descriptor load): | Index | Requests | |---|---| | `s_lshl_b32` of an SGPR the program never writes: an entry user-data word | 603 | | `s_lshl_b32` of `s_and_b32` | 297 | | `s_lshl_b32` of `s_mul_hi_u32` / `s_add_u32` / `s_or_b32` / other scalar ops | 153 | 603 of 1,053 index the heap with `entry word << 5`. The runtime already has that word at dispatch, as a root constant or a table word that it reads for other bindings (`pass.compute_constants`, the `word_param` path). So for those, the exact slot is known on the CPU before the dispatch, with no readback. **Revised proposal (a narrow B):** the translator accepts a heap descriptor load whose index is `user-data word << 5` (later, maybe, simple scalar functions of user data), and publishes which word it is. At each dispatch the runtime reads that word, takes heap record `word`, checks its view type against what the program reads (raw / typed, the existing `global_srv_contract` rules), and binds it as that view. If the record doesn't fit, it refuses by name before the dispatch, the same check the `.views` route does but per dispatch. The 297 `s_and` cases come next, once I see what is masked. @R0Y00 @Leyukaka does this narrow B work for you? I'll start on the translator side under that assumption and won't open a PR before one of you agrees. AI-assisted.
JB2WIN commented 2026-11-29 01:51:18 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-29T01:51:18Z.


Correction to my previous comment: the "603 from an entry user-data word" was wrong. My provenance diagnostic missed the instruction that writes the source SGPR. With a corrected scan (same cohort, same build), the heap index sN << 5 comes from:

Writer of the source SGPR Requests
s_buffer_load_dword{x2,x4,x8,x16} with an SGPR offset 1,027
s_buffer_load_dword* with an immediate offset 24
s_mov / s_mul 11

Marking root constant SGPRs explicitly confirms it: no heap index in this cohort is a root constant shifted by 5. So the narrow B I proposed (index = root constant) covers almost nothing, and I'm withdrawing it.

What the data does point at: the index is a word the program reads from a constant buffer, mostly at an offset held in an SGPR. The runtime already reads such words at dispatch for srv <i> buf heap word table <param> <byte> at <x> [rootconst <a> <b> times <n>] (#2532). It refuses by name when the word is not in the list's upload memory. Whether these 1,027 match that shape depends on where the SGPR offset comes from (a root constant times a stride, or something GPU-dependent). I'm measuring that next and will post the numbers before proposing anything else.

Sorry for the noise.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7249057172 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7249057172). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-29T01:51:18Z. --- Correction to my previous comment: the "603 from an entry user-data word" was wrong. My provenance diagnostic missed the instruction that writes the source SGPR. With a corrected scan (same cohort, same build), the heap index `sN << 5` comes from: | Writer of the source SGPR | Requests | |---|---| | `s_buffer_load_dword{x2,x4,x8,x16}` with an SGPR offset | 1,027 | | `s_buffer_load_dword*` with an immediate offset | 24 | | `s_mov` / `s_mul` | 11 | Marking root constant SGPRs explicitly confirms it: no heap index in this cohort is a root constant shifted by 5. So the narrow B I proposed (index = root constant) covers almost nothing, and I'm withdrawing it. What the data does point at: the index is a word the program reads from a constant buffer, mostly at an offset held in an SGPR. The runtime already reads such words at dispatch for `srv <i> buf heap word table <param> <byte> at <x> [rootconst <a> <b> times <n>]` (#2532). It refuses by name when the word is not in the list's upload memory. Whether these 1,027 match that shape depends on where the SGPR offset comes from (a root constant times a stride, or something GPU-dependent). I'm measuring that next and will post the numbers before proposing anything else. Sorry for the noise. AI-assisted.
JB2WIN commented 2026-11-29 02:00:18 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-29T02:00:18Z.


The measurement I promised (same cohort and build, diagnostics still uncommitted). Of the 1,073 requests first refused at the heap descriptor load:

Shape of the heap index Requests
s_buffer_load_dword* at offset (v_readfirstlane(vN) & mask) * stride, a waterfall over lane values 998
s_buffer_load_dword* at s_add_u32(s_and_b32(<loaded word>), …) 27
s_buffer_load_dword* at an immediate offset 24
the index is not loaded by SMEM, or no index was found (only 13 were classified) 24

For all 998 waterfalls the mask is between 1,024 and 65,535, and the s_mulk_i32 stride is above 16 bytes.

What that means for stage 3:

  • Each lane picks its own heap record from a table word, and the waterfall walks the distinct values. So one dispatch reads several records, chosen by per-lane GPU values.
  • A per-dispatch selection (.views, or reading the word on the CPU) does not describe that.
  • The masks are far too wide to check every reachable record per dispatch.
  • Only the 24 immediate-offset cases fit the existing heap word table … at <x> runtime line, and only if their constant buffer is in upload memory.

So neither A nor a narrow B covers this family. To me it looks like it needs a runtime that guarantees the view type of every record the program can reach. For example, desktop heap records that are always created as the view kind the title described (note_view). The shader would then read them through ResourceDescriptorHeap and need no per-dispatch selection. That is a bigger design decision than the contract work so far, so I'll leave it for your input, @R0Y00 @Leyukaka, rather than guess. I'm not building anything for stage 3 until then.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7249149187 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7249149187). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-29T02:00:18Z. --- The measurement I promised (same cohort and build, diagnostics still uncommitted). Of the 1,073 requests first refused at the heap descriptor load: | Shape of the heap index | Requests | |---|---| | `s_buffer_load_dword*` at offset `(v_readfirstlane(vN) & mask) * stride`, a waterfall over lane values | 998 | | `s_buffer_load_dword*` at `s_add_u32(s_and_b32(<loaded word>), …)` | 27 | | `s_buffer_load_dword*` at an immediate offset | 24 | | the index is not loaded by SMEM, or no index was found (only 13 were classified) | 24 | For all 998 waterfalls the mask is between 1,024 and 65,535, and the `s_mulk_i32` stride is above 16 bytes. What that means for stage 3: - Each lane picks its own heap record from a table word, and the waterfall walks the distinct values. So one dispatch reads several records, chosen by per-lane GPU values. - A per-dispatch selection (`.views`, or reading the word on the CPU) does not describe that. - The masks are far too wide to check every reachable record per dispatch. - Only the 24 immediate-offset cases fit the existing `heap word table … at <x>` runtime line, and only if their constant buffer is in upload memory. So neither A nor a narrow B covers this family. To me it looks like it needs a runtime that guarantees the view type of every record the program can reach. For example, desktop heap records that are always created as the view kind the title described (`note_view`). The shader would then read them through `ResourceDescriptorHeap` and need no per-dispatch selection. That is a bigger design decision than the contract work so far, so I'll leave it for your input, @R0Y00 @Leyukaka, rather than guess. I'm not building anything for stage 3 until then. AI-assisted.
Leyukaka commented 2026-11-29 02:25:08 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T02:25:08Z.


The design choice is yours and R0Y00's. I have no data on the runtime side (how the desktop heap records are created), so nothing to add on whether a per-record guarantee is feasible. Two counts from a static trace of the 331 compute programs that stop at this refusal in the #3224 census (main 0614f68c; disassembly only, no build):

Use of the descriptor returned by the refused load, i.e. the view kind a guaranteed record would have to be:

Use Programs
raw buffer reads only 318
raw and typed buffer reads 7
typed buffer reads only 2
texture 4

Index form: in 6 of the 331 the heap index itself is a per-lane value read through a v_readfirstlane_b32 waterfall and then the s_add_u32 address form. In the other 325 it is a word from s_buffer_load shifted left by 5; I did not trace where that load's offset comes from, so this neither confirms nor contradicts your waterfall count.

The same refusal is also the first refusal of 370 of the 543 slot 57 mesh requests in #3416. I have not looked at the index shape of those.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7249415119 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7249415119). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T02:25:08Z. --- The design choice is yours and R0Y00's. I have no data on the runtime side (how the desktop heap records are created), so nothing to add on whether a per-record guarantee is feasible. Two counts from a static trace of the 331 compute programs that stop at this refusal in the #3224 census (`main` `0614f68c`; disassembly only, no build): Use of the descriptor returned by the refused load, i.e. the view kind a guaranteed record would have to be: | Use | Programs | |---|---| | raw buffer reads only | 318 | | raw and typed buffer reads | 7 | | typed buffer reads only | 2 | | texture | 4 | Index form: in 6 of the 331 the heap index itself is a per-lane value read through a `v_readfirstlane_b32` waterfall and then the `s_add_u32` address form. In the other 325 it is a word from `s_buffer_load` shifted left by 5; I did not trace where that load's offset comes from, so this neither confirms nor contradicts your waterfall count. The same refusal is also the first refusal of 370 of the 543 slot 57 mesh requests in #3416. I have not looked at the index shape of those.
JB2WIN commented 2026-11-29 02:26:11 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-29T02:26:11Z.


Thanks @Leyukaka, that count settles the direction for me: 318 of 331 read the selected record as a raw buffer only.

Concrete proposal (C), raw-only first, for @R0Y00 to accept or reject:

  • Runtime: a raw twin of the title's CBV/SRV/UAV heap. The stand-in already records every view the title creates into a heap slot (note_view, with its desktop destination). For each record that is a buffer view, the twin gets a raw SRV (R32_TYPELESS, RAW) over the same byte range at the same index. Any other record gets a null raw SRV, which reads 0. The twin follows view creation and the descriptor copies the stand-in already tracks.
  • Translator: a program whose heap descriptor loads feed only raw loads (no typed load, no byte-window field, no stride read) is translated without a .views contract. It reads ResourceDescriptorHeap[i] from the twin, bound directly indexed (root flag 0x400).
  • Why it is safe on D3D12: every index the shader can reach holds a raw buffer view or a null view, so there is never a view-type mismatch, whatever the per-lane waterfall picks. It needs no per-dispatch selection and no readback. The only deviation from the console: a program that reads a texture record as a raw buffer gets 0 instead of the image descriptor's bits.
  • Not covered: the 7 mixed, 2 typed and 4 texture programs keep today's refusal. A typed twin could follow later the same way.

Steps would be (1) the twin heap with a fixture that creates, copies and overwrites views; (2) the translator acceptance; (3) a measurement on the census requests. Each would be its own PR. I won't start building before you say whether a twin heap fits the stand-in, since it changes how views are kept.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7249426271 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7249426271). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-29T02:26:11Z. --- Thanks @Leyukaka, that count settles the direction for me: 318 of 331 read the selected record as a raw buffer only. Concrete proposal (C), raw-only first, for @R0Y00 to accept or reject: - **Runtime:** a raw twin of the title's CBV/SRV/UAV heap. The stand-in already records every view the title creates into a heap slot (`note_view`, with its desktop destination). For each record that is a buffer view, the twin gets a raw SRV (`R32_TYPELESS`, `RAW`) over the same byte range at the same index. Any other record gets a null raw SRV, which reads 0. The twin follows view creation and the descriptor copies the stand-in already tracks. - **Translator:** a program whose heap descriptor loads feed only raw loads (no typed load, no byte-window field, no stride read) is translated without a `.views` contract. It reads `ResourceDescriptorHeap[i]` from the twin, bound directly indexed (root flag 0x400). - **Why it is safe on D3D12:** every index the shader can reach holds a raw buffer view or a null view, so there is never a view-type mismatch, whatever the per-lane waterfall picks. It needs no per-dispatch selection and no readback. The only deviation from the console: a program that reads a texture record as a raw buffer gets 0 instead of the image descriptor's bits. - **Not covered:** the 7 mixed, 2 typed and 4 texture programs keep today's refusal. A typed twin could follow later the same way. Steps would be (1) the twin heap with a fixture that creates, copies and overwrites views; (2) the translator acceptance; (3) a measurement on the census requests. Each would be its own PR. I won't start building before you say whether a twin heap fits the stand-in, since it changes how views are kept. AI-assisted.
JB2WIN commented 2026-11-29 09:33:20 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-29T09:33:20Z.


I'm withdrawing Plan C (https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7249426271). I measured it before building it, and it unlocks nothing on its own.

I ran compile_dxil --refusals on main (1a0120ba) over the same local cohort of 2,689 compute requests. For the measurement only, requests without a .views contract were treated as if a heap twin existed:

Heap contract assumed Requests that translate Next refusal after the heap one
none (main) 487 1073 direct resource-heap load requires the selected GPU slot and its view type
raw_buffer (Plan C as posted) 487 1013 a GPU-selected heap slot is read as a raw buffer SRV only, all from a typed_buffer_srv load
raw_and_typed_dword (#3415) 487 701 direct indexed descriptor load shape, 328 unbound numeric SGPR sN, 164 heap byte window loaded inside a loop

So in this cohort:

  • most of these requests read their heap slot with a formatted (typed) load, not raw. My earlier "mostly raw" assumption was wrong for them.
  • even with both raw and typed heap reads allowed, not one more request translates. The next blockers are tied to the per-lane waterfall loop around the heap index (v_readfirstlane, then the heap load inside the loop), not to how the heap is bound.

A heap twin would add runtime work and would not translate a single extra request. The next step is the waterfall loop itself. I'm looking at the 701 direct indexed descriptor load shape cases first and will post what they look like.

The cohort is local only and was not committed. The measurement switch was a local getenv override and is not part of any branch.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7253840860 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7253840860). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-29T09:33:20Z. --- I'm withdrawing Plan C (https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7249426271). I measured it before building it, and it unlocks nothing on its own. I ran `compile_dxil --refusals` on `main` (1a0120ba) over the same local cohort of 2,689 compute requests. For the measurement only, requests without a `.views` contract were treated as if a heap twin existed: | Heap contract assumed | Requests that translate | Next refusal after the heap one | |---|---|---| | none (main) | 487 | 1073 `direct resource-heap load requires the selected GPU slot and its view type` | | raw_buffer (Plan C as posted) | 487 | 1013 `a GPU-selected heap slot is read as a raw buffer SRV only`, all from a `typed_buffer_srv` load | | raw_and_typed_dword (#3415) | 487 | 701 `direct indexed descriptor load shape`, 328 `unbound numeric SGPR sN`, 164 `heap byte window loaded inside a loop` | So in this cohort: - most of these requests read their heap slot with a formatted (typed) load, not raw. My earlier "mostly raw" assumption was wrong for them. - even with both raw and typed heap reads allowed, not one more request translates. The next blockers are tied to the per-lane waterfall loop around the heap index (`v_readfirstlane`, then the heap load inside the loop), not to how the heap is bound. A heap twin would add runtime work and would not translate a single extra request. The next step is the waterfall loop itself. I'm looking at the 701 `direct indexed descriptor load shape` cases first and will post what they look like. The cohort is local only and was not committed. The measurement switch was a local `getenv` override and is not part of any branch. AI-assisted.
JB2WIN commented 2026-11-29 09:39:05 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-29T09:39:05Z.


Follow-up on the 701 direct indexed descriptor load shape refusals in the raw_and_typed_dword run: all 701 are s_load_dwordx8 from the resource heap with a GPU-selected SGPR offset. So they fetch an image descriptor by a GPU value, which is bindless texture access, not a buffer read. The direct path only accepts a GPU-selected heap load of one buffer descriptor (s_load_dwordx4).

So for this bucket the blocker is GPU-selected heap textures, not raw versus typed buffers. For a texture, ResourceDescriptorHeap[i] needs its dimension and format in the shader, and a heap slot can hold any view. A heap twin could still help there, as a texture twin: real views only for slots that match the type the shader declares, null for every other slot. I'll write that up as a design before building anything. The remaining refusals (328 unbound numeric SGPR sN, 164 heap byte window loaded inside a loop) come after it.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7253904638 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7253904638). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-29T09:39:05Z. --- Follow-up on the 701 `direct indexed descriptor load shape` refusals in the `raw_and_typed_dword` run: all 701 are `s_load_dwordx8` from the resource heap with a GPU-selected SGPR offset. So they fetch an image descriptor by a GPU value, which is bindless texture access, not a buffer read. The direct path only accepts a GPU-selected heap load of one buffer descriptor (`s_load_dwordx4`). So for this bucket the blocker is GPU-selected heap textures, not raw versus typed buffers. For a texture, `ResourceDescriptorHeap[i]` needs its dimension and format in the shader, and a heap slot can hold any view. A heap twin could still help there, as a texture twin: real views only for slots that match the type the shader declares, null for every other slot. I'll write that up as a design before building anything. The remaining refusals (328 `unbound numeric SGPR sN`, 164 `heap byte window loaded inside a loop`) come after it. AI-assisted.
JB2WIN commented 2026-11-29 14:09:11 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-29T14:09:11Z.


Measured the bound view heap for the GPU-selected heap texture reads (the 696 s_load_dwordx8 cases above). One launcher run (Series X preset, NVIDIA), sampled at the first compute dispatch and at dispatch 4096, with a temporary local counter (not committed):

dispatch 1 dispatch 4096
logical descriptors in the bound CBV/SRV/UAV heap 1,245,184 1,245,184
slots holding a registered SRV token: Texture2D 565 2,000
Texture2DArray 6 2,839
other texture dimensions 129 213
buffer SRVs 296 5,176
other views (CBV/UAV) 558 5,286
one full scan of the heap records 12.8 ms 10.3 ms

What follows for a design:

  • A 1:1 mirror of the title heap is not possible. 1,245,184 is above the desktop shader-visible limit of 1,000,000.
  • Any per-dispatch walk over the heap costs ~10 ms, so validation at dispatch time is out.
  • CreateDescriptorHeap in d3d12_xs_device.cpp notes that the title copies descriptors between heaps with its own memory copies, so tracking API writes alone would miss copies.

The direction I'm writing up (local design, nothing built yet): the translated shader reads the 32-byte record at the GPU-selected index from the title heap memory itself, through a raw SRV over that memory (the zero-copy alias d3d12_memory_srv.inl already uses). If word 0 is the view token magic and word 1 is a known view id, it indexes ResourceDescriptorHeap[base_dim + id]. Otherwise it reads a null slot. The runtime fills one descriptor per view record id of the matching dimension when the record is created (about 5,000 textures in this run, not 1.2M). Copies made by the title are then handled because the shader reads the token that is in memory when it runs. Open points before code: resource lifetime of mirrored ids, the resource state of textures the shader may pick, and whether this belongs in the runtime the way you want it, @R0Y00.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7257080862 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7257080862). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-29T14:09:11Z. --- Measured the bound view heap for the GPU-selected heap texture reads (the 696 `s_load_dwordx8` cases above). One launcher run (Series X preset, NVIDIA), sampled at the first compute dispatch and at dispatch 4096, with a temporary local counter (not committed): | | dispatch 1 | dispatch 4096 | |---|---|---| | logical descriptors in the bound CBV/SRV/UAV heap | 1,245,184 | 1,245,184 | | slots holding a registered SRV token: Texture2D | 565 | 2,000 | | Texture2DArray | 6 | 2,839 | | other texture dimensions | 129 | 213 | | buffer SRVs | 296 | 5,176 | | other views (CBV/UAV) | 558 | 5,286 | | one full scan of the heap records | 12.8 ms | 10.3 ms | What follows for a design: - A 1:1 mirror of the title heap is not possible. 1,245,184 is above the desktop shader-visible limit of 1,000,000. - Any per-dispatch walk over the heap costs ~10 ms, so validation at dispatch time is out. - `CreateDescriptorHeap` in `d3d12_xs_device.cpp` notes that the title copies descriptors between heaps with its own memory copies, so tracking API writes alone would miss copies. The direction I'm writing up (local design, nothing built yet): the translated shader reads the 32-byte record at the GPU-selected index from the title heap memory itself, through a raw SRV over that memory (the zero-copy alias `d3d12_memory_srv.inl` already uses). If word 0 is the view token magic and word 1 is a known view id, it indexes `ResourceDescriptorHeap[base_dim + id]`. Otherwise it reads a null slot. The runtime fills one descriptor per view record id of the matching dimension when the record is created (about 5,000 textures in this run, not 1.2M). Copies made by the title are then handled because the shader reads the token that is in memory when it runs. Open points before code: resource lifetime of mirrored ids, the resource state of textures the shader may pick, and whether this belongs in the runtime the way you want it, @R0Y00. AI-assisted.
JB2WIN commented 2026-11-29 16:26:06 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-29T16:26:06Z.


Result of a local prototype of the texture route, before any more design work. For measurement only, compute s_load_dwordx8 heap loads with an SGPR offset were routed like the pixel heap path, and a placeholder ResourceDescriptorHeap handle stood in for the token lookup. I then ran compile_dxil --refusals on the same 2,689-request cohort (main 1a0120ba plus the earlier raw_and_typed_dword override):

  • requests that translate: still 487, no change;
  • direct indexed descriptor load shape (the 701): gone;
  • unbound numeric SGPR sN: 328 → 837, so about 500 of them stop there right after the texture load;
  • smaller next stops: gather through the sampler heap is not translated 84, non-contiguous resource descriptor 67, invalid pixel heap texture descriptor address 55.

So the texture route alone translates nothing extra in this cohort either. Two fresh design reviews of the view-id-token design also found gaps in PR 1 (symbol routing, consumer checks, dimension validity). I'm parking stage 3 here and not opening a PR. The measurements above, the heap-size numbers and the view-id-token direction stay on this issue for whoever takes the unbound numeric SGPR chain next. The prototype was local getenv switches only, nothing pushed.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7258900077 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7258900077). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-29T16:26:06Z. --- Result of a local prototype of the texture route, before any more design work. For measurement only, compute `s_load_dwordx8` heap loads with an SGPR offset were routed like the pixel heap path, and a placeholder `ResourceDescriptorHeap` handle stood in for the token lookup. I then ran `compile_dxil --refusals` on the same 2,689-request cohort (`main` 1a0120ba plus the earlier `raw_and_typed_dword` override): - requests that translate: still 487, no change; - `direct indexed descriptor load shape` (the 701): gone; - `unbound numeric SGPR sN`: 328 → 837, so about 500 of them stop there right after the texture load; - smaller next stops: `gather through the sampler heap is not translated` 84, `non-contiguous resource descriptor` 67, `invalid pixel heap texture descriptor address` 55. So the texture route alone translates nothing extra in this cohort either. Two fresh design reviews of the view-id-token design also found gaps in PR 1 (symbol routing, consumer checks, dimension validity). I'm parking stage 3 here and not opening a PR. The measurements above, the heap-size numbers and the view-id-token direction stay on this issue for whoever takes the `unbound numeric SGPR` chain next. The prototype was local `getenv` switches only, nothing pushed. AI-assisted.
JB2WIN commented 2026-11-29 23:09:26 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-29T23:09:26Z.


Status of stage 3 (GPU-selected heap textures in compute). I'm now building PR 1, the translator part only.

The approach changed since my last update. A GPU-selected s_load_dwordx8 from the resource heap reads the 32-byte view token in title heap memory at the guest's own byte address. It checks the magic, the id range and the view dimension per id, and samples ResourceDescriptorHeap[base_dim + id]. A wrong token reads a null slot and bumps a per-wave miss counter. There is no slot mirror and no per-dispatch heap scan. The measured heap has about 1.25 M logical descriptors, of which about 15.5 k hold view tokens. It covers 1D, 2D and 2D array textures with loads, image_sample_l/_lz (literal or fixed sampler-heap samplers), gather4_lz with a literal sampler, and get_resinfo. A load with any other use keeps today's refusal.

PR 1 publishes manifest lines that the runtime reader still refuses by name (heap token textures are not bound yet), so game runs do not change. The runtime part (a raw view over the bound heap's memory, per-dimension id tables, lifetime, states) is PR 2.

@R0Y00, before I start PR 2, are you OK with that runtime outline? It is the one from issuecomment-7257080862, plus 1D and a dims table per view id.

Prerequisites already up: #3500 (image fields), #3524 (fold), #3526 (comparison CLAMP_BORDER). #3076 stage 2a (runtime sampler heap) is in progress.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7264240898 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7264240898). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-29T23:09:26Z. --- Status of stage 3 (GPU-selected heap textures in compute). I'm now building PR 1, the translator part only. The approach changed since my last update. A GPU-selected `s_load_dwordx8` from the resource heap reads the 32-byte view token in title heap memory at the guest's own byte address. It checks the magic, the id range and the view dimension per id, and samples `ResourceDescriptorHeap[base_dim + id]`. A wrong token reads a null slot and bumps a per-wave miss counter. There is no slot mirror and no per-dispatch heap scan. The measured heap has about 1.25 M logical descriptors, of which about 15.5 k hold view tokens. It covers 1D, 2D and 2D array textures with loads, `image_sample_l`/`_lz` (literal or fixed sampler-heap samplers), `gather4_lz` with a literal sampler, and `get_resinfo`. A load with any other use keeps today's refusal. PR 1 publishes manifest lines that the runtime reader still refuses by name (`heap token textures are not bound yet`), so game runs do not change. The runtime part (a raw view over the bound heap's memory, per-dimension id tables, lifetime, states) is PR 2. @R0Y00, before I start PR 2, are you OK with that runtime outline? It is the one from issuecomment-7257080862, plus 1D and a dims table per view id. Prerequisites already up: #3500 (image fields), #3524 (fold), #3526 (comparison CLAMP_BORDER). #3076 stage 2a (runtime sampler heap) is in progress. AI-assisted.
JB2WIN commented 2026-11-30 04:26:48 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-30T04:26:48Z.


Measurement after #3544, so the next step goes to the right place. This is my local cohort of 2,689 slot-67 compute requests, counts only, with a temporary diagnostic that is not in any PR.

Why a GPU-selected texture load (s_load_dwordx8 from the heap at an SGPR offset) is still not eligible under #3544's rules. This is the first failing rule per program:

Rule Programs
the same program also reads the heap through an s_add_u32 address (the buffer route) 874
a word of the load's registers is read later with another symbol 289
a token word read by a non-image instruction 34
T# above s105 21
unsupported image op 4

The 289 case is overly strict: those registers are simply reused by a later table load. As a test I narrowed that rule to an unbound join loss and applied the buffer-route rule per load instead of per program. With both changes, the census barely moves: the heap refusal goes from 1323 to 1320, and 831 compile either way. With the textures handled, these programs stop at their buffer loads through the resource heap (s_load_dwordx4 at a GPU-selected offset, or the s_add_u32 form). That agrees with @Leyukaka's static count above, where 318 of 331 are raw buffer reads.

A follow-up to #3544 that makes image field reads of token textures eligible moves 0 requests. So I'm not opening it for now.

That makes the next lever GPU-selected buffer views through the same token route. The token records also cover buffer views (5,176 buffer records in the measured run), so a raw or typed buffer SRV per view id would be the buffer analogue of the per-dimension texture tables. I'll write that up as a design before building anything. @RonLogic, does this overlap the #3063 retarget work you mentioned above?

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7268782468 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7268782468). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-30T04:26:48Z. --- Measurement after #3544, so the next step goes to the right place. This is my local cohort of 2,689 slot-67 compute requests, counts only, with a temporary diagnostic that is not in any PR. Why a GPU-selected texture load (`s_load_dwordx8` from the heap at an SGPR offset) is still not eligible under #3544's rules. This is the first failing rule per program: | Rule | Programs | |---|---| | the same program also reads the heap through an `s_add_u32` address (the buffer route) | 874 | | a word of the load's registers is read later with another symbol | 289 | | a token word read by a non-image instruction | 34 | | T# above s105 | 21 | | unsupported image op | 4 | The 289 case is overly strict: those registers are simply reused by a later table load. As a test I narrowed that rule to an `unbound` join loss and applied the buffer-route rule per load instead of per program. With both changes, the census barely moves: the heap refusal goes from 1323 to 1320, and 831 compile either way. With the textures handled, these programs stop at their **buffer** loads through the resource heap (`s_load_dwordx4` at a GPU-selected offset, or the `s_add_u32` form). That agrees with @Leyukaka's static count above, where 318 of 331 are raw buffer reads. A follow-up to #3544 that makes image field reads of token textures eligible moves 0 requests. So I'm not opening it for now. That makes the next lever GPU-selected **buffer** views through the same token route. The token records also cover buffer views (5,176 buffer records in the measured run), so a raw or typed buffer SRV per view id would be the buffer analogue of the per-dimension texture tables. I'll write that up as a design before building anything. @RonLogic, does this overlap the #3063 retarget work you mentioned above? AI-assisted.
lukaslw-lab commented 2026-11-30 14:05:37 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T14:05:37Z.


@JB2WIN, slot 57 mesh programs hit the same GPU-selected heap pattern on the buffer side. It is the largest C++ refusal by refused DispatchMesh calls in a 360 s native run (1.13 M; #3416, claimed in #2413). The chain:

  1. s_load_dwordx4 of a buffer SRV from a root descriptor table (an immediate offset);
  2. s_buffer_load_dword of a dword from it, the selector;
  3. s_lshl_b32 … 5, then s_load_dwordx4 from the resource heap at that SGPR offset;
  4. buffer_load_format_x … idxen: a one-channel typed read.

The selector is not masked. A local prototype recognises the chain behind an opt-in .mslayout contract and emits ResourceDescriptorHeap[selector] as a TypedBuffer<U32> read. A source-built fixture covers it, with six refusal controls. It trusts the caller like the #2908 typed_dword contract, so an unmasked index stays unbounded.

I would rather use your token guard than open that: read the token at the guest heap address, check the magic, id < count and the view type, read ResourceDescriptorHeap[base + id], otherwise read a null slot. For a typed buffer, the per-id record would hold the view type plus format or element size, not a texture dimension. Is the buffer route (your 874 programs) already planned on your side? If it is, I'll build the mesh variant on your helpers rather than a parallel one. If it isn't, I can take the typed-buffer check for mesh on top of #3544.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7280822474 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7280822474). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T14:05:37Z. --- @JB2WIN, slot 57 mesh programs hit the same GPU-selected heap pattern on the buffer side. It is the largest C++ refusal by refused `DispatchMesh` calls in a 360 s native run (1.13 M; #3416, claimed in #2413). The chain: 1. `s_load_dwordx4` of a buffer SRV from a root descriptor table (an immediate offset); 2. `s_buffer_load_dword` of a dword from it, the selector; 3. `s_lshl_b32 … 5`, then `s_load_dwordx4` from the resource heap at that SGPR offset; 4. `buffer_load_format_x … idxen`: a one-channel typed read. The selector is not masked. A local prototype recognises the chain behind an opt-in `.mslayout` contract and emits `ResourceDescriptorHeap[selector]` as a `TypedBuffer<U32>` read. A source-built fixture covers it, with six refusal controls. It trusts the caller like the #2908 `typed_dword` contract, so an unmasked index stays unbounded. I would rather use your token guard than open that: read the token at the guest heap address, check the magic, `id < count` and the view type, read `ResourceDescriptorHeap[base + id]`, otherwise read a null slot. For a typed buffer, the per-id record would hold the view type plus format or element size, not a texture dimension. Is the buffer route (your 874 programs) already planned on your side? If it is, I'll build the mesh variant on your helpers rather than a parallel one. If it isn't, I can take the typed-buffer check for mesh on top of #3544.
lukaslw-lab commented 2026-11-30 15:37:21 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T15:37:21Z.


@JB2WIN, follow-up to my note above: I went ahead with the mesh side in #3619, translator only, using the same token shape as #3544.

  • Route: a heap descriptor at a GPU-computed byte offset (a value shifted left by 5 or more) is read through its view token: magic 0x56573258, view id, then a per-id kind table. A valid token reads ResourceDescriptorHeap[base + id] as a typed U32 buffer; anything else reads the null slot, and the first lane counts a miss.
  • Kind value 16 marks a one-channel 32-bit typed buffer. Your dimension table uses 1 + image dimension (at most 8), so one table could serve both routes. Could you keep 16 free for this?
  • Bindings: token memory and kind table (raw SRVs), a miss UAV, and base/count/null in cbuffer b1. They're opt-in (heap_tokens in .mslayout), and native preparation still refuses these programs.

On the two top refused mesh programs (#3416), the refusal moves from the heap slot (+0x2a0 / +0x2a8) to v_readfirstlane_b32 (+0x470 / +0x474).

When #3544 lands I'll switch to its helpers wherever they fit. The runtime binding for mesh comes next.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7283296658 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3023#issuecomment-7283296658). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T15:37:21Z. --- @JB2WIN, follow-up to my note above: I went ahead with the mesh side in #3619, translator only, using the same token shape as #3544. - **Route:** a heap descriptor at a GPU-computed byte offset (a value shifted left by 5 or more) is read through its view token: magic `0x56573258`, view id, then a per-id kind table. A valid token reads `ResourceDescriptorHeap[base + id]` as a typed U32 buffer; anything else reads the null slot, and the first lane counts a miss. - **Kind value 16** marks a one-channel 32-bit typed buffer. Your dimension table uses 1 + image dimension (at most 8), so one table could serve both routes. Could you keep 16 free for this? - **Bindings:** token memory and kind table (raw SRVs), a miss UAV, and `base`/`count`/`null` in cbuffer `b1`. They're opt-in (`heap_tokens` in `.mslayout`), and native preparation still refuses these programs. On the two top refused mesh programs (#3416), the refusal moves from the heap slot (+0x2a0 / +0x2a8) to `v_readfirstlane_b32` (+0x470 / +0x474). When #3544 lands I'll switch to its helpers wherever they fit. The runtime binding for mesh comes next.
Sign in to join this conversation.
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#3023
No description provided.