Beginning Metal - Part 10: Instancing | Ray Wenderlich

Learn how you can using instancing to render crowd scenes or a field of grass using minimal resources.

This is a companion discussion topic for the original entry at

Great tutorial series! Watching the last 3 lessons today.

One code issue in InstanceScene.swift in the video and the download materials…

In InstanceScene.swift, the outer “for _ in 0…<40” loop is not needed after the “for human in humans.nodes” loop is added is it?

Hello Caroline. Awesome tutorial! I have a question regarding the uint instanceID. Is it possible to create an “instanceDescriptor” and utilize the [stage_in] qualifier as opposed to using the [instance_id] qualifier.

@twohyjr - I’m not quite sure where your question’s coming from.

The [[ stage_in ]] qualifier is per vertex.

When you use instancing, you’re using the same vertex over and over, but just different parameters for each instance.

Hi Caroline. Great series so far – thanks!

One problem. I tried following the challenge through but noticed that no grass was appearing (this is using Swift 4 and Xcode 9, beta 6). Tapping ‘Capture GPU Frame’ I noticed the following issue appears in the instance debug group:

The Compiler was not able to Preload your Buffer
(Issue) The compiler was not able to preload your buffer. Simplify your memory access pattern by using the constant address space, a struct, or a descriptor.

I double checked against the final project included in the chapter resources, only adding the two necessary lines to compile (pipelineDescriptor.depthAttachmentPixelFormat = .depth32Float and metalView.depthStencilPixelFormat = .depth32Float), and I’m seeing the same result – although the models do display here.

Any ideas?

Missing grass and the issue above were in fact unrelated.

My grass was just underground. Clearly just needed some watering a.k.a. setting grass.position.z not grass.position.y!

1 Like

@cldr - so glad you were able to fix it! It can be very frustrating when the mesh just disappears.

1 Like