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

Merged
Not-Saii merged 3 commits from upstream-pr/3253 into main 2026-11-28 03:21:49 +00:00
Not-Saii commented 2026-11-28 01:57:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-28T01:57:55Z.


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.

  • 4 of the 12 have both heap flags, and their first refusal moves.
  • The other 8 have only CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED and a single leftover user SGPR. main doesn't bind the heap there; #3221 does. With #3221 they should take the same path. I haven't measured that.

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.

  • #3063 edits the same SMEM heap branch and the heap view contracts. This change calls refuse_heap_contract and produces the same indexed descriptor symbol, so it should follow whichever contracts land. Both PRs add to tests/native_global_srv_heap_replay_check.py (this one at the end), so a rebase conflict is possible there.
  • #3221 is needed for the single-flag layouts and is not duplicated here.
  • The stride and record-count arithmetic after the load is not touched (see RonLogic's SCC claim on #3224).

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

AI-assisted.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5535589838 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3253). Originally posted by [Not-Saii](https://github.com/Not-Saii) on 2026-11-28T01:57:55Z. --- 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. - 4 of the 12 have both heap flags, and their first refusal moves. - The other 8 have only `CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED` and a single leftover user SGPR. `main` doesn't bind the heap there; #3221 does. With #3221 they should take the same path. I haven't measured that. **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. ```powershell 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.** - #3063 edits the same SMEM heap branch and the heap view contracts. This change calls `refuse_heap_contract` and produces the same indexed descriptor symbol, so it should follow whichever contracts land. Both PRs add to `tests/native_global_srv_heap_replay_check.py` (this one at the end), so a rebase conflict is possible there. - #3221 is needed for the single-flag layouts and is not duplicated here. - The stride and record-count arithmetic after the load is not touched (see RonLogic's SCC claim on #3224). `docs/experiments/native-global-srv-heap-replay.md` describes the new section and records these results. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tedin7 commented 2026-11-28 03:20:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-28T03:20:45Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6095400103 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3253#pullrequestreview-6095400103). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T03:20:45Z. **Review:** COMMENTED --- 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 commented 2026-11-28 03:21:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-28T03:21:03Z.


Win2025 WARP receipt for head fb071338 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: fb071338 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7233002071 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3253#issuecomment-7233002071). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-28T03:21:03Z. --- Win2025 WARP receipt for head fb071338 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: fb071338 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!3253
No description provided.