Should I calculate matrices on the GPU or on the CPU?

前端 未结 2 795
南笙
南笙 2020-12-13 06:24

Should I prefer to calculate matrices on the CPU or GPU?

Let\'s say I have the following matrices P * V * M , should I calculate them on the CPU so tha

2条回答
  •  抹茶落季
    2020-12-13 06:26

    General rule: If you can pass it to a shader in form of a uniform, always precalculate on the CPU; no exceptions. Calculations on the shader side make sense only for values that vary between vertices and fragments. Everything that's constant among a whole batch of vertices is most efficiently dealt with on the CPU.

    GPUs are not magic "can do faster everything" machines. There are certain tasks where a CPU can easily outperform a GPU, even for very large datasets. So a very simple guideline is: If you can move it to the CPU without spending more CPU time doing the calculation than it takes for the GPU in total overhead to process it, then do it on the CPU. The calculation of a single matrix is among those tasks.

提交回复
热议问题