Skip to content

native: read the byte-address rewrite of a GPU-selected heap descriptor - #3025

Merged
R0Y00 merged 2 commits into
R0Y00:cpp-migrationfrom
JB2WIN:native/compute-heap-view-contract
Nov 27, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:cpp-migrationfrom
JB2WIN:native/compute-heap-view-contract

Conversation

@JB2WIN

@JB2WIN JB2WIN commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Change

Target branch cpp-migration. Refs #3023, part of #2935 (follow-up to #2908 / #2972).

Under the raw_buffer heap view contract, the direct compute path now reads the byte-address rewrite of a GPU-selected heap descriptor. byte_descriptor_field already models this rewrite for table descriptors: stride (s_bfe_u32 ... 0xe0010), s_max_u32 ... 1, byte count (s_mul_i32), stride cleared (s_and_b32 ... 0xc000ffff), raw out-of-bounds mode (s_and_b32 ... 0xcfffffff, s_or_b32 ... 0x30000000), word 0 copied. With this PR it also accepts the words of a heap descriptor load. A raw load through the rewritten descriptor reads the same ResourceDescriptorHeap[slot] raw view that #2972 binds.

  • src/gfx1013_compute_native.cpp: parse and transfer take heap_window, which translate_program sets to direct_dxil && heap_view == raw_buffer and passes on to byte_descriptor_field. The HLSL route (direct_dxil == false, numeric heap_stride_srv) and the graphics route keep the default false, so they are unchanged.
  • src/gfx1013_direct_compute.inl, heap_resource:
    • It accepts byte_window_srv. The four words must come from one heap load (same pc, word types indexed_descriptor, zero_stride_word, byte_count, byte_oob).
    • As a precaution, a backward branch whose loop contains the heap load refuses the window: "heap byte window loaded inside a loop". Such a loop would run the same load again for another selection while the symbols stay equal. Loops elsewhere do not refuse it.
  • src/gfx1013_compute_native.h: the HeapViewContract comment states the caller's part. Every slot the program can select must be a raw view of exactly num_records * max(stride, 1) bytes. The translator does not check that size, the swizzle bits (word 1 bits 31:30) or the other word 3 fields.
  • Without a contract nothing changes, so the first refusal stays as before.

Why this step: compile_dxil --refusals over a local start-up capture (2,689 slot 67 requests, counts only) gives 941 first refusals direct resource-heap load requires the selected GPU slot and its view type. It is the largest compute refusal. Local prototype runs with the contract forced through an uncommitted switch (not reproducible from the repo) give these counts:

Run Requests stopping there Refusal
Contract only 929 the stride read
Contract plus this rewrite tracking 906 buffer_load_format through the heap descriptor (a typed heap load, a GPU-selected heap slot is read as a raw buffer SRV only)

No additional request compiles yet. This is one step of the chain, and typed heap loads are the next wall. In those programs the slot index comes from buffer data per wave, so the runtime cannot resolve it at Dispatch. Passing a contract from the runtime needs a check over all selectable slots (stage 2 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, D3D12 debug layer not enabled. Base 999e17cd.

cmake --preset dev
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
  • Build: exit 0, no warning C in the touched files.
  • native_global_srv_heap_replay_hardware: passed, 84 assertions (70 before).
    • New shapes, refused with no .cso:

      Shape Refusal
      wrong stride mask unbound numeric SGPR s21
      word 0 from a second heap load non-contiguous resource descriptor
      store through the window a GPU-selected heap slot is read as a raw buffer SRV only
      never-taken backward branch to the heap load heap byte window loaded inside a loop
    • stride_read now uses the stride as a number (v_mov_b32 v3, s24) and is refused with unbound numeric SGPR s24. This keeps the control that a stride never becomes a number. Before, the bare read was refused only because the rewrite was not modelled.

    • A stride read that nothing uses compiles, and so does a never-taken backward branch after the heap load.

    • The full rewrite is recorded for selections 0 and 1 (output equals the slot's data), compiled with compile_dxil --requests, and replayed with the same result. Replaying selection 0 against the slot 1 reference reports a mismatch.

  • native_global_srv_heap_replay_warp: skipped (77), no 32-lane waves on WARP, as before.
  • Discrimination: the new check run against compile_dxil and the fixture built at 999e17cd fails at stride_read with the old text "a GPU-selected heap slot stride read is not translated with a view contract". With the shapes skipped, it fails at "an unused stride read compiles".
  • Loop guard (second commit 837728dd): the first version refused the window for any backward branch. With the contract forced locally, it refused 921 of the 2,689 requests of the capture. Limited to loops around the heap load, it refuses none of them; 906 then stop at the typed heap load named above. The check run against 7582c01d fails at the window_loop shape (old text). After the change, the regression set, the census with contract none and the 84 assertions give the same results as listed here.
  • Regression set: 147 tests, 142 passed, 4 skipped (77, WARP), 1 failed (native_cvt_pk_u8_hardware). The same set gave the same result at 999e17cd on this machine before the change.
  • compile_dxil --refusals on the local capture: identical output before and after. It translates without a contract.
  • tests/docs_links_check.py and tests/bidi_controls_check.py pass.

Evidence and follow-up

  • Fixture programs are source-built, and their instruction words were assembled with LLVM 15 (clang -cc1as -triple amdgcn-amd-amdhsa -target-cpu gfx1013 -show-encoding).
  • The descriptor words in the fixture are symbolic and never evaluated. A stride above 1 and the size rule of the contract are therefore not exercised, and the doc says so.
  • Docs: docs/experiments/native-global-srv-heap-replay.md.
  • Follow-ups on cpp-migration: pass captured heap view types into the in-runtime native compute route (#2958) #3023:
    • typed heap loads (buffer_load_format_* through a GPU-selected descriptor);
    • scalar loads through a heap descriptor;
    • the runtime side: a shader-visible heap with title slot k at desktop index k as raw views, plus the contract check over all selectable slots.
  • Pre-existing and not changed here: a plain heap read inside a loop has the same equal-symbol property.
  • The old explicit stride refusal in the direct path stays in place. Under raw_buffer it is now reachable only for a stride read into a destination above s105, and no shape covers that case.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

🤖 Generated with Claude Code

Under the raw_buffer heap view contract the direct compute path now tracks
the byte-address rewrite (stride, max 1, byte count, stride cleared, raw
out-of-bounds mode) of a descriptor loaded from the GPU-selected heap slot,
as byte_descriptor_field already does for table descriptors, and reads a raw
load through it as the same ResourceDescriptorHeap[slot] raw view. The words
must come from one heap load; a program with a backward branch refuses the
window as a precaution. Without a contract nothing changes.

Refs R0Y00#3023, part of R0Y00#2935.

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.

Independent review at 7582c01d on cpp-migration 999e17cd. I rebuilt native_global_srv_heap_replay and compile_dxil and ran ctest --preset <dev|release> --no-tests=error -V -R '^native_global_srv_heap_replay_(hardware|warp)$'. Both RTX 4060 Laptop runs (Debug and Release /O2) passed. Each selected slot returned its own 64 words with all eight guards intact in capture and offline replay. The wrong-slot comparison failed at word 0, and the mixed-load, wrong-mask, store and backward-branch controls refused without publishing bytecode. WARP skipped with 77 in both presets because it reports only four-lane waves. Windows 11 build 26200.9974, SDK 10.0.26100, RTX driver 32.0.16.1656 and WARP 10.0.26100.9818, replay debug layer off.

The result covers the offline compiler slice under its raw-view contract. The fixtures use symbolic descriptor words and do not exercise a stride above one or a mismatch between guest byte count and the desktop view. Keep both checks in #3023's runtime acceptance criteria before supplying a raw-view contract for GPU-selected slots.

The first guard refused the window for any backward branch in the program.
On a local start-up capture (contract forced locally) that refused 921 of
2,689 requests, although their loops do not contain the heap descriptor
load. Only a loop around that load runs it again for another selection, so
the guard now checks whether a backward branch's range contains the load pc
(symbol.definition). The test refuses a loop back to the load and compiles a
loop after it.

Refs R0Y00#3023.

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

JB2WIN commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I added both checks to #3023's runtime acceptance criteria (issuecomment-7212816337).

Pushed 837728dd, which narrows the loop guard. The first version refused the window for any backward branch in the program. On the local capture, with the contract forced through an uncommitted switch, that refused 921 of 2,689 requests whose loops do not contain the heap descriptor load. The guard now refuses only a backward branch whose range contains the heap load's pc, because only such a loop runs that load again for another selection.

With the narrower guard, none of those 921 is refused for a loop, and 906 move on to the typed heap load (buffer_load_format_*), the next step on #3023. The test now refuses a loop back to the load and compiles a loop after it (84 assertions). The run against 7582c01d fails at the new loop shape. RTX 3080, driver 32.0.16.2124: the regression set and the census with contract none are unchanged.

AI-assisted.

@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 837728dd on cpp-migration 999e17cd. The narrower guard tests whether a backward edge spans the recorded heap-load definition. The new control compiled when its loop was after the load, and the loop that reaches the load retained the named refusal with no bytecode. I also checked that #3023 now records the stride-above-one and exact desktop-view byte count acceptance criteria.

I rebuilt native_global_srv_heap_replay and compile_dxil and ran ctest --preset <dev|release> --no-tests=error -V -R '^native_global_srv_heap_replay_(hardware|warp)$'. The RTX 4060 Laptop hardware case passed in Debug and Release /O2, including the slot readback and guards. WARP skipped with 77 for four-lane waves in both presets. Windows 11 build 26200.9974, SDK 10.0.26100, NVIDIA driver 32.0.16.1656, WARP 10.0.26100.9818, replay debug layer off. Hosted Windows, Linux Python and gfx1013 checks passed. The approval covers the offline compiler slice.

@R0Y00
R0Y00 merged commit 1507f0e into R0Y00:cpp-migration Nov 27, 2026
5 checks passed
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