filament icon indicating copy to clipboard operation
filament copied to clipboard

Metal performance seems not better than OpenGL in iOS

Open JiangXiaotian opened this issue 4 years ago • 10 comments

Describe the bug I tried iOS sample hello-gltf app, metal-backend gpu frame time is 7.5 ms, while opengl-backend gpu frame time is 6.8ms. the rendering time of opengl is also shorter than that of metal in instrument->GamePerformance.

To Reproduce Steps to reproduce the behavior: just change backend, both of them "build configuration" choose release.

Expected behavior metal performance better than opengl

Screenshots 截屏2021-07-08 下午4 34 26 截屏2021-07-08 下午4 34 57 截屏2021-07-08 下午4 38 37 截屏2021-07-08 下午4 50 15 截屏2021-07-08 下午5 22 35

Desktop (please complete the following information):

  • OS: iOS
  • Backend: [Metal/OpenGL]

Smartphone (please complete the following information):

  • Device: iphone 11
  • OS: 13.7

JiangXiaotian avatar Jul 08 '21 09:07 JiangXiaotian

What are you rendering? With a scene with not many draw calls and mostly shader bound there's no reason for Metal to be faster if you look at vertex/fragment processing time on the GPU.

romainguy avatar Jul 08 '21 14:07 romainguy

Also note that as long as you are under 16ms the GPU is probably not clocked as high at it can be, so exact timings are not really comparable.

romainguy avatar Jul 08 '21 23:07 romainguy

I re-used a glb with 980018 vertices and 100011 faces on iphone 7 for test. And I enabled bloom, AmbientOcclusion, and fxaa. The result still seems to be that metal is not faster than opengl, and even the cpu usage rate of metal is 42%. , OpengGL is only 17%.

I tested it in iOS hello-gltf sample, the Screenshot below is the code I changed. 截屏2021-07-10 上午2 17 26

glb link: https://drive.google.com/file/d/1xwKpoiMxDfhLc8lMpknbA7w-VZRkrgvg/view?usp=sharing hello-gltf sample link: https://drive.google.com/file/d/1FT5adwJNCW1LU4CxTnKVUdrl2liO1934/view?usp=sharing

截屏2021-07-10 上午1 39 51 截屏2021-07-10 上午1 39 04

JiangXiaotian avatar Jul 09 '21 18:07 JiangXiaotian

For this use case, there's no reason for Metal to be faster than GL on the GPU. CPU usage should/could be the same or better though, looks like we have improvements to make.

romainguy avatar Jul 09 '21 18:07 romainguy

Is it convenient to give an example Metal is faster than GL?

JiangXiaotian avatar Jul 09 '21 18:07 JiangXiaotian

Is it recommended to use opengl instead of metal even in iOS?

JiangXiaotian avatar Jul 09 '21 18:07 JiangXiaotian

There are a handful of optimizations I'm working on to improve both CPU and GPU performance for Metal. You're welcome to use OpenGL, though the goal is to eventually remove support for it on Apple platforms.

bejado avatar Jul 09 '21 18:07 bejado

I would not recommend using the opengl backend on iOS (not macos) because we're planning to remove support soon.

Also when doing performance comparisons you need to also look at other factors like GPU/CPU clocks. Sometimes, when some code is more optimized it runs slower but at a lower power usage. As long as rendering happens in less than the vsync rate, there is no problem.

And finally, there is no reason for metal to be significantly faster or slower than gl, it's the same GPU in the end.

pixelflinger avatar Jul 10 '21 19:07 pixelflinger

There are a handful of optimizations I'm working on to improve both CPU and GPU performance for Metal. You're welcome to use OpenGL, though the goal is to eventually remove support for it on Apple platforms.

Could you share your optimization idea in details? How much improvement could we expected, and in which scenarios we can expect big improvements, and how soon is the optimization expected to be completed?

JiangXiaotian avatar Jul 13 '21 13:07 JiangXiaotian

It won't be significantly faster than gl.

What kind of improvement are you hoping for?

pixelflinger avatar Jul 23 '21 02:07 pixelflinger

This issue is a year-old and a bit vague, so closing. We do have some Metal-specific improvements in the pipeline, including using argument buffers to reduce CPU encoding time.

bejado avatar Aug 15 '22 20:08 bejado