SCNNode.flattenedClone() does not reduce draw calls

独自空忆成欢 提交于 2019-12-12 19:13:36

问题


I'm trying to optimize my SceneKit app by reducing draw calls. From the Apple Documentation, and many WWDC talks, combining many child nodes into a single node via flattenedClone() should reduce draw calls, but I am unable to reduce draw calls by utilizing this method.

I have attached a simple example SceneKit app that demonstrates how flattenedClone is not reducing draw calls.

When the app starts, 5 objects are displayed, and you can see 5 draw calls. (well, 6 actually if you interact with the camera).

Then, if you press the toggle button, the 5 nodes will be flattened into a single node. This still results in 5 draw calls!

This seems to completely contradict all sorts of documentation and talks around flattenedClone. Any ideas on what's happening?

You can run the simple app here, either in the simulator or iOS device: https://drive.google.com/open?id=1ZJQZAnHtOCeK_3WzbdD0vLLJ2kWTKao- Note that you need to wiggle the camera around to get the draw call statistics to update.

let nodes = SCNScene.init(named: 
"nodes.scn")!.rootNode.childNode(withName: "parentNode", recursively: true)!;

//Unflattened version:
scene.rootNode.addChildNode(nodes)

//Flattened version:
let flattenedNode = nodes.flattenedClone()
scene.rootNode.addChildNode(flattenedNode)

screenshot


回答1:


OK, I solved this. James P was correct. All 5 of the objects were using a different material.

If you use the same material for all objects, and then flatten into a single node, the draw calls reduce from 6 to 2. You can run this yourself to see: https://drive.google.com/open?id=1En3tZ9QFTZPd2-xJwCA-0CMO3QWX8UZt

I filed a bug to Apple and they confirmed that the reason why the draw calls aren't being reduced is because of the 5 separate materials. So, in conclusions: SceneKit is behaving as expected.



来源:https://stackoverflow.com/questions/50898979/scnnode-flattenedclone-does-not-reduce-draw-calls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!