Skip to content

D3D12-WARM-AMD-SINGLE-PROCESS: default leonida warm to one process on AMD - #2830

Open
bobcatchris wants to merge 1 commit into
ProjectLeonida:mainfrom
bobcatchris:fix/d3d12-warm-amd-single-process
Open

bobcatchris wants to merge 1 commit into
ProjectLeonida:mainfrom
bobcatchris:fix/d3d12-warm-amd-single-process

Conversation

@bobcatchris

@bobcatchris bobcatchris commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Claim: D3D12-WARM-AMD-SINGLE-PROCESS (#2570 (comment)).

What and why

leonida warm defaulted to two thirds of the logical cores. On an RX 7900 XTX that starts ten amdxc64.dll compiler processes; the driver silently refuses most PSOs and ends some processes with 0xc0000005. The same machine warmed 1,845 of 1,845 used pipelines with --jobs 1 and zero crashes, leaving warm-bad.txt empty.

This changes the default to one process when the DXGI adapter reports vendor 0x1002. --jobs still wins when passed explicitly, so the old behaviour remains available for A/B. Every other vendor keeps two thirds of the logical cores.

The vendor is queried through DXGI without creating a device, and LEONIDA_ADAPTER is honoured the same way the host device honours it. Two unit tests pin the pure default helper for AMD, another vendor and an unknown adapter.

No rendering or visual setting changes: this only chooses how many compiler processes warm uses before a run.

Verification (offline, no game files)

cargo test --locked -p leonida --bin leonida warm::tests
  test warm::tests::amd_compiles_one_pipeline_at_a_time ... ok
  test warm::tests::other_vendors_keep_two_thirds_of_the_cores ... ok
  test result: ok. 2 passed; 0 failed

cargo clippy --locked -p leonida --bin leonida   # no new warnings from this diff
python -I scripts/check_no_game_data.py <the four changed files>  # clean
git diff --check                                 # clean

The two leonida clippy warnings (player.rs:570 and the pre-existing count % 1000 in warm.rs) are on main before this change.

Hardware

Measured on AMD Ryzen 7 7800X3D, Radeon RX 7900 XTX (24 GB, driver 32.0.32029.2010), Windows 11. The compiler fault and the single-process warm are from the reporter's 48-minute log; this pull request changes only the default and was verified with the tests above, not by launching the game.

No game data, archives, shaders, textures or logs are in this change.

AI-assisted: yes.

Default `leonida warm` to one compiler process when the DXGI adapter reports
vendor 0x1002, unless --jobs is passed explicitly. On an RX 7900 XTX the old
two-thirds-of-cores default started ten amdxc64.dll compiler processes; the
driver refused most PSOs and crashed with 0xc0000005. A single process made
1,845 of 1,845 pipelines with no crashes. Other vendors keep the old default.

The vendor is read from DXGI without making a device, and LEONIDA_ADAPTER is
honoured as it is for the host device. Two unit tests pin the pure default
helper; no game files or shader data are involved.

AI-assisted: yes
@bobcatchris
bobcatchris force-pushed the fix/d3d12-warm-amd-single-process branch from 07c45c2 to c6fc64b Compare December 1, 2026 04:17
@ecox982745

Copy link
Copy Markdown
Contributor

Independent Windows CLI verification. Head c6fc64b05 merged cleanly into 86c30fcea (tree 556ef0ca1). I built it on Windows 11 with Rust 1.98.1/MSVC. For this CPU-only probe I stubbed adapter detection and the driver fingerprint in a scratch build and made any attempt to create the D3D12 host fail the fixture. The warm argument parser and job-selection path were unchanged.

Each invocation used warm --limit 0 with its own empty synthetic pipeline store. The two existing warm::tests also passed in this build.

Invocation Selected jobs in CLI output Vendor lookups
Default, AMD stub 1 1
Default, NVIDIA stub 10 1
Default, no adapter stub 10 1
Explicit --jobs 7 7 0
Explicit --jobs 0 1 0

The NVIDIA and no-adapter defaults used 16 logical cores. Both explicit cases were configured to fail if the new vendor lookup was called. All five invocations exited successfully with zero pipelines to compile. Actual DXGI selection and AMD compiler stability remain hardware checks.

AI-assisted with OpenAI Codex (GPT-6.2 Sol).

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On this NVIDIA box the new path is inert, which is the first thing to want: adapter_vendor_id() returns 0x10de and default_jobs(Some(0x10de), 32) is 21 (two thirds of 32) — the same as before — while --jobs still wins and never queries DXGI when passed. warm::tests is 2/2, flipping the vendor comparison fails both, and d3d12_switches.py --check, check_no_game_data and git diff --check are clean. Shaders' "every logical core" and LEONIDA_PIPELINE_WORKERS are untouched, so the shader-translation process count does not change — only how many warm processes run.

The risk I would write down, because I could not observe AMD here: the helper takes the first non-software EnumAdapters1 adapter (host.rs:1431), while create passes NULL to D3D12CreateDevice and lets Windows choose. On an Intel-iGPU + AMD-dGPU hybrid those can disagree — an OS per-app preference, or the iGPU enumerated first — and then warm picks two thirds of the cores while the runtime device is AMD, which is exactly the compiler-concurrency problem this default exists to avoid. LEONIDA_ADAPTER is the only way to align them today; the DXGI selection has no test (only default_jobs does). A sentence in the doc/comment about LEONIDA_ADAPTER would be cheap; a helper that takes the adapter list by injection would let the selection be tested.

Nit: with LEONIDA_ADAPTER set, the warm query calls chosen_adapter, which logs "host device on the card …" before any device exists, and then the device logs the same line again.

@imShangLi

Copy link
Copy Markdown
Contributor

VERIFY-2830 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), Wine 11.21, no GPU device, no game files

Verdict: PASS. The repository's own red/green idea holds under Wine: the new test fails on the merge base and passes with the pull request, and nothing that worked before is broken.

Head c6fc64b0, base the current main 85ec1d33, merge base 86c30fce, 4 files, +61/−2: d3d12/apps/leonida/src/warm.rs, d3d12/apps/leonida/src/main.rs, d3d12/crates/leonida-gpu/src/host.rs, d3d12/crates/leonida-gpu/src/lib.rs.

1. What it changes

AMD's driver compiler refuses most pipelines when several processes ask it at once, and faults (0xc0000005) when enough are refused. The warm command (which makes the title's pipelines ahead of time) used to run two thirds of the logical cores' worth of processes. The change asks the adapter for its vendor id and uses one process on AMD:

fn default_jobs(vendor: Option<u32>, cores: usize) -> usize {
    if vendor == Some(AMD) { 1 } else { (cores * 2 / 3).max(1) }
}

and the vendor id comes from a plain DXGI enumeration that makes no device:

/// PCI vendor ID of the adapter a run would use, without making a device.
/// `None` when no hardware adapter answers; callers then keep their old
/// behaviour. `LEONIDA_ADAPTER` is honoured, as it is for the device in [`create`],
/// otherwise the first hardware adapter Windows would pick.
pub fn adapter_vendor_id() -> Option<u32> { ... }

The enumeration skips software adapters (DXGI_ADAPTER_FLAG_SOFTWARE), so a WARP-only machine gets None and keeps the old default ✓.

2. What I checked

  • The arithmetic. The old default was cores * 2 / 3 and the new one is (cores * 2 / 3).max(1) for a non-AMD vendor — the same value as before (the old code's .max(1) was applied after unwrap_or, the new one after unwrap_or_else, so a caller-passed --jobs is still taken as given) ✓. On 16 cores that is 10, on one core 1 ✓.
  • The None case keeps the old behaviour, as the comment says: no adapter → the old two-thirds default ✓, which the new test checks (default_jobs(None, 16) == 10).
  • AMD is detected by the vendor id, 0x1002, the same constant the driver fault is attributed to ✓; a non-AMD vendor (0x10de) keeps two thirds ✓.
  • The enumeration is a read-only query — EnumAdapters1 and GetDesc1, no device made — which matters because the caller is the leonida app, before any device exists ✓.

3. Red and green, run under Wine

apps/leonida and leonida-gpu do not build on Linux (upstream: "The crates are Windows-only today … Linux follows #2577"), so I cross-compiled them for x86_64-pc-windows-gnu and ran the tests under Wine 11.21:

the merge base with only this pull request's tests 643 tests
the pull request's head 643 tests
red → green 1 test — the new one fails on the base and passes with the pull request
regressions 0
failing on both sides 3 — the watch tests that need Microsoft's VirtualAlloc/VirtualQuery behaviour, which Wine does not have

4. What I did not check

  • AMD's driver. That concurrent compiler processes refuse most pipelines and fault with 0xc0000005 is a claim about an AMD card and its driver; I have no AMD card here, and the fix's effect (one process instead of ten) cannot be measured.
  • Whether one process is enough on AMD — i.e. whether the warm-up now takes much longer. The pull request says one is what AMD's compiler accepts; I did not measure the time.
  • LEONIDA_ADAPTER being honoured by adapter_vendor_id(): I read that it uses the same chosen_adapter() the device path uses, and did not run it with that variable set.
  • Windows and MSVC. Everything above is Linux with Wine 11.21 (staging) and no GPU device.

AI-assisted: MiniMax M3.1 Flash.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants