d3d12: background shader work off by default on NVIDIA with Developer Mode (D3D12-BACKGROUND-OFF-NVIDIA) #3437

Merged
leonida/mandy
OreoFR merged 7 commits from oreofr/background-off-nvidia into main 2026-12-04 07:36:27 +00:00 AGit

Pull request successfully merged and closed

Member

Claimed in the coordination issue as D3D12-BACKGROUND-OFF-NVIDIA. Validated with conditions by MoonEyes.

Depends on: #3301 (it changes the same lines; this branch merges its head 810d3c6a2 and resolves its Cargo.toml conflict with main)
Refs #2821

What and why

The driver's background shader work ("D3D Background Threads", ID3D12Device6::SetBackgroundProcessingMode(DISABLE_BACKGROUND_WORK, KEEP_ALL)) was switched off only with LEONIDA_D3D12_BACKGROUND=0. On NVIDIA that switch stopped the DXGI_ERROR_DEVICE_REMOVED (0x887A0005) losses of #2821. This makes it the default there, under MoonEyes' conditions:

LEONIDA_D3D12_BACKGROUND NVIDIA (0x10DE), Developer Mode on NVIDIA, Developer Mode off other vendors, WARP, unknown adapter
unset (or another value) off (new default) kept, one log line with the advice kept (as before)
0 off off is requested; the call's failure is logged (#3301) off
1 kept kept, no log line kept
  • Developer Mode is read, never changed. developer_mode() reads AllowDevelopmentWithoutDevLicense under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock (RegGetValueW, read only, through tdr::machine_dword, the reader the TDR log already used). It is read only for an NVIDIA adapter with the variable unset.
  • Why the registry and not the call's result: the decision is made before anything is asked of the runtime, so the "Developer Mode is off" log line is certain instead of guessed from an HRESULT that can also mean no ID3D12Device6 or a driver refusal; the decision stays a pure function (background_work(setting, vendor, developer_mode)) that unit tests cover entirely; and no call is made on a PC where it is known to be refused. The call's result is still logged (from #3301): ok=true, or a warning with the HRESULT if the registry says on and the runtime refuses anyway.
  • Without Developer Mode on NVIDIA, one info line: the background shader work stays on; Mandy switches it off on NVIDIA (it stopped the #2821 losses), which Windows allows only with Developer Mode; turning on Settings > System > For developers > Developer Mode lets Mandy do it, and also lets the PC install apps from any source, not only the Store and signed packages; LEONIDA_D3D12_BACKGROUND=1 silences it.
  • The vendor comes from the device's own adapter (EnumAdapterByLuid(device.GetAdapterLuid()), the lookup Host::adapter already did, moved up a few lines), so it is right with -Adapter, the default adapter and WARP.
  • Documented in the code comment, d3d12/docs/switches.md (regenerated) and a new d3d12/docs/findings.md section.
  • MEASURED, device losses with =0 on NVIDIA: about 14 runs on 5 PCs, 0 losses (RTX 4060 Laptop: 5 losses in 6 runs without it, 3 runs of 30-45 min with it; RTX 4080 SUPER: 3 of 3 without, 0 in 1 with (n=1); RTX 4070: 0 in 2 runs of 33 min and 1 h 36 min; RTX 3070: 5 of 6 without, 0 in 2 with (n=2); RTX 4080).
  • MEASURED, cost on an RTX 3090 (comment 25327, ABBA, 600 s, Series X 1440p DLSS Quality, n=1 valid pair): +0.4 fps (inside the noise), median frame -0.65 ms, p99 -3 ms; 0 losses in 4 runs (that card does not lose the device in such runs, so this is the cost, not the cure).
  • Against it: one run on an RTX 4060 Ti on 2026-11-27 (findings.md, "Frame-rate switches measured on a six-core PC") was slower with the work off (118.6 against about 80 ms, n=1, many runtime changes ago). =1 gives the work back where it costs frames.
  • Why the background recompiles end in a loss is not known.

Tested

  • Unit tests (host::tests): background_work_is_off_by_default_on_nvidia_with_developer_mode covers the vendor (NVIDIA, AMD, Intel, WARP, unknown) x Developer Mode (on, off) x variable (unset, 0, 1, other) table, and that 0/1/other vendors never read Developer Mode. Red/green: with the old default (unset keeps the work) it fails (left: KeptWithoutDeveloperMode, right: DisableByDefault), with the change it passes. #3301's log test is extended to the new decisions (advice line, default on NVIDIA reason, failure warnings).
  • cargo test --locked -p leonida-gpu: 735 passed, 0 failed (59 ignored). cargo clippy --locked -p leonida-gpu --all-targets: no warning.
  • cargo build --locked --profile diag -p leonida --features diagnostics,dlss,mimalloc: builds (the one leonida-gpu warning, book.rs:247, is on main too).
  • python -I tests/test_d3d12_switches.py: 22 OK; python -I scripts/check_no_game_data.py on the changed files: clean.
  • Not measured before/after on this PC: tested on RTX 4070 Laptop without Developer Mode (only the off path ran: the work stays on and the advice line is the only change there). No game run was made for this pull request.

GPUs tested: NVIDIA GeForce RTX 4070 Laptop GPU, Windows 11 Pro, Developer Mode off (unit tests and build only).

Follow-up (not in this pull request)

  • A launcher hint or setting for Developer Mode is left to the launcher's owner (OreoFR): this pull request only logs the advice and adds no launcher UI.

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

Checklist

  • Based on current main (plus #3301) and merges cleanly.
  • One topic.
  • No game data, keys or decryption.

🤖 Generated with Claude Code

Claimed in the coordination issue as [D3D12-BACKGROUND-OFF-NVIDIA](https://git.leonida.now/leonida/mandy/issues/3312#issuecomment-25336). Validated with conditions by MoonEyes. Depends on: #3301 (it changes the same lines; this branch merges its head `810d3c6a2` and resolves its `Cargo.toml` conflict with `main`) Refs #2821 ### What and why The driver's background shader work ("D3D Background Threads", `ID3D12Device6::SetBackgroundProcessingMode(DISABLE_BACKGROUND_WORK, KEEP_ALL)`) was switched off only with `LEONIDA_D3D12_BACKGROUND=0`. On NVIDIA that switch stopped the `DXGI_ERROR_DEVICE_REMOVED` (0x887A0005) losses of #2821. This makes it the default there, under MoonEyes' conditions: | `LEONIDA_D3D12_BACKGROUND` | NVIDIA (0x10DE), Developer Mode on | NVIDIA, Developer Mode off | other vendors, WARP, unknown adapter | |---|---|---|---| | unset (or another value) | **off** (new default) | kept, one log line with the advice | kept (as before) | | `0` | off | off is requested; the call's failure is logged (#3301) | off | | `1` | kept | kept, no log line | kept | - **Developer Mode is read, never changed.** `developer_mode()` reads `AllowDevelopmentWithoutDevLicense` under `HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock` (`RegGetValueW`, read only, through `tdr::machine_dword`, the reader the TDR log already used). It is read only for an NVIDIA adapter with the variable unset. - **Why the registry and not the call's result:** the decision is made before anything is asked of the runtime, so the "Developer Mode is off" log line is certain instead of guessed from an HRESULT that can also mean no `ID3D12Device6` or a driver refusal; the decision stays a pure function (`background_work(setting, vendor, developer_mode)`) that unit tests cover entirely; and no call is made on a PC where it is known to be refused. The call's result is still logged (from #3301): `ok=true`, or a warning with the HRESULT if the registry says on and the runtime refuses anyway. - **Without Developer Mode on NVIDIA**, one info line: the background shader work stays on; Mandy switches it off on NVIDIA (it stopped the #2821 losses), which Windows allows only with Developer Mode; turning on Settings > System > For developers > Developer Mode lets Mandy do it, and also lets the PC install apps from any source, not only the Store and signed packages; `LEONIDA_D3D12_BACKGROUND=1` silences it. - The vendor comes from the device's own adapter (`EnumAdapterByLuid(device.GetAdapterLuid())`, the lookup `Host::adapter` already did, moved up a few lines), so it is right with `-Adapter`, the default adapter and WARP. - Documented in the code comment, `d3d12/docs/switches.md` (regenerated) and a new `d3d12/docs/findings.md` section. ### Evidence (#2821; details and links in `findings.md`) - MEASURED, device losses with `=0` on NVIDIA: about 14 runs on 5 PCs, 0 losses ([RTX 4060 Laptop](https://git.leonida.now/leonida/mandy/issues/2821#issuecomment-7868): 5 losses in 6 runs without it, 3 runs of 30-45 min with it; [RTX 4080 SUPER](https://git.leonida.now/leonida/mandy/issues/2821#issuecomment-7870): 3 of 3 without, 0 in 1 with (n=1); [RTX 4070](https://git.leonida.now/leonida/mandy/issues/2821#issuecomment-7871): 0 in 2 runs of 33 min and 1 h 36 min; [RTX 3070](https://git.leonida.now/leonida/mandy/issues/2821#issuecomment-25224): 5 of 6 without, 0 in 2 with (n=2); [RTX 4080](https://git.leonida.now/leonida/mandy/issues/2821#issuecomment-25163)). - MEASURED, cost on an RTX 3090 ([comment 25327](https://git.leonida.now/leonida/mandy/issues/2821#issuecomment-25327), ABBA, 600 s, Series X 1440p DLSS Quality, n=1 valid pair): +0.4 fps (inside the noise), median frame -0.65 ms, p99 -3 ms; 0 losses in 4 runs (that card does not lose the device in such runs, so this is the cost, not the cure). - Against it: one run on an RTX 4060 Ti on 2026-11-27 (`findings.md`, "Frame-rate switches measured on a six-core PC") was slower with the work off (118.6 against about 80 ms, n=1, many runtime changes ago). `=1` gives the work back where it costs frames. - Why the background recompiles end in a loss is not known. ### Tested - Unit tests (`host::tests`): `background_work_is_off_by_default_on_nvidia_with_developer_mode` covers the vendor (NVIDIA, AMD, Intel, WARP, unknown) x Developer Mode (on, off) x variable (unset, `0`, `1`, other) table, and that `0`/`1`/other vendors never read Developer Mode. Red/green: with the old default (unset keeps the work) it fails (`left: KeptWithoutDeveloperMode, right: DisableByDefault`), with the change it passes. #3301's log test is extended to the new decisions (advice line, `default on NVIDIA` reason, failure warnings). - `cargo test --locked -p leonida-gpu`: 735 passed, 0 failed (59 ignored). `cargo clippy --locked -p leonida-gpu --all-targets`: no warning. - `cargo build --locked --profile diag -p leonida --features diagnostics,dlss,mimalloc`: builds (the one `leonida-gpu` warning, `book.rs:247`, is on `main` too). - `python -I tests/test_d3d12_switches.py`: 22 OK; `python -I scripts/check_no_game_data.py` on the changed files: clean. - **Not measured before/after on this PC:** tested on RTX 4070 Laptop without Developer Mode (only the off path ran: the work stays on and the advice line is the only change there). No game run was made for this pull request. GPUs tested: NVIDIA GeForce RTX 4070 Laptop GPU, Windows 11 Pro, Developer Mode off (unit tests and build only). ### Follow-up (not in this pull request) - A launcher hint or setting for Developer Mode is left to the launcher's owner (OreoFR): this pull request only logs the advice and adds no launcher UI. AI-assisted: Claude Code (Claude Opus 5.5). ### Checklist - [x] Based on current `main` (plus #3301) and merges cleanly. - [x] One topic. - [x] No game data, keys or decryption. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
# Conflicts:
#	d3d12/crates/leonida-gpu/Cargo.toml
LEONIDA_D3D12_BACKGROUND unset now switches the runtime's background
shader work off (SetBackgroundProcessingMode DISABLE_BACKGROUND_WORK)
on an NVIDIA host adapter (0x10DE) when Windows Developer Mode is
already on, read from AllowDevelopmentWithoutDevLicense (read only).
=1 keeps it, =0 still forces it off on any card. On NVIDIA without
Developer Mode one log line says the work stays on and how to turn
Developer Mode on. Evidence and the RTX 3090 cost in findings.md
(#2821). Builds on #3301's result logging.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator

Gate run on an RTX 3090 (NVIDIA 621.40, Windows 11 Pro build 26300, Developer Mode on), head d96dbaaa9 (which contains #3301) merged into main 04a838fc4 without conflict, diag profile with diagnostics,dlss,mimalloc, msvc target. Run with LEONIDA_D3D12_BACKGROUND unset. Reference: main 04a838fc4 built the same way. Series X output 2560x1440, DLSS quality, no frame generation, 300 s standing at the save, fresh data.

  • The PR's decision line is logged once, with ok=true and the reason (NVIDIA, Developer Mode on) in the line itself. No variable was needed.
  • An all-threads sampler over the run saw no "D3D Background Thread" at all (it read 106 thread names, so naming works). On main the same sampler had seen 4 of them in an earlier run.
  • 0 device lost, 0 crash, 0 ERROR lines.
  • 35.6 frames/s over 150-300 s against 34.5 for main; median frame 27.66 against 28.69 ms, p99 42.2 against 45.5 ms. Other processes used about 7 points less CPU in this run than in the reference, so read this as "no cost", not as a gain. Pauses as in the reference (the loading one, then a few of 1.3-3.4 s right after reaching the world), none after 150 s.
  • Captures at 150 and 300 s: the same picture as main.
  • #3301's mesh path was active in this run (mesh programs not turned into compute) with no fault.

Verdict: PASS. On a PC with Developer Mode on, the background work is off by default, logged clearly, and costs nothing here.

GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40.
AI-assisted: run and report by Claude Code (Claude Opus 5.5).

Gate run on an RTX 3090 (NVIDIA 621.40, Windows 11 Pro build 26300, Developer Mode on), head `d96dbaaa9` (which contains #3301) merged into `main` `04a838fc4` without conflict, diag profile with `diagnostics,dlss,mimalloc`, msvc target. Run with `LEONIDA_D3D12_BACKGROUND` unset. Reference: `main` `04a838fc4` built the same way. Series X output 2560x1440, DLSS quality, no frame generation, 300 s standing at the save, fresh data. - The PR's decision line is logged once, with `ok=true` and the reason (NVIDIA, Developer Mode on) in the line itself. No variable was needed. - An all-threads sampler over the run saw no "D3D Background Thread" at all (it read 106 thread names, so naming works). On `main` the same sampler had seen 4 of them in an earlier run. - 0 device lost, 0 crash, 0 ERROR lines. - 35.6 frames/s over 150-300 s against 34.5 for `main`; median frame 27.66 against 28.69 ms, p99 42.2 against 45.5 ms. Other processes used about 7 points less CPU in this run than in the reference, so read this as "no cost", not as a gain. Pauses as in the reference (the loading one, then a few of 1.3-3.4 s right after reaching the world), none after 150 s. - Captures at 150 and 300 s: the same picture as `main`. - #3301's mesh path was active in this run (mesh programs not turned into compute) with no fault. Verdict: PASS. On a PC with Developer Mode on, the background work is off by default, logged clearly, and costs nothing here. GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40. AI-assisted: run and report by Claude Code (Claude Opus 5.5).
OreoFR merged commit 6b5ceb9349 into main 2026-12-04 07:36:27 +00:00
Author
Member

Merged by OreoFR (agent) at MoonEyes' request. His judge accepted it with no blocking or medium point. The one useful minor point was fixed in d96dbaaa9: Developer Mode forced by a group policy now counts too.

enlighted ran it in game on an RTX 3090 with Developer Mode on and no variable, 300 s:

  • the decision line printed once with ok=true;
  • no "D3D Background Thread" left;
  • 0 lost, 0 crash, 0 ERROR;
  • picture identical to main;
  • no fps cost.

Local CI (normal mode, --trust-pr-code) on head d96dbaaa9 merged into main 30a851050: PASS.

  • --trust-pr-code was used after reading the change: a tracing-subscriber dev-dependency from the workspace, with one line in Cargo.lock and no new crate.
  • Passing checks: merge clean, no game data, Python compiles, make_game.py --help, Rust tests 845 s, Rust replay test 77 s, Rust build as shipped 86 s, standard-library Python tests 603 s.
  • Report-only steps, as in the GitHub workflow: asset policy and Clippy.

The forge refused the merge while the head was behind main. main (30a851050) was merged into the head as e6fdc8c40, with the same tree the CI tested. Merged as 6b5ceb934.

This brings #3301 (head 810d3c6a2) into main with its conflict resolved, as MoonEyes asked. #3301 is closed with a link here.

Not run on the RTX 4070 Laptop: Developer Mode is off there, so only the "kept, with the log line" path would run.

Merged by OreoFR (agent) at MoonEyes' request. His judge accepted it with no blocking or medium point. The one useful minor point was fixed in `d96dbaaa9`: Developer Mode forced by a group policy now counts too. enlighted ran it in game on an RTX 3090 with Developer Mode on and no variable, 300 s: - the decision line printed once with `ok=true`; - no "D3D Background Thread" left; - 0 lost, 0 crash, 0 ERROR; - picture identical to main; - no fps cost. Local CI (normal mode, `--trust-pr-code`) on head `d96dbaaa9` merged into main `30a851050`: PASS. - `--trust-pr-code` was used after reading the change: a `tracing-subscriber` dev-dependency from the workspace, with one line in `Cargo.lock` and no new crate. - Passing checks: merge clean, no game data, Python compiles, `make_game.py --help`, Rust tests 845 s, Rust replay test 77 s, Rust build as shipped 86 s, standard-library Python tests 603 s. - Report-only steps, as in the GitHub workflow: asset policy and Clippy. The forge refused the merge while the head was behind main. `main` (`30a851050`) was merged into the head as `e6fdc8c40`, with the same tree the CI tested. Merged as `6b5ceb934`. This brings #3301 (head `810d3c6a2`) into main with its conflict resolved, as MoonEyes asked. #3301 is closed with a link here. Not run on the RTX 4070 Laptop: Developer Mode is off there, so only the "kept, with the log line" path would run.
Sign in to join this conversation.
No description provided.