MTLPixelFormat
The data formats that describe the organization and characteristics of individual pixels in a texture.
Declaration
enum MTLPixelFormatOverview
There are three varieties of pixel formats: ordinary, packed, and compressed. For ordinary and packed formats, the name of the pixel format specifies the order of components (such as R, RG, RGB, RGBA, BGRA), bits per component (such as 8, 16, 32), and data type for the component (such as Float, Sint, Snorm, Uint, Unorm). If the pixel format name has the _sRGB suffix, then reading and writing pixel data applies sRGB gamma compression and decompression. The alpha component of sRGB pixel formats is always treated as a linear value. For compressed formats, the name of the pixel format specifies a compression family (such as ASTC, BC, EAC, ETC2, PVRTC).
Storage characteristics
The number and size of each pixel component determines the storage size of each pixel format. For example, the storage size of MTLPixelFormat.bgra8Unorm is 32 bits (four 8-bit components) and the storage size of MTLPixelFormat.bgr5A1Unorm is 16 bits (three 5-bit components and one 1-bit component).
For normalized signed integer formats (Snorm), values in the range [-1.0, 1.0] map to [MIN_INT, MAX_INT], where MIN_INT is the most negative integer and MAX_INT is the most positive integer for the number of bits in the storage size. Positive values and zero distribute uniformly in the range [0.0, 1.0], and negative integer values greater than (MIN_INT + 1) distribute uniformly in the range (-1.0, 0.0).
For normalized unsigned integer formats (Unorm), values in the range [0.0, 1.0] are uniformly mapped to [0, MAX_UINT], where MAX_UINT is the largest unsigned integer for the number of bits in the storage size.
Metal stores format data in little-endian byte order, with the least-significant byte at the lowest memory address. For formats with components that are themselves byte-aligned and more than one byte, Metal also stores each component in little-endian byte order.
See Table 7.7 in the Metal Shading Language Specification (PDF) for details on pixel format normalization.
Topics
Ordinary 8-bit pixel formats
MTLPixelFormat.a8UnormMTLPixelFormat.r8UnormMTLPixelFormat.r8Unorm_srgbMTLPixelFormat.r8SnormMTLPixelFormat.r8UintMTLPixelFormat.r8Sint
Ordinary 16-bit pixel formats
MTLPixelFormat.r16UnormMTLPixelFormat.r16SnormMTLPixelFormat.r16UintMTLPixelFormat.r16SintMTLPixelFormat.r16FloatMTLPixelFormat.rg8UnormMTLPixelFormat.rg8Unorm_srgbMTLPixelFormat.rg8SnormMTLPixelFormat.rg8UintMTLPixelFormat.rg8Sint
Packed 16-bit pixel formats
MTLPixelFormat.b5g6r5UnormMTLPixelFormat.a1bgr5UnormMTLPixelFormat.abgr4UnormMTLPixelFormat.bgr5A1Unorm
Ordinary 32-bit pixel formats
MTLPixelFormat.r32UintMTLPixelFormat.r32SintMTLPixelFormat.r32FloatMTLPixelFormat.rg16UnormMTLPixelFormat.rg16SnormMTLPixelFormat.rg16UintMTLPixelFormat.rg16SintMTLPixelFormat.rg16FloatMTLPixelFormat.rgba8UnormMTLPixelFormat.rgba8Unorm_srgbMTLPixelFormat.rgba8SnormMTLPixelFormat.rgba8UintMTLPixelFormat.rgba8SintMTLPixelFormat.bgra8UnormMTLPixelFormat.bgra8Unorm_srgb
Packed 32-bit pixel formats
MTLPixelFormat.bgr10a2UnormMTLPixelFormat.rgb10a2UnormMTLPixelFormat.rgb10a2UintMTLPixelFormat.rg11b10FloatMTLPixelFormat.rgb9e5Float
Ordinary 64-bit pixel formats
MTLPixelFormat.rg32UintMTLPixelFormat.rg32SintMTLPixelFormat.rg32FloatMTLPixelFormat.rgba16UnormMTLPixelFormat.rgba16SnormMTLPixelFormat.rgba16UintMTLPixelFormat.rgba16SintMTLPixelFormat.rgba16Float
Ordinary 128-bit pixel formats
Compressed PVRTC pixel formats
MTLPixelFormat.pvrtc_rgb_2bppMTLPixelFormat.pvrtc_rgb_2bpp_srgbMTLPixelFormat.pvrtc_rgb_4bppMTLPixelFormat.pvrtc_rgb_4bpp_srgbMTLPixelFormat.pvrtc_rgba_2bppMTLPixelFormat.pvrtc_rgba_2bpp_srgbMTLPixelFormat.pvrtc_rgba_4bppMTLPixelFormat.pvrtc_rgba_4bpp_srgb
Compressed EAC/ETC pixel formats
MTLPixelFormat.eac_r11UnormMTLPixelFormat.eac_r11SnormMTLPixelFormat.eac_rg11UnormMTLPixelFormat.eac_rg11SnormMTLPixelFormat.eac_rgba8MTLPixelFormat.eac_rgba8_srgbMTLPixelFormat.etc2_rgb8MTLPixelFormat.etc2_rgb8_srgbMTLPixelFormat.etc2_rgb8a1MTLPixelFormat.etc2_rgb8a1_srgb
Compressed ASTC pixel formats
MTLPixelFormat.astc_4x4_srgbMTLPixelFormat.astc_5x4_srgbMTLPixelFormat.astc_5x5_srgbMTLPixelFormat.astc_6x5_srgbMTLPixelFormat.astc_6x6_srgbMTLPixelFormat.astc_8x5_srgbMTLPixelFormat.astc_8x6_srgbMTLPixelFormat.astc_8x8_srgbMTLPixelFormat.astc_10x5_srgbMTLPixelFormat.astc_10x6_srgbMTLPixelFormat.astc_10x8_srgbMTLPixelFormat.astc_10x10_srgbMTLPixelFormat.astc_12x10_srgbMTLPixelFormat.astc_12x12_srgbMTLPixelFormat.astc_4x4_ldrMTLPixelFormat.astc_5x4_ldrMTLPixelFormat.astc_5x5_ldrMTLPixelFormat.astc_6x5_ldrMTLPixelFormat.astc_6x6_ldrMTLPixelFormat.astc_8x5_ldrMTLPixelFormat.astc_8x6_ldrMTLPixelFormat.astc_8x8_ldrMTLPixelFormat.astc_10x5_ldrMTLPixelFormat.astc_10x6_ldrMTLPixelFormat.astc_10x8_ldrMTLPixelFormat.astc_10x10_ldrMTLPixelFormat.astc_12x10_ldrMTLPixelFormat.astc_12x12_ldrMTLPixelFormat.astc_4x4_hdrMTLPixelFormat.astc_5x4_hdrMTLPixelFormat.astc_5x5_hdrMTLPixelFormat.astc_6x5_hdrMTLPixelFormat.astc_6x6_hdrMTLPixelFormat.astc_8x5_hdrMTLPixelFormat.astc_8x6_hdrMTLPixelFormat.astc_8x8_hdrMTLPixelFormat.astc_10x5_hdrMTLPixelFormat.astc_10x6_hdrMTLPixelFormat.astc_10x8_hdrMTLPixelFormat.astc_10x10_hdrMTLPixelFormat.astc_12x10_hdrMTLPixelFormat.astc_12x12_hdr
Compressed BC pixel formats
MTLPixelFormat.bc1_rgbaMTLPixelFormat.bc1_rgba_srgbMTLPixelFormat.bc2_rgbaMTLPixelFormat.bc2_rgba_srgbMTLPixelFormat.bc3_rgbaMTLPixelFormat.bc3_rgba_srgbMTLPixelFormat.bc4_rUnormMTLPixelFormat.bc4_rSnormMTLPixelFormat.bc5_rgUnormMTLPixelFormat.bc5_rgSnormMTLPixelFormat.bc6H_rgbFloatMTLPixelFormat.bc6H_rgbuFloatMTLPixelFormat.bc7_rgbaUnormMTLPixelFormat.bc7_rgbaUnorm_srgb
YUV pixel formats
Depth and stencil pixel formats
MTLPixelFormat.depth16UnormMTLPixelFormat.depth32FloatMTLPixelFormat.stencil8MTLPixelFormat.depth24Unorm_stencil8MTLPixelFormat.depth32Float_stencil8MTLPixelFormat.x32_stencil8MTLPixelFormat.x24_stencil8
Extended range and wide color pixel formats
MTLPixelFormat.bgra10_xrMTLPixelFormat.bgra10_xr_srgbMTLPixelFormat.bgr10_xrMTLPixelFormat.bgr10_xr_srgb