I'm adding one line of code that makes this Apple sample code crash.
Heres a direct link to the line I added - line 47
The line in question is
Code Block renderer.isJitteringEnabled = true
When I remove the line, it works fine.
When I add the line, the app crashes with an assertion error saying that the pixel buffer's pixel format and the metal texture's pixel format don't match.
[MTLDebugRenderCommandEncoder validateFramebufferWithRenderPipelineState:]:1288: failed assertion `Framebuffer With Render Pipeline State Validation
For color attachment 0, the render pipeline's pixelFormat (MTLPixelFormatRGBA16Float) does not match the framebuffer's pixelFormat (MTLPixelFormatBGRA8Unorm_sRGB).
So I tried setting the Metal Texture's pixel format like thisFor color attachment 1, the renderPipelineState pixelFormat must be MTLPixelFormatInvalid, as no texture is set.
Code Block let pixelFormat = MTLPixelFormat.rgba16Uint
But now I'm getting another error I don't understand
_mtlValidateStrideTextureParameters:1656: failed assertion `Texture Descriptor Validation
IOSurface texture: bytesPerRow (5120) must be greater or equal to (10240) bytes
It is as I stated in my first reply, you need to ensure the texture settings match, and then you will not get the error regarding the textures.
After you change to rgba16 in both places (such as kCVPixelFormatType_64RGBAHalf), you will then be confronted by another texture setting match problem for the texture in the second attachment. Since you are overriding the render pass descriptor for SceneKit, it would be logically assumed that you then have to create and setup that texture on your own. If you spend more time with Metal, these things will be more obvious as they are very normal things.
I will leave that to you to complete, but I will say that the entire thing is clunky, extremely inefficient, and I would not personally recommended following this sample code's strategy or even using SceneKit or Swift. The use of AVAssetWriter is also not recommended. These, in their current form today and in the past, are Apple's half-baked attempts at providing convenience with a heavy price. There is little expectation based on Apple's prior results, that the standards of quality will change anytime soon. (Even though I hope for that every day)
I would instead recommend avoiding as many Apple frameworks as you can, and becoming more familiar with Metal and C, and get to your goals that way.