graphics: run the GPU thread at highest priority on Windows (cp2077) #2106
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2106
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2106"
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?
@ArtyomZabroda on GitHub · 2026-11-04 13:27 UTC · original
ArtyomZabroda:pr/gpu-thread-priority→main· +17 −0 · 3 files · 1 commits · openIf Cyberpunk 2077 starts more job threads than the host has cores, they
spin while they wait for work. Windows shares the cores evenly between
them, so the GPU thread, which bounds the frame, keeps losing its core to
threads that only spin.
Raise the GPU thread to THREAD_PRIORITY_HIGHEST when it starts. Other
platforms are unchanged: Linux needs CAP_SYS_NICE to raise a thread's
priority, and neither has been measured.
Cyberpunk 2077 on a Ryzen 5 7500F (6 cores, 12 threads)


Before (2 FPS):
After (8 FPS):
@coderabbitai[bot] on GitHub · 2026-11-04 13:33 UTC · original
No actionable comments were generated in the recent review.
Walkthrough
On Windows,
Common::Threadadds a method that requestsTHREAD_PRIORITY_HIGHESTfor the calling thread and returns whether the request succeeded.GuestGpu::ThreadRuncalls this method before its work loop and logs if the request fails. Other platforms do not run this priority-setting code.Suggested reviewers:
nmzikChange: Bug fix
Merge Risk:
Minimal · up to
5fd2eThe change is limited to Windows and preserves normal GPU operation if priority elevation fails.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 3 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
bd5b9cee-fbc1-4207-bf72-7c62d2f4737aReviewing files that changed from the base of the PR and between
b2f40c6c03and5fd2efcbf1.src/common/threads.cppsrc/common/threads.hsrc/graphics/guest_gpu/graphicsRun.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@Nmzik on GitHub · 2026-11-04 19:13 UTC · original
@ArtyomZabroda I think it’s related to AMD multi die CPU
@ArtyomZabroda on GitHub · 2026-11-04 19:26 UTC · original · edited 2026-11-04 19:55 UTC
@Nmzik I don't think so. The 7500F has the same layout as the 7700X: one CCD
plus an I/O die. In #182 the 7700X (8 cores) gets 7-10 FPS in gameplay without this change, while my 7500f gets ~1 FPS on the same code and ~8 FPS with it. So the die layout is the same and the difference is core count: with fewer cores, the spinning job threads take the GPU thread's time unless it runs at a higher priority.
@ArtyomZabroda on GitHub · 2026-11-04 19:37 UTC · original · edited 2026-11-04 19:55 UTC
I can run a test: I'll try #2110, which fixes the 100% CPU usage across all threads, without this patch, and see whether the FPS goes up once the GPU thread no longer has to compete for CPU time. I'll post the results here when I'm done.
@ArtyomZabroda on GitHub · 2026-11-04 19:53 UTC · original · edited 2026-11-04 19:55 UTC
#2110 fixes the FPS issue on its own. But I don't think this PR is redundant: the two tackle the same problem from different sides. #2110 removes one source of CPU contention (Wwise polling an event flag), while this PR keeps the GPU thread from losing its core to any guest thread that spins, not just that one.
@Nmzik on GitHub · 2026-11-04 21:36 UTC · original · edited 2026-11-04 21:37 UTC
@ArtyomZabroda Thanks for investigating!
I've seen multiple PRs doing the following solutions to get "better FPS":
1)give the GPU thread the highest priority.
2)give GPU thread a dedicated CPU core.
3)GPU thread runs on a performance core (on newer Intel CPUs).
4)Something related to multi-die AMD CPUs?
For me, options 1–3 don't seem to provide ANY benefits on Linux (Intel 275HX) as they all depend on the OS scheduler
I haven't tested any of these solutions on Windows, though :)
@ArtyomZabroda on GitHub · 2026-11-04 21:40 UTC · original
@Nmzik Let’s postpone this issue until the weekend. I'll download linux and investigate it more thoroughly. #2110 fixes the FPS, so it's probably worth taking a look at now.
@ArtyomZabroda on GitHub · 2026-11-04 22:06 UTC · original · edited 2026-11-04 22:11 UTC
@Nmzik
Could you try running Cyberpunk on a build without #2110, limited to fewer cores to simulate a low-core CPU:
taskset -c 0-7 ./kyty_emulator
taskset -c 0-11 ./kyty_emulator
I expect much worse performance with the first command, which is exactly what my patch is trying to fix.
If it does get worse, could you then raise the GPU thread's priority with
sudo renice -n -10 -p tid
(tid = the GPU thread's id from
top -H -p <emulator pid>)? That's roughly the linux equivalent of what my patch does on windows.@Nawid3333 on GitHub · 2026-11-10 18:29 UTC · original
I tested this PR with a second game, Demon's Souls (PPSA01341), and sampled the emulator's threads with and without it. The CPU is a Ryzen 5 7600X (one CCD, 6 cores / 12 threads), so no multi-die layout here either. Windows 11, RX 9070 XT, emulator limited to 10 logical CPUs.
Game result. main
782a85c62against the same commit plus this PR's commit (5fd2efcbf). Both builds of a pair also carry the same local test-only commits (a scripted pad input player and logging); they differ only in this PR's commit. Same input script and same run length for every run, each build warmed up with one run first. Overlay values from the last screenshot of each run:The FPS values come from different scenes, so they are not like for like. The result is how far each build got with the same input: with the PR all four runs reached the 3D scene, main never left the first screens.
Thread CPU use, sampled in the middle of a run (percent of one logical CPU):
BPE JobWorkerThreadWhat the GPU thread does on main. 60 stack samples of it in that window: 42 % are blocked in a wait inside the Vulkan driver below
MasterSemaphore::Wait <- CommandScheduler::Wait <- BufferCache::DownloadBufferMemory(a buffer readback waiting for the GPU), and 55 % have the instruction pointer in user-mode code (the remaining 3 % are in rows my sampler did not print), although the thread received only 0.3 % of a CPU in the same window. A thread that sits in user-mode code and gets no CPU time is ready to run and is not being scheduled. So on main the GPU thread waits in the ready queue behind the workers; with the PR it runs.Why the workers never free a CPU. The workers' idle loop is
pause+rdtsc(eboot 0x83b6ba to 0x83b82c). A worker only goes to sleep when its last job is older than2 * sceKernelGetTscFrequency()ticks, so while the game is running all 13 spin between jobs and keep the CPUs busy (959 % of the 1000 % available in the table above).The Windows side, measured outside the emulator. A small standalone program on the same PC: 10 CPUs, 13 threads spinning on
pause+rdtscat normal priority, plus one thread that wakes fromSleepConditionVariableCS(..., 1)by timeout (1 ms timer period):So at equal priority a thread that becomes ready on Windows can wait 17 to 33 ms for a CPU behind spinning threads, and at a higher priority it does not wait. This is a standalone test, not a measurement inside the game, and I have not measured Linux.
@ArtyomZabroda on GitHub · 2026-11-21 15:37 UTC · original
@Nmzik Update: I've tested cyberpunk on linux without this patch (and without the patch that fixes 100% cpu load #2110) and I didn't notice the same fps drop that I saw on windows. So it seems that this issue only affects CPUs with <16 logical cores on windows.
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.