Group Group Group Group Group Group Group Group Group

Why MTLPixelFormat.bgra8Unorm?

A lot of Metal examples, including ones from Apple, use MTLPixelFormat.bgra8Unorm as the pixelFormat in the pipeline state. I was wondering if you had any insight as to whether or not this might be preferred over, say, MTLPixelFormat.rgba8Unorm, which has a more familiar RGBA ordering or even something like MTLPixelFormat.rgba8Unorm_srgb.

I remember some old graphics cards/OpenGL drivers preferred BGRA, which made it a faster choice in some cases. I had thought that was lost in the past though.

Perhaps there is a later section of the book that discusses when and why to choose one of the other many formats. I haven’t looked ahead yet.


I’m not sure why Apple chose BRGA rather than RGBA - it’s probably for historical reasons, and it may be faster on the GPU because of that.

But the real reason for using BGRA here is because MTKView only allows a few pixel formats:

You wouldn’t use a float texture here because you only need 0 to 255. Later on, in deferred rendering, you’ll use a float texture when you need more accuracy.

You can use RGB for textures, as long as it’s not going to a view’s drawable texture. I probably do use RGB in places.

1 Like