For speeding up loops, for example when making procedural meshes.
Which is best to use? Parallel.For with .Net 4, Job System or ComputeShaders?
There’s a lot of options.
For speeding up loops, for example when making procedural meshes.
Which is best to use? Parallel.For with .Net 4, Job System or ComputeShaders?
There’s a lot of options.
Agreed. Start with one. If it’s performant enough you’re done. Never again think of it.
If it’s not performant enough, try the next one. Lather, rinse, repeate.
When you have run them all in enough contexts on the specific targets you are interested in, you will have some solid empirical data.
In the case between the first two options and ComputeShader, you have to factor in the translation time of the data onto the GPU so it can work with it, and any potential breaking down and reconstructing of the data that needs to be done to make it GPU compatible. If you can keep the initial bulk of the data on the GPU for a long period of time to be re-used when re-computing, minimizing data-translation, and the operation is naturally highly-parallel, then the GPU will most likely be the most performant, often by a huge margin.
But like Kurt-Dekker said, most surefire way to know for your given problem is to just test it, but of course sometimes you don’t want to focus that much time on a problem and just want to make an educated guess too.
Between the first two options, if your operation can work within the constraints of the Job system, then it will likely be faster there, assuming it’s a parallel job, primarily due to the efficient way that the job system packs data that you likely wouldn’t be bothering with yourself in a Parallel.For.