user3813850
user3813850

Reputation: 51

SCNNode.flattenedClone() does not reduce draw calls

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

app screenshot

Upvotes: 4

Views: 1005

Answers (1)

enjoiful
enjoiful

Reputation: 61

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.

Upvotes: 4

Related Questions