fix: put the runtime's background shader threads at idle priority when it refuses to stop them #307
No reviewers
Labels
No labels
accessibility
bloqué : binaire console
bug
chargeur
console-dll
cpu
documentation
duplicate
enhancement
good first issue
gpu
help wanted
invalid
performance
question
runtime-gdk
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LooperSalty--AnyXboxX!307
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-307"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Skyfrye on GitHub · 2026-11-26 02:05 UTC · original
Skyfrye:nep/background-threads-idle→main· +141 −2 · 4 files · 1 commits · draftChange
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 loggedthe 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):
nvgpucomp64.dll);Now, when the runtime refuses,
crate::background::watchstarts 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-sysgets theWin32_System_Diagnostics_ToolHelpfeature 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
mainatc4c93bd, fromthird_party/victory:The 3 failures are the same on
mainwithout 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 theSetThreadPrioritycall 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 priorityand, 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
E_NOTIMPL), never a fake success. (Nothing unimplemented here.)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
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]>@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 --lockedinthird_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'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_oncepasses everywhere. No new failure.Notes from reading the diff:
donekeys 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)fromGetThreadTimes, or just re-check the priority.TH32CS_SNAPTHREADsnapshots 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.AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.
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.Merge
Merge the changes and update on Forgejo.