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

前端 未结 2 799
南笙
南笙 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:50

    Like most situations with OpenGL, it depends.

    In most cases, a single calculation can be done faster on the CPU than on the GPU. The GPU's advantage is that it can do lots of calculations in parallel.

    On the other hand, it also depends where your bottlenecks are. If your CPU is doing lots of other work, but your shaders are not a bottleneck yet on the lowest-powered target system, then you could easily see some performance improvement by moving some matrix multiplications to the vertex shader.

    Generally, you should avoid any work in the fragment shader that could also be done in the vertex shader or on the CPU, but beyond that, it depends on the situation. Unless you are running into performance issues, just do it whatever way is easiest for you, and if you are having performance issues, do it both ways and profile the performance to see which works better.

提交回复
热议问题