Hi,
I'm trying to port this to Swift. https://developer.apple.com/documentation/metal/hello_triangle
To get it to run I had to add the following line to the renderer class. Any idea why it's not needed in the Objective-C version?
pipelineStateDescriptor.depthAttachmentPixelFormat = metalView.depthStencilPixelFormat
Without it I get an error: -[MTLDebugRenderCommandEncoder validateFramebufferWithRenderPipelineState:]:1232: failed assertion `For depth attachment, the render pipeline's pixelFormat (MTLPixelFormatInvalid) does not match the framebuffer's pixelFormat (MTLPixelFormatDepth32Float).'
Rob
Did you perchance create a new storyboard and drop a MetalKit View from the Object Library in Interface Builder? By default, the MetalKit View from the Object Library sets MTKView.depthStencilPixelformat to MTLPixelFormatDepth32Float.
The HelloTrangle samplw was created using just a ViewController from the ObjectLibrary and setting the view's class to MTKView. If you do that, the MTKView.depthStencilPixelformat is set the MTLPixelFormatInvalid (which is the same as saying, I don't need a depth buffer). By default, MTLRenderPipelineStateDescriptor.depthAttachementPixelFormat is also MTLPixelFormatInvalid, so it matches already.
Really, you should always do what you've done and set the depthAttachmentPixelFormat in code becasue it doesn't hurt to make sure your pipeline matches, but in this intro sample we're just keeping it simple.