How the pixelFormat validation works

If we enable the "Metal API Validation" in the scheme, then sometimes my code crashed here:



failed assertion For color attachment 0, the render pipeline's pixelFormat (MTLPixelFormatRGBA8Unorm) does not match the framebuffer's pixelFormat (MTLPixelFormatBGRA8Unorm).

Replies

I know we should keep the pixelformts of pipeline the same as the rendered texture. However I found that, if we disable the validation, my app runs normally. I am really puzzled, What is the purpose of this validation, and what's the benefit of this?

The error says you're rendering as RGBA into a BGRA buffer, which is usually an error (if you draw red, it will show blue). You can work around that in the shader but it's better to know about the error and fix it instead.