Skip to content

shader: lower bounded per-lane heap record indices in compute waterfalls (#2644 T3) - #2861

Merged
pigalot merged 6 commits into
R0Y00:mainfrom
stan495:startup/compute-waterfall-heap-record
Nov 28, 2026
Merged

pigalot merged 6 commits into
R0Y00:mainfrom
stan495:startup/compute-waterfall-heap-record

Conversation

@stan495

@stan495 stan495 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Completes T3 of #2644 (per-lane resource-heap record indexing inside a compute v_readfirstlane_b32 waterfall loop). Refs #2644.

Summary

  • Translator (tools/startup/gfx2hlsl.py):
    • Added sound forward CFG VGPR upper-bound tracking (vgpr_heap_bounds) over explicit bounding forms (v_and_b32, v_min_u32, v_bfe_u32, v_lshrrev_b32, pre-shifted v_lshlrev_b32 ..., 5, and v_mov_b32) with strict EXEC handling across branches/merges (RESHEAP_RANGE_MAX = 1024).
    • Extended waterfall_refusal / waterfall_heap_check and Stage.heap_record / Stage.scalar (_complete_resheap_carry) to lower bounded resheap record loads (s_lshl_b32 ..., 5 + s_load_dwordx4 s[...], s[heap:0], sOff and the adjacent 64-bit s_add_u32 + s_add_u32 ..., 0, src_scc / s_addc_u32 carry form) to ByteAddressBuffer rh[N] : register(t0, space2); indexed via rh[NonUniformResourceIndex(...)], publishing resheap <N> 2 in compute manifests while refusing unbounded indices, modified descriptors, non-resheap pointers, exit-live scalars, and store/formatted/idxen accesses.
  • Runtime (src/startup_stubs/translated_sampler_bindings.h, d3d12_compute_dispatch.inl, d3d12_draw.inl, d3d12_xs_device.cpp):
    • Extended create_translated_root and ComputeTranslation to accept resheap <N> <space> (space 2, up to 1024 entries), validate every reachable descriptor 0..N-1 in pass.title_view_heap (also tracking title_view_heap_entries so stride-64 devices cannot accept out-of-range descriptor indices by byte size), and bind all N raw SRVs before Dispatch (refusing cleanly beforehand on short-range heaps or invalid descriptors).
  • Tests (tests/startup_compute_waterfall_heap_check.py, tests/compute_check.cpp, tests/startup_stream_consumer.cpp, CMake/CI fragments):
    • Retained the four-record oracle (reference, static-switch, first-active producing 12/25 mismatches, no-marker) via --compute-waterfall-oracle.
    • Added independent DXC cs_6_0 DXIL nonUniformIndex metadata verification (NonUniformResourceIndex present vs omitted).
    • Added end-to-end stand-in Dispatch tests for both direct-offset and 64-bit carry forms across all five oracle key patterns and partial active counts, plus a short-range control (3-descriptor heap omitting highest record 3) that refuses before Dispatch.

Verification

Commit tested: c15baa0b (rebased cleanly on main 6a094052).
Environment: Windows 11 (10.0.26200.9974), DXC 1.8.2502.11, adapters Microsoft Basic Render Driver (WARP) and AMD Radeon RX 7900 XTX (PCI\VEN_1002&DEV_744C, driver 32.0.32029.2010), D3D12 debug layer enabled for stand-in Dispatch checks.

  • Pure-Python & DXIL checks (all passed after final edit):
    • ./out/pe-env/Scripts/python.exe -B tools/run_checks_parallel.py --from-dir tests/checks/python-linux tests/startup_compute_readfirstlane_check.py tests/startup_gfx2hlsl_heap_record_check.py tests/startup_gfx2hlsl_heap_word_check.py tests/startup_gfx2hlsl_compute_check.py tests/bidi_controls_check.py tests/run_checks_parallel_check.py -> all 11 checks passed (startup_compute_waterfall_heap: PASS (translator + 16 refused controls), run_checks_fragments_check ok, bidi_controls_check, etc.)
    • ./out/pe-env/Scripts/python.exe -B tests/docs_links_check.py -> Checked 28 Markdown files and 543 links. passed
    • ./out/pe-env/Scripts/python.exe -B tests/startup_compute_waterfall_heap_check.py --dxil dxc.exe -> PASS (nonUniformIndex true with intrinsic, false without)
  • CTest suite (XBOX2WINDOWS_ADAPTER=7900, after final edit):
    • ctest --preset dev --no-tests=error -R "^(startup_compute_waterfall_heap_|startup_compute_dispatch_heap|startup_translated_sampler_bindings)" --output-on-failure -> 10/10 passed (including startup_compute_waterfall_heap_oracle_warp, startup_compute_waterfall_heap_dispatch_warp, startup_compute_waterfall_heap_oracle_hardware, startup_compute_waterfall_heap_dispatch_hardware, and existing startup_compute_dispatch_heap* / startup_translated_sampler_bindings*).

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comprehensive review of PR for T3 of #2644: bounded per-lane heap record indices in compute waterfalls.

Summary

This PR is a significant and well-designed addition to the compute shader translation pipeline. It enables lowering of bounded per-lane resource-heap record selections in compute waterfalls by:

  1. Forward CFG VGPR bounds tracking to prove per-lane indices are bounded
  2. Extended root signature with a descriptor range (space 2) for up to 1024 resheap SRVs
  3. Runtime pre-bind of all resheap SRVs with strict index validation
  4. Comprehensive refusal paths rejecting unbounded, modified, computed, or non-resheap accesses

Translator Changes (gfx2hlsl.py, ~350 additions)

vgpr_heap_bounds()

Solid forward CFG dataflow over explicit bounding forms (v_and_b32, v_min_u32, v_bfe_u32, v_lshrrev_b32, pre-shifted v_lshlrev_b32, v_mov_b32). Handles EXEC changes correctly by requiring joins on every path after EXEC modifications. The flag propagates through branches and merges. RESHEAP_RANGE_MAX = 1024 caps bounds conservatively.

Key design notes:

  • Work queue (BFS) ensures all successors are visited and merged
  • iterates over register ranges from multi-register destinations
  • Single-register writes preserve bound info; multiple-register writes lose it (safe)
  • Branch targets clear and re-merge states correctly

waterfall_heap_check()

Excellent analysis of the waterfall body between readfirstlane head and s_andn2_wrexec close:

  • Validates s_add_u32 + s_add_u32/s_addc_u32 64-bit carry pairs for extended pointer arithmetic
  • Tracks local_idx / local_off5 / local_ptrs / local_descs through the body
  • Ensures the resource descriptor loaded is the resheap SGPR (not a modified/computed value)
  • Rejects if pending carry is unresolved at close (the loop ends with carry pending)

_complete_resheap_carry()

Handles the second half of the 64-bit carry in the scalar lowering pass. The comparison ensures the carry is right after the add. The check for const(0) on the high word confirms it's a proper 64-bit address formation.

Per-lane index tracking

The dict maps SGPRs to from the waterfall head's readfirstlane. This propagates through mark_heap_index when s_lshl_b32 ... 5 is applied to the per-lane index, creating 'per_lane' heap marks.

The symbol chain is correctly established:
per_lane index → s_lshl_b32 → heap_index[d] = ('per_lane', expr, bound)
→ s_load_dwordx4 → _capture_resheap_desc → sym = ('desc', per_lane, ...)

Runtime Changes (C++)

d3d12_compute_dispatch.inl

  • field parsed from manifest line
  • Validates and
  • now builds vector
  • Iterates over heap SRVs reading each 16-byte record from pass.title_view_heap
  • Validates before reading
  • Rejects indirect Dispatch when heap SRVs are present (correct conservative choice)

d3d12_draw.inl

  • Tracks from the descriptor heap set by slot 32
  • Sets for later validation

translated_sampler_bindings.h

  • New constants: ,
  • signature extended with parameter
  • Descriptor ranges built dynamically with (only includes ranges with non-zero size)
  • Space 2 SRV range starts at offset

Refusal Path Safety

The PR establishes clear refusal paths for unsupported cases:

  • Unbounded per-lane index: returns None → refusal
  • Modified source SGPR: tracked writes discard from local_idx/local_off5
  • Computed descriptor (non-resheap SGPR): load_hit fails
  • Non-resheap pointer:
  • Exit-live scalar: rejected by / checks
  • Formatted/idxen stores: explicitly rejected in
  • Store through resheap: rejected in
  • Indirect Dispatch with heap SRVs: refused before Dispatch

Test Coverage

The new test file (483 lines) is thorough:

  • Oracle mode: tests 5 key patterns + active-lane subsets through d3d12_xs.dll
  • Dispatch mode: end-to-end with debug layer and raw DXIL verification
  • NonUniformResourceIndex metadata checks via DXIL IR parsing
  • Short-range control (3-descriptor heap omitting record 3) that refuses cleanly
  • 64-bit carry form tested alongside direct offset

10/10 tests passed on WARP and hardware (XBOX2WINDOWS_ADAPTER=7900)

Minor Notes

  • The in the test file uses nonUniformIndex only when a bounded per-lane index is detected; scalar/constant indices use direct indexing (correct HLSL behavior)
  • The temporary SGPRs are declared but only emitted if non-empty (clean)
  • The set ensures matching low/high word pairs for 64-bit extended pointers
  • The manifest line emits both count and space, matching the runtime parser

Verdict

This is a well-designed, thoroughly tested implementation. The CFG dataflow analysis is principled and conservative (bounds are only propagated when proven on every path). The refusal paths are comprehensive. The runtime validation provides an additional safety layer. I see no issues that need addressing.

Approved for merge.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comprehensive review of PR for T3 of #2644.

Summary

This PR implements lowered bounded per-lane heap record indices in compute waterfalls. The approach is sound: CFG dataflow bounds tracking, runtime pre-bind of up to 1024 resheap SRVs in space 2, strict index validation, and comprehensive refusal paths.

Translator (gfx2hlsl.py, ~350 lines added)

  • vgpr_heap_bounds(): Forward CFG dataflow over explicit bounding forms (v_and_b32, v_min_u32, v_bfe_u32, v_lshrrev_b32, pre-shifted v_lshlrev_b32, v_mov_b32). EXEC changes handled correctly by requiring joins on every path after EXEC modifications.
  • waterfall_heap_check(): Validates the waterfall body between readfirstlane head and s_andn2_wrexec close. Handles 64-bit carry pairs (s_add_u32 + s_addc_u32). Rejects pending unresolved carries.
  • _complete_resheap_carry(): Handles the second half of the 64-bit carry in the scalar pass. const(0) check on high word confirms proper 64-bit address formation.
  • Per-lane index tracking propagates through mark_heap_index when s_lshl_b32 ... 5 is applied, creating per_lane heap marks.

Runtime (C++)

  • heap_srvs parsed from manifest resheap N space line, validated against max_translated_resheap.
  • record_translated_dispatch iterates heap SRVs reading each 16-byte record from title_view_heap, validates index < title_view_heap_entries.
  • Rejects indirect Dispatch with heap SRVs (correct conservative choice).
  • Descriptor ranges built dynamically with range_count (zero-size ranges omitted).

Refusal paths cover: unbounded index, modified SGPR, computed descriptor, non-resheap pointer, exit-live scalar, formatted/idxen, indirect Dispatch with heap SRVs.

Tests: 483 line test file with oracle/direct/DS modes. NonUniformResourceIndex metadata checks via DXIL IR parsing. 10/10 pass on WARP and hardware.

Verdict: Well-designed implementation with thorough refusal paths. No blocking issues.

Approved for merge.

@thepatrickworld

Copy link
Copy Markdown
Contributor

Second-site reproduction on a different AMD generation (RX 9070 XT, RDNA 4): all four waterfall-heap entries pass (two WARP, two hardware), and the fixture has no negative control for the pre-loop stride

Not a code change; measurements only.

Environment

  • Windows 11 25H2 10.0.26200.9974; MSVC 19.44.35230, BuildTools 14.44.35207; DXC 1.9.2602.17 from the 10.0.26100.0 kit (path read from the build's CMakeCache.txt).
  • Adapter AMD Radeon RX 9070 XT (vendor=1002 device=7550), driver 32.0.32029.2010.
  • dev preset with -DINTAKE_PYTHON on a shared venv; startup_stream_consumer and offscreen_check built from c15baa0b; tracked tree empty (git status --porcelain --untracked-files=no) before and after every run.
  • D3D12 debug layer not installed: Get-WindowsCapability reports NotPresent for Tools.Graphics.DirectX and d3d12SDKLayers.dll is absent, so no layer message can appear in any of these runs.

Commands

set "XBOX2WINDOWS_ADAPTER=AMD Radeon RX 9070 XT"
ctest --preset dev --no-tests=error -V -R "^startup_compute_waterfall_heap_(oracle|dispatch)_(warp|hardware)$"

Three consecutive runs, twelve executions, exit 0 each.

Observed

4 of 4 passed on every run. The fixture's own lines:

startup_compute_waterfall_heap_oracle (warp): PASS {'reference': (25, 0), 'static-switch': (25, 0), 'first-active': (13, 12), 'no-marker': (25, 0)}
startup_compute_waterfall_heap_oracle (hardware): PASS {'reference': (25, 0), 'static-switch': (25, 0), 'first-active': (13, 12), 'no-marker': (13, 12)}
startup_compute_waterfall_heap_dispatch (warp): PASS (direct + carry64 translated, DXIL nonUniformIndex verified, all 7 key/active readbacks matched, short-range control refused)
startup_compute_waterfall_heap_dispatch (hardware): PASS (direct + carry64 translated, DXIL nonUniformIndex verified, all 7 key/active readbacks matched, short-range control refused)

The (13, 12) signature that the comment in check_oracle documents as lane-0 scalarisation for the RX 7900 XTX reproduces on RDNA 4, while WARP still reports (25, 0); the mechanism is inferred from that signature, not read back per lane. A passing run prints neither the adapter nor the layer, so I replayed check_oracle(dxc, offscreen_check, 'hardware') with subprocess.run wrapped (it still executes the child) and recorded the child's stdio; all four variants report

adapter=AMD Radeon RX 9070 XT vendor=1002 device=7550
driver=32.0.32029.2010

so the (13, 12) above came from the card and the (25, 0) from WARP.

The fixture has no negative control for the pre-loop stride

The probe below builds the fixture's own programs and only asks for translation; no device is involved. Baseline:

pre-loop v_lshlrev_b32 5 (fixture form)      -> ACCEPTED: ['h0 = (s22 >> 5);'] | 'resheap 4 2'
pre-loop v_lshlrev_b32 4 (stride 16, wrong)  -> REFUSED: compute readfirstlane waterfall: per-lane descriptor selection requires a proven bound heap range
in-body s_lshl_b32 4 (fixture 'wrong shift') -> REFUSED: compute readfirstlane waterfall: per-lane descriptor selection requires a proven bound heap range

The guard is there and sound; nothing tests it in the pre-loop form. One-line mutation of tools/startup/gfx2hlsl.py ((shift & 31) == 5 becomes in (4, 5); applied with count(old) == 1 asserted, sha256 printed before and after, M tools/startup/gfx2hlsl.py visible in git status during the run, restored with git checkout --, tree empty afterwards):

pre-loop v_lshlrev_b32 4 (stride 16, wrong)  -> ACCEPTED: ['h0 = (s22 >> 5);'] | 'resheap 4 2'

The emitted line is unchanged (h0 = (s22 >> 5);) while s22 is 16·i, so the descriptor index collapses to floor(i/2): for indices 0–3 it yields 0, 0, 1, 1, so three of the four lanes read a different record and records 2–3 are never selected. That is read off the emitted HLSL; the mutated program was not dispatched. The manifest still says resheap 4 2 because it carries the proven bound and space, not the stride — it is not evidence that the index is right.

No fixture entry exercises a pre-loop stride other than 5, so relaxing the guard changes no verdict: under the mutation the four entries still pass, 4 of 4, exit 0, WARP and card. The existing wrong shift control only feeds the in-body scalar form (s_lshl_b32 s23, s22, 4), which the mutation leaves refused.

A control of the same shape as the accepted pre-loop case would close it:

('wrong pre-loop shift',
 build_program(bound=(MASK_AND3, ('v_lshlrev_b32_e32 v5, 4, v5', '840a0a34')),
               body=(*CARRY_ADD_S22, WAIT_LGKM, BODY_LOAD, WAIT_VM)),
 'per-lane descriptor selection requires a proven bound heap range'),

840a0a34 because the fixture's encodings read 850a0a34 for the shift of 5 (bytes are imm, vsrc1 << 1, vdst << 1, 0x34); the pair is passed as a literal tuple, since row_pair would need the line added to ENCODINGS first.

Limits

  • One adapter (RDNA 4), one driver, one preset, one session. The pr test preset does not select these entries and the dev job runs them with -E '_hardware$' (.github/workflows/windows.yml:494), so the two _hardware entries run in no CI job.
  • One mutation, one relaxation ((4, 5)): shifts 3 and 6, and the src1 == dst condition, were not tried, and with the mutation in place I re-ran the four entries of this family, not the suite.
  • The no-marker tuple is a diagnostic, not an assertion: the fixture accepts (25, 0) or (13, 12) on either adapter, so that entry cannot fail on this point and does not pin the split.
  • The dispatch fixture's short-heap refusal and descriptor-range validation print nothing on success; what that entry covers is read from the fixture source, not observed.
  • The wrong-record effect above is source-level only: the mutated translator never dispatched a program.
  • I did not audit the CFG bound tracking (vgpr_heap_bounds) itself, only whether the stride guard has a witness.

AI-assisted.

@stan495

stan495 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the second-site RDNA 4 (\AMD Radeon RX 9070 XT) verification and for catching the missing pre-loop stride negative control.

Added the \wrong pre-loop shift\ control (\�_lshlrev_b32_e32 v5, 4, v5\ / \840a0a34\ in \ENCODINGS, checked by \check_translator\ and \llvm-mc-15) in commit \ee6edd60:

  • Verified relaxing (shift & 31) == 5\ to (shift & 31) in (4, 5)\ now fails \ ests/startup_compute_waterfall_heap_check.py\ at \wrong pre-loop shift.
  • Re-ran .\out\pe-env\Scripts\python.exe -B tests/startup_compute_waterfall_heap_check.py --dxil dxc.exe\ (\ ranslator + 17 refused controls\ and DXIL
    onUniformIndex\ checks pass), \ctest --preset dev --no-tests=error -R '^startup_compute_waterfall_heap_'\ (4/4 pass on WARP and \AMD Radeon RX 7900 XTX, D3D12 debug layer enabled), \ ools/run_checks_parallel.py -j 4 --from-dir tests/checks/python-linux\ (5/5 pass), \ ests/bidi_controls_check.py, and \ ests/docs_links_check.py.

@thepatrickworld

Copy link
Copy Markdown
Contributor

Independent re-check of the new control on ee6edd60 — translator only, no device

Not a code change; measurements only.

What the commit touches

git show --numstat --format= ee6edd60 gives 5 0 tests/startup_compute_waterfall_heap_check.py: five insertions, no deletions. The parent file is therefore this fixture minus exactly those five lines — the four-line wrong pre-loop shift control (297-300) and the 840a0a34 entry (93). git diff c15baa0b ee6edd60 -- tools/startup/gfx2hlsl.py is empty, so the translator behind the earlier RDNA 4 receipts is the same one on this head.

Does the added control bite?

One worktree, same fixture path, git status --porcelain --untracked-files=no empty before and after, the guard line restored at the end:

new fixture,    clean translator  exit 0  startup_compute_waterfall_heap: PASS (translator + 17 refused controls)
new fixture,    guard relaxed     exit 1  AssertionError: wrong pre-loop shift: accepted, expected a refusal naming
                                          'per-lane descriptor selection requires a proven bound heap range'
parent fixture, guard relaxed     exit 0  startup_compute_waterfall_heap: PASS (translator + 16 refused controls)
parent fixture, clean translator  exit 0  startup_compute_waterfall_heap: PASS (translator + 16 refused controls)

The relaxation is (shift & 31) == 5 -> (shift & 31) in (4, 5) at line 2300, applied with count(old) == 1 asserted and the sha256 of gfx2hlsl.py printed before and after (512dc074c56641bd6f38600ad68a0377d22cf5872813c76e27cde28a087bc992 -> 710c2b77e60865bc8b86ce027a1ce390639c6440ef36a689015b1cb3bf6870d8), with M tools/startup/gfx2hlsl.py in git status during the run.

What that pair of runs does not say

The control loop aborts on the first failure (332-336), and the added control is the seventh of the sixteen entries, so under the relaxation the nine entries after it and the trailing root_blob refusal (337-338) were never exercised in that run. What carries "only one witness" is the parent run: fifteen entries plus that trailing refusal, all passing under the same relaxed guard, on a file that differs by exactly the five lines above. Neither run says anything about controls outside this file.

What the relaxed guard accepts

Same fixture imported, translation only, no device:

clean    pre-loop v_lshlrev_b32 5 (accepted form)  -> ACCEPTED: ['h0 = (s22 >> 5);'] | 'resheap 4 2'
clean    pre-loop v_lshlrev_b32 4 (stride 16)      -> REFUSED: ... requires a proven bound heap range
relaxed  pre-loop v_lshlrev_b32 5                  -> ACCEPTED: ['h0 = (s22 >> 5);'] | 'resheap 4 2'
relaxed  pre-loop v_lshlrev_b32 4 (stride 16)      -> ACCEPTED: ['h0 = (s22 >> 5);'] | 'resheap 4 2'
relaxed  in-body s_lshl_b32 4 ('wrong shift')      -> REFUSED: ... requires a proven bound heap range

The accepted pre-loop case (253) and the new control (297-300) are the same build_program call with the immediate 5 against 4, so the pair is a one-operand change. The emitted HLSL is identical in both cases: the head register is indexed with a hard-coded (s%d >> 5) (5913), so the shift moves the value upstream rather than the emitted expression. With the pre-loop shift at 4 the offset register is s22 = i << 4, hence s22 >> 5 = floor(i/2) (0, 0, 1, 1 for i = 0..3), and the same s22 is added to the heap base in the pointer add (s_add_u32 s24, s8, s22), so the descriptor address becomes base + 16i instead of base + 32i. Both indices are wrong; the relaxed program was never dispatched.

The in-body form carries its own guard, ops[2] == '5' at 3180, which this relaxation does not touch — that is why wrong shift still refuses under it.

Where this check runs

ctest --preset dev -N -R "^startup_compute_waterfall_heap" lists four entries on this head, 2416-2419 (oracle/dispatch x warp/hardware). The translator check is not one of them: it is registered as a tools/run_checks_parallel.py --from-dir tests/checks/python-linux fragment (tests/checks/python-linux/startup_compute_waterfall_heap.txt). LLVM_MC_EXECUTABLE is absent from out/build/dev/CMakeCache.txt, so the --llvm-mc reassembly loop (340-351) is inactive here and 840a0a34 was not assembled. Read off the table instead: both words share the opcode byte 34 and the register bytes 0a 0a, and only the byte that carries the immediate differs, 84 against 85 — the same byte that holds 83 in MASK_AND3 (v_and_b32_e32 v5, 3, v5). I did not decode either word with an assembler, so I do not claim the operand fields are v5/v5. The two additions are coupled anyway: row_pair looks the control's line up in ENCODINGS (161), so dropping the encoding entry alone would raise KeyError.

Environment

Windows 11 25H2, build 26200.9974, CPython 3.15.2 from out/pe-env. DXC_EXECUTABLE is set in the cache but this entry never calls it; nothing touched an adapter or a debug layer — the check imports the translator and nothing else.

Limits

  • One head, one relaxation. Shifts 3 and 6, the single-register conjunct (rs[1] == rs[2]), and the 'idx' provenance conjunct (regs[rs[1]][0] == 'idx', 2301) were not tried.
  • The relaxed program was never dispatched; the effect above is read off the emitted HLSL and the operand arithmetic.
  • I re-ran this file's check only, not the suite.
  • I did not audit vgpr_heap_bounds itself.

AI-assisted.

@tedin7

tedin7 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

This PR now conflicts with main. Conflicting files:

  • tests/startup_stream_consumer.cpp
  • tools/startup/gfx2hlsl.py

Could you merge main into your branch (a merge commit, no force push needed) and resolve these? Thank you.

AI-assisted; commands listed were executed locally. (git merge-tree origin/main <head>)

…erfall-heap-record

# Conflicts:
#	tests/startup_stream_consumer.cpp
#	tools/startup/gfx2hlsl.py
@stan495

stan495 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@tedin7 Merged main (805d7df7) into startup/compute-waterfall-heap-record as merge commit 75d5c13d (no force push) and resolved the conflicts in tests/startup_stream_consumer.cpp and tools/startup/gfx2hlsl.py.

Local verification on 75d5c13d:

  • cmake --build --preset dev --target d3d12_xs_shim startup_stream_consumer offscreen_check: passed
  • tests/startup_compute_waterfall_heap_check.py (translator + 17 refused controls, and --dxil) plus startup_gfx2hlsl_heap_record_check.py, startup_gfx2hlsl_compute_check.py, startup_compute_image_store_check.py, startup_compute_translate_check.py, and startup_shader_cache_key_check.py: passed
  • ctest --preset dev -R ^startup_compute_waterfall_heap_: 4/4 passed (oracle/dispatch x warp/hardware)
  • ctest --preset dev on startup_compute_dispatch_warp, startup_compute_dispatch_heap_warp, startup_compute_dispatch_heap_word_warp, startup_compute_image_store_warp, startup_compute_root_srv_dispatch_warp, startup_compute_dispatch_texture_warp, startup_compute_dispatch_input_warp, and startup_compute_dispatch_array_warp: 8/8 passed

…erfall-heap-record

# Conflicts:
#	src/startup_stubs/d3d12_compute_dispatch.inl
#	tools/startup/gfx2hlsl.py
@tedin7

tedin7 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Heads-up: #3083 (comparison samplers in the published compute manifest reader) just landed, and this PR now conflicts with main in src/startup_stubs/d3d12_compute_dispatch.inl only. Could you merge main into your branch (a merge commit is fine) and keep both changes? I will run the Windows tests on the new head and review it then.

Command: git merge-tree --write-tree origin/main pull/2861/head.

AI-assisted; commands listed were executed locally.

Resolved conflicts:
- src/startup_stubs/d3d12_compute_dispatch.inl
- tests/startup_stream_consumer.cpp
@pigalot

pigalot commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Merged main 8007a539 into this branch as 0656c2bf, a fast-forward from 12ba9764. There was no rebase and no force-push.

Conflicts and how they were resolved.

  • src/startup_stubs/d3d12_compute_dispatch.inl, manifest reader. This branch adds the resheap %u %u line and a smpc refusal ("a comparison sampler"). main now reads smpc lines as comparison static samplers. I kept the resheap branch, dropped the smpc refusal and took main's sampler comment, so a smpc line is decoded as it is on main.
  • src/startup_stubs/d3d12_compute_dispatch.inl, View declaration. This branch drops the fixed views[40] array for a std::vector<View> sized count + heap_srvs. main makes View::desc a union of the SRV and UAV descriptions and replaces the == 40 size assert with >= ViewRecord::{srv,uav}_desc_bytes. I kept the vector and took main's union and both asserts. Nothing in this branch's new code writes desc, so the heap SRV views leave it value-initialized.
  • tests/startup_stream_consumer.cpp, dispatch_slot67. I kept main's pixel, write_zero and widened groups selection, plus this branch's heap_waterfall flag and mem_bytes allocation (0x60000 for heap waterfall, otherwise main's 0x30000/0x20000).

git diff --check origin/main...HEAD is clean.

What I ran. I built everything in dev and in release (/O2). Then I ran

ctest --test-dir out/build/<preset> --no-tests=error -j 8 -R '^(startup_compute_.*|startup_slot67_.*|startup_sampler_comparison)$' -E '_hardware$'
python with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_compute_.*|startup_slot67_.*)_hardware$'
  • Non-hardware: 97/97 pass in Debug and in Release. Two are capability skips (exit 77) because WARP has no 32-lane waves: startup_compute_descriptor_scc_warp and startup_compute_dispatch_native_warp.
  • _hardware: 74/74 pass in Debug and in Release, with no skips.

Both runs include this branch's startup_compute_waterfall_heap_{oracle,dispatch}_{warp,hardware} and main's startup_sampler_comparison.

This needs a re-review by someone else; I won't review or merge it myself.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0 DXC (the one CTest picked up); Python 3.12.10.

This reply was AI-assisted.

@pigalot pigalot 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.

I reviewed 0656c2bf (c's merge of main) merged over main c827d8ba. That merge was clean (tree e4705363) and git diff --cached --check was clean.

Main has moved since. main 5033d2d3 (#2862) now conflicts with this PR in tests/startup_stream_consumer.cpp, in dispatch_slot67:

  • #2862 sizes the allocation with long_run ? 0x28000 + long_records * sizeof(UINT) : ..., and moves between to 0x28000 for its long-run modes.
  • This PR sizes it with heap_waterfall ? 0x60000 : ..., and puts the four heap record buffers at 0x20000 + rec * 0x10000.

The modes don't overlap, so I expect the resolution to keep both. But this needs another merge of main, and that merge needs its own review. d3d12_compute_dispatch.inl auto-merges with #2862; I have not tested that combination.

c's earlier resolution. I checked git show --remerge-diff 0656c2bf. In d3d12_compute_dispatch.inl it keeps both sides: main's changes and this PR's resheap manifest line, the count + heap_srvs view vector, and the heap-record loop.

What I traced.

  • vgpr_heap_bounds proves a per-lane index bound from v_and/v_bfe/bounded copies. It joins bounds across CFG edges (both sides must be bounded) and drops them under a narrowed EXEC.
  • waterfall_heap_check accepts the readfirstlane waterfall only when the heap base SGPR is not written in the body, and only when root flag 0x400 is set.
  • The emitted access is rh[NonUniformResourceIndex(...)].
  • At runtime, the manifest resheap <base> <count> line adds a third descriptor range in space 2. Each record must fall inside title_view_heap_entries, or the dispatch is refused.

What I ran. I built dev and release, then ran:

ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R 'startup_(compute|gfx2hlsl)' -E '_hardware'
python .agentic\scripts\with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R 'startup_(compute|gfx2hlsl).*_hardware'
  • Non-hardware: 369/369 pass in both Debug and Release /O2. Two tests skip with 77, the same as on main: startup_compute_descriptor_scc_warp and startup_compute_dispatch_native_warp.
  • Hardware: 190/190 pass in both presets.
  • Translator mode: tests/startup_compute_waterfall_heap_check.py passes, both with and without --dxil. ctest doesn't register this mode, and it runs only in the Linux CI job.
  • Negative control: on main bf1bc769, the PR's check fails in translator mode with "per-lane descriptor selection requires a proven bound heap range". The --dispatch mode has no heap-waterfall case in main's startup_stream_consumer.

Runtime mutants. Each was rebuilt in dev, then I ran startup_compute_waterfall_heap_*:

Mutant Result
heap entry count not checked against title_view_heap_entries killed (refused later, with a different reason)
last heap record skipped killed (direct case 0, word 3: got 0, expected 0xfd3)
heap views created as UAVs killed (device removed, DXGI_ERROR_INVALID_CALL)
heap range placed in space 0 killed (pipeline creation fails)

Translator mutants. I ran each against the translator check, with and without --dxil:

Mutant Result
bound accepted under a narrowed EXEC killed
CFG join keeps a one-sided bound killed
v_bfe bound one low killed
NonUniformResourceIndex dropped killed
root flag 0x400 not required killed
heap base SGPR written in the body accepted (body_writes check removed) survives
v_mov copy of an unbounded VGPR treated as bounded survives

Restored afterwards; git diff --quiet is clean.

Non-blocking.

  1. No control for a copy of an unbounded VGPR. I probed with v_mov_b32 v5, v9 as the index source and no bound on v9. The PR refuses it, and with v_and_b32 v9, 3, v9 first, it accepts it (resheap 4 2). But with the copy rule loosened, nothing in the check fails. A controls entry for the unbounded copy would pin this.
  2. The body_writes guard looks redundant. With it removed, the same probe (s_mov_b32 s8, 0 in the body) is still refused by an earlier check. So the surviving mutant is not a gap in coverage. It may still be worth keeping as defence in depth.
  3. The translator controls are Linux-CI-only. The 17 translator controls run only in Run platform-independent Python checks on Linux; Windows ctest runs only --oracle and --dispatch. Registering the translator mode in ctest would let local runs catch translator regressions too.

Verdict: approve on 0656c2bf. It can't merge until the conflict with #2862 is resolved, and that merge needs re-review.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088 and WARP, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10, wave32; I did not check the debug-layer status.
CI: Build and test on Windows passes on 0656c2bf.

This reply was AI-assisted.

@pigalot

pigalot commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

I merged main 240e0fb9 into this branch as 8a133409, a merge commit on top of 0656c2bf. There was no rebase and no force-push.

Conflicts and how they were resolved. Both were textual. In each case I kept both sides.

  • tests/startup_stream_consumer.cpp, dispatch_slot67: this PR's dispatch-heap-waterfall mode and main's dispatch-input-snapshot-long modes changed the same two lines. Each picks a different allocation size, and the modes are mutually exclusive:
    • the allocation is now heap_waterfall ? 0x60000 : long_run ? 0x28000 + long_records * sizeof(UINT) : (indirect || root_srv) ? 0x30000 : 0x20000;
    • this PR's record-buffer block is kept, followed by main's between = memory + (long_run ? 0x28000 : 0x8000).
  • tools/startup/gfx2hlsl.py:

git diff --check is clean.

What I ran on 8a133409. I did a full build of dev and release, then ran:

ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^(startup_|compute_)' -E '(startup_audio|_hardware)'
python .agentic\scripts\with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_|compute_).*_hardware$' -E 'startup_audio'
  • Non-hardware: 994 tests per preset. 983 pass and 11 skip with 77, all capability skips:
    • 5 WARP;
    • 3 addrlib;
    • startup_run_sh;
    • 2 startup_gameinput_*.
  • Hardware: 471/471 pass in both presets, including startup_compute_waterfall_heap_* and main's startup_compute_dispatch_input_*.
  • I did not run the startup_audio_* tests.

Because I pushed this merge, I won't review or merge it myself. It needs a re-review by someone else.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088 and WARP, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Windows SDK 10.0.28000.0 DXC, Python 3.12.10, wave32; I did not check the debug-layer status.

This reply was AI-assisted.

@pigalot pigalot 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.

Retested 8a133409 (f's merge of main 240e0fb9) integrated over current main 6a1968a1. The merge is clean (tree 1a829b53) and git diff --cached --check is clean.

The main merge in 8a133409. I checked it with git show --remerge-diff 8a133409. All three conflicts keep both sides:

  • tests/startup_stream_consumer.cpp, dispatch_slot67: the allocation is now heap_waterfall ? 0x60000 : long_run ? 0x28000 + long_records * sizeof(UINT) : (indirect || root_srv) ? 0x30000 : 0x20000, and between keeps #2862's long_run ? 0x28000 : 0x8000. The PR's four heap record descriptors are unchanged. heap_waterfall (dispatch-heap-waterfall*) and long_run (dispatch-input-snapshot-long or keep_closed) come from different modes, so the two sizes never meet.
  • tools/startup/gfx2hlsl.py, waterfall detection: this branch's waterfall_refusal(..., vbounds) call is kept, and the pre_sub mask-subset dataflow from #2877 follows it unchanged.
  • tools/startup/gfx2hlsl.py, SRV declarations: main's texcube entry is kept, followed by this branch's rh[] resource-heap declaration.

Apart from those three hunks, the PR's diff against its merge base is the same as at 0656c2bf. So the earlier review of 0656c2bf, with its traced bounds proof, negative control and runtime mutants, still covers the code.

What I ran.

  • Builds: full dev and release /O2.
  • Translator mode: python -B tests/startup_compute_waterfall_heap_check.py passes (translator plus 17 refused controls).
  • CPU: ctest --test-dir out/build/<preset> --no-tests=error -j 8 -R '(startup_compute_waterfall|startup_compute_dispatch|startup_gfx2hlsl_|compute_check|stream_consumer|startup_flat_param|ps_raw_descriptor)' -E '(_hardware$|startup_audio)' gives 285 tests in each preset: 284 pass, 0 fail and 1 is a capability skip (startup_compute_dispatch_native_warp, which the review of 0656c2bf also saw skip on main).
  • Hardware: under the GPU lock, ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(startup_compute_waterfall_heap_.*|startup_compute_dispatch.*|startup_flat_param)_hardware$' passes 14/14 in each preset, with no skips. That includes startup_compute_waterfall_heap_oracle_hardware, startup_compute_waterfall_heap_dispatch_hardware and the 11 startup_compute_dispatch_*_hardware tests that share dispatch_slot67.
  • Full suite: ctest --test-dir out/build/dev --no-tests=error -j 8 -E '(startup_audio|_hardware$)' gives 2042 tests: 1982 pass, 0 fail and 60 are capability skips.

Verdict: approve on 8a133409.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; wave32; debug layer off.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on 8a133409.

This reply was 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.

5 participants