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

Closed
Skyfrye wants to merge 1 commit from upstream-pr/307 into main
Skyfrye commented 2026-11-26 02:05:27 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Skyfrye on 2026-11-26T02:05:27Z.


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

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5502656322 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/307). Originally posted by [Skyfrye](https://github.com/Skyfrye) on 2026-11-26T02:05:27Z. --- ## 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)
KainanP commented 2026-11-26 10:32:29 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-26T10:32:29Z.


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.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7189502263 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/307#issuecomment-7189502263). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-26T10:32:29Z. --- 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._
LooperSalty commented 2026-11-27 13:03:01 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T13:03:01Z.


Closing: this draft conflicts with main and has had no activity from its author for more than 24 hours. Please reopen after a rebase on main if it is still wanted.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7218994591 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/307#issuecomment-7218994591). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-27T13:03:01Z. --- Closing: this draft conflicts with main and has had no activity from its author for more than 24 hours. Please reopen after a rebase on main if it is still wanted.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LooperSalty/AnyXboxX!307
No description provided.