Skip to content

native: read one-channel typed loads through a GPU-selected heap descriptor - #3042

Merged
R0Y00 merged 1 commit into
R0Y00:cpp-migrationfrom
JB2WIN:native/heap-typed-dword-load
Nov 27, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:cpp-migrationfrom
JB2WIN:native/heap-typed-dword-load

Conversation

@JB2WIN

@JB2WIN JB2WIN commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Change

Target branch cpp-migration. Refs #3023. Follow-up to #3034 (merged as b405cf71).

The direct compute path translated GPU-selected heap reads only under the raw_buffer view contract, so a formatted MUBUF load (buffer_load_format_x with an idxen element index) through a heap descriptor was refused ("a GPU-selected heap slot is read as a raw buffer SRV only"). This adds a second contract class for one-channel 32-bit typed buffer slots.

  • src/gfx1013_compute_native.h: HeapViewContract::typed_dword with its caller guarantee in the comment; binding kind ComputeViewKind::heap_typed_srv; compute_heap_binding covers both heap kinds.
  • src/gfx1013_direct_compute.inl, heap_resource: under typed_dword only typed_buffer_srv with one channel is accepted. The handle is ResourceDescriptorHeap[slot] annotated as a typed buffer of one U32 component (annotateHandle kind 10, props 5 + 1 * 256), module flag 0x40000000 only. Raw loads, byte windows, tbuffer loads ("… read as a typed dword buffer SRV only") and 2-4 channel loads ("typed heap load reads one channel only") are refused. raw_buffer behaviour is unchanged.
  • src/direct_compute_cache.cpp: cache identity /heap-view/typed_dword; the binding decoder's kind bound moves to the new last kind.
  • src/startup_stubs/native_global_srv.h: GlobalSrvView::dword_channels (from typed_dword_channels); .views gains a dword <slot> <channels> line after the slot lines (header stays version 2; the decoder accepts it only for an earlier typed buffer slot, once, 1-4 channels); global_srv_contract() maps need raw_buffer → raw_buffer and need typed_buffer → typed_dword when every captured typed buffer slot is a one-channel 32-bit buffer.
  • tools/startup/compile_dxil.cpp: read_captured_views uses the helper; the heap-read re-check uses compute_heap_binding.
  • tests/native_global_srv_heap_replay.cpp: record … [--no-guard] [--need typed_buffer]; record and replay build the request first and pass the helper's contract to the pipeline.

Why this step: on a local start-up capture (compile_dxil --refusals, 2,689 slot 67 requests, counts only, raw contract forced by an uncommitted switch), 906 requests stopped first at the typed heap load, and all 906 are this one-channel idxen shape. No additional request compiles from this alone: with typed_dword forced instead, 895 of them then stop at a raw read of another heap slot. Those programs read the heap both ways, which one captured selection does not cover (the existing contract comment already says so for two selectors). That mixed case is the next step.

Verification

Environment: Windows 11 build 26200, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), MSVC 14.51.36231, Windows SDK 10.0.26100 DXC, D3D12 debug layer not enabled. Measured on e67f1017 (#3034 before its merge); cpp-migration b405cf71 has the same tree.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R "^(native_global_srv_heap_replay_hardware|native_mtbuf_hardware|native_direct_container|compute_load_format_controls|native_heap_handle_probe_hardware)$" -V
ctest --preset dev --no-tests=error -R "native_|startup_compute_dispatch|compute_heap" -j 6
  • Targeted: 5/5 passed. native_global_srv_heap_replay_hardware: 122 assertions (94 before), 9 s.
    • Section 10: buffer_load_format_x v2, v0, s[20:23], 0 idxen recorded with --need typed_buffer for slot 3 (R32_UINT) → output equals the slot 3 data; .views has need typed_buffer and dword 3 1. Selections 0 (raw) and 2 (texture) are refused before the dispatch. compile_dxil --requests compiles it; a second run reports frontend_cache_hit=1 and the same .cso (the new binding kind decodes). Replay equals the slot 3 data; replay against slot 0 data reports a mismatch.
    • Ten compile refusals, no .cso: a two-channel typed load; the raw program and a tbuffer load under the typed contract; the typed load under the raw .views; .views without the dword line ("… (no 32-bit channel metadata)"), with select 0, with dword 3 5, with a dword line for a raw slot, twice, or before the slot lines.
  • Discrimination: the new check run with compile_dxil and the fixture built at e67f1017 passes the 94 earlier assertions and fails at the first typed record (the old fixture has no --need). The old compile_dxil given the typed request refuses it with "GPU-selected heap slot view type typed_buffer is not raw_buffer; only raw buffer heap reads are translated"; the new one compiles it.
  • Regression set: 147 tests, 3 failed, the same three as at the base on this machine: native_cvt_pk_u8_hardware (known), and native_sdwa_f16_ir / native_sdwa_f16_hardware, which fail at e67f1017 as well. On this machine native_sdwa_f16_ir asserts (0, 'add', '0xa55a4200', '0xa55a4200'): the printed values are equal, but the match fails.
  • compile_dxil --refusals on the local capture without a contract: identical before and after.
  • tests/compute_heap_view_check.py, tests/startup_gfx2hlsl_heap_record_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py pass.

Evidence and follow-up

  • Instruction words assembled with LLVM 15 (clang -cc1as -triple amdgcn-amd-amdhsa -target-cpu gfx1013 -show-encoding); fixtures are source-built.
  • Limits (also in docs/experiments/native-global-srv-heap-replay.md): the translator sees no descriptor values. Every selectable slot must be an R32_UINT, R32_SINT or R32_FLOAT view bound as R32_UINT over the same element range, and the guest descriptor must have stride 4, a 32-bit format, identity dst_sel_x, swizzle/add_tid off and num_records equal to the view's element count. .views records resource sizes, so global_srv_contract checks necessary conditions only. Only R32_UINT is exercised. No runtime binds a typed heap slot yet.
  • Next on cpp-migration: pass captured heap view types into the in-runtime native compute route (#2958) #3023: programs that read the heap raw and typed (more than one captured selection), then the runtime contract (stage 3).

Checklist

  • One behaviour, tests added, no test weakened
  • Docs updated
  • No game files, dumps or title-specific content

AI-assisted.

🤖 Generated with Claude Code

…riptor

A formatted MUBUF load (buffer_load_format_x, idxen) through a heap
descriptor was refused: only the raw_buffer heap view contract existed.
HeapViewContract::typed_dword now covers programs whose heap reads are
one-channel typed loads of 32-bit typed buffer slots. heap_resource
annotates ResourceDescriptorHeap[slot] as a typed buffer of one U32
component and records the new binding kind heap_typed_srv; raw loads,
byte windows and multi-channel loads stay refused under it. The cache
identity and the cache decoder know the new kind, and compile_dxil's
heap-read re-check uses compute_heap_binding.

.views records the 32-bit channel count of each typed buffer slot in a
"dword <slot> <channels>" line. global_srv_contract derives the contract
from the request: need raw_buffer -> raw_buffer, need typed_buffer with
every captured typed slot a one-channel 32-bit buffer -> typed_dword.
The fixture's record mode takes --need typed_buffer.

The guest descriptor fields (stride 4, 32-bit format, identity dst_sel,
no swizzle, num_records = element count) stay the caller's guarantee;
the doc lists them.

Tests: native_global_srv_heap_replay_check.py section 10 records,
compiles (twice, frontend cache hit) and replays the typed load on the
R32_UINT slot, checks the cross-slot mismatch and two refused
selections, and ten compile refusals.

Refs R0Y00#3023

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

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Reviewed 9521d13d on cpp-migration b405cf71 (integration ad6be657). I rebuilt compile_dxil, native_global_srv_heap_replay and native_store_replay, then ran ctest --preset <dev|release> --no-tests=error -V -R '^(native_global_srv_heap_replay_(hardware|warp)|native_mtbuf_hardware|native_direct_container|compute_load_format_controls)$'. Each preset gave four passes and one WARP 77 skip for four-lane waves. RTX 4060 Laptop, driver 32.0.16.1656, Windows 11 26200.9974, SDK 10.0.26100, WARP 10.0.26100.9818, heap replay debug layer off. Typed slot 3 matched the captured data on the GPU and in offline replay, the warm frontend cache hit, and the wrong-slot comparisons and malformed metadata controls refused or mismatched as expected. Hosted Windows, Linux and gfx1013 passed. Scope is the single-channel R32_UINT fixture and the documented offline contract. Mixed selection and the runtime view validation stay in #3023.

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.

2 participants