Skip to content

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

Merged
MasterDomino merged 8 commits into
R0Y00:cpp-migrationfrom
JB2WIN:native/global-srv-heap-replay
Nov 27, 2026
Merged

MasterDomino merged 8 commits into
R0Y00:cpp-migrationfrom
JB2WIN:native/global-srv-heap-replay

Conversation

@JB2WIN

@JB2WIN JB2WIN commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2908. Continues #2912 (handed over by @tedin7 in #2912 (comment); his four commits are kept as they are, plus the 32-lane WARP skip from tedin7#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 test: native DXIL read of a GPU-selected descriptor heap slot (probe) #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 test: native DXIL read of a GPU-selected descriptor heap slot (probe) #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 c1933a6) 85/86 passed; after 87/88 passed. In both runs the only failure is native_wave_request_hardware (cpp-migration 40365770: native _hardware tests crash (0xC0000005) on an RX 9070 XT; wave_request expects a different refusal message #2915, fixed by tests: expect the decoder's refusal for the invalid word in native_wave_request #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

c1 and others added 8 commits November 26, 2026 20:25
…(ResourceDescriptorHeap probe)

Adds DxilModule::heap_handle (dx.op.createHandleFromHeap, opcode 218, annotated with the view class) and a probe that
compiles the same selection shader as DXC HLSL and as the native module, creates the pipeline with the heap-indexed root
flag, and dispatches it twice with different selector words: each readback must be the data of the selected slot and the
UAV guard word must stay intact. The adapter needs shader model 6.6 and resource binding tier 3, else the test skips.
…p slot as a raw buffer SRV

A buffer load through a descriptor loaded from the whole resource heap at a GPU-computed index used to be refused
(whole-heap buffer access needs a matching descriptor at the GPU-selected index). The direct DXIL lowering now emits
ResourceDescriptorHeap[slot] (createHandleFromHeap, annotated as a raw buffer) and records a heap_buffer_srv binding with
no table register; the pipeline then creates its root signature with the heap-indexed flag and sets the heap on the list.
Adds the view-type classification header (native_global_srv.h) that the dispatch guard will use; no guard yet.
The native module declares WaveSize=32 (the guest wave). WARP offers only
4-lane waves, so CreateComputePipelineState refuses the native shader and
native_heap_handle_probe_warp failed with "pipeline state of the native
shader". Return 77 when the adapter cannot run 32-lane waves, as
native_store_replay and native_recording_check already do.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The direct compute translation takes a view contract for a GPU-selected
descriptor heap slot (HeapViewContract none / raw_buffer / other). A heap
descriptor load is translated only with raw_buffer; without a contract the
existing refusal stays. Constant heap indices, immediate offsets, scalar
buffer loads from the heap base and stride reads of a selected slot are
refused. Heap-reading modules set shader flag 0x40000000, which the
validator requires.

compile_dxil gfx1013-container-cs reads an optional req_<key>.views
(native_global_srv.h, format version 2 with buffer sizes), refuses a
selection whose slot holds another view type before publishing a .cso, and
reports the captured selection.

native_global_srv_heap_replay records a dispatch that selects its slot from
GPU data (selector read back before recording, guard before Dispatch,
NativeRecording + NativeDispatchStates) and replays the compile_dxil output
on a heap rebuilt from the captured view types, with negative controls on
both paths.

Fixes R0Y00#2908. AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the conflicts with R0Y00#2932-R0Y00#2971 (keeps both sides: HeapViewContract next
to the MODE tracking and lane-shape checks; .views handling inside the new
compile_one). The check follows the new --requests output name <key>.cs.cso
from R0Y00#2955, and the notes mention the stand-in's native slot 67 path (R0Y00#2958),
which translates without a heap view contract.

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

@MasterDomino MasterDomino left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants