doitsujin / dxvk

Vulkan-based implementation of D3D8, 9, 10 and 11 for Linux / Wine
zlib License
13.17k stars 848 forks source link

Worker count calculation formula #3257

Closed rskryptik61636 closed 1 year ago

rskryptik61636 commented 1 year ago

How was this worker count calculation formula devised? Was it by trial and error?

https://github.com/doitsujin/dxvk/blob/caf31033d711460e86781b16a4d9b0f41fa9e817/src/dxvk/dxvk_pipemanager.cpp#L100

doitsujin commented 1 year ago

This code is trying to solve two problems:

  1. Strike a good balance between fast shader compiles and leaving enough CPU cores for the game to run on. This is somewhat needed even with the low priority stuff, and I found that these numbers tend to do a reasonable job, it's certainly not perfect in all situations but in geneal we want to prioritize compiling shaders over minimizing the (temporary) performance hit anyway.
  2. Reserve some threads for latency-critical high-priority shaders. The idea is that if the app binds a shader that hasn't been compiled by any of the workers yet, we can add it to a high-priority queue and immediately start working on it to minimize the inevitable stutter, even if all other threads are busy. Without this, some games (such as Elex 2 on Nvidia) would hang for extended periods of time just waiting for shaders to build.
rskryptik61636 commented 1 year ago

Cool, thanks for the explanation 👍