Skip to content

compute: read a resource-heap descriptor at an added byte offset - #3253

Merged
tedin7 merged 3 commits into
R0Y00:mainfrom
Not-Saii:compute/heap-offset-add
Nov 28, 2026
Merged

tedin7 merged 3 commits into
R0Y00:mainfrom
Not-Saii:compute/heap-offset-add

Conversation

@Not-Saii

Copy link
Copy Markdown
Contributor

Refs #3224. Target branch main.

Gap. Some start-up compute shaders read a buffer descriptor from the resource heap in a waterfall loop over a lane-selected slot. They form the descriptor address by adding the slot's byte offset to the heap base, instead of passing the offset as the SGPR offset of the load:

v_readfirstlane_b32 sI, vX
v_cmpx_eq_i32_e32   sI, vX
s_add_u32           sLo, <resource heap>, sI
s_add_u32           sHi, 0, src_scc
s_load_dwordx4      s[D:D+3], s[sLo:sHi], 0x0

The direct path refused the first add as a numeric use of the heap table (unbound numeric SGPR sN). In the census on #3224, this is the largest group left in that family after #3006: 12 wave32 shaders.

Change (src/gfx1013_compute_native.cpp, src/gfx1013_direct_compute.inl):

  • The analysis tracks SCC, but only as the carry of s_add_u32 lo, <resource heap>, <non-constant SGPR>. Every other scalar ALU instruction clears it.
  • s_add_u32 hi, 0, src_scc or s_addc_u32 hi, 0, 0 right after that add marks the high word as its carry.
  • An s_load_dwordx4 with no SGPR offset from exactly that pair becomes the same indexed heap descriptor as the existing SGPR-offset form. It is lowered the same way, slot index = byte offset >> 5, and it goes through the same heap view contract (refuse_heap_contract).
  • These stay refused:
    • a constant offset (still unbound numeric SGPR sN);
    • a high word that isn't the add's carry, or SCC clobbered between the adds (new text: heap descriptor address high word is not the carry of its offset add);
    • an immediate offset on the load, or a second offset register;
    • any width other than s_load_dwordx4.
  • Only the resource heap is matched. Other descriptor tables and the sampler heap are unchanged.

What this does and doesn't do for the start-up shaders. A .c67 request has no view metadata, so these loads now stop at direct resource-heap load requires the selected GPU slot and its view type. That's the resource-heap family of #3023 / #3063. The descriptor rewrite inside the loop would then meet heap byte window loaded inside a loop. None of the 12 compiles because of this PR alone.

Tests. Dev build (Debug), NVIDIA GeForce RTX 4090 (driver 32.0.16.1088), Windows 11 build 26300, Windows SDK 10.0.26100 DXC, D3D12 debug layer not enabled, main 8007a539 plus this change.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R "^(native_heap_offset_add|native_global_srv_heap_replay_warp|native_global_srv_heap_replay_hardware)$" -V
ctest --preset dev --no-tests=error -R "native_|startup_compute|compile_dxil" -j 8
  • native_global_srv_heap_replay_hardware: passed, 118 assertions. The new section 11 of tests/native_global_srv_heap_replay_check.py covers the container route with the raw_buffer contract:
    • the added-address program is recorded, compiled offline and replayed for selections 0 and 1, and each output equals that slot's data;
    • replaying selection 0 against slot 1's data reports a mismatch;
    • without .views it is refused with the heap text;
    • the swapped operand order with s_addc_u32 compiles;
    • a constant offset, s_mov_b32 as the high word, an s_cmp between the adds and an immediate offset are each refused with their own text.
  • native_heap_offset_add (new, compile-only): passed, 5 of 5. It writes a slot 67 request from source with the start-up shaders' entry layout: a table in s4, the resource heap in s5 and the sampler heap in s6, both heap flags, wave32.
    • The added form reaches the heap-contract text, like the SGPR-offset control.
    • The mismatched-high-word, clobbered-SCC and constant-offset controls keep their refusals.
  • native_global_srv_heap_replay_warp: skipped (77). The in-box WARP has no 32-lane waves.
  • Regression: 415 tests, 404 passed, 0 failed, 11 skipped (77, WARP).
  • Before the change: with the compiler sources of 8007a539, the replay fails at its first section 11 assertion (unbound numeric SGPR s2) and native_heap_offset_add fails 3 of 5 (unbound numeric SGPR s5).
  • Mutation: with the high-word check removed from heap_offset_address, the replay fails at added_mov_high and native_heap_offset_add fails mov_high and scc_clobbered.

Captured requests (counts only). I took the 156 slot 67 requests that stop first at unbound numeric SGPR on 7fcde81f, from a local start-up run (runtime 2e12dd8e, 300 s). I ran compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests on them with 8007a539 and with 8007a539 plus this change:

  • both compile 29;
  • exactly 4 first refusals change, all from unbound numeric SGPR s10 to direct resource-heap load requires the selected GPU slot and its view type;
  • the other 152 are unchanged.

A program that compiled before can't contain the heap add, because the add was refused, and SCC is only tracked after such an add. So already translated requests are unaffected by construction.

Overlap.

docs/experiments/native-global-srv-heap-replay.md describes the new section and records these results.

AI-assisted.

🤖 Generated with Claude Code

Not-Saii and others added 3 commits November 28, 2026 03:49
A waterfall loop over a lane-selected heap slot forms the descriptor
address as s_add_u32 lo, <resource heap>, <offset>; s_add_u32 hi, 0,
src_scc (or s_addc_u32 hi, 0, 0); s_load_dwordx4 ..., s[lo:hi], 0x0.
The direct path refused the add as a numeric use of the heap table
("unbound numeric SGPR sN").

Track SCC as the carry of such an add and treat the load from that
exact pair as the indexed heap descriptor of the SGPR-offset form, read
under the same heap view contract. A constant offset, a high word that
is not the add's carry, SCC clobbered between the adds and an immediate
offset on the load stay refused.

Refs R0Y00#3224

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs R0Y00#3224

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

@tedin7 tedin7 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 fb071338 (the PR's own change is the same as bc0d714a; the new head only merges current main).

What I checked:

  • heap_offset_add / heap_offset_carry / heap_offset_address in src/gfx1013_compute_native.cpp: SCC is tracked only as the carry of s_add_u32 lo, <resource heap>, <non-constant SGPR>, it is cleared by every other SOP1/SOP2/SOPC/SOPK instruction, and a CFG join with a different SCC drops it. Anything that does not match stays refused, so the change can only widen what compiles in this exact shape.
  • src/gfx1013_direct_compute.inl: the lowered slot index (low word >> 5) is the same as the existing SGPR-offset heap load next to it, and the new path goes through the same refuse_heap_contract. The add itself writes the offset to the low word and 0 to SCC (write(128, ...)), so the following s_add_u32 hi, 0, src_scc / s_addc_u32 hi, 0, 0 gives a high word of 0, as the slot-0 heap base needs.
  • Tests: native_heap_offset_add (request-level refusals and controls) and section 11 of native_global_srv_heap_replay_check.py, a real D3D12 record/compile/replay with GPU readback for selections 0 and 1 plus the slot-1 mismatch control. The expected outputs are the fixture's slot data, not derived from the translator.
  • No other open or merged PR covers this slice in the direct compute path (#2861 is the gfx2hlsl path).

Commands run:

  • Linux: python3 tests/docs_links_check.py ok, python3 tests/bidi_controls_check.py ok, git diff --check origin/main...HEAD clean, python3 -m py_compile on both test files ok.
  • Windows Server 2025, D3D12 WARP 1.0.22, -R '^native_(heap_offset_add|global_srv_heap_replay_warp|compute_clear|compute_raw_root|descriptor_scc_warp|direct_container|heap_handle_probe_warp|lane_spill_descriptor_warp)$': dev 8/8 passed, release 8/8 passed. native_global_srv_heap_replay_warp ran (not skipped) on this WARP version.
  • Mutation 1 (heap_offset_carry no longer accepts s_add_u32 hi, 0, src_scc): native_heap_offset_add fails at added, native_global_srv_heap_replay_warp fails at the section 11 no-metadata assertion.
  • Mutation 2 (slot index >> 6 instead of >> 5 on the added address): native_global_srv_heap_replay_warp fails at record added select 1.

No blocking findings. The receipt follows in a separate comment.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Win2025 WARP receipt for head fb07133 after updating with main.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit fb071338d4d82b0532b521b8c72bb8a740554840:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target compile_dxil native_global_srv_heap_replay native_store_replay native_heap_handle_probe -- -j 4): 8.82s (configure 1.84s)
    • Test (ctest --preset dev -R '^native_(heap_offset_add|global_srv_heap_replay_warp|compute_clear|compute_raw_root|descriptor_scc_warp|direct_container|heap_handle_probe_warp|lane_spill_descriptor_warp)$' --parallel 5 --no-tests=error --output-on-failure): 8/8 passed (16.03s: native_heap_handle_probe_warp 0.32s, native_compute_clear 0.44s, native_heap_offset_add 0.85s, native_lane_spill_descriptor_warp 1.00s, native_descriptor_scc_warp 1.45s, native_compute_raw_root 1.69s, native_global_srv_heap_replay_warp 6.21s, native_direct_container 15.40s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target compile_dxil native_global_srv_heap_replay native_store_replay native_heap_handle_probe -- -j 4): 34.68s (configure 2.49s)
    • Test (ctest --preset release -R '^native_(heap_offset_add|global_srv_heap_replay_warp|compute_clear|compute_raw_root|descriptor_scc_warp|direct_container|heap_handle_probe_warp|lane_spill_descriptor_warp)$' --parallel 5 --no-tests=error --output-on-failure): 8/8 passed (12.34s: native_heap_handle_probe_warp 0.17s, native_compute_clear 0.25s, native_heap_offset_add 0.30s, native_descriptor_scc_warp 0.68s, native_compute_raw_root 0.77s, native_lane_spill_descriptor_warp 0.36s, native_global_srv_heap_replay_warp 3.73s, native_direct_container 11.89s)
  • sccache: 39/70 hits; wall 60.1s
    tested: fb07133 via fetch (pull/3253/head, no patch)

The new tests native_heap_offset_add and native_global_srv_heap_replay_warp (section 11) ran in both legs.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit bf1bc76 into R0Y00:main Nov 28, 2026
5 checks passed
Leyukaka added a commit to Leyukaka/Xbox2Windows that referenced this pull request Nov 28, 2026
Direct wave64 compute now gives scalar loads the same SGPR bound as
wave32 since R0Y00#3180: destination ranges may end at s107 (VCC_HI), and
VCC_LO/VCC_HI may be the SGPR offset. In the direct wave64 model VCC
is two scalar words that both host wave32 halves hold identically
(ballot writers publish both words through the exchange), so a
uniform numeric load into s106/s107 is read back the same way by
s_mov, v_cndmask and the VCC branches. Table descriptor loads and
resource-heap loads at an added byte offset (R0Y00#3253), which track
descriptor identity or a slot index instead of payload bits, still
refuse when their destination overlaps VCC in wave64. Graphics and ranges past
s107 keep their refusals.

New test native_smem_vcc_wave64 (controls, hardware): x4 and x8 loads
ending at s107, VCC_LO and VCC_HI offsets, and a 64-bit mask loaded
into VCC driving v_cndmask in both host halves under a patterned EXEC.
native_direct_container replaces the wave64 VCC refusals it had with a
symbolic-destination refusal.

native_heap_offset_add gains a wave64 control: an added-offset heap
address loaded into s[104:107] refuses with the overlap message.
R0Y00 pushed a commit that referenced this pull request Nov 28, 2026
Direct wave64 compute now gives scalar loads the same SGPR bound as
wave32 since #3180: destination ranges may end at s107 (VCC_HI), and
VCC_LO/VCC_HI may be the SGPR offset. In the direct wave64 model VCC
is two scalar words that both host wave32 halves hold identically
(ballot writers publish both words through the exchange), so a
uniform numeric load into s106/s107 is read back the same way by
s_mov, v_cndmask and the VCC branches. Table descriptor loads and
resource-heap loads at an added byte offset (#3253), which track
descriptor identity or a slot index instead of payload bits, still
refuse when their destination overlaps VCC in wave64. Graphics and ranges past
s107 keep their refusals.

New test native_smem_vcc_wave64 (controls, hardware): x4 and x8 loads
ending at s107, VCC_LO and VCC_HI offsets, and a 64-bit mask loaded
into VCC driving v_cndmask in both host halves under a patterned EXEC.
native_direct_container replaces the wave64 VCC refusals it had with a
symbolic-destination refusal.

native_heap_offset_add gains a wave64 control: an added-offset heap
address loaded into s[104:107] refuses with the overlap message.
tedin7 added a commit to tedin7/Xbox2Windows that referenced this pull request Nov 28, 2026
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