Skip to content

startup: bind a compute heap record whose index is read from a table buffer - #2580

Merged
tedin7 merged 74 commits into
R0Y00:mainfrom
NiiRoZz:startup/compute-dispatch-heap-bufindex
Nov 26, 2026
Merged

tedin7 merged 74 commits into
R0Y00:mainfrom
NiiRoZz:startup/compute-dispatch-heap-bufindex

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Depends on #2532 (this branch is stacked on it; review the commits after its head).

What changed

  • tools/startup/gfx2hlsl.py: the heap-record index may be a word that s_buffer_load_dword(xN) reads from an unmodified table buffer descriptor, at a literal byte offset or at <root constant word> * k + c (s_mul_i32, s_mulk_i32, s_add_u32, s_add_i32, s_addk_i32 with literals, plus any offset: modifier), dword-aligned, with no branch target between the arithmetic and the load or between the load and the shift. The manifest line is srv <i> buf heap word table <parameter> <byte> at <offset> [rootconst <parameter> <word> times <k>]. Every other buffer-read index keeps a refusal, now worded ... whose index is read from a buffer other than a table buffer at a dispatch-constant offset.
  • src/startup_stubs/d3d12_compute_dispatch.inl: parses the two new forms, reads the table record, computes the byte offset in 32-bit arithmetic, reads the index word and binds the heap record through the existing startup: compute input named by a resource heap record a root constant indexes #2532 path. New refusals, each one logged reason and nothing recorded: a heap index word is not in the list's upload memory (view token or memory outside the list's slot 148 upload allocations) and a heap index word is outside its table buffer (word past stride * num_records bytes, with a stride of 0 counted as 1).
  • tests/startup_stream_consumer.cpp: dispatch-heap-word modes and three controls.
  • tests/startup_gfx2hlsl_heap_record_check.py: the two "index read from a buffer" controls used a literal offset, which is now accepted; they now read the index at a group-ID offset (s14), which stays refused with the same message prefix.
  • New: tests/startup_gfx2hlsl_heap_word_check.py, tests/startup_compute_dispatch_heap_word_check.py; registered in CMakeLists.txt, the Windows workflow and AGENTS.md. docs/experiments.md paragraph next to the heap-record text.

Why the CPU read is sound

The word is read when the dispatch is recorded, not when the GPU runs. That is only correct if nothing on the GPU writes the word, so the stand-in reads it only from the recording's upload memory, which no GPU command writes, and refuses a placed buffer or a view token. A per-thread or group-ID index can't be read once on the CPU, and neither can a register sum or a modified descriptor, so all of these keep a refusal.

Tests

Commit under test: ba79c8b (code; the docs commits 5c248dc and 62b5ccc change no code), on #2532 head 1efce19.

python -B tests/startup_gfx2hlsl_heap_word_check.py --llvm-mc llvm-mc-15
python -B tests/startup_gfx2hlsl_heap_record_check.py --llvm-mc llvm-mc-15
python -B tests/startup_translator_check.py
cmake --build --preset dev --target startup_stream_consumer
ctest --preset dev --no-tests=error -R "^startup_compute_dispatch_|heap_record|heap_word" -V

Results: both translator checks PASS with reassembly, startup_translator_check.py reports 0 failed, ctest 10/10 passed, no exit-77 skips.

Environment: Windows 10.0.26300.10075. WARP is the Microsoft Basic Render Driver 10.0.26100.10068. The hardware run used an NVIDIA GeForce RTX 5090 on driver 32.0.16.2135. The debug layer was enabled and logged no error message.

Each control was checked against a mutant: apply the mutant, rebuild, rerun, then revert. No mutant was committed.

Mutant Fails
runtime ignores the scale (times) dispatch: 288 words differ
runtime ignores the byte offset (at) dispatch: 288 words differ
runtime uses the constant instead of the read word dispatch: 288 words differ
runtime drops the upload-memory check -placed control
runtime drops the buffer-range check -past control (output written)
translator drops the alignment check scale control
translator drops the modified-descriptor check modified-descriptor control
translator accepts any register offset group-ID control
translator keeps a register add register-add control
translator keeps marks across a branch target branch-target control

Measured vs hypothesis

Measured: one synthetic program, on WARP and on one physical adapter. In a local set of 158 compute requests that hold such a load, 153 stopped first at the buffer-read index. All 153 change their first refusal, and none translates fully yet. 145 now stop at a non-heap instruction, 6 at the narrower buffer refusal and 2 at an 8-dword record. Their next first refusals:

  • 82: a per-lane vcc live at an s_cbranch_execz join
  • 24: v_fma_mix_f32
  • 14: src_scc in s_mul_i32
  • 6: a buffer read in another form
  • 6: a formatted load without a hardware table descriptor
  • 5: a buffer store through a modified descriptor
  • 3: v_mad_u32_u16
  • 2: src_scc in s_mov_b32
  • 2: s_and_b32 live at an execz join
  • 2: an 8-dword heap record
  • 1: v_readfirstlane_b32
  • 6: s_buffer_load_dwordx8 live at an execz join

Ceiling: 145 programs hold a heap load that now lowers, but counting every refusal site, 120 of the 158 still hold a refused heap-record load:

  • 101 have the narrower buffer refusal;
  • 32 have an offset that is not a root constant shifted by 5;
  • 2 have an 8-dword record.

With the branch-target clear disabled in a scratch copy (a diagnostic only, never committed), the programs with a refused x4 buffer-form site drop from 90 to 10. The main shape that stays refused is therefore an offset computed, or a word read, before a branch target. It stays refused because another path into the join may carry a different word. About 97 programs also load an 8-dword (image) heap record, which stays refused regardless.

Hypothesis, not measured:

  • the title leaves the upload memory unchanged between recording and execution (the heap-record read already relies on this);
  • the real index buffers live in upload memory rather than in a placed buffer;
  • any dispatch gain, because no program translates fully yet.

🤖 Generated with Claude Code

tedin7 and others added 30 commits November 24, 2026 19:53
…33 and 35)

Header-only state in list_compute_root.h with a Linux-testable check. Dispatch (slot 14) is not handled here; the state is exposed through ready() and table() for it. Refs R0Y00#870.
Compute root constants are kept per list next to the graphics ones, in a shared 16 x 8 word store that refuses parameter >= 16 and offset >= 8. A new compute root signature clears them.
Part of R0Y00#870. Forward Dispatch only with a desktop compute pipeline and root
bound and group counts within 65535 per axis; refuse otherwise.
…t against the bound root

Slot 43 clears a parameter's binding when a replacement is rejected, slot 33 clears all bindings, and the compute pipeline records its root so a mismatched pair is refused.
Compute root constants are kept per list next to the graphics ones, in a shared 16 x 8 word store that refuses parameter >= 16 and offset >= 8. A new compute root signature clears them.
Part of R0Y00#870. Forward Dispatch only with a desktop compute pipeline and root
bound and group counts within 65535 per axis; refuse otherwise.
…t against the bound root

Slot 43 clears a parameter's binding when a replacement is rejected, slot 33 clears all bindings, and the compute pipeline records its root so a mismatched pair is refused.
Conflicts in d3d12_xs_device.cpp and docs/experiments.md resolved by keeping both sides: the pipeline root
out-parameter of the stream builder next to the cached-mesh root, the bound root SRV mask next to the recorded
upload SRV addresses, and both table entries and document sections.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Conflicts in d3d12_draw.inl and d3d12_xs_device.cpp resolved by keeping both sides: graphics root constants
go through the shared store and still mark the words a slot 40 call set.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A device slot 67 placeholder keeps the key of its published request. At
list slot 14 the stand-in loads the stage cs manifest and compiled
program for that key and records the dispatch: raw buffer inputs and
outputs from hardware descriptors in the recorded compute tables, entry
values from the recorded compute root constants. Other manifest lines
leave the pipeline untranslated; a dispatch that cannot be bound
completely is refused with one logged reason and records nothing.

startup_compute_dispatch_{warp,hardware} drives a source-built program
through the stand-in list and reads the output back, with controls
before translation, without a Dispatch and for a refused output.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Dispatches that arrive before the offline translation no longer use up
the lines kept for refusals at bind time.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The per-call refusal lines share one small budget, so a run cannot rank
keys by dispatch count. Each key now keeps its Dispatch count, the calls
recorded and the reason and table descriptor of its first refusal; the
periodic totals are followed by the refused dispatches per reason and the
40 keys with the most dispatches. A manifest that exists but cannot be
bound is counted apart from an absent one ("not modelled").

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A `uav <i> tex2d float table <param> <byte> channels 4` manifest line is
bound from the token of the unordered access view the title created in
its descriptor memory. Everything else is refused with its own reason: an
entry that is no such token, a view the desktop did not create, a view
that is not 2D, a format a float4 store cannot target, and a texture
bound to two slots of one dispatch. Programs without entry values, inputs
or outputs load too: the translated root no longer emits an empty range
or drops the table when only outputs exist.

The fixture stores through the stand-in's own list into a 32x8
RGBA16_FLOAT texture and reads it back with CopyTextureRegion.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A `srv <i> tex2d table <param> <byte>` manifest line is bound from the
token of the shader resource view the title created, through the texture
the draw path samples for that resource, uploaded first when the title
filled it in memory. `smp` lines become static samplers of the translated
root. A dispatch is refused, never bound to a null view, when the entry
is no such token, the resource has no desktop texture, the view is not 2D
or names a packed format, or the upload fails. Sampler heaps, comparison
samplers and other texture kinds keep the translation unavailable.

The fixture samples a 1x1 texture into the stored words of the raw buffer
case; without a view the dispatch is refused and the output is untouched.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…s test

The device check drains the debug layer; a draw runs it on every 64th call
and the queue's execute drains the rest. A view token whose resource the
caller released is the caller's misuse, as on the draw path.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…puts, print every census key

A texture is refused only when the same call reads and writes it; two
outputs of one texture share the unordered access state. A packed output
view format gets its own refusal reason. The census prints every
dispatched key instead of the first 40, and the wording on refused calls
says what may already be recorded (an input texture upload).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NiiRoZz and others added 5 commits November 26, 2026 00:13
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tch-translated

# Conflicts:
#	docs/experiments.md
… into startup/compute-dispatch-heap-rootconst
NiiRoZz and others added 2 commits November 26, 2026 01:05
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
NiiRoZz and others added 4 commits November 26, 2026 01:23
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Merged origin/main into this branch (merge commit e2b58be, no rebase, no force-push). #2532 landed on main as one squash commit, so the branch conflicted in 9 files. I kept main's version of the #2532 content and re-applied only this PR's own five commits on top (the heap index word change, its two docs commits and the two test-tolerance fixes). The conflicts were list entries in AGENTS.md, CMakeLists.txt, the workflow and docs/experiments.md, plus the compute dispatch code. The sources were merged by hand, keeping both sides.

Commands executed locally:

  • Linux: startup_gfx2hlsl_heap_word_check.py and startup_gfx2hlsl_heap_record_check.py (both PASS), docs_links_check.py, bidi_controls_check.py, git diff --check origin/main..HEAD (all clean).
  • Win2025 (default 5 slots, merged tree applied as a patch on c314f36): startup_gfx2hlsl_heap_word, startup_gfx2hlsl_heap_record, startup_compute_dispatch_heap_word_warp and _hardware, startup_compute_dispatch_heap_{warp,hardware} and startup_compute_dispatch_{warp,hardware}: Passed.
  • startup_compute_dispatch_texture_{warp,hardware} fail with "an output texture view was not created on the desktop". They fail the same way on current main without this PR's change, so they predate it. startup_gfx2hlsl_scalar_table_arity_check also fails on main (fix in test: count the s_mul_hi templates in the scalar arity control #2696).
  • Not run: the release build and the full dev suite on the merged head. Re-run both once main is green.

AI-assisted; commands listed were executed locally.

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

Merged origin/main into the branch (plain merge, no rebase, no force): f56592de.

  • One conflict, in CMakeLists.txt (the compute dispatch test block). Kept both sides: this PR's startup_compute_dispatch_heap_word_* and main's startup_compute_live_retry_*, both in the shared set_tests_properties list.

Verification, run on the merged tree with the diff of #2710 applied on top (so it is tested as it will land):

  • x2w_pipe.py win2025 2580 --patch <merge diff + gh pr diff 2710> --regex 'startup_compute_dispatch|startup_gfx2hlsl_heap|startup_pixel_uav|startup_compute_live_retry|startup_stream'
  • Win2025 dev: 32/32 passed. Win2025 release: 32/32 passed (D3D12 WARP).
  • The one conflict between this PR and #2710 (a comment line in tests/startup_stream_consumer.cpp) was resolved by keeping both sides. When #2710 lands in main, the merge should be mechanical.

Ready to squash-merge once #2710 is in main and CI is green.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Win2025 WARP receipt after merging origin/main into this branch (new head 9f97acc; the run applied the same merge as a patch on f56592d). Main was merged twice; the only conflict was a comment block in tests/startup_stream_consumer.cpp, kept both sides.

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

  • Debug (--preset dev) and Release /O2 (--preset release), targets startup_stream_consumer d3d12_xs_shim, each: 100% tests passed, 8 of 8.
  • Tests that ran in both: startup_compute_dispatch_heap_word_warp, startup_compute_dispatch_heap_word_hardware, startup_compute_dispatch_heap_warp, startup_compute_dispatch_heap_hardware, startup_compute_dispatch_warp, startup_compute_dispatch_hardware, startup_gfx2hlsl_heap_word, startup_gfx2hlsl_heap_record.
  • Windows Python checks: tests/startup_gfx2hlsl_heap_word_check.py rc=0, tests/startup_gfx2hlsl_heap_record_check.py rc=0.
  • Note: the _hardware tests ran on the VM's WARP adapter only.

Linux: git diff --check origin/main...HEAD, docs_links_check.py, bidi_controls_check.py clean.

Code review of this PR's own change: reads the index word only from the recording's upload memory and refuses placed buffers, view tokens and out-of-range words, each with a negative control. The author's mutation table covers all of them. No game progress is claimed. @ChazY11's note about #2580, #2585 and #2596 sharing the same hunks still applies: whichever merges first will make the others conflict.

AI-assisted; commands listed were executed locally.

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

Win2025 WARP receipt after merging origin/main into this branch (new head 9f97acc; the run applied the same merge as a patch on f56592d). Main was merged twice; the only conflict was a comment block in tests/startup_stream_consumer.cpp, kept both sides.

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

  • Debug (--preset dev) and Release /O2 (--preset release), targets startup_stream_consumer d3d12_xs_shim, each: 100% tests passed, 8 of 8.
  • Tests that ran in both: startup_compute_dispatch_heap_word_warp, startup_compute_dispatch_heap_word_hardware, startup_compute_dispatch_heap_warp, startup_compute_dispatch_heap_hardware, startup_compute_dispatch_warp, startup_compute_dispatch_hardware, startup_gfx2hlsl_heap_word, startup_gfx2hlsl_heap_record.
  • Windows Python checks: tests/startup_gfx2hlsl_heap_word_check.py rc=0, tests/startup_gfx2hlsl_heap_record_check.py rc=0.
  • Note: the _hardware tests ran on the VM's WARP adapter only.

Linux: git diff --check origin/main...HEAD, docs_links_check.py, bidi_controls_check.py clean.

Code review of this PR's own change: reads the index word only from the recording's upload memory and refuses placed buffers, view tokens and out-of-range words, each with a negative control. The author's mutation table covers all of them. No game progress is claimed. @ChazY11's note about #2580, #2585 and #2596 sharing the same hunks still applies: whichever merges first will make the others conflict.

AI-assisted; commands listed were executed locally.

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.

4 participants