Skip to content

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

Merged
tedin7 merged 4 commits into
R0Y00:mainfrom
ColorMeBoom:fix/split-dispatch-teardown
Nov 26, 2026
Merged

tedin7 merged 4 commits into
R0Y00:mainfrom
ColorMeBoom:fix/split-dispatch-teardown

Conversation

@ColorMeBoom

@ColorMeBoom ColorMeBoom commented Nov 26, 2026 •

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

Lifetime boundary. The splitter cache is process-owned and released only by process exit. Explicitly unloading and reloading d3d12_xs.dll in a live host is not a supported path: each load allocates a new cache and nothing tears the previous one down outside the loader lock, so its entries stay allocated. Supporting it needs that teardown and its own coverage, which is a separate change. The header comment and docs/experiments.md say the same.

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

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

On the RX 9070 XT (driver 32.0.32029.2010, Windows build 26200.9974, no debug layer), @thepatrickworld measured the pair in this thread. With this change merged onto main, startup_indirect_count_split_hardware passed and 6 of 6 direct runs exited 0. With only the header restored to the static, 4 of 4 ended in 0xC0000409, and the dump showed the static's destructor at DLL detach.

Head 50cd7fe7 (lifetime statement, docs) on this RX 5700 XT: startup_indirect_count_split_(warp|hardware) passed, and startup_indirect_count_split_warp --repeat until-fail:20 passed on WARP 10.0.26100.9818. docs_links, bidi_controls and git diff --check are clean.

Not verified

The RX 5700 XT and WARP exited 0 before this change too, so runs here show no regression, not the fix; the RX 9070 XT pair above is the fix's evidence. The startup_indirect_count_split_warp failure on WARP 10.0.26100.33648 is not reproduced here or on WARP 10.0.26100.9818.

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.

@thepatrickworld

Copy link
Copy Markdown
Contributor

Coverage for the unload/reload path you asked about, measured in a live host. Not a code change to this PR: a new fixture and its result, on the same adapter and driver that reported the fault.

What it does

A host that links the shim only through LoadLibraryExW + GetProcAddress, so FreeLibrary can actually unmap it. dumpbin /imports on the built executable lists d3d12.dll, dxgi.dll, D3DCOMPILER_47.dll, the CRT and KERNEL32 — with LoadLibraryExW, GetProcAddress and FreeLibrary — and no d3d12_xs.dll. Phase A loads the module, runs the counted split dispatch (X2W_SPLIT_INDIRECT_DISPATCH=1, MaxCommandCount 3) and checks the readback; the module is unloaded; phase B loads it again and repeats the same case on a new device. The process exit code is the verdict.

Result on the RX 9070 XT

backend=hardware adapter=AMD Radeon RX 9070 XT vendor=1002 device=7550
driver=32.0.32029.2010
windows=10.0.26200
debug_layer=unavailable
split_indirect_dispatch=1
reload phase A: module base=00007FFB92730000
reload phase A: split scratch held=1, so the count was split instead of run natively
reload phase A: count word=3, executed=3, result=0x31415a64 (expected 0x31415a64)
reload phase A unload: FreeLibrary ok, module unmapped (no module under the name, none at the export address: no reference is left)
reload phase B: module base=00007FFB92730000
reload phase B: the loader reused phase A's address; the unload check above, not the address, is the evidence that this is a distinct image
reload phase B: split scratch held=1, so the count was split instead of run natively
reload phase B: count word=3, executed=3, result=0x31415a64 (expected 0x31415a64)
reload phase B unload: FreeLibrary ok, module unmapped (no module under the name, none at the export address: no reference is left)

The CTest entry startup_split_reload_hardware — add_test(NAME startup_split_reload_hardware COMMAND startup_split_reload "$<TARGET_FILE:d3d12_xs_shim>") — reports Passed 0.41 sec, and the log's CTEST=0; a direct run of the same executable ends DIRECT_EXIT=0.

One reading note on the log: the shim's log() writes to stderr while the fixture uses printf, so in a captured file every x2w-* line lands before the fixture's own. The two x2w-* blocks are in phase order among themselves (two devices, two Device::CreateRootSignature at 0000012F251B3570 then 0000012F6E24F450, two slot-41 command signatures), but their position relative to the reload phase … lines is not evidence of anything.

What this establishes, and what it does not

Established: an explicit unload is clean here — both times the image is gone from the process, measured by name and by the export's address rather than by FreeLibrary's TRUE — and phase B runs the counted split again on a new device. The split branch has no native fallback: if the rewrite cannot be set up it refuses the call (d3d12_xs_device.cpp, refuse("split indirect Dispatch rewrite is unavailable")) and the readback would fail, so the matching 0x31415a64 means the shim's own split pipeline and root signature were used for that device. On this run the loader path does not reproduce the 0xC0000409.

Not established, and I do not claim it: that phase B builds a new cache. SplitIndirectDispatch is not observable — no export reports it, its entries or their objects — so a harness cannot count instances, and a cache that survived the reload or lived outside the module would print exactly the same lines. The only argument is that a freshly mapped image reinitialises its data segment, and nothing here observes that.

What the source says about lifetime, which this run does not: the first cache's root signature and pipeline are abandoned, never freed — entry_for's comment says so ("Entries are never freed"), entries_ is never cleared, and the splitter itself is a leaked new in split_indirect_dispatch() (src/startup_stubs/split_indirect_dispatch.h). So an unload does not release the entries of the load it unmaps; they stay allocated for the life of the process. That is a reading of the header, not a measurement — and it is what the "process-owned" wording should say.

One thing worth a look, offered as a question

entry_for keys entries_ on a raw, never-AddRef'd ID3D12Device* compared by pointer equality, and never frees an entry. A device destroyed and a new device created at the same address would match the stale entry and get back the old root signature and pipeline, which rewrite would then bind on the new device's list. Unless those retained objects keep the old device alive — they may — which would make the case unreachable. I have not measured either way, so this is a question rather than a report.

The fixture lives on my fork at panam/2734-reload, commit 2b877c75 (tests/startup_split_reload.cpp, +14 lines in CMakeLists.txt). Say if you want it as a PR of its own and where — against main, or as a patch on this branch.

AI-assisted.

Review of R0Y00#2734: 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 allocates a new cache that nothing
tears down outside the loader lock; supporting it needs that teardown and
its own coverage. The header comment and docs/experiments.md now say so.

The docs also record the RX 9070 XT pair from the review (6 of 6 exit 0
with the change, 4 of 4 0xC0000409 with the static restored) and a
measured answer to the device-pointer question: the cached root signature
and pipeline each hold a device reference (count 1 -> 3, still 2 after the
application's Release, on the RX 5700 XT and WARP), so a cached device is
never destroyed and its address cannot be reused while an entry holds them.

AI-assisted.
@ColorMeBoom

Copy link
Copy Markdown
Contributor Author

@MasterDomino @R0Y00: 50cd7fe7 adds the lifetime boundary to the header comment, to docs/experiments.md and to the description. The splitter cache is process-owned and released only by process exit. Explicitly unloading and reloading d3d12_xs.dll in a live host is not a supported path: each load allocates a new cache and nothing tears the previous one down outside the loader lock. Supporting it needs that teardown and its own coverage, as a separate change. The docs also record @thepatrickworld's RX 9070 XT pair (6 of 6 exit 0 with the change, 4 of 4 0xC0000409 with only the header restored).

@thepatrickworld, on the raw ID3D12Device* key in entry_for: the objects an entry keeps hold their device. A small standalone program created a device, a root signature and a compute pipeline, and read the device's count after each step:

Step RX 5700 XT (32.0.21045.29003) WARP 10.0.26100.9818
after D3D12CreateDevice 1 1
plus a root signature 2 2
plus a compute pipeline 3 3
after the application's own Release() 2 2

pipeline->GetDevice() then returned the original pointer. So a device with a cached entry is never destroyed, and no new device can appear at its address while the entry holds those objects. The one gap is an entry whose build failed, which holds neither object: a later device at the same address would get the "rewrite is unavailable" refusal instead of a fresh build. The docs paragraph says this. On the reload fixture: since this PR now says unload and reload is unsupported, I'd keep it out of this PR. If the maintainers want that path covered, it fits best as its own PR against main, together with the teardown it would need.

@tedin7, on startup_indirect_count_split_warp: on this head (50cd7fe7, dev preset), ctest -R '^startup_indirect_count_split_warp$' --repeat until-fail:20 passed all 20 on WARP 10.0.26100.9818. That matches MasterDomino's runs on the same WARP build, so the failure stays specific to WARP 10.0.26100.33648 so far. Your A/B with --repeat until-fail:10 on both variants would show whether it follows the change there.

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

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Win2025 WARP receipt for head 973a8b2 after updating with main.

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

  • Debug (--preset dev): build of d3d12_xs_device_obj d3d12_xs_shim OK. ctest --preset dev -R '^startup_indirect_count_(split_)?(warp|hardware)$' --no-tests=error: 4/4 passed (startup_indirect_count_warp, startup_indirect_count_split_warp, startup_indirect_count_hardware, startup_indirect_count_split_hardware).
  • Release /O2 (--preset release): same build and same regex: 4/4 passed.
  • startup_indirect_count_split_warp passes on this head in both presets.

Review of this head (code + fixtures only):

  • The diff is two files: a new-and-never-delete function-local pointer in src/startup_stubs/split_indirect_dispatch.h, plus a comment and docs/experiments.md text. No test file is changed, so the split tests are not weakened. They still exercise the same splitter code path.
  • The intentional leak is bounded: entries were already kept for the process lifetime (see entry_for), and the new comment states that DLL unload/reload is unsupported.
  • git diff --check, tests/docs_links_check.py, tests/bidi_controls_check.py: clean.
  • The RX 9070 XT behaviour (0xC0000409 at DLL detach) was measured on real hardware by others in this thread; this run only covers WARP. Merge stays with @R0Y00 / MasterDomino.

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.

Review of head 973a8b2 (code + fixtures; Win2025 receipt posted above):

  • The diff is two files: a new-and-never-delete function-local pointer in src/startup_stubs/split_indirect_dispatch.h, plus a comment and docs/experiments.md text. No test file is changed, so the split tests are not weakened. They still exercise the same splitter code path.
  • The intentional leak is bounded: entries were already kept for the process lifetime (see entry_for), and the new comment states that DLL unload/reload is unsupported.
  • git diff --check, tests/docs_links_check.py, tests/bidi_controls_check.py: clean.
  • The RX 9070 XT behaviour (0xC0000409 at DLL detach) was measured on real hardware by others in this thread; this run only covers WARP. Hardware evidence is theirs to weigh.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 merged commit a606465 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.

6 participants