xref: /aosp_15_r20/external/mesa3d/docs/gallium/format.rst (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1*61046927SAndroid Build Coastguard WorkerFormats in gallium
2*61046927SAndroid Build Coastguard Worker==================
3*61046927SAndroid Build Coastguard Worker
4*61046927SAndroid Build Coastguard WorkerGallium format names mostly follow D3D10 conventions, with some extensions.
5*61046927SAndroid Build Coastguard Worker
6*61046927SAndroid Build Coastguard WorkerFormat names like XnYnZnWn have the X component in the lowest-address n bits
7*61046927SAndroid Build Coastguard Workerand the W component in the highest-address n bits; for B8G8R8A8, byte 0 is
8*61046927SAndroid Build Coastguard Workerblue and byte 3 is alpha.  Note that platform endianness is not considered
9*61046927SAndroid Build Coastguard Workerin this definition.  In C::
10*61046927SAndroid Build Coastguard Worker
11*61046927SAndroid Build Coastguard Worker    struct x8y8z8w8 { uint8_t x, y, z, w; };
12*61046927SAndroid Build Coastguard Worker
13*61046927SAndroid Build Coastguard WorkerFormat aliases like XYZWstrq are (s+t+r+q)-bit integers in host endianness,
14*61046927SAndroid Build Coastguard Workerwith the X component in the s least-significant bits of the integer.  In C::
15*61046927SAndroid Build Coastguard Worker
16*61046927SAndroid Build Coastguard Worker    uint32_t xyzw8888 = (x << 0) | (y << 8) | (z << 16) | (w << 24);
17*61046927SAndroid Build Coastguard Worker
18*61046927SAndroid Build Coastguard WorkerFormat suffixes affect the interpretation of the channel:
19*61046927SAndroid Build Coastguard Worker
20*61046927SAndroid Build Coastguard Worker- ``SINT``:     N bit signed integer [-2^(N-1) ... 2^(N-1) - 1]
21*61046927SAndroid Build Coastguard Worker- ``SNORM``:    N bit signed integer normalized to [-1 ... 1]
22*61046927SAndroid Build Coastguard Worker- ``SSCALED``:  N bit signed integer [-2^(N-1) ... 2^(N-1) - 1]
23*61046927SAndroid Build Coastguard Worker- ``FIXED``:    Signed fixed point integer, (N/2 - 1) bits of mantissa
24*61046927SAndroid Build Coastguard Worker- ``FLOAT``:    N bit IEEE754 float
25*61046927SAndroid Build Coastguard Worker- ``NORM``:     Normalized integers, signed or unsigned per channel
26*61046927SAndroid Build Coastguard Worker- ``UINT``:     N bit unsigned integer [0 ... 2^N - 1]
27*61046927SAndroid Build Coastguard Worker- ``UNORM``:    N bit unsigned integer normalized to [0 ... 1]
28*61046927SAndroid Build Coastguard Worker- ``USCALED``:  N bit unsigned integer [0 ... 2^N - 1]
29*61046927SAndroid Build Coastguard Worker
30*61046927SAndroid Build Coastguard WorkerThe difference between ``SINT`` and ``SSCALED`` is that the former are pure
31*61046927SAndroid Build Coastguard Workerintegers in shaders, while the latter are floats; likewise for ``UINT`` versus
32*61046927SAndroid Build Coastguard Worker``USCALED``.
33*61046927SAndroid Build Coastguard Worker
34*61046927SAndroid Build Coastguard WorkerThere are two exceptions for ``FLOAT``.  ``R9G9B9E5_FLOAT`` is nine bits
35*61046927SAndroid Build Coastguard Workereach of red green and blue mantissa, with a shared five bit exponent.
36*61046927SAndroid Build Coastguard Worker``R11G11B10_FLOAT`` is five bits of exponent and five or six bits of mantissa
37*61046927SAndroid Build Coastguard Workerfor each color channel.
38*61046927SAndroid Build Coastguard Worker
39*61046927SAndroid Build Coastguard WorkerFor the ``NORM`` suffix, the signedness of each channel is indicated with an
40*61046927SAndroid Build Coastguard WorkerS or U after the number of channel bits, as in ``R5SG5SB6U_NORM``.
41*61046927SAndroid Build Coastguard Worker
42*61046927SAndroid Build Coastguard WorkerThe ``SRGB`` suffix is like ``UNORM`` in range, but in the sRGB colorspace.
43*61046927SAndroid Build Coastguard Worker
44*61046927SAndroid Build Coastguard WorkerCompressed formats are named first by the compression format string (``DXT1``,
45*61046927SAndroid Build Coastguard Worker``ETC1``, etc), followed by a format-specific subtype.  Refer to the
46*61046927SAndroid Build Coastguard Workerappropriate compression spec for details.
47*61046927SAndroid Build Coastguard Worker
48*61046927SAndroid Build Coastguard WorkerFormats used in video playback are named by their FOURCC code.
49*61046927SAndroid Build Coastguard Worker
50*61046927SAndroid Build Coastguard WorkerFormat names with an embedded underscore are subsampled.  ``R8G8_B8G8`` is a
51*61046927SAndroid Build Coastguard Workersingle 32-bit block of two pixels, where the R and B values are repeated in
52*61046927SAndroid Build Coastguard Workerboth pixels.
53*61046927SAndroid Build Coastguard Worker
54*61046927SAndroid Build Coastguard WorkerIndex buffers do not have a natural format in Gallium structures. For purposes
55*61046927SAndroid Build Coastguard Workerof ``is_format_supported`` queries, the formats ``R8_UINT``, ``R16_UINT``, and
56*61046927SAndroid Build Coastguard Worker``R32_UINT`` are used with ``PIPE_BIND_INDEX_BUFFER`` for 8-bit, 16-bit, and
57*61046927SAndroid Build Coastguard Worker32-bit index buffers respectively.
58*61046927SAndroid Build Coastguard Worker
59*61046927SAndroid Build Coastguard WorkerReferences
60*61046927SAndroid Build Coastguard Worker----------
61*61046927SAndroid Build Coastguard Worker
62*61046927SAndroid Build Coastguard WorkerDirectX Graphics Infrastructure documentation on DXGI_FORMAT enum:
63*61046927SAndroid Build Coastguard Workerhttps://learn.microsoft.com/en-us/windows/win32/api/dxgiformat/ne-dxgiformat-dxgi_format
64*61046927SAndroid Build Coastguard Worker
65*61046927SAndroid Build Coastguard WorkerFOURCC codes for YUV formats:
66*61046927SAndroid Build Coastguard Workerhttp://web.archive.org/web/20220523043110/https://www.fourcc.org/yuv/
67