Skip to content

native: read GPU-selected heap slots raw and typed in one program - #3063

Open
JB2WIN wants to merge 1 commit into
R0Y00:cpp-migrationfrom
JB2WIN:native/heap-mixed-raw-typed
Open

JB2WIN wants to merge 1 commit into
R0Y00:cpp-migrationfrom
JB2WIN:native/heap-mixed-raw-typed

Conversation

@JB2WIN

@JB2WIN JB2WIN commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Change

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

Programs that read some GPU-selected heap slots raw and others with a one-channel typed load were refused under both heap view contracts: raw_buffer refuses the typed load ("a GPU-selected heap slot is read as a raw buffer SRV only"), typed_dword the raw load ("… read as a typed dword buffer SRV only"). This adds a third contract class for that mixed case.

  • src/gfx1013_compute_native.h: HeapViewContract::raw_and_typed_dword, with its caller guarantee in the comment. The old clause "a program with two heap loads from different selectors is outside what one captured selection covers" is replaced by an explicit limit for every contract.
  • src/gfx1013_direct_compute.inl, heap_resource: under the new contract the kind of each heap load picks the path. buffer_load_format_* (typed_buffer_srv) follows the typed_dword rules, including the one-channel limit. Every other kind, tbuffer_load_format_* through a plain or rewritten descriptor included, follows the raw_buffer rules: raw handle, byte windows and the loop guard. One line of logic changed; refusal texts are unchanged.
  • src/gfx1013_compute_native.cpp: the byte-address rewrite of a heap descriptor is tracked under raw_buffer and raw_and_typed_dword.
  • src/direct_compute_cache.cpp: cache identity /heap-view/raw_and_typed_dword.
  • src/startup_stubs/native_global_srv.h:
    • .views gains zero or more also <slot> <type> lines, each a further selection of the same dispatch. Selector word k is selection k (select/need first). The header stays version 2; an older decoder refuses such a file with unknown line 'also'.
    • The decoder refuses a slot named twice, even with the same type: one selection per selector word.
    • refuse_global_srv_selections() checks every selection in order.
    • global_srv_contract() returns raw_and_typed_dword when raw and typed selections are both present.
  • tools/startup/compile_dxil.cpp: maps the contract with a switch and uses the plural check at both sites. The report line gains also=<slot>:<type>.
  • tests/native_global_srv_heap_replay.cpp:
    • record … [--also SELECTOR TYPE] writes selector word 1.
    • record and replay dispatch every selected slot and compare against the sum of the slot data (N+M reference in replay).
    • replay uses the plural check.
    • A small type_from_argument helper is shared by --need and --also.

Why this step: on a local start-up capture (compile_dxil --refusals, 2,689 slot 67 requests, counts only), 895 of the 906 programs with a typed heap load also read another heap slot raw. With this contract forced by an uncommitted switch, compiled requests go from 392 to 397. The others now stop at general refusals: 717 unbound numeric SGPR sN, 460 direct indexed descriptor load shape, 291 direct descriptor address outside bound table. That is an upper bound for what translation allows. No runtime produces also lines or binds heap slots under a contract yet; that is stage 3 of #3023.

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. Base cpp-migration a0f67731.

cmake --build --preset dev
ctest --preset dev --no-tests=error -R "^native_global_srv_heap_replay_hardware$" -V
ctest --preset dev --no-tests=error -R "native_|startup_compute_dispatch|compute_heap" -j 6
ctest --preset dev --no-tests=error -R "^(compute_heap_view_controls|startup_gfx2hlsl_heap_record|docs_links|bidi_controls)$"
  • native_global_srv_heap_replay_hardware: passed, 174 assertions (122 before), 11.5 s (11.25 s before). New section 11 uses a source-built mixed program: two selector words, a raw buffer_load_dword through one heap descriptor and a buffer_load_format_x idxen through another, with the sum stored.
    • Record for raw slots 0 and 1 with typed slot 3: output equals the sum of the slot data, and .views has also 3 typed_buffer.
    • compile_dxil --requests with a fresh frontend cache: compiled with frontend_cache_hit=0, then =1 with the same .cso.
    • Replay equals the sum. Replay against slots 1+3 for the slot-0 shader reports a mismatch.
    • A typed selection of a raw slot is refused before the dispatch.
    • Three replay refusals, no dispatch: wrong type, unknown slot, texture.
    • Nine compile refusals, no .cso: the mixed program under the raw-only and the typed-only .views; also with a texture, wrong type, unknown slot, unreadable line, or duplicate slot; a missing dword line; a two-channel typed load.
    • Four compile-only cases under the mixed contract: two also lines, a byte window, a formatted byte window, and a plain tbuffer load.
  • Discrimination:
    • The new check run with compile_dxil and the fixture built at a0f67731 passes the 122 earlier assertions and fails at the first mixed record (the old fixture has no --also).
    • The old compile_dxil refuses a mixed .views with unknown line 'also'; the new one compiles it.
    • Mutation 1 (mixed clause of typed set to false): the first mixed record fails.
    • Mutation 2 (mixed contract dropped from the heap-window tracking): the byte-window case under the mixed contract fails.
    • Both mutations were reverted afterwards.
  • Regression set: 147 tests, 3 failed, the same three as at the base on this machine (native_cvt_pk_u8_hardware, native_sdwa_f16_ir, native_sdwa_f16_hardware).
  • compile_dxil --refusals on the local capture without a contract: identical to the base.
  • The four Python checks 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 cannot tell which heap index feeds which load and does not limit the number of heap loads.
    • The caller guarantees the raw_buffer conditions for every slot a raw load can select, and the typed_dword conditions for every slot a typed load can select.
    • A swapped pairing (typed slot read through the raw handle) is undefined and not run on the GPU.
    • tbuffer counts as raw.
  • Next on cpp-migration: pass captured heap view types into the in-runtime native compute route (#2958) #3023: stage 3, the runtime contract (produce the selections and bind the heap slots).

Checklist

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

AI-assisted.

🤖 Generated with Claude Code

A program that reads some GPU-selected heap slots raw and others with a
one-channel typed load was refused under both heap view contracts:
raw_buffer refuses the typed load, typed_dword the raw load.
HeapViewContract::raw_and_typed_dword now lets the kind of each heap
load pick its path: buffer_load_format_* (typed_buffer_srv) takes the
typed_dword rules, every other kind (tbuffer included) the raw_buffer
rules, byte windows included. Which heap index feeds which load stays
the caller's guarantee; the comment and the doc say so.

.views gains zero or more "also <slot> <type>" lines: further
selections of the same dispatch, selector word k = selection k. The
decoder refuses a slot named twice. refuse_global_srv_selections checks
every selection; global_srv_contract returns raw_and_typed_dword when
raw and typed selections are both present. compile_dxil and the fixture
map the contract with a switch, and compile_dxil reports also=<slot>:<type>.
The fixture's record takes --also SELECTOR TYPE (selector word 1),
dispatches every selected slot and compares against the sum of the
slot data (N+M in replay).

Tests: native_global_srv_heap_replay_check.py section 11 records,
compiles (fresh frontend cache, then a cache hit) and replays a mixed
program for raw slots 0 and 1 with typed slot 3, checks a cross-slot
mismatch, a refused typed selection, three replay refusals, nine compile
refusals and four compile-only cases (two also lines, byte window,
formatted byte window, plain tbuffer under the mixed contract).

Refs R0Y00#3023

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

R0Y00 commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thanks for documenting the dependency on #3042. New translator PRs target main, but changing this base today would pull #3034 and #3042 into the same diff. At main ff04a75e, the typed-dword heap contract from #3042 is still absent. Please leave the base here while those prerequisites are carried to main in order, then we can retarget this PR and verify the mixed raw/typed fixture against the new base. The pending runtime capture work stays tracked in #3023.

@JB2WIN

JB2WIN commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Understood, leaving the base on cpp-migration. Once #3034 and #3042 are on main, I will retarget, rebase and rerun the mixed raw/typed fixture (native_global_srv_heap_replay_hardware) plus the regression set against the new base, and report the results here.

AI-assisted.

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