fix: put the runtime's background shader threads at idle priority when it refuses to stop them #307

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

@⁠Skyfrye on GitHub · 2026-11-26 02:05 UTC · original
Skyfrye:nep/background-threads-idle → main · +141 −2 · 4 files · 1 commits · draft

Change

The launcher's set has VICTORY_D3D12_BACKGROUND=0, which asks the D3D12 runtime to switch its background work off (ID3D12Device6::SetBackgroundProcessingMode(DISABLE_BACKGROUND_WORK)). On a Windows without Developer Mode the runtime refuses: every run here logged the host's background shader work is switched off (VICTORY_D3D12_BACKGROUND=0) ok=false, and with this change the error is named: "The application requested an operation that depends on an SDK component that is missing". The driver then goes on recompiling shaders on four "D3D Background Thread"s in our process.

What that costs, measured here (RTX 5080, Ryzen 7 9800X3D, launcher fast set):

  • in a 30 s Nsight Systems capture of the world, the four threads were 2.3 cores, 94 % of their time in the driver's shader compiler (nvgpucomp64.dll);
  • in an A/B of the world, the runs where they still ran were 16.1 fps (2.67 cores on them) against 17.6-18.2 fps for the runs where they had stopped.

Now, when the runtime refuses, crate::background::watch starts a thread of ours (lowest priority) that looks every 2 s for this process's threads named "D3D Background Thread" and puts each one found at idle priority, once. They still compile, on cores nothing else wants. windows-sys gets the Win32_System_Diagnostics_ToolHelp feature for the thread list. Where the runtime accepts the switch, nothing changes.

Linked issue: none.

Verification

Windows 11 26300, Rust 1.98.1 (MSVC), on upstream main at c4c93bd, from third_party/victory:

cargo build --locked --release -p victory                 -> Finished, no new warning
cargo test --locked -p victory-gpu --lib -- background::  -> 1 passed
cargo test --locked -p victory-gpu --lib                  -> 3 failed, the rest passed

The 3 failures are the same on main without this change: descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed, indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots, indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others.

New test threads_named_so_go_to_idle_priority_once: two threads of the test, one named with the prefix it looks for; that one is at idle priority after the call, the other is not, and a second call idles nothing. Revert check: without the SetThreadPriority call it fails (left: 0, right: -15).

In the game (my copy, world, launcher fast set): the log says the host refused to switch its background shader work off ... its threads go to idle priority and, 34 ms later, the runtime's background shader threads put at idle priority ... idled=4 all=4.

What I could not measure cleanly: the frame rate it gives. In four runs of a build with this and other changes, the first runs after an update of the translator still had the driver recompiling the new shaders on those threads, 3.0 cores at idle priority on cores that were free, and 0.0-0.3 cores in the later runs; the scene and the shader cache moved the frame rate more than this can. What it does do, as the log shows: the threads no longer run at the priority of ours.

Draft until a cleaner A/B (a run with the driver's work still to do, with and without the change).

Oracle and test data

No game file. The test makes its own threads.

Checklist

  • The PR covers a single reviewable behaviour (the runtime's background threads go to idle priority when it refuses to stop them).
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success. (Nothing unimplemented here.)
  • README: not touched.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: thread and module names from a profile of the engine; no title code.
  • Code taken from another project: none.

AI assistance: written with Claude Code. Claude Opus 5.5 found the refusal in the logs and the threads in a profile, wrote the change and its test, and wrote this description.

🤖 Generated with Claude Code

**@⁠Skyfrye** on GitHub · 2026-11-26 02:05 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/307) `Skyfrye:nep/background-threads-idle` → `main` · +141 −2 · 4 files · 1 commits · draft ## Change The launcher's set has `VICTORY_D3D12_BACKGROUND=0`, which asks the D3D12 runtime to switch its background work off (`ID3D12Device6::SetBackgroundProcessingMode(DISABLE_BACKGROUND_WORK)`). On a Windows without Developer Mode the runtime refuses: every run here logged `the host's background shader work is switched off (VICTORY_D3D12_BACKGROUND=0) ok=false`, and with this change the error is named: "The application requested an operation that depends on an SDK component that is missing". The driver then goes on recompiling shaders on four "D3D Background Thread"s in our process. What that costs, measured here (RTX 5080, Ryzen 7 9800X3D, launcher fast set): - in a 30 s Nsight Systems capture of the world, the four threads were 2.3 cores, 94 % of their time in the driver's shader compiler (`nvgpucomp64.dll`); - in an A/B of the world, the runs where they still ran were 16.1 fps (2.67 cores on them) against 17.6-18.2 fps for the runs where they had stopped. Now, when the runtime refuses, `crate::background::watch` starts a thread of ours (lowest priority) that looks every 2 s for this process's threads named "D3D Background Thread" and puts each one found at idle priority, once. They still compile, on cores nothing else wants. `windows-sys` gets the `Win32_System_Diagnostics_ToolHelp` feature for the thread list. Where the runtime accepts the switch, nothing changes. Linked issue: none. ## Verification Windows 11 26300, Rust 1.98.1 (MSVC), on upstream `main` at `c4c93bd`, from `third_party/victory`: ``` cargo build --locked --release -p victory -> Finished, no new warning cargo test --locked -p victory-gpu --lib -- background:: -> 1 passed cargo test --locked -p victory-gpu --lib -> 3 failed, the rest passed ``` The 3 failures are the same on `main` without this change: `descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed`, `indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots`, `indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others`. New test `threads_named_so_go_to_idle_priority_once`: two threads of the test, one named with the prefix it looks for; that one is at idle priority after the call, the other is not, and a second call idles nothing. Revert check: without the `SetThreadPriority` call it fails (`left: 0`, `right: -15`). In the game (my copy, world, launcher fast set): the log says `the host refused to switch its background shader work off ... its threads go to idle priority` and, 34 ms later, `the runtime's background shader threads put at idle priority ... idled=4 all=4`. What I could not measure cleanly: the frame rate it gives. In four runs of a build with this and other changes, the first runs after an update of the translator still had the driver recompiling the new shaders on those threads, 3.0 cores at idle priority on cores that were free, and 0.0-0.3 cores in the later runs; the scene and the shader cache moved the frame rate more than this can. What it does do, as the log shows: the threads no longer run at the priority of ours. **Draft** until a cleaner A/B (a run with the driver's work still to do, with and without the change). ## Oracle and test data No game file. The test makes its own threads. ## Checklist - [x] The PR covers a single reviewable behaviour (the runtime's background threads go to idle priority when it refuses to stop them). - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. (Nothing unimplemented here.) - [x] README: not touched. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: thread and module names from a profile of the engine; no title code. - [x] Code taken from another project: none. AI assistance: written with Claude Code. Claude Opus 5.5 found the refusal in the logs and the threads in a profile, wrote the change and its test, and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The launcher sets VICTORY_D3D12_BACKGROUND=0, which asks the D3D12 runtime
to switch its background work off (SetBackgroundProcessingMode). Without
Windows' Developer Mode the runtime refuses ("ok=false" in every run here),
and the driver goes on recompiling shaders on four "D3D Background
Thread"s in our process: 2.3 cores in a profile of the world, and 16.1
fps in the runs where they ran against 17.6-18.2 where they did not.

When the call is refused, a thread of ours now looks for those threads
every 2 s and puts each one at idle priority, so that they compile on
cores nothing else wants. The refusal is logged with its error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:42:35 +00:00
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 10:32 UTC · original

Test report for #307 on three adapters.

Merges cleanly onto current main. Setup: current origin/main (c4c93bd) merged with this PR, Windows 11, cargo test --locked in third_party/victory. Adapters: RTX 4060 Laptop (DXGI 0), Intel UHD 8086:a78b (16-lane waves, no FP64), WARP. The hardware adapter is picked by name through a local, uncommitted test hook and confirmed in its log; WARP for victory-gpu is --features diagnostics + VICTORY_D3D12_WARP=1. victory-gpu runs with --test-threads=1.

victory-gpu --lib main main + #307
RTX 4060 Laptop 183 passed, main's 3 failed 184 passed, main's 3 failed
Intel UHD 183 passed, main's 3 failed 184 passed, main's 3 failed
WARP 196 passed, main's 3 failed 197 passed, main's 3 failed

"main's 3" = descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed, indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots, indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others. They fail on all three adapters on main too. threads_named_so_go_to_idle_priority_once passes everywhere. No new failure.

Notes from reading the diff:

  • done keys on thread ids. If the runtime ends a background thread and a new one gets the same id, the new one is never idled. A minor case, but you could keep (tid, creation time) from GetThreadTimes, or just re-check the priority.
  • TH32CS_SNAPTHREAD snapshots every thread on the system, not only ours, every 2 s for the life of the process. That is cheap, but the watcher could stop once it has found the runtime's usual 4 threads and seen nothing new for a while.
  • "D3D Background Thread" is the D3D12 runtime's name, so it should be the same on every vendor. I could not check it on the Intel UHD without the game, since the tests never create the runtime's threads.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.

**@⁠KainanP** on GitHub · 2026-11-26 10:32 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/307#issuecomment-7189502263) Test report for #307 on three adapters. Merges cleanly onto current main. Setup: current `origin/main` (c4c93bd) merged with this PR, Windows 11, `cargo test --locked` in `third_party/victory`. Adapters: RTX 4060 Laptop (DXGI 0), Intel UHD 8086:a78b (16-lane waves, no FP64), WARP. The hardware adapter is picked by name through a local, uncommitted test hook and confirmed in its log; WARP for victory-gpu is `--features diagnostics` + `VICTORY_D3D12_WARP=1`. victory-gpu runs with `--test-threads=1`. | `victory-gpu --lib` | main | main + #307 | |---|---|---| | RTX 4060 Laptop | 183 passed, main's 3 failed | 184 passed, main's 3 failed | | Intel UHD | 183 passed, main's 3 failed | 184 passed, main's 3 failed | | WARP | 196 passed, main's 3 failed | 197 passed, main's 3 failed | "main's 3" = `descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed`, `indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots`, `indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others`. They fail on all three adapters on main too. `threads_named_so_go_to_idle_priority_once` passes everywhere. No new failure. Notes from reading the diff: - `done` keys on thread ids. If the runtime ends a background thread and a new one gets the same id, the new one is never idled. A minor case, but you could keep `(tid, creation time)` from `GetThreadTimes`, or just re-check the priority. - `TH32CS_SNAPTHREAD` snapshots every thread on the system, not only ours, every 2 s for the life of the process. That is cheap, but the watcher could stop once it has found the runtime's usual 4 threads and seen nothing new for a while. - "D3D Background Thread" is the D3D12 runtime's name, so it should be the same on every vendor. I could not check it on the Intel UHD without the game, since the tests never create the runtime's threads. _AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this._
This pull request has changes conflicting with the target branch.
  • third_party/victory/crates/victory-gpu/Cargo.toml
  • third_party/victory/crates/victory-gpu/src/lib.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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