native: capture and replay view types for GPU-selected global SRV slots #2972

Merged
JB2WIN merged 8 commits from upstream-pr/2972 into cpp-migration 2026-11-27 01:03:27 +00:00
JB2WIN commented 2026-11-27 00:46:22 +00:00 (Migrated from github.com)

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


Fixes #2908. Continues #2912 (handed over by @tedin7 in https://github.com/R0Y00/Xbox2Windows/pull/2912#issuecomment-7204144181; his four commits are kept as they are, plus the 32-lane WARP skip from tedin7/Xbox2Windows#2). Target branch cpp-migration.

What

  • View contract for GPU-selected heap slots (src/gfx1013_direct_compute.inl, src/gfx1013_compute_native.*, src/direct_compute_cache.*, src/native_compute_pipeline.*): the direct compute translation takes x2w::HeapViewContract (none, raw_buffer, other). An SMEM descriptor load from the resource heap is translated only with raw_buffer (then #2912's ResourceDescriptorHeap[slot] raw buffer read is used). Without a contract the existing refusal text stays ("direct resource-heap load requires the selected GPU slot and its view type"). A scalar buffer load from the heap base, a heap descriptor load with a constant index or an immediate offset (both could address another slot than the captured one) and a stride read of a GPU-selected slot in the direct path get their own refusals. The contract is in the frontend cache key when it is not none. Heap-reading modules now also carry shader flag 0x40000000, as DXC sets for the HLSL reference; without it the validator refuses the module ("Flags must match usage. Validation failed.", measured by removing the flag).
  • View metadata v2 (src/startup_stubs/native_global_srv.h, from #2912): the slot line gains the buffer size (slot <n> <type> <stride> <bytes>); header x2w-global-srv-views 2; the header is self-contained.
  • Offline replay (tools/startup/compile_dxil.cpp): gfx1013-container-cs reads an optional req_<key>.views next to the .cdx, refuses a selection whose slot holds another view type than need (slot/type diagnostic), refuses a need other than raw_buffer, translates with the contract and prints global_srv select=<n> need=<type>. All refusals happen before the .cso is published.
  • Fixture native_global_srv_heap_replay (tests/native_global_srv_heap_replay.cpp, _check.py, tests/cmake/native_global_srv_heap_replay.cmake): source-built container that reads ResourceDescriptorHeap[selector] with the selector in a GPU buffer; heap slots 0/1 raw buffers with different data, 2 Texture2D, 3 typed buffer. record reads the selector back from the GPU before recording (one sync per recorded dispatch), captures {select, view types, sizes} into req_<key>.views, refuses incompatible slots before Dispatch, and records with x2w_startup::NativeRecording + NativeDispatchStates. replay runs the compile_dxil output on a heap rebuilt from the captured types.
  • Notes: docs/experiments/native-global-srv-heap-replay.md.

"Native recording" / "runtime path" here: the issue's reproduction names native_recording_check and native_dispatch_states_warp, which test NativeRecording and NativeDispatchStates. On cpp-migration only tests use these classes, so the fixture's record mode is the native recording path and its UAV sentinels are the runtime-path sentinels. The stand-in's native slot 67 path from #2958 calls translate_compute without a heap view contract, so a GPU-selected heap read stays refused there; passing captured views into it would be a follow-up. Please say if the issue meant more.

How tested

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R "^native_global_srv_heap_replay(_warp|_hardware)?$" -V
ctest --preset dev --no-tests=error -R ^native_ -j 1
  • native_global_srv_heap_replay_hardware: passed, 70 assertions:
    • offline, no .views: refused with the heap text, no .cso;
    • record 0/1: fenced output equals the selected slot's 64 words, sentinels intact, .views captured; 2/3: "global SRV slot 2 has view type texture, the shader needs raw_buffer" / "... slot 3 has view type typed_buffer ..." before the dispatch, nothing dispatched, sentinels intact;
    • discrimination control: record --no-guard on slot 0 expecting a refusal sees the changed sentinels (exit 3);
    • compile_dxil --requests on each capture: 0/1 compiled with global_srv select=<n> need=raw_buffer, 2/3 refused, no .cso;
    • replay of the compiled .cso: 0/1 match the CPU reference, 2/3 refused with sentinels intact;
    • mutation control: selection 0 against the slot 1 reference reports a mismatch;
    • negative controls on both compile_dxil and replay: mismatched type, no need, no select, no line for the selected slot, select 7, missing .views file — explicit diagnostic, no .cso, sentinels intact;
    • shader shapes refused with valid metadata: constant heap index, immediate offset, stride read of the selected slot.
  • native_global_srv_heap_replay_warp: skipped (77), "adapter has no 32-lane waves (4..4)" — the native module declares WaveSize=32. Not evidence.
  • ^native_ with -j 1: before (base c1933a61) 85/86 passed; after 87/88 passed. In both runs the only failure is native_wave_request_hardware (#2915, fixed by #2928); skips native_comparison_pso_warp, native_heap_handle_probe_warp, and the new _warp.
  • Flag control: without 0x40000000 the hardware test fails at validation.
  • Revert control: with the heap refusal restored for every contract, record for selection 0 exits 4 with "direct resource-heap load requires the selected GPU slot and its view type".
  • python -B tests/docs_links_check.py: passed.

Environment: NVIDIA GeForce RTX 3080, driver 32.0.16.2124, Windows 11 build 26200, MSVC toolset 14.51.36231, Windows SDK 10.0.26100 DXC, D3D12 debug layer not enabled.

Limits

  • Only raw buffer heap reads are translated; other classes are refused with a named diagnostic.
  • No static bound on the per-lane index; reads stay inside the raw buffer view.
  • Replay regenerates slot contents from the slot index; .views captures type, stride and size.
  • The HLSL path's heap_stride_srv (used by native_compute_grid) is unchanged; only the direct path refuses a stride read of a GPU-selected slot.
  • The captured select must be the slot index the dispatch addresses; producing it from a title capture is outside this fixture.
  • Notes are in docs/experiments/native-global-srv-heap-replay.md (new notes go in docs/experiments/, per its README).

AI-assisted.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5519241347 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2972). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-27T00:46:22Z. --- Fixes #2908. Continues #2912 (handed over by @tedin7 in https://github.com/R0Y00/Xbox2Windows/pull/2912#issuecomment-7204144181; his four commits are kept as they are, plus the 32-lane WARP skip from tedin7/Xbox2Windows#2). Target branch `cpp-migration`. ## What - **View contract for GPU-selected heap slots** (`src/gfx1013_direct_compute.inl`, `src/gfx1013_compute_native.*`, `src/direct_compute_cache.*`, `src/native_compute_pipeline.*`): the direct compute translation takes `x2w::HeapViewContract` (`none`, `raw_buffer`, `other`). An SMEM descriptor load from the resource heap is translated only with `raw_buffer` (then #2912's `ResourceDescriptorHeap[slot]` raw buffer read is used). Without a contract the existing refusal text stays ("direct resource-heap load requires the selected GPU slot and its view type"). A scalar buffer load from the heap base, a heap descriptor load with a constant index or an immediate offset (both could address another slot than the captured one) and a stride read of a GPU-selected slot in the direct path get their own refusals. The contract is in the frontend cache key when it is not `none`. Heap-reading modules now also carry shader flag `0x40000000`, as DXC sets for the HLSL reference; without it the validator refuses the module ("Flags must match usage. Validation failed.", measured by removing the flag). - **View metadata v2** (`src/startup_stubs/native_global_srv.h`, from #2912): the slot line gains the buffer size (`slot <n> <type> <stride> <bytes>`); header `x2w-global-srv-views 2`; the header is self-contained. - **Offline replay** (`tools/startup/compile_dxil.cpp`): `gfx1013-container-cs` reads an optional `req_<key>.views` next to the `.cdx`, refuses a selection whose slot holds another view type than `need` (slot/type diagnostic), refuses a `need` other than `raw_buffer`, translates with the contract and prints `global_srv select=<n> need=<type>`. All refusals happen before the `.cso` is published. - **Fixture** `native_global_srv_heap_replay` (`tests/native_global_srv_heap_replay.cpp`, `_check.py`, `tests/cmake/native_global_srv_heap_replay.cmake`): source-built container that reads `ResourceDescriptorHeap[selector]` with the selector in a GPU buffer; heap slots 0/1 raw buffers with different data, 2 Texture2D, 3 typed buffer. `record` reads the selector back from the GPU before recording (one sync per recorded dispatch), captures `{select, view types, sizes}` into `req_<key>.views`, refuses incompatible slots before `Dispatch`, and records with `x2w_startup::NativeRecording` + `NativeDispatchStates`. `replay` runs the `compile_dxil` output on a heap rebuilt from the captured types. - Notes: `docs/experiments/native-global-srv-heap-replay.md`. "Native recording" / "runtime path" here: the issue's reproduction names `native_recording_check` and `native_dispatch_states_warp`, which test `NativeRecording` and `NativeDispatchStates`. On `cpp-migration` only tests use these classes, so the fixture's `record` mode is the native recording path and its UAV sentinels are the runtime-path sentinels. The stand-in's native slot 67 path from #2958 calls `translate_compute` without a heap view contract, so a GPU-selected heap read stays refused there; passing captured views into it would be a follow-up. Please say if the issue meant more. ## How tested ``` cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R "^native_global_srv_heap_replay(_warp|_hardware)?$" -V ctest --preset dev --no-tests=error -R ^native_ -j 1 ``` - `native_global_srv_heap_replay_hardware`: **passed**, 70 assertions: - offline, no `.views`: refused with the heap text, no `.cso`; - `record` 0/1: fenced output equals the selected slot's 64 words, sentinels intact, `.views` captured; 2/3: "global SRV slot 2 has view type texture, the shader needs raw_buffer" / "... slot 3 has view type typed_buffer ..." before the dispatch, nothing dispatched, sentinels intact; - discrimination control: `record --no-guard` on slot 0 expecting a refusal sees the changed sentinels (exit 3); - `compile_dxil --requests` on each capture: 0/1 compiled with `global_srv select=<n> need=raw_buffer`, 2/3 refused, no `.cso`; - `replay` of the compiled `.cso`: 0/1 match the CPU reference, 2/3 refused with sentinels intact; - mutation control: selection 0 against the slot 1 reference reports a mismatch; - negative controls on both `compile_dxil` and `replay`: mismatched type, no `need`, no `select`, no line for the selected slot, `select 7`, missing `.views` file — explicit diagnostic, no `.cso`, sentinels intact; - shader shapes refused with valid metadata: constant heap index, immediate offset, stride read of the selected slot. - `native_global_srv_heap_replay_warp`: **skipped (77)**, "adapter has no 32-lane waves (4..4)" — the native module declares `WaveSize=32`. Not evidence. - `^native_` with `-j 1`: before (base c1933a61) 85/86 passed; after 87/88 passed. In both runs the only failure is `native_wave_request_hardware` (#2915, fixed by #2928); skips `native_comparison_pso_warp`, `native_heap_handle_probe_warp`, and the new `_warp`. - Flag control: without `0x40000000` the hardware test fails at validation. - Revert control: with the heap refusal restored for every contract, `record` for selection 0 exits 4 with "direct resource-heap load requires the selected GPU slot and its view type". - `python -B tests/docs_links_check.py`: passed. Environment: NVIDIA GeForce RTX 3080, driver 32.0.16.2124, Windows 11 build 26200, MSVC toolset 14.51.36231, Windows SDK 10.0.26100 DXC, D3D12 debug layer not enabled. ## Limits - Only raw buffer heap reads are translated; other classes are refused with a named diagnostic. - No static bound on the per-lane index; reads stay inside the raw buffer view. - Replay regenerates slot contents from the slot index; `.views` captures type, stride and size. - The HLSL path's `heap_stride_srv` (used by `native_compute_grid`) is unchanged; only the direct path refuses a stride read of a GPU-selected slot. - The captured `select` must be the slot index the dispatch addresses; producing it from a title capture is outside this fixture. - Notes are in `docs/experiments/native-global-srv-heap-replay.md` (new notes go in `docs/experiments/`, per its README). AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MasterDomino commented 2026-11-27 01:03:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-27T01:03:25Z.

Review: APPROVED


Review of head 7c955a09, tested merged onto cpp-migration 7bcff286 (after #2973). It auto-merges cleanly, and CI on the head is green. Approving and merging.

Code read:

  • Contract: HeapViewContract gates the heap read. With none, the existing refusal text is kept, so #2958's in-runtime native path, which passes no contract, behaves as before. other is refused by name, and only raw_buffer lowers to ResourceDescriptorHeap[slot] with the 0x40000000 flag.
  • Index guards: the index must be the GPU-selected SGPR offset. A constant index or an immediate offset is refused, because either could address a slot other than the captured one.
  • Removed stride-read lowering: this is not a regression. Before this PR every direct-path heap descriptor load was refused before an indexed heap descriptor could form, so that code was unreachable. heap_stride_srv in the HLSL path is unchanged.
  • Replay: compile_dxil refuses a .views slot type mismatch, or a need other than raw_buffer, before publishing.
  • native_global_srv.h is not included by any runtime source, so no start-up run is needed.

Run on AMD: Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), release. ctest --preset release --no-tests=error -R '^native_' gives 57 tests, 54 passed and 3 skipped (77: native_comparison_pso_warp, native_heap_handle_probe_warp and native_global_srv_heap_replay_warp, because WARP has no 32-lane waves). native_heap_handle_probe_hardware and native_global_srv_heap_replay_hardware pass. That matches @thepatrickworld's RX 9070 XT result on #2912 after the #2932 rebase.

Mutation here: indexing the heap one slot off (symbol.offset / 32 + 1) fails native_global_srv_heap_replay_hardware with mismatch word 0: got 0xb0000000 expected 0xa0000000 (reference slot 0). With it restored, it passes.

The follow-up you name, passing captured views into #2958's in-runtime path, is the natural next step for this to reach a start-up run. I will close #2908 by hand. Thanks to @tedin7 for #2912.

AI-assisted; the commands above were run locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6082144305 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2972#pullrequestreview-6082144305). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-27T01:03:25Z. **Review:** APPROVED --- Review of head `7c955a09`, tested merged onto `cpp-migration` `7bcff286` (after #2973). It auto-merges cleanly, and CI on the head is green. Approving and merging. **Code read:** - **Contract:** `HeapViewContract` gates the heap read. With `none`, the existing refusal text is kept, so #2958's in-runtime native path, which passes no contract, behaves as before. `other` is refused by name, and only `raw_buffer` lowers to `ResourceDescriptorHeap[slot]` with the `0x40000000` flag. - **Index guards:** the index must be the GPU-selected SGPR offset. A constant index or an immediate offset is refused, because either could address a slot other than the captured one. - **Removed stride-read lowering:** this is not a regression. Before this PR every direct-path heap descriptor load was refused before an indexed heap descriptor could form, so that code was unreachable. `heap_stride_srv` in the HLSL path is unchanged. - **Replay:** `compile_dxil` refuses a `.views` slot type mismatch, or a `need` other than `raw_buffer`, before publishing. - `native_global_srv.h` is not included by any runtime source, so no start-up run is needed. **Run on AMD:** Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), release. `ctest --preset release --no-tests=error -R '^native_'` gives 57 tests, 54 passed and 3 skipped (77: `native_comparison_pso_warp`, `native_heap_handle_probe_warp` and `native_global_srv_heap_replay_warp`, because WARP has no 32-lane waves). `native_heap_handle_probe_hardware` and `native_global_srv_heap_replay_hardware` pass. That matches @thepatrickworld's RX 9070 XT result on #2912 after the #2932 rebase. **Mutation here:** indexing the heap one slot off (`symbol.offset / 32 + 1`) fails `native_global_srv_heap_replay_hardware` with `mismatch word 0: got 0xb0000000 expected 0xa0000000 (reference slot 0)`. With it restored, it passes. The follow-up you name, passing captured views into #2958's in-runtime path, is the natural next step for this to reach a start-up run. I will close #2908 by hand. Thanks to @tedin7 for #2912. AI-assisted; the commands above were run locally.
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!2972
No description provided.