DXC: unload a candidate folder that is not a usable dxcompiler (#2413) #2643

Open
github-bot wants to merge 1 commit from github-bot/gh-2643 into main AGit
Owner

@⁠kotekompotek on GitHub · 2026-11-26 04:52 UTC · original
kotekompotek:fix/dxc-candidate-leak → main · +77 −26 · 1 files · 1 commits · open

load() scans candidate folders for a usable DXC: it loads dxil.dll (the signer) and dxcompiler.dll, and keeps the first folder whose dxcompiler.dll exports DxcCreateInstance. When dxcompiler.dll failed to load, or loaded without the entry point, load() moved on without FreeLibrary – the failed folder's dxil.dll (and dxcompiler.dll) stayed mapped for the rest of the process. A stale dxil.dll in the loaded-module list is the one a later candidate's dxcompiler.dll binds by name when it loads its own dxil dependency, so a bad early folder poisons the later good one. Fixes #2413 (the candidate-load half; the empty-blob half is #2580).

What is in it

  • gpu/recomp/dxc.rs: the per-folder attempt is try_dir now and frees both handles before moving on (opus.rs uses the same FreeLibrary pattern).
  • candidate_unload_tests: a mapped file refuses deletion on Windows, so each test copies a stand-in DLL into a temp candidate folder, runs try_dir, and deletes the files – a leaked module keeps its file locked. One test covers the dxcompiler.dll-won't-load path, the other the missing-DxcCreateInstance path; both fail before the fix (PermissionDenied).

Tested

  • NVIDIA GeForce GTX 1050 (driver supports up to SM 6.5, no mesh shaders), AMD Ryzen 5 3600, Windows 11, rustc stable-x86_64-pc-windows-msvc; debug tests, release smoke builds
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on the head 5371d1df: 1434 passed, 3 failed, 47 ignored (SKIPPED GPU tests: 357 – this adapter has no SM 6.6 / mesh shaders)
  • cargo test -p xcl --lib candidate_unload: 2 passed
  • the lib failures are environmental on this machine, unrelated to the change (driver HRESULT/0x80070057, no SM 6.6 PSOs); details in the Not tested section

Regression run (0 s, default settings, a retail title)

main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce GTX 1050
title: 9cc6a39e
seconds: 0
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0
device removals: 0
crashes: 0
peak commit: 897 MB

this PR:

xcl-smoke v1
commit: 5371d1df53ab3a7232f16d4b5be39e07126505e8
gpu: NVIDIA GeForce GTX 1050
title: 9cc6a39e
seconds: 0
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0
device removals: 0
crashes: 0
peak commit: 874 MB

Not tested

  • hle::d3d12x::vram::tests::gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark, shaders::pipeline_cap_tests::stale_blob_cannot_bypass_the_offline_pipeline_cap, shaders::pipeline_cap_tests::split_compute_program_prebuilds_and_caches_chain_pieces: fail on main identically (GTX 1050 is SM 6.5 max; driver answers 0x80070057).
  • Anything needing SM 6.6, wave64, or mesh shaders: skipped on this adapter.
  • The GTA6 title crashes ~2–12 s into its own early init on this hardware (breakpad catch, not an XCL removal), so only -Seconds 0 produces a clean run; frames shown is 0 in both blocks. peak commit reads either ~900 MB (title killed during DLL loading) or ~5.4 GB (title reached its GDK heap reservation) depending on kill-vs-init timing under load; both blocks here are the ~900 MB outcome of otherwise identical runs.

AI use

  • Devin (SWE-2 High) verified the issue claims against the code, wrote the fix and the tests, ran the suite and the smoke runs, and opened the PR.
**@⁠kotekompotek** on GitHub · 2026-11-26 04:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/2643) `kotekompotek:fix/dxc-candidate-leak` → `main` · +77 −26 · 1 files · 1 commits · open `load()` scans candidate folders for a usable DXC: it loads `dxil.dll` (the signer) and `dxcompiler.dll`, and keeps the first folder whose `dxcompiler.dll` exports `DxcCreateInstance`. When `dxcompiler.dll` failed to load, or loaded without the entry point, `load()` moved on **without `FreeLibrary`** – the failed folder's `dxil.dll` (and `dxcompiler.dll`) stayed mapped for the rest of the process. A stale `dxil.dll` in the loaded-module list is the one a later candidate's `dxcompiler.dll` binds by name when it loads its own `dxil` dependency, so a bad early folder poisons the later good one. Fixes #2413 (the candidate-load half; the empty-blob half is #2580). **What is in it** - `gpu/recomp/dxc.rs`: the per-folder attempt is `try_dir` now and frees both handles before moving on (`opus.rs` uses the same `FreeLibrary` pattern). - `candidate_unload_tests`: a mapped file refuses deletion on Windows, so each test copies a stand-in DLL into a temp candidate folder, runs `try_dir`, and deletes the files – a leaked module keeps its file locked. One test covers the `dxcompiler.dll`-won't-load path, the other the missing-`DxcCreateInstance` path; both fail before the fix (`PermissionDenied`). **Tested** - NVIDIA GeForce GTX 1050 (driver supports up to SM 6.5, no mesh shaders), AMD Ryzen 5 3600, Windows 11, rustc stable-x86_64-pc-windows-msvc; debug tests, release smoke builds - `cargo test --workspace --no-fail-fast -- --test-threads=4` on the head `5371d1df`: 1434 passed, 3 failed, 47 ignored (SKIPPED GPU tests: 357 – this adapter has no SM 6.6 / mesh shaders) - `cargo test -p xcl --lib candidate_unload`: 2 passed - the lib failures are environmental on this machine, unrelated to the change (driver `HRESULT`/`0x80070057`, no SM 6.6 PSOs); details in the Not tested section **Regression run** (0 s, default settings, a retail title) main: ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce GTX 1050 title: 9cc6a39e seconds: 0 exit: 0x0 frames shown: 0 (PresentX 0) presents per 2 s (last 3): 0 device removals: 0 crashes: 0 peak commit: 897 MB ``` this PR: ``` xcl-smoke v1 commit: 5371d1df53ab3a7232f16d4b5be39e07126505e8 gpu: NVIDIA GeForce GTX 1050 title: 9cc6a39e seconds: 0 exit: 0x0 frames shown: 0 (PresentX 0) presents per 2 s (last 3): 0 device removals: 0 crashes: 0 peak commit: 874 MB ``` **Not tested** - `hle::d3d12x::vram::tests::gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark`, `shaders::pipeline_cap_tests::stale_blob_cannot_bypass_the_offline_pipeline_cap`, `shaders::pipeline_cap_tests::split_compute_program_prebuilds_and_caches_chain_pieces`: fail on `main` identically (GTX 1050 is SM 6.5 max; driver answers `0x80070057`). - Anything needing SM 6.6, wave64, or mesh shaders: skipped on this adapter. - The GTA6 title crashes ~2–12 s into its own early init on this hardware (breakpad catch, not an XCL removal), so only `-Seconds 0` produces a clean run; frames shown is 0 in both blocks. `peak commit` reads either ~900 MB (title killed during DLL loading) or ~5.4 GB (title reached its GDK heap reservation) depending on kill-vs-init timing under load; both blocks here are the ~900 MB outcome of otherwise identical runs. **AI use** - Devin (SWE-2 High) verified the issue claims against the code, wrote the fix and the tests, ran the suite and the smoke runs, and opened the PR.
load() kept a candidate's dxil.dll (and dxcompiler.dll when it loaded but
lacked DxcCreateInstance) mapped for the rest of the process when the
candidate was skipped: the h.is_null() and GetProcAddress-miss paths both
fell through without FreeLibrary. A stale dxil.dll in the loaded-module
list is the one a later candidate's dxcompiler.dll binds by name. The
per-folder attempt is try_dir now and frees both handles before moving on;
a mapped file refuses deletion on Windows, so the test reads the leak back
through the filesystem.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:14:27 +00:00
Author
Owner

@⁠DarkPanda69 on GitHub · 2026-11-26 05:07 UTC · original

The three GPU tests listed as not tested (they fail on the GTX 1050, which has SM 6.5 at most) pass with this PR on two SM 6.6 cards, an RX 9070 XT and an RTX 3060. The 2 new tests pass too.

Head 5371d1d applied on main b49be18, debug, Windows 11 Pro 26200, card chosen with XCL_ADAPTER, each run with --nocapture:

cargo test -p xcl --lib -- <filter> RX 9070 XT (RDNA4, 32.0.32029.2010) RTX 3060 (32.0.16.1088)
a_candidate_ (a_candidate_without_dxc_create_instance_is_unloaded, a_candidate_whose_dxcompiler_dll_does_not_load_keeps_no_dxil) 2 passed 2 passed
gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark ok, no SKIPPED ok, no SKIPPED
pipeline_cap_tests (both blob tests and the cap test) 3 passed, no SKIPPED 3 passed, no SKIPPED
recomp::dxc:: 22 passed, 0 failed 22 passed, 0 failed

Not tested: the whole suite with this PR, a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

**@⁠DarkPanda69** on GitHub · 2026-11-26 05:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/2643#issuecomment-7183207257) The three GPU tests listed as not tested (they fail on the GTX 1050, which has SM 6.5 at most) pass with this PR on two SM 6.6 cards, an RX 9070 XT and an RTX 3060. The 2 new tests pass too. Head `5371d1d` applied on `main` `b49be18`, debug, Windows 11 Pro 26200, card chosen with `XCL_ADAPTER`, each run with `--nocapture`: | `cargo test -p xcl --lib -- <filter>` | RX 9070 XT (RDNA4, 32.0.32029.2010) | RTX 3060 (32.0.16.1088) | |---|---|---| | `a_candidate_` (`a_candidate_without_dxc_create_instance_is_unloaded`, `a_candidate_whose_dxcompiler_dll_does_not_load_keeps_no_dxil`) | 2 passed | 2 passed | | `gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark` | ok, no SKIPPED | ok, no SKIPPED | | `pipeline_cap_tests` (both blob tests and the cap test) | 3 passed, no SKIPPED | 3 passed, no SKIPPED | | `recomp::dxc::` | 22 passed, 0 failed | 22 passed, 0 failed | Not tested: the whole suite with this PR, a title. AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Author
Owner

@⁠sage-sage on GitHub · 2026-11-26 05:18 UTC · original

Test report: passes on NVIDIA, and both new tests fail without the unloads. Exact head 5371d1df (its base is current main b49be18, so head = merged).

Tested

  • RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100), debug build
  • cargo test --workspace -- --test-threads=4: 1437 passed, 0 failed, 47 ignored; both candidate_unload_tests pass
  • SKIPPED (29 lines, the same as on main on this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (d3d12SDKLayers.dll not installed), 1 no heap windows, 1 pso_measurement_compiles_an_exact_synthetic_record (Developer Mode off)
  • With the FreeLibrary calls in try_dir taken out (the old behaviour, local only): both new tests fail, dxcompiler.dll still mapped – leaked / dxil.dll still mapped – leaked (Access is denied). So they cover the fix.

Not tested

  • A real second DXC folder (an old or broken SDK before a good one); no game.

Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

**@⁠sage-sage** on GitHub · 2026-11-26 05:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/2643#issuecomment-7183362278) **Test report: passes on NVIDIA, and both new tests fail without the unloads.** Exact head `5371d1df` (its base is current `main` `b49be18`, so head = merged). **Tested** - RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100), debug build - `cargo test --workspace -- --test-threads=4`: 1437 passed, 0 failed, 47 ignored; both `candidate_unload_tests` pass - SKIPPED (29 lines, the same as on `main` on this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (`d3d12SDKLayers.dll` not installed), 1 `no heap windows`, 1 `pso_measurement_compiles_an_exact_synthetic_record` (Developer Mode off) - With the `FreeLibrary` calls in `try_dir` taken out (the old behaviour, local only): both new tests fail, `dxcompiler.dll still mapped – leaked` / `dxil.dll still mapped – leaked` (`Access is denied`). So they cover the fix. **Not tested** - A real second DXC folder (an old or broken SDK before a good one); no game. Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 08:47 UTC · original · reviewed

At exact head 5371d1df on current main b49be18, one “unusable candidate” path still retains the early DLL and prevents a later working folder from being tried. This is a source-derived review; I did not build a fake DXC DLL.

try_dir accepts and caches a candidate as soon as dxcompiler.dll exports DxcCreateInstance. Its library() call probes version info but explicitly treats that probe's failure as nonfatal. The interface XCL actually needs is CLSID_DxcCompiler / IDxcCompiler3, requested only later in compiler(). A DLL with the export that returns E_NOINTERFACE (or a null pointer) for that interface is therefore published in LIB; every compile then fails, while a later usable DXC candidate is never visited. The early dxil.dll also stays mapped. The new unload tests cover a missing DLL and a missing export, but not an export that cannot create the required interface.

Could try_dir probe IDxcCompiler3 before publishing the candidate, release the probe object, and unload both handles on failure? An injected export that fails this IID followed by a good candidate would cover selection and cleanup.

AI assistance: GPT-6.2 Sol found the missing interface check; GPT-6.2 Astra verified the exact-head loader and compiler paths.

**@⁠luckyteagirl** on GitHub · 2026-11-26 08:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/2643#pullrequestreview-6070940049) · **reviewed** At exact head `5371d1df` on current main `b49be18`, one “unusable candidate” path still retains the early DLL and prevents a later working folder from being tried. This is a source-derived review; I did not build a fake DXC DLL. `try_dir` accepts and caches a candidate as soon as `dxcompiler.dll` exports `DxcCreateInstance`. Its `library()` call probes version info but explicitly treats that probe's failure as nonfatal. The interface XCL actually needs is `CLSID_DxcCompiler` / `IDxcCompiler3`, requested only later in `compiler()`. A DLL with the export that returns `E_NOINTERFACE` (or a null pointer) for that interface is therefore published in `LIB`; every compile then fails, while a later usable DXC candidate is never visited. The early `dxil.dll` also stays mapped. The new unload tests cover a missing DLL and a missing export, but not an export that cannot create the required interface. Could `try_dir` probe `IDxcCompiler3` before publishing the candidate, release the probe object, and unload both handles on failure? An injected export that fails this IID followed by a good candidate would cover selection and cleanup. AI assistance: GPT-6.2 Sol found the missing interface check; GPT-6.2 Astra verified the exact-head loader and compiler paths.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2643/head:github-bot/gh-2643'
git switch 'github-bot/gh-2643'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2643'
git switch 'github-bot/gh-2643'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2643'
git switch 'github-bot/gh-2643'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2643'
git switch 'main'
git merge --squash 'github-bot/gh-2643'
git switch 'main'
git merge --ff-only 'github-bot/gh-2643'
git switch 'main'
git merge 'github-bot/gh-2643'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.