I love the job system though I’ve very recently come across compute shaders and they seem extremely similar. Both require their inputs to be blittable types. Both are great for multithreaded computation. But to a beginner like myself, how would I know when a task is better suited to one method over the other? Could there be a project that uses both at the same time? What are the strengths and weaknesses of either one?
Any clarification would be greatly appreciated!
2 Likes
Usually you would use Compute Shaders for Jobs where the results are also gonna be used on the GPU. For example Particle Systems or Fluid Simulations. From my knowlegde this is mainly because theres a lot of latency involved when moving data between VRAM and RAM. However, I’m not 100% sure about the situation with newer low-level APIs like DirectX 12 and Vulkan. 
The answer to this question used to always be “use compute shaders” but the rules have changed a bit.
The first question to answer is how much data does your algorithm generate that the GPU needs to draw? If the answer is “way more than the size of a texture”, then you want to do it on the GPU. Otherwise…
The second question is whether you are currently CPU or GPU bottlenecked. With DOTS, it is way easier to become GPU bottlenecked.
And third question, is the result of the algorithm needed by the CPU or the GPU? GPUs have a tendency to lag a couple frames behind the CPU, so going from GPU to CPU is much more involved than going from CPU to GPU.
You’ll often find that different simulations will lead to different answers. And different hardware will react differently to your simulations. Generally you don’t want a single simulation to run on both CPU and GPU at the same time, but having CPU run some simulations and GPU run others is totally viable.
1 Like
Another question to ask yourself is how parallel is the problem you are solving? Modern CPU can only benefit from like 16 threads max, whereas a GPU can benefit from hundreds or thousands. If you have less than 100 chunks to run in parallel, using a compute shader is not beneficial. If you are generating the output equivalent of a 4k texture where each pixel can be generated independently, then a computer shader is definitely the better option, but then you need to consider the pipeline implications as mentioned by @DreamingImLatios
1 Like