Skip to content

startup: opt-in split of a batched indirect Dispatch (Refs #2626) - #2683

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
ColorMeBoom:fix/rdna1-split-indirect-dispatch
Nov 26, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
ColorMeBoom:fix/rdna1-split-indirect-dispatch

Conversation

@ColorMeBoom

Copy link
Copy Markdown
Contributor

What / Why

On an AMD Radeon RX 5700 XT (RDNA 1), desktop ExecuteIndirect with a Dispatch signature runs only its first command, and a single-command call ignores its count buffer (#2626). As agreed on the issue, this adds an opt-in workaround for slot 61. The native call stays the default on every adapter.

With X2W_SPLIT_INDIRECT_DISPATCH=1, a batched or counted Dispatch with a rootless signature and a desktop compute pipeline and root is split:

  1. The count word and the records are copied into a scratch buffer. The title's buffers are only read by copies, as in rect_indirect_args.h.
  2. A one-group compute pass rewrites record i as itself while i < min(count, MaxCommandCount) and as (0,0,0) otherwise.
  3. The title's compute pipeline is set again, and restore_compute_root sets the compute root with its views.
  4. MaxCommandCount single-command calls without a count buffer read the rewritten records.

The translated compute path (#2470), graphics and mesh signatures, and rooted Dispatch signatures are unchanged.

Change

  • src/startup_stubs/split_indirect_dispatch.h (new): the scratch layout and the rewrite pass.
  • d3d12_xs_device.cpp:
    • The split in list_execute_indirect, behind X2W_SPLIT_INDIRECT_DISPATCH=1.
    • bind_compute_root_view and restore_compute_root. Slot 43 now records its root SRVs through bind_compute_root_view. The split and the indexed-draw validation pass (d3d12_draw.inl) restore through restore_compute_root, which before this lived inline in the validation pass. The rectangle-list refusal checks the same recorded views.
    • Fixture exports, not guest slots:
      • x2w_d3d12_fixture_compute_root_uav binds a desktop root UAV through bind_compute_root_view. Slot 45 is not forwarded, so no guest slot can bind the fixture's output.
      • x2w_d3d12_recording_scratches reports how many scratch buffers the recording's desktop allocator holds.
    • The split scratch is kept in that allocator's scratches, so it is released only when the allocator is reset after its submits' fences have passed.
  • tests/startup_indirect_dispatch.cpp:
    • The result UAV is bound through the hook.
    • Count mode adds GPU-written counts 1 and 3.
    • A follow-up case records Dispatch(1, 1, 2) on the desktop list after slot 61, adding 102 only if the consumer pipeline, compute root and result UAV are still bound.
    • Every counted run checks the recording's scratch count after Close.
    • With the split on, a retire case submits through a guest queue held behind a gate fence, resets the guest allocator while the work is pending, and requires the scratch to still be held and the count-2 result after the gate opens.
  • CMakeLists.txt: startup_indirect_count_split_(warp|hardware) run count mode with X2W_SPLIT_INDIRECT_DISPATCH=1. startup_indirect_count_split_warp is added to the pr test preset.
  • docs/experiments.md: section "Batched indirect Dispatch on RDNA 1".

startup_indirect_count_(warp|hardware) keep the native call and stay strict.

Tests

Commit under test: 7ed5e7f9 on f4c6998a. Windows 11 Home build 26200.9974, VS 2022 Build Tools (MSVC 19.44.35230), Windows SDK 10.0.26100.0, DXC 1.9.2602.17. Debug layer unavailable (Graphics Tools not installed). Hardware: AMD Radeon RX 5700 XT (device 731f), driver 32.0.21045.29003. WARP 10.0.26100.9818.

cmake --build --preset dev --target startup_indirect_dispatch
ctest --preset dev --no-tests=error -R '^startup_indirect_(count|count_split|dispatch|root_constants)_(warp|hardware)$' -V
Test WARP RX 5700 XT
startup_indirect_dispatch_*, startup_indirect_root_constants_* pass pass
startup_indirect_count_* (native, strict) pass fails at its first case, as reported: result=0x31415929, expected 0x31415935
startup_indirect_count_split_* (opt-in) pass pass

Split runs, both adapters, whole readback compared:

  • count 2: 0x31415935
  • count 9 (clamped to 3): 0x31415a64
  • count 0: 0x31415926 (result untouched)
  • count 1: 0x31415929
  • count 3: 0x31415a64
  • follow-up Dispatch: 0x3141599b
  • retire: allocator reset while pending returned S_OK, the recording still held 1 scratch, and the result was 0x31415935
  • omitted writer: 0x31415926
  • no count buffer: 0x31415a64
  • five refusals: 0x31415926

Negative controls (local edits, not committed). Each made both split tests fail:

  • skipping restore_compute_root after the pass: first case result=0x31415926, expected 0x31415935;
  • not retaining the scratch with the recording: recording holds 0 split scratch buffers after Close, expected 1.

ctest --preset pr --no-tests=error: 39/39 passed.

Full ctest --preset dev --no-tests=error -j 8 --timeout 600 on the RX 5700 XT: 2,154/2,166 passed, and 12 failed:

  • Five timeouts under -j 8 passed when rerun serially: compute_store_aot_hardware, compute_store_aot_lds_qword_hardware, compute_store_aot_lds_arithmetic_hardware, compute_store_aot_lds_private_hardware and pixel_aot_cvt_f64_f32_hardware.
  • startup_indirect_count_hardware fails as reported (native call, kept strict).
  • gpu_alias_window_hardware, gpu_alias_lookup_writes_hardware and compute_store_aot_mac_f32_hardware are the RX 5700 XT results already listed on RX 5700 XT (RDNA 1): ExecuteIndirect Dispatch with max count > 1 runs only the first command (startup_indirect_count_hardware) #2626.
  • startup_gfx2hlsl_f32_med3_hardware, startup_gfx2hlsl_fma_mix_dispatch_hardware and pixel_aot_sdwa_int_extra_hardware were added on main since that report. They run through offscreen_check, which does not link d3d12_xs and has no source changed here. Their failures: the branchless-lowering control is not detected on hardware; two fma_mix hardware checks fail (negated inline-0 addend, and the control without the high-half shift); and sdwa_int_extra_co_ci_2 has channel 1 0x00000000 against 0x0000ffff. I can report them separately.

python -B tests/docs_links_check.py, python -B tests/bidi_controls_check.py and git diff --check: clean.

Not verified

  • No second RDNA 1 adapter; the split is not enabled by device id.
  • The debug layer was unavailable here.
  • The follow-up Dispatch is recorded on the desktop list, since slot 14 refuses a compute root with a UAV parameter.

Refs #2626.

AI-assisted with Claude Code (Claude Opus 5.5).

On an AMD Radeon RX 5700 XT (RDNA 1, device 731f), desktop
ExecuteIndirect with a Dispatch signature runs only its first command,
and a single-command call ignores its count buffer. With
X2W_SPLIT_INDIRECT_DISPATCH=1, slot 61 splits a batched or counted
Dispatch with a rootless signature and a desktop compute pipeline and
root: the count word and records are copied into a scratch buffer, a
one-group pass rewrites record i as itself while i < min(count,
MaxCommandCount) and as (0,0,0) otherwise, and MaxCommandCount
single-command calls without a count buffer read the result. The native
call stays the default on every adapter. The translated compute path,
graphics, mesh and rooted Dispatch signatures are unchanged.

The pass replaces the compute root and pipeline. The split sets the
pipeline again and restore_compute_root sets the root with every view
recorded by bind_compute_root_view. Slot 43 records its root SRVs there,
the indexed-draw validation pass restores through the same function, and
the rectangle-list refusal checks the same views. The fixture-only export
x2w_d3d12_fixture_compute_root_uav binds the fixture's desktop result UAV
through bind_compute_root_view; x2w_d3d12_recording_scratches reports the
scratch the recording's allocator holds until its fences pass.

startup_indirect_count_(warp|hardware) keep the native call and stay
strict. startup_indirect_count_split_(warp|hardware) run count mode with
the split: GPU-written counts 2, 9, 0, 1 and 3, a follow-up Dispatch that
needs the restored root, pipeline and UAV, the scratch count after Close,
and a guest-queue submission behind a gate whose allocator is reset
while pending.

AI-assisted.
@thepatrickworld

Copy link
Copy Markdown
Contributor

Independent AMD RDNA 4 result on 7ed5e7f9: the split opt-in produces every expected readback here, then the process exit faults with 0xC0000409 in the DLL detach, from the new function-local static.
Measurements and one attribution experiment on this head; nothing pushed.

The short version

  • With X2W_SPLIT_INDIRECT_DISPATCH=1 on an RX 9070 XT (RDNA 4), startup_indirect_count_split_hardware prints every check, reports no mismatch, and then dies with 0xC0000409 — 3 of 3 runs, and ctest records Exit code 0xc0000409 ***Exception: 3.24 sec.
  • The same binary without the variable exits 0, and with the variable in warp it exits 0.
  • This is the mirror image of the report: on the RX 5700 XT the native count tests fail and the split passes; here the native tests pass and the split faults at exit. The readbacks are identical in both modes, so what fails is the teardown, not the workaround's result.
  • The stack is the DLL detach path of d3d12_xs.dll, through static SplitIndirectDispatch splitter; at src/startup_stubs/split_indirect_dispatch.h:165. The same cache as a never-destroyed instance exits 0, 3 of 3.
  • No shim change can fix the driver: the faulting instruction is in amdxc64. What is fixable is destroying the pipeline state during CRT detach.

Environment

Windows 11 25H2, build 10.0.26200.9974. AMD Radeon RX 9070 XT (PCI\VEN_1002&DEV_7550, gfx1201), driver 32.0.32029.2010. MSVC 19.44.35230.0 (BuildTools 14.44.35207), CMake 4.4.4, Ninja, preset dev (Debug). D3D12 debug layer not installed.

Commands

git fetch origin pull/2683/head:refs/panam/2683
git checkout -f refs/panam/2683
cmake --preset dev -DINTAKE_PYTHON=...\pe-env\Scripts\python.exe
cmake --build --preset dev --target d3d12_xs_shim startup_indirect_dispatch
ctest --preset dev --no-tests=error -R "^startup_indirect_(count|count_split|dispatch|root_constants)_(warp|hardware)$" -V
set "X2W_SPLIT_INDIRECT_DISPATCH=1"
out\build\dev\startup_indirect_dispatch.exe hardware count

Observed

ctest selected 8 entries: 7 pass, and

8/8 Test #268: startup_indirect_count_split_hardware ......Exit code 0xc0000409***Exception:   3.24 sec
88% tests passed, 1 tests failed out of 8

Exit codes, from a batch that writes !errorlevel! to a file, with the build stamp each run reported:

unmodified header, build=7ed5e7f9      (run log ok_r1.log)
  split hardware   EXIT=-1073740791
  split hardware   EXIT=-1073740791
  split hardware   EXIT=-1073740791
  native hardware  EXIT=0
  native warp      EXIT=0
patched header,    build=7ed5e7f9-dirty (run log q1.log)
  split hardware   EXIT=0
  split hardware   EXIT=0
  split hardware   EXIT=0

-1073740791 is 0xC0000409 as a signed exit code.

Before dying, the count chain printed all 15 of its result lines with no word N: got ... line. The lines the split adds:

GPU writer: count word=1, executed=1, result=0x31415929 (expected 0x31415929)
GPU writer: count word=3, executed=3, result=0x31415a64 (expected 0x31415a64)
GPU writer + follow-up Dispatch: count word=2, executed=2, result=0x3141599b (expected 0x3141599b)
retire: allocator reset while pending -> 0x00000000, recording holds 1 split scratch buffers
GPU writer + retired allocator: count word=2, executed=2, result=0x31415935 (expected 0x31415935)

and the rest (counts 2, 9, 0, omitted writer, no count buffer, five refusals) are identical to what the native mode prints here. 15 lines is what the 14 verify calls at tests/startup_indirect_dispatch.cpp:479-492 produce, because the retire case at :485 prints two; the chain is &&, so one mismatch would have cut it short.

The dump

0xC0000409, subcode 0x7 FAST_FAIL_FATAL_APP_EXIT: a deliberate __fastfail, not a stack-buffer overrun — the "Security check failure or stack buffer overrun" text in the dump header is the generic wording for the code. !analyze -v reports SYMBOL_NAME: amdxc64+553b9, IMAGE_NAME: amdxc64.dll, bucket FAIL_FAST_FATAL_APP_EXIT_c0000409_amdxc64.dll!Unknown, and IMAGE_VERSION: 32.0.32029.2010 — the same driver version the passing runs report.

17 of the 57 frames, in the order cdb prints them (the fault is at the top). Template argument lists are abbreviated; the rest is verbatim.

amdxc64!OpenShimInterface+0x8db4
amdxc64!GetSettingsBlobsAll+0x20518
amdxc64!GetSettingsBlobsAll+0x35d
D3D12Core!CPipelineState::FinalRelease+0x4d
D3D12Core!CLayeredObject<CPipelineState>::Release+0x9
D3D12!CUseCountedObject<NOutermost::CDeviceChild>::Release+0xa9
D3D12Core!CLayeredObject<CBackingCommandAllocator>::CContainedObject::Release+0x17
d3d12_xs!Microsoft::WRL::ComPtr<ID3D12PipelineState>::InternalRelease+0x43
d3d12_xs!ComPtr<ID3D12PipelineState>::~ComPtr<ID3D12PipelineState>+0x14
d3d12_xs!x2w_startup::SplitIndirectDispatch::Entry::~Entry+0x1b
d3d12_xs!std::vector<…>::~vector<…>+0x2a
d3d12_xs!x2w_startup::SplitIndirectDispatch::~SplitIndirectDispatch+0x1b
d3d12_xs!`x2w_startup::split_indirect_dispatch'::`2'::`dynamic atexit destructor for 'splitter''+0x12
d3d12_xs!_execute_onexit_table+0x34
d3d12_xs!_cexit+0x13
d3d12_xs!dllmain_crt_process_detach+0x4d
d3d12_xs!_DllMainCRTStartup+0x32

Read it from the bottom up as execution order: DllMain receives the process-detach, the CRT runs its atexit table, which destroys the function-local static splitter, which destroys its vector<unique_ptr<Entry>>, which runs ~Entry, which releases ComPtr<ID3D12PipelineState>, which reaches CPipelineState::FinalRelease and then the driver — and the driver fast-fails. Above this selection sit the fast-fail frame and two more amdxc64 frames, then the three ntdll exception-dispatch frames; below it sit 13 process-exit frames (ntdll!LdrShutdownProcess, ucrtbased!exit, the main return). The 7 D3D12/D3D12Core refcount frames between InternalRelease and FinalRelease are the ones hidden by the selection.

The d3d12_xs names are real symbols: they carry the private x2w_startup namespace, lambda_… names and an anonymous-namespace static's dynamic atexit destructor, with short offsets (+0x12, +0x14, +0x1b, +0x43). None of that can come from an export table. The amdxc64 names are the opposite: nearest-public-symbol artifacts of a stripped vendor module (+0x8db4, +0x20518, +0x553b9), so read them as offsets. The instruction that faults is in the vendor module.

Site and the two experiments

  • The static at split_indirect_dispatch.h:165 is destroyed from _execute_onexit_table during dllmain_crt_process_detach. It owns std::vector<std::unique_ptr<Entry>> entries_ (:160), and each Entry owns ComPtr<ID3D12RootSignature> root and ComPtr<ID3D12PipelineState> pipeline (:110-111). Entry::device (:109) is a raw pointer and is not released here.
  • Experiment A: static SplitIndirectDispatch* splitter = new SplitIndirectDispatch(); → 3 of 3 exit 0 with the same 15 readback lines. The source was checked for that line before the build, git diff --stat shows one file +4/-2, and the run log stamps build=7ed5e7f9-dirty.
  • Experiment B, the control: unmodified header, same commands → 3 of 3 crash.
  • That is an experiment, not a fix I would merge: never destroying the cache trades the detach fault for a leaked singleton. The shape already accepted in this repository is a teardown boundary — release when the module unloads, as startup: release the per-device D3D12 caches only when the module is unloaded #2590 does.
  • Not established: which of the two owned references faults. The frame nearest the shim is the ComPtr<ID3D12PipelineState> release and it reaches CPipelineState::FinalRelease, so the pipeline state is the reference that gets to the driver; I did not run a variant that keeps only the root signature.

This is a class the repository already closed

#2572 ("The five indirect tests fault at process exit: static pipeline states are destroyed during teardown") is the same shape, closed 25/11 by #2590 and #2631. At b2564017, the base this PR was opened against, the placed-page cache detaches instead of releasing when x2w_startup::d3d12_process_terminating is true (d3d12_xs_device.cpp:4622, teardown_report at :4633); the same code sits at :4631/:4642 at 0c8f5dab. This head is 7ed5e7f9, which the PR body records as tested on f4c6998a, and at that tree d3d12_xs_device.cpp contains neither d3d12_process_terminating nor teardown_report — the branch predates those changes. So a rebase puts this static next to the guarded caches rather than making the fault disappear: #2631's boundary covers the placed page aliases and the draw dumps, not this new cache.

Limits

  • One adapter, one driver package, one Windows build, Debug configuration. Reproduced on an RX 9070 XT with 32.0.32029.2010; I have no RDNA 1 card and no older package for this card, so I cannot say whether the RX 5700 XT would fault too. On this machine the same binary detaches cleanly on the native path and on WARP, so it is the split path that aborts, not the teardown in general.
  • Three runs each way; deterministic here, on this machine only.
  • The fault happens at process exit, after the results, so as a measurement the workaround's output is exact on this adapter; as a test entry it fails here.
  • The opt-in is off by default, so no default user reaches the new path.
  • No debug layer, so no D3D12 validation message was inspected.
  • The dump came from LocalDumps for this executable only; that key has been removed.

AI-assisted; runs executed on the machine above.

@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 7ed5e7f (code and fixture tests only; I have no RDNA 1 or other AMD hardware, so I did not run any adapter-specific result).

Blocking finding: src/startup_stubs/split_indirect_dispatch.h:165 holds static SplitIndirectDispatch splitter; inside split_indirect_dispatch(). Its destructor runs during DLL detach and releases a pipeline state there. The independent RDNA 4 report above (3 of 3 runs, exit 0xC0000409 after all readbacks pass, ctest Exit code 0xc0000409) points exactly at this destructor, and the same cache held as a never-destroyed instance exited 0. That makes startup_indirect_count_split_hardware fail on a GPU where the native path is fine, even though the opt-in is off by default. Suggested fix: keep the cache in a leaked heap instance (static auto* splitter = new SplitIndirectDispatch;) or release it from the device teardown while the device is alive, and add the exit code to the hardware test's expectations.

Otherwise the design matches R0Y00's scope on #2626: opt-in only, native call stays the default, startup_indirect_count_* stays strict and unsplit, counts 0, 1, 2, 3 and above max are covered, and count 0 leaves the output untouched.

Not merging: this is a main-executable shim change with an open exit fault, and the verification that matters (a second RDNA 1 adapter) is on hardware we do not have. The merge stays with MasterDomino or @R0Y00.

AI-assisted; commands listed were executed locally.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Integrated main and ran 12/12 Windows Release CTests on WARP and RTX 4060 Laptop with no skips. The native and opt-in dispatch tests passed, including counts 0 through 3, the clamped count, the subsequent dispatch with restored bindings, and the fenced allocator reset. The translated target and pixel UAV alias controls also passed in this combined tree. RDNA 1 behavior remains the contributor report in #2626.

@R0Y00
R0Y00 merged commit 2a772bd into R0Y00:main Nov 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants