Repository navigation
native: capture and replay view types for GPU-selected global SRV slots - #2972
Conversation
…(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
left a comment
There was a problem hiding this comment.
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:
HeapViewContractgates the heap read. Withnone, the existing refusal text is kept, so #2958's in-runtime native path, which passes no contract, behaves as before.otheris refused by name, and onlyraw_bufferlowers toResourceDescriptorHeap[slot]with the0x40000000flag. - 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_srvin the HLSL path is unchanged. - Replay:
compile_dxilrefuses a.viewsslot type mismatch, or aneedother thanraw_buffer, before publishing. native_global_srv.his 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.
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
src/gfx1013_direct_compute.inl,src/gfx1013_compute_native.*,src/direct_compute_cache.*,src/native_compute_pipeline.*): the direct compute translation takesx2w::HeapViewContract(none,raw_buffer,other). An SMEM descriptor load from the resource heap is translated only withraw_buffer(then test: native DXIL read of a GPU-selected descriptor heap slot (probe) #2912'sResourceDescriptorHeap[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 notnone. Heap-reading modules now also carry shader flag0x40000000, 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).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>); headerx2w-global-srv-views 2; the header is self-contained.tools/startup/compile_dxil.cpp):gfx1013-container-csreads an optionalreq_<key>.viewsnext to the.cdx, refuses a selection whose slot holds another view type thanneed(slot/type diagnostic), refuses aneedother thanraw_buffer, translates with the contract and printsglobal_srv select=<n> need=<type>. All refusals happen before the.csois published.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 readsResourceDescriptorHeap[selector]with the selector in a GPU buffer; heap slots 0/1 raw buffers with different data, 2 Texture2D, 3 typed buffer.recordreads the selector back from the GPU before recording (one sync per recorded dispatch), captures{select, view types, sizes}intoreq_<key>.views, refuses incompatible slots beforeDispatch, and records withx2w_startup::NativeRecording+NativeDispatchStates.replayruns thecompile_dxiloutput on a heap rebuilt from the captured types.docs/experiments/native-global-srv-heap-replay.md."Native recording" / "runtime path" here: the issue's reproduction names
native_recording_checkandnative_dispatch_states_warp, which testNativeRecordingandNativeDispatchStates. Oncpp-migrationonly tests use these classes, so the fixture'srecordmode is the native recording path and its UAV sentinels are the runtime-path sentinels. The stand-in's native slot 67 path from #2958 callstranslate_computewithout 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
native_global_srv_heap_replay_hardware: passed, 70 assertions:.views: refused with the heap text, no.cso;record0/1: fenced output equals the selected slot's 64 words, sentinels intact,.viewscaptured; 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;record --no-guardon slot 0 expecting a refusal sees the changed sentinels (exit 3);compile_dxil --requestson each capture: 0/1 compiled withglobal_srv select=<n> need=raw_buffer, 2/3 refused, no.cso;replayof the compiled.cso: 0/1 match the CPU reference, 2/3 refused with sentinels intact;compile_dxilandreplay: mismatched type, noneed, noselect, no line for the selected slot,select 7, missing.viewsfile — explicit diagnostic, no.cso, sentinels intact;native_global_srv_heap_replay_warp: skipped (77), "adapter has no 32-lane waves (4..4)" — the native module declaresWaveSize=32. Not evidence.^native_with-j 1: before (base c1933a6) 85/86 passed; after 87/88 passed. In both runs the only failure isnative_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); skipsnative_comparison_pso_warp,native_heap_handle_probe_warp, and the new_warp.0x40000000the hardware test fails at validation.recordfor 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
.viewscaptures type, stride and size.heap_stride_srv(used bynative_compute_grid) is unchanged; only the direct path refuses a stride read of a GPU-selected slot.selectmust be the slot index the dispatch addresses; producing it from a title capture is outside this fixture.docs/experiments/native-global-srv-heap-replay.md(new notes go indocs/experiments/, per its README).AI-assisted.
🤖 Generated with Claude Code