Skip to content

startup: keep the split indirect Dispatch cache past DLL detach - #2734

Open
ColorMeBoom wants to merge 2 commits into
R0Y00:mainfrom
ColorMeBoom:fix/split-dispatch-teardown
Open

ColorMeBoom wants to merge 2 commits into
R0Y00:mainfrom
ColorMeBoom:fix/split-dispatch-teardown

Conversation

@ColorMeBoom

Copy link
Copy Markdown
Contributor

What / Why

Follow-up to the blocking finding in the review of #2683. With X2W_SPLIT_INDIRECT_DISPATCH=1 on an RX 9070 XT (driver 32.0.32029.2010), startup_indirect_count_split_hardware printed every expected readback and then exited with 0xC0000409. That is a fail-fast in amdxc64.dll, reached through the destructor of the function-local static SplitIndirectDispatch splitter during DLL detach, which released the rewrite's pipeline state there. The same review measured a never-destroyed instance exiting 0 in 3 of 3 runs on that adapter. #2683 was merged with the static in place, so main still has it.

Change

  • src/startup_stubs/split_indirect_dispatch.h: split_indirect_dispatch() returns a heap instance that is never destroyed (static SplitIndirectDispatch* const splitter = new SplitIndirectDispatch;). Its entries were already kept for the life of the process.
  • docs/experiments.md: the lifetime and the fault, in "Batched indirect Dispatch on RDNA 1".

rect_indirect_args.h has the same pattern (static RectIndirectArguments converter), which predates #2683. I left it unchanged: no fault has been reported for it, and this PR covers one behavior.

Tests

Commit 27ae0401 on feec219e. Windows 11 Home build 26200.9974, VS 2022 Build Tools (MSVC 19.44.35230), Windows SDK 10.0.26100.0. AMD Radeon RX 5700 XT (1002:731f), driver 32.0.21045.29003; WARP 10.0.26100.9818. Debug layer unavailable.

cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^startup_indirect_(count|count_split|dispatch|root_constants)_(warp|hardware)$|^docs_links$|^startup_tools_lint' -V

9 of 10 passed: both startup_indirect_count_split_*, the dispatch and root-constant tests, docs_links and startup_tools_lint. startup_indirect_count_hardware fails at its first case as reported in #2626 (native call, kept strict).

startup_indirect_dispatch.exe <hardware|warp> count with X2W_SPLIT_INDIRECT_DISPATCH=1, three runs each: exit 0 on all six, each printing all 14 result= lines.

Not verified

The RX 5700 XT and WARP also exited 0 before this change, so these runs show no regression, not the fix. The fault was measured on the RX 9070 XT in the #2683 review. A rerun there of startup_indirect_count_split_hardware on this head would confirm the exit.

Refs #2683, #2626.

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

Review of R0Y00#2683: with X2W_SPLIT_INDIRECT_DISPATCH=1 on an RX 9070 XT
(driver 32.0.32029.2010), startup_indirect_count_split_hardware printed
every expected readback and then exited with 0xC0000409 (fail-fast in
amdxc64.dll). The stack ran through the destructor of the function-local
static SplitIndirectDispatch during DLL detach, which released the
rewrite's pipeline state there. The reviewer measured a never-destroyed
instance exiting 0 in 3 of 3 runs on that adapter.

split_indirect_dispatch() now returns a heap instance that is never
destroyed. Its entries were already kept for the life of the process.
docs/experiments.md records the lifetime and the fault.

AI-assisted.
@R0Y00

R0Y00 commented Nov 26, 2026

Copy link
Copy Markdown
Owner

The reviewed failure happens after successful readbacks. Please rerun the exact candidate on the RX 9070 XT that hit 0xC0000409, using startup_indirect_count_split_hardware with the split rewrite enabled. The receipt should include the readback verdict and the child process exit code. Please also make the lifetime boundary explicit: this cache is process-owned. If explicit DLL unload and reload in a live host is a supported path, that path needs teardown outside the loader lock and its own coverage because each reload would allocate a new cache.

@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 27ae040 (comment only, no approval).

What I checked:

  • The change itself is correct and minimal. A function-local static instance is replaced by a never-deleted heap instance, so no destructor runs at DLL detach. The only callsite is d3d12_xs_device.cpp:3311, and it only needs a stable reference.
  • Entries were already kept for the process lifetime, so no behavior changes besides skipping the teardown.
  • Docs: the new paragraph in docs/experiments.md reads fine and links resolve.

Not verified, and cannot be by me:

  • The fault is a driver fail-fast on an RX 9070 XT (driver 32.0.32029.2010). Windows Server 2025 has WARP only, so a WARP run would not exercise this path. I did not run it and make no claim about it.
  • @R0Y00's request in the thread is still open: a receipt from the exact candidate on the RX 9070 XT with the readback verdict and the child exit code, and an explicit statement of the lifetime boundary (process-owned cache; explicit unload and reload of the DLL in a live host would need teardown outside the loader lock and its own coverage). The PR text describes the lifetime but does not yet say whether unload/reload is a supported path.
  • No test fails without the change. The existing startup_indirect_count_split_hardware only shows the difference on that GPU, so a regression guard exists only on that hardware.

Linux checks run on this head: git diff --check origin/main...HEAD clean, python3 tests/docs_links_check.py pass, python3 tests/bidi_controls_check.py pass.

Note: rect_indirect_args.h:171 has the same static pattern; the author left it on purpose, which is reasonable for a single-behavior PR.

Merge is left to @R0Y00 / MasterDomino once the hardware receipt is posted.

AI-assisted; commands listed were executed locally.

Copy link
Copy Markdown
Contributor

Independent MSVC x64 Release regression check of 27ae04015d4cffa4a28749b1ce76e3daed4f4bcf on Windows 26300.10075: ctest --preset release --no-tests=error -j 1 -R '^startup_indirect_(count|count_split|dispatch|root_constants)_(warp|hardware)$' -V passed 8/8, no skips. With X2W_SPLIT_INDIRECT_DISPATCH=1, I also launched three fresh startup_indirect_dispatch.exe <backend> count processes per adapter. All six printed 14 expected-value results and exited 0 after teardown. The D3D12 debug layer was enabled on in-box WARP 10.0.26100.10068 and the RTX 4070 32.0.16.2124. This verifies the two comparison adapters. The reported RX 9070 XT fail-fast still needs that adapter for confirmation.

@MasterDomino

Copy link
Copy Markdown
Collaborator

RX 9070 XT run at 27ae0401, as the description asks (Windows 11 build 26300, --preset dev Debug; AMD Radeon RX 9070 XT, driver 32.0.32029.2010; WARP 10.0.26100.9818; D3D12 debug layer installed).

  • This head: ctest --preset dev --no-tests=error -R '^startup_indirect_count_split_(warp|hardware)$' passed 3 of 3 on both backends, and every hardware run exited 0. The CMake entry sets X2W_SPLIT_INDIRECT_DISPATCH=1 itself.
  • Negative control: with split_indirect_dispatch() changed back to main's function-local static (static SplitIndirectDispatch splitter; return splitter;), rebuilt, startup_indirect_count_split_hardware also exited 0, 3 of 3. On this machine the original fault doesn't reproduce.

So this shows no regression, but it doesn't confirm the fix. I'm not merging on these runs alone: a main-executable change needs a negative control that catches the failure.

The one setup difference I can see from the #2683 report: there, Windows build 26200 with no D3D12 debug layer installed; here, build 26300 with the debug layer installed. That could change the teardown path in D3D12Core, which is where the faulting stack ran.

@thepatrickworld, you reproduced 0xC0000409 3 of 3 on 7ed5e7f9. Could you rerun startup_indirect_count_split_hardware on this head (27ae0401), and on main as the control? If this head exits 0 where main faults, I'll merge.

AI-assisted; commands listed were executed locally.

@thepatrickworld

Copy link
Copy Markdown
Contributor

Independent AMD result: startup_indirect_count_split_hardware passes on the merged candidate 659bbf5c and ends in 0xC0000409 when one header is restored to main.

Not a code change; measurements and one dump. This is the head-passes / control-fails pair asked for above, with the ctest entry itself on both states, on the adapter and driver that reported the fault.

Tree measured

  • PR head 27ae0401 (unchanged, still refs/pull/2734/head), merged locally into 434aa90d, which was main when I fetched it — GitHub records this PR's base as 343dc04f. Merge 659bbf5c, git merge --no-ff, dev preset.
  • Control: the same merge with only src/startup_stubs/split_indirect_dispatch.h restored from origin/main. The PR's other file is docs/experiments.md, so no built binary depends on it.

Environment

  • Windows 11 25H2, build 26200.9974
  • MSVC 19.44.35230 (VCToolsVersion 14.44.35207), Windows SDK 10.0.26100.0
  • DXC 1.9.2602.17 (10.0.26100.0 user-mode)
  • hardware: AMD Radeon RX 9070 XT, 1002:7550, driver 32.0.32029.2010
  • WARP: Microsoft Basic Render Driver, driver 10.0.26100.9818
  • preset dev (CMAKE_BUILD_TYPE=Debug), debug_layer=unavailable (no d3d12SDKLayers.dll)

Commands

git -c user.name=panam -c user.email=panam@local merge --no-ff refs/panam/2734
cmake --preset dev "-DINTAKE_PYTHON=C:/Users/walde/Downloads/x2w-pr641/out/pe-env/Scripts/python.exe"
cmake --build --preset dev
ctest --preset dev --no-tests=error -R "^startup_indirect_count_split_hardware$" -V

set "XBOX2WINDOWS_ADAPTER=AMD Radeon RX 9070 XT"
set "X2W_SPLIT_INDIRECT_DISPATCH=1"
out\build\dev\startup_indirect_dispatch.exe hardware count
out\build\dev\startup_indirect_dispatch.exe warp count

rem control: header restored to main, full preset rebuild, then the same three commands
git checkout origin/main -- src/startup_stubs/split_indirect_dispatch.h
cmake --build --preset dev
ctest --preset dev --no-tests=error -R "^startup_indirect_count_split_hardware$" -V

Observed

The entry on the merged tree (header restored after the control), with X2W_SPLIT_INDIRECT_DISPATCH cleared from the environment so the entry's own property (CMakeLists.txt:1523) supplies it:

1/1 Test #277: startup_indirect_count_split_hardware ...   Passed    0.41 sec

The entry, on the control tree (findstr on the source right before the build printed 165: static SplitIndirectDispatch splitter;, run stamp build=659bbf5c-dirty):

1/1 Test #277: startup_indirect_count_split_hardware ...Exit code 0xc0000409***Exception:   2.37 sec
0% tests passed, 1 tests failed out of 1

Direct runs of the executable the entry invokes: six hardware runs on the merged tree, each a fresh process, all exit 0; four hardware runs on the control tree, all exit -1073740791, which is how %ERRORLEVEL% reports NTSTATUS 0xC0000409 (STATUS_STACK_BUFFER_OVERRUN, the generic fail-fast status). Every log reports adapter: AMD Radeon RX 9070 XT, driver: 32.0.32029.2010 and 14 result= lines with observed equal to expected, e.g. count word=2, executed=2, result=0x31415935 (expected 0x31415935) — checked line by line, no mismatch in any log.

The recorded output is identical line for line once per-run addresses and the build stamp are set aside: 58 lines each, same last line, empty normalized diff. The only difference left in the run is the exit status.

Neighbouring entries ^startup_indirect_(dispatch|root_constants|count|count_split)_(warp|hardware)$: 8/8 passed, 0 failed, 0 skipped, one run each; I did not run the full suite. The zero-skip number is meaningful because those entries carry SKIP_RETURN_CODE 77 (CMakeLists.txt:1527-1528).

On WARP the control tree also exits 0 in three runs. That is not a control for this fault — WARP does not load amdxc64 — so I read nothing into it.

What this establishes: on this adapter and driver the change moves the process out of the failing path. With the header restored the entry and the executable both end in 0xC0000409; with it, both exit 0.

The dump

One control run was instrumented with a LocalDumps key (DumpType 2, set for that run, removed afterwards); the dump is …\dumps\startup_indirect_dispatch.exe.9888.dmp. cdb -z … -c "!analyze -v" gives EXCEPTION_CODE_STR: c0000409, EXCEPTION_PARAMETER1: 7 (FAST_FAIL_FATAL_APP_EXIT), MODULE_NAME: amdxc64, PROCESS_NAME: startup_indirect_dispatch.exe, and IMAGE_VERSION: 32.0.32029.2010, the driver the run log reports.

STACK_TEXT is unfiltered, 57 frames. The list below keeps the frames that matter and elides the CRT and STL internals. From mainCRTStartup inward: ucrtbased!exit → kernel32!ExitProcessImplementation → ntdll!RtlExitUserProcess → ntdll!LdrShutdownProcess → d3d12_xs!dllmain_crt_process_detach → _cexit → _execute_onexit_table → `dynamic atexit destructor for 'splitter'` → ~SplitIndirectDispatch → ~vector<unique_ptr<Entry>> → ~Entry → ~ComPtr<ID3D12PipelineState> → InternalRelease → D3D12Core!CPipelineState::FinalRelease → amdxc64 → fail-fast. Two amdxc64 blocks appear, separated by three ntdll exception-dispatch frames, because the fail-fast itself raises an exception.

So in the control state the pipeline state is released inside _execute_onexit_table at process detach, and the termination is inside the AMD user-mode driver. The merged build raises no exception, so there is no crash dump to take from it.

On the other runs in this thread

tedin7 notes that the regression guard exists only on that GPU; these are runs on that GPU, not a new guard. Nothing fails without the change in CI because the hardware entries are excluded there (-E '_hardware$', .github/workflows/windows.yml:470 and :590).

MasterDomino measured his own negative control — the same function-local static — and it exited 0 in 3 of 3 on Windows build 26300 with the debug layer installed, then declined to conclude and asked for this replay. Here, on build 26200.9974 without the layer, the same replay fails 4 of 4. Two things differ between those setups; the cheap discriminating run is 26200 with the layer installed, since 26300 changes both at once.

R0Y00's third point, the lifetime boundary: no entry in this PR exercises an unload and reload — the harness contains no LoadLibrary/FreeLibrary — so that path is covered by nothing here. The boundary is the author's to state; what I can add is that nothing in the tree exercises it.

Limits

  • One machine, one adapter, one driver, and only the X2W_SPLIT_INDIRECT_DISPATCH path.
  • debug_layer=unavailable here: no API validation output, so nothing above speaks to binding or resource-state errors, and the difference with MasterDomino's setup is not isolated.
  • 6 green and 4 red hardware runs show the exit is not a one-off; they are not a statistical claim.
  • The revert is a control, not a candidate: it shows the exit tracks that line on this build, not how any other lifetime site behaves. The two phases ran different binaries (d3d12_xs.dll 7b7ff6205126f52d… control, 8fef57429f1cc4d7… restored); the header diff of the reverted state is +2 -5 against the merge.
  • startup_indirect_count_hardware, the entry without the rewrite enabled, also passed (0.27 s) in the same ctest run; I did not compare its output with the failing case in RX 5700 XT (RDNA 1): ExecuteIndirect Dispatch with max count > 1 runs only the first command (startup_indirect_count_hardware) #2626 and draw no conclusion from it.
  • Upstream main has moved since the merge I measured (fd033046 at the time of writing); the PR head is unchanged, and I can redo the merge on a fresh main.

AI-assisted.

@MasterDomino

Copy link
Copy Markdown
Collaborator

Thanks, @thepatrickworld. That's the pair this needed, on the adapter and driver that reported the fault:

  • This change merged onto main: startup_indirect_count_split_hardware passes, and 6 of 6 direct hardware runs exit 0 with all 14 readbacks matching.
  • Only split_indirect_dispatch.h restored to main: 4 of 4 runs end in 0xC0000409.
  • The dump: the fail-fast is in amdxc64 under the static's destructor in _execute_onexit_table at DLL detach.

That covers @R0Y00's first request, the receipt with the readback verdict and the child exit code. It also explains my green control: here the build is 26300 with the debug layer installed, and there it's 26200 without it.

One item left before I merge, @ColorMeBoom: @R0Y00's second request, a statement of the lifetime boundary. Please add one or two sentences, in the PR description and in the docs/experiments.md paragraph or the header comment, saying:

  • the splitter cache is process-owned and released only by process exit;
  • explicit unload and reload of d3d12_xs.dll in a live host is not a supported path, since each load would allocate a new cache and nothing tears it down outside the loader lock. If you'd rather it be supported, it needs that teardown and its own coverage, which is a separate change.

Once that's in, this is ready to merge. CI is green, and the code change itself is correct as @tedin7 reviewed.

AI-assisted.

@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 d7f8fe9 (code + fixture tests only; no game runs).

The change is small and reads as sound: split_indirect_dispatch() now returns a never-destroyed heap instance, and the docs note matches the code. The fault it targets (driver fail-fast during DLL detach on RX 9070 XT) was measured on hardware that is not available here, so that claim is not verified in this review.

Win2025 WARP (dev build, ctest, run twice on d7f8fe9 after updating with main):

  • startup_indirect_dispatch_warp: passed
  • docs_links: passed
  • startup_indirect_count_split_warp: FAILED both times. Output: word 11: got 0x31415926, expected 0x31415935, GPU writer: count word=2, executed=2, result=0x31415926 (expected 0x31415935), adapter Microsoft Basic Render Driver 10.0.26100.33648.

I did not compare against main on the same VM, so I cannot say whether this failure comes from the PR or already exists. The lifetime change should not affect that readback value, so it may be a pre-existing WARP difference. Could the author or @R0Y00 confirm how startup_indirect_count_split_warp behaves on main with this WARP version? Not merging until that is clear.

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.

Follow-up on head d7f8fe9: the startup_indirect_count_split_warp failure comes from this change.

Win2025 WARP, dev build, same driver (10.0.26100.33648), regex ^startup_indirect_count_split_warp$:

  • PR head d7f8fe9 (never-destroyed heap instance): FAILED twice, word 11: got 0x31415926, expected 0x31415935.
  • Same head with this PR's two-file diff reverted (function-local static, as on main): 100% tests passed out of 1.

So on WARP the test passes with the static and fails with the heap instance. Please check why the result of the last case changes, for example whether the test relies on the splitter's pipelines being released at exit, or on a fresh instance per process state. Not merging until it passes.

AI-assisted; commands listed were executed locally.

@MasterDomino

Copy link
Copy Markdown
Collaborator

@tedin7, on startup_indirect_count_split_warp: it passes on main and on this head here. These are our runs on Windows 11 build 26300, WARP 10.0.26100.9818, and an AMD Radeon RX 9070 XT (driver 32.0.32029.2010).

ctest --no-tests=error -j1 -V -R '^startup_indirect_(count|count_split|dispatch|root_constants)_(warp|hardware)$' passed 8/8 in each of these:

Tree Preset Result
main 475bb730 dev 8/8
this head d7f8fe99 dev 8/8
this head d7f8fe99 release 8/8
this head with main's function-local static restored release 8/8

The last row is a control. As in my earlier run, the detach fail-fast doesn't reproduce on this machine; @thepatrickworld's pair on 26200 is the one that shows it.

Your failure is word 11: got 0x31415926, the untouched sentinel, so the split dispatch didn't write. The lifetime change only affects destruction at DLL detach, after every readback, so it can't change that word. That points to WARP 10.0.26100.33648 rather than this PR. Confirming would take a main run on your VM.

Still open, @ColorMeBoom: of the two lifetime sentences I asked for at 05:18, docs/experiments.md now has the first: the cache is kept for the life of the process. The second is still missing: that explicitly unloading and reloading d3d12_xs.dll in a live host isn't a supported path, because each load would allocate a new cache that nothing tears down. With that sentence added, this is ready from my side.

AI-assisted; commands listed were executed locally.

@MasterDomino

Copy link
Copy Markdown
Collaborator

@tedin7, thanks for the A/B. That contradicts my "can't change that word", so I withdraw it.

What I checked: the only in-process difference I can find between the two forms is storage location. A function-local static is zero-initialized before construction, and new T leaves members without an initializer indeterminate. But SplitIndirectDispatch holds only a std::mutex and a std::vector<std::unique_ptr<Entry>>, and Entry initializes device = nullptr. So nothing is indeterminate in either form, and both live until process exit.

Your failing run ran the split, but neither record wrote: count word=2, executed=2, with the result left at the sentinel 0x31415926. A different heap layout under the new instance changing that would point at something address-dependent, for example entry_for matching a raw ID3D12Device*. It could also be a flake on that WARP build.

Could you check two things on the VM?

  • Run ctest --preset dev -R '^startup_indirect_count_split_warp$' --repeat until-fail:10 on both variants (the head and the two-file revert).
  • If the head still fails while the revert never does, capture the x2w-d3d12 / split log lines of one failing run. I can't reproduce it with WARP 10.0.26100.9818 here: 8/8 on the head, dev and release.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

@MasterDomino Win2025 run for head d7f8fe99b5622226f8af599baf510901e93ba215 (Windows Server 2025, MSVC, D3D12 WARP):

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

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim -- -j 2): 3.01s (configure 0.00s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target d3d12_xs_device_obj d3d12_xs_shim -- -j 2): 51.69s (configure 0.00s)
  • sccache: 2/6 hits; wall 59.7s

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.

6 participants