Home | History | Annotate | Download | only in isl
      1 /*
      2  * Copyright 2015 Intel Corporation
      3  *
      4  *  Permission is hereby granted, free of charge, to any person obtaining a
      5  *  copy of this software and associated documentation files (the "Software"),
      6  *  to deal in the Software without restriction, including without limitation
      7  *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8  *  and/or sell copies of the Software, and to permit persons to whom the
      9  *  Software is furnished to do so, subject to the following conditions:
     10  *
     11  *  The above copyright notice and this permission notice (including the next
     12  *  paragraph) shall be included in all copies or substantial portions of the
     13  *  Software.
     14  *
     15  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     18  *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     20  *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     21  *  IN THE SOFTWARE.
     22  */
     23 
     24 #include <assert.h>
     25 
     26 #include "isl.h"
     27 #include "common/gen_device_info.h"
     28 
     29 struct surface_format_info {
     30    bool exists;
     31    uint8_t sampling;
     32    uint8_t filtering;
     33    uint8_t shadow_compare;
     34    uint8_t chroma_key;
     35    uint8_t render_target;
     36    uint8_t alpha_blend;
     37    uint8_t input_vb;
     38    uint8_t streamed_output_vb;
     39    uint8_t color_processing;
     40    uint8_t lossless_compression;
     41 };
     42 
     43 /* This macro allows us to write the table almost as it appears in the PRM,
     44  * while restructuring it to turn it into the C code we want.
     45  */
     46 #define SF(sampl, filt, shad, ck, rt, ab, vb, so, color, ccs_e, sf) \
     47    [ISL_FORMAT_##sf] = { true, sampl, filt, shad, ck, rt, ab, vb, so, color, ccs_e},
     48 
     49 #define Y 0
     50 #define x 255
     51 /**
     52  * This is the table of support for surface (texture, renderbuffer, and vertex
     53  * buffer, but not depthbuffer) formats across the various hardware generations.
     54  *
     55  * The table is formatted to match the documentation, except that the docs have
     56  * this ridiculous mapping of Y[*+~^#&] for "supported on DevWhatever".  To put
     57  * it in our table, here's the mapping:
     58  *
     59  * Y*: 45
     60  * Y+: 45 (g45/gm45)
     61  * Y~: 50 (gen5)
     62  * Y^: 60 (gen6)
     63  * Y#: 70 (gen7)
     64  *
     65  * The abbreviations in the header below are:
     66  * smpl  - Sampling Engine
     67  * filt  - Sampling Engine Filtering
     68  * shad  - Sampling Engine Shadow Map
     69  * CK    - Sampling Engine Chroma Key
     70  * RT    - Render Target
     71  * AB    - Alpha Blend Render Target
     72  * VB    - Input Vertex Buffer
     73  * SO    - Steamed Output Vertex Buffers (transform feedback)
     74  * color - Color Processing
     75  * ccs_e - Lossless Compression Support (gen9+ only)
     76  * sf    - Surface Format
     77  *
     78  * See page 88 of the Sandybridge PRM VOL4_Part1 PDF.
     79  *
     80  * As of Ivybridge, the columns are no longer in that table and the
     81  * information can be found spread across:
     82  *
     83  * - VOL2_Part1 section 2.5.11 Format Conversion (vertex fetch).
     84  * - VOL4_Part1 section 2.12.2.1.2 Sampler Output Channel Mapping.
     85  * - VOL4_Part1 section 3.9.11 Render Target Write.
     86  * - Render Target Surface Types [SKL+]
     87  */
     88 static const struct surface_format_info format_info[] = {
     89 /* smpl filt shad CK  RT  AB  VB  SO  color ccs_e */
     90    SF( Y, 50,  x,  x,  Y,  Y,  Y,  Y,  x,   90,   R32G32B32A32_FLOAT)
     91    SF( Y,  x,  x,  x,  Y,  x,  Y,  Y,  x,   90,   R32G32B32A32_SINT)
     92    SF( Y,  x,  x,  x,  Y,  x,  Y,  Y,  x,   90,   R32G32B32A32_UINT)
     93    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32G32B32A32_UNORM)
     94    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32G32B32A32_SNORM)
     95    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R64G64_FLOAT)
     96    SF( Y, 50,  x,  x,  x,  x,  x,  x,  x,    x,   R32G32B32X32_FLOAT)
     97    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32G32B32A32_SSCALED)
     98    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32G32B32A32_USCALED)
     99    SF( x,  x,  x,  x,  x,  x, 75,  x,  x,    x,   R32G32B32A32_SFIXED)
    100    SF( x,  x,  x,  x,  x,  x, 80,  x,  x,    x,   R64G64_PASSTHRU)
    101    SF( Y, 50,  x,  x,  x,  x,  Y,  Y,  x,    x,   R32G32B32_FLOAT)
    102    SF( Y,  x,  x,  x,  x,  x,  Y,  Y,  x,    x,   R32G32B32_SINT)
    103    SF( Y,  x,  x,  x,  x,  x,  Y,  Y,  x,    x,   R32G32B32_UINT)
    104    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32G32B32_UNORM)
    105    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32G32B32_SNORM)
    106    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32G32B32_SSCALED)
    107    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32G32B32_USCALED)
    108    SF( x,  x,  x,  x,  x,  x, 75,  x,  x,    x,   R32G32B32_SFIXED)
    109    SF( Y,  Y,  x,  x,  Y, 45,  Y,  x, 60,   90,   R16G16B16A16_UNORM)
    110    SF( Y,  Y,  x,  x,  Y, 60,  Y,  x,  x,   90,   R16G16B16A16_SNORM)
    111    SF( Y,  x,  x,  x,  Y,  x,  Y,  x,  x,   90,   R16G16B16A16_SINT)
    112    SF( Y,  x,  x,  x,  Y,  x,  Y,  x,  x,   90,   R16G16B16A16_UINT)
    113    SF( Y,  Y,  x,  x,  Y,  Y,  Y,  x,  x,   90,   R16G16B16A16_FLOAT)
    114    SF( Y, 50,  x,  x,  Y,  Y,  Y,  Y,  x,   90,   R32G32_FLOAT)
    115    SF( Y, 70,  x,  x,  Y,  Y,  Y,  Y,  x,    x,   R32G32_FLOAT_LD)
    116    SF( Y,  x,  x,  x,  Y,  x,  Y,  Y,  x,   90,   R32G32_SINT)
    117    SF( Y,  x,  x,  x,  Y,  x,  Y,  Y,  x,   90,   R32G32_UINT)
    118    SF( Y, 50,  Y,  x,  x,  x,  x,  x,  x,    x,   R32_FLOAT_X8X24_TYPELESS)
    119    SF( Y,  x,  x,  x,  x,  x,  x,  x,  x,    x,   X32_TYPELESS_G8X24_UINT)
    120    SF( Y, 50,  x,  x,  x,  x,  x,  x,  x,    x,   L32A32_FLOAT)
    121    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32G32_UNORM)
    122    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32G32_SNORM)
    123    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R64_FLOAT)
    124    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   R16G16B16X16_UNORM)
    125    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,   90,   R16G16B16X16_FLOAT)
    126    SF( Y, 50,  x,  x,  x,  x,  x,  x,  x,    x,   A32X32_FLOAT)
    127    SF( Y, 50,  x,  x,  x,  x,  x,  x,  x,    x,   L32X32_FLOAT)
    128    SF( Y, 50,  x,  x,  x,  x,  x,  x,  x,    x,   I32X32_FLOAT)
    129    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R16G16B16A16_SSCALED)
    130    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R16G16B16A16_USCALED)
    131    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32G32_SSCALED)
    132    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32G32_USCALED)
    133    SF( x,  x,  x,  x,  x,  x, 75,  x,  x,    x,   R32G32_SFIXED)
    134    SF( x,  x,  x,  x,  x,  x, 80,  x,  x,    x,   R64_PASSTHRU)
    135    SF( Y,  Y,  x,  Y,  Y,  Y,  Y,  x, 60,   90,   B8G8R8A8_UNORM)
    136    SF( Y,  Y,  x,  x,  Y,  Y,  x,  x,  x,    x,   B8G8R8A8_UNORM_SRGB)
    137 /* smpl filt shad CK  RT  AB  VB  SO  color ccs_e */
    138    SF( Y,  Y,  x,  x,  Y,  Y,  Y,  x, 60,    x,   R10G10B10A2_UNORM)
    139    SF( Y,  Y,  x,  x,  x,  x,  x,  x, 60,    x,   R10G10B10A2_UNORM_SRGB)
    140    SF( Y,  x,  x,  x,  Y,  x,  Y,  x,  x,    x,   R10G10B10A2_UINT)
    141    SF( Y,  Y,  x,  x,  x,  x,  Y,  x,  x,    x,   R10G10B10_SNORM_A2_UNORM)
    142    SF( Y,  Y,  x,  x,  Y,  Y,  Y,  x, 60,   90,   R8G8B8A8_UNORM)
    143    SF( Y,  Y,  x,  x,  Y,  Y,  x,  x, 60,    x,   R8G8B8A8_UNORM_SRGB)
    144    SF( Y,  Y,  x,  x,  Y, 60,  Y,  x,  x,   90,   R8G8B8A8_SNORM)
    145    SF( Y,  x,  x,  x,  Y,  x,  Y,  x,  x,   90,   R8G8B8A8_SINT)
    146    SF( Y,  x,  x,  x,  Y,  x,  Y,  x,  x,   90,   R8G8B8A8_UINT)
    147    SF( Y,  Y,  x,  x,  Y, 45,  Y,  x,  x,   90,   R16G16_UNORM)
    148    SF( Y,  Y,  x,  x,  Y, 60,  Y,  x,  x,   90,   R16G16_SNORM)
    149    SF( Y,  x,  x,  x,  Y,  x,  Y,  x,  x,   90,   R16G16_SINT)
    150    SF( Y,  x,  x,  x,  Y,  x,  Y,  x,  x,   90,   R16G16_UINT)
    151    SF( Y,  Y,  x,  x,  Y,  Y,  Y,  x,  x,   90,   R16G16_FLOAT)
    152    SF( Y,  Y,  x,  x,  Y,  Y, 75,  x, 60,    x,   B10G10R10A2_UNORM)
    153    SF( Y,  Y,  x,  x,  Y,  Y,  x,  x, 60,    x,   B10G10R10A2_UNORM_SRGB)
    154    SF( Y,  Y,  x,  x,  Y,  Y,  Y,  x,  x,    x,   R11G11B10_FLOAT)
    155    SF( Y,  x,  x,  x,  Y,  x,  Y,  Y,  x,   90,   R32_SINT)
    156    SF( Y,  x,  x,  x,  Y,  x,  Y,  Y,  x,   90,   R32_UINT)
    157    SF( Y, 50,  Y,  x,  Y,  Y,  Y,  Y,  x,   90,   R32_FLOAT)
    158    SF( Y, 50,  Y,  x,  x,  x,  x,  x,  x,    x,   R24_UNORM_X8_TYPELESS)
    159    SF( Y,  x,  x,  x,  x,  x,  x,  x,  x,    x,   X24_TYPELESS_G8_UINT)
    160    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   L16A16_UNORM)
    161    SF( Y, 50,  Y,  x,  x,  x,  x,  x,  x,    x,   I24X8_UNORM)
    162    SF( Y, 50,  Y,  x,  x,  x,  x,  x,  x,    x,   L24X8_UNORM)
    163    SF( Y, 50,  Y,  x,  x,  x,  x,  x,  x,    x,   A24X8_UNORM)
    164    SF( Y, 50,  Y,  x,  x,  x,  x,  x,  x,    x,   I32_FLOAT)
    165    SF( Y, 50,  Y,  x,  x,  x,  x,  x,  x,    x,   L32_FLOAT)
    166    SF( Y, 50,  Y,  x,  x,  x,  x,  x,  x,    x,   A32_FLOAT)
    167    SF( Y,  Y,  x,  Y, 80, 80,  x,  x, 60,   90,   B8G8R8X8_UNORM)
    168    SF( Y,  Y,  x,  x, 80, 80,  x,  x,  x,    x,   B8G8R8X8_UNORM_SRGB)
    169    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   R8G8B8X8_UNORM)
    170    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   R8G8B8X8_UNORM_SRGB)
    171    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   R9G9B9E5_SHAREDEXP)
    172    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   B10G10R10X2_UNORM)
    173    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   L16A16_FLOAT)
    174    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32_UNORM)
    175    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32_SNORM)
    176 /* smpl filt shad CK  RT  AB  VB  SO  color ccs_e */
    177    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R10G10B10X2_USCALED)
    178    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R8G8B8A8_SSCALED)
    179    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R8G8B8A8_USCALED)
    180    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R16G16_SSCALED)
    181    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R16G16_USCALED)
    182    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32_SSCALED)
    183    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R32_USCALED)
    184    SF( Y,  Y,  x,  Y,  Y,  Y,  x,  x,  x,    x,   B5G6R5_UNORM)
    185    SF( Y,  Y,  x,  x,  Y,  Y,  x,  x,  x,    x,   B5G6R5_UNORM_SRGB)
    186    SF( Y,  Y,  x,  Y,  Y,  Y,  x,  x,  x,    x,   B5G5R5A1_UNORM)
    187    SF( Y,  Y,  x,  x,  Y,  Y,  x,  x,  x,    x,   B5G5R5A1_UNORM_SRGB)
    188    SF( Y,  Y,  x,  Y,  Y,  Y,  x,  x,  x,    x,   B4G4R4A4_UNORM)
    189    SF( Y,  Y,  x,  x,  Y,  Y,  x,  x,  x,    x,   B4G4R4A4_UNORM_SRGB)
    190    SF( Y,  Y,  x,  x,  Y,  Y,  Y,  x,  x,    x,   R8G8_UNORM)
    191    SF( Y,  Y,  x,  Y,  Y, 60,  Y,  x,  x,    x,   R8G8_SNORM)
    192    SF( Y,  x,  x,  x,  Y,  x,  Y,  x,  x,    x,   R8G8_SINT)
    193    SF( Y,  x,  x,  x,  Y,  x,  Y,  x,  x,    x,   R8G8_UINT)
    194    SF( Y,  Y,  Y,  x,  Y, 45,  Y,  x, 70,    x,   R16_UNORM)
    195    SF( Y,  Y,  x,  x,  Y, 60,  Y,  x,  x,    x,   R16_SNORM)
    196    SF( Y,  x,  x,  x,  Y,  x,  Y,  x,  x,    x,   R16_SINT)
    197    SF( Y,  x,  x,  x,  Y,  x,  Y,  x,  x,    x,   R16_UINT)
    198    SF( Y,  Y,  x,  x,  Y,  Y,  Y,  x,  x,    x,   R16_FLOAT)
    199    SF(50, 50,  x,  x,  x,  x,  x,  x,  x,    x,   A8P8_UNORM_PALETTE0)
    200    SF(50, 50,  x,  x,  x,  x,  x,  x,  x,    x,   A8P8_UNORM_PALETTE1)
    201    SF( Y,  Y,  Y,  x,  x,  x,  x,  x,  x,    x,   I16_UNORM)
    202    SF( Y,  Y,  Y,  x,  x,  x,  x,  x,  x,    x,   L16_UNORM)
    203    SF( Y,  Y,  Y,  x,  x,  x,  x,  x,  x,    x,   A16_UNORM)
    204    SF( Y,  Y,  x,  Y,  x,  x,  x,  x,  x,    x,   L8A8_UNORM)
    205    SF( Y,  Y,  Y,  x,  x,  x,  x,  x,  x,    x,   I16_FLOAT)
    206    SF( Y,  Y,  Y,  x,  x,  x,  x,  x,  x,    x,   L16_FLOAT)
    207    SF( Y,  Y,  Y,  x,  x,  x,  x,  x,  x,    x,   A16_FLOAT)
    208    SF(45, 45,  x,  x,  x,  x,  x,  x,  x,    x,   L8A8_UNORM_SRGB)
    209    SF( Y,  Y,  x,  Y,  x,  x,  x,  x,  x,    x,   R5G5_SNORM_B6_UNORM)
    210    SF( x,  x,  x,  x,  Y,  Y,  x,  x,  x,    x,   B5G5R5X1_UNORM)
    211    SF( x,  x,  x,  x,  Y,  Y,  x,  x,  x,    x,   B5G5R5X1_UNORM_SRGB)
    212    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R8G8_SSCALED)
    213    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R8G8_USCALED)
    214 /* smpl filt shad CK  RT  AB  VB  SO  color ccs_e */
    215    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R16_SSCALED)
    216    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R16_USCALED)
    217    SF(50, 50,  x,  x,  x,  x,  x,  x,  x,    x,   P8A8_UNORM_PALETTE0)
    218    SF(50, 50,  x,  x,  x,  x,  x,  x,  x,    x,   P8A8_UNORM_PALETTE1)
    219    SF( x,  x,  x,  x,  x,  x,  x,  x,  x,    x,   A1B5G5R5_UNORM)
    220    /* According to the PRM, A4B4G4R4_UNORM isn't supported until Sky Lake
    221     * but empirical testing indicates that at least sampling works just fine
    222     * on Broadwell.
    223     */
    224    SF(80, 80,  x,  x, 90,  x,  x,  x,  x,    x,   A4B4G4R4_UNORM)
    225    SF(90,  x,  x,  x,  x,  x,  x,  x,  x,    x,   L8A8_UINT)
    226    SF(90,  x,  x,  x,  x,  x,  x,  x,  x,    x,   L8A8_SINT)
    227    SF( Y,  Y,  x, 45,  Y,  Y,  Y,  x,  x,    x,   R8_UNORM)
    228    SF( Y,  Y,  x,  x,  Y, 60,  Y,  x,  x,    x,   R8_SNORM)
    229    SF( Y,  x,  x,  x,  Y,  x,  Y,  x,  x,    x,   R8_SINT)
    230    SF( Y,  x,  x,  x,  Y,  x,  Y,  x,  x,    x,   R8_UINT)
    231    SF( Y,  Y,  x,  Y,  Y,  Y,  x,  x,  x,    x,   A8_UNORM)
    232    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   I8_UNORM)
    233    SF( Y,  Y,  x,  Y,  x,  x,  x,  x,  x,    x,   L8_UNORM)
    234    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   P4A4_UNORM_PALETTE0)
    235    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   A4P4_UNORM_PALETTE0)
    236    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R8_SSCALED)
    237    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R8_USCALED)
    238    SF(45, 45,  x,  x,  x,  x,  x,  x,  x,    x,   P8_UNORM_PALETTE0)
    239    SF(45, 45,  x,  x,  x,  x,  x,  x,  x,    x,   L8_UNORM_SRGB)
    240    SF(45, 45,  x,  x,  x,  x,  x,  x,  x,    x,   P8_UNORM_PALETTE1)
    241    SF(45, 45,  x,  x,  x,  x,  x,  x,  x,    x,   P4A4_UNORM_PALETTE1)
    242    SF(45, 45,  x,  x,  x,  x,  x,  x,  x,    x,   A4P4_UNORM_PALETTE1)
    243    SF( x,  x,  x,  x,  x,  x,  x,  x,  x,    x,   Y8_UNORM)
    244    SF(90,  x,  x,  x,  x,  x,  x,  x,  x,    x,   L8_UINT)
    245    SF(90,  x,  x,  x,  x,  x,  x,  x,  x,    x,   L8_SINT)
    246    SF(90,  x,  x,  x,  x,  x,  x,  x,  x,    x,   I8_UINT)
    247    SF(90,  x,  x,  x,  x,  x,  x,  x,  x,    x,   I8_SINT)
    248    SF(45, 45,  x,  x,  x,  x,  x,  x,  x,    x,   DXT1_RGB_SRGB)
    249    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   R1_UNORM)
    250    SF( Y,  Y,  x,  Y,  Y,  x,  x,  x, 60,    x,   YCRCB_NORMAL)
    251    SF( Y,  Y,  x,  Y,  Y,  x,  x,  x, 60,    x,   YCRCB_SWAPUVY)
    252    SF(45, 45,  x,  x,  x,  x,  x,  x,  x,    x,   P2_UNORM_PALETTE0)
    253    SF(45, 45,  x,  x,  x,  x,  x,  x,  x,    x,   P2_UNORM_PALETTE1)
    254    SF( Y,  Y,  x,  Y,  x,  x,  x,  x,  x,    x,   BC1_UNORM)
    255    SF( Y,  Y,  x,  Y,  x,  x,  x,  x,  x,    x,   BC2_UNORM)
    256    SF( Y,  Y,  x,  Y,  x,  x,  x,  x,  x,    x,   BC3_UNORM)
    257    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   BC4_UNORM)
    258    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   BC5_UNORM)
    259    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   BC1_UNORM_SRGB)
    260    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   BC2_UNORM_SRGB)
    261    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   BC3_UNORM_SRGB)
    262    SF( Y,  x,  x,  x,  x,  x,  x,  x,  x,    x,   MONO8)
    263    SF( Y,  Y,  x,  x,  Y,  x,  x,  x, 60,    x,   YCRCB_SWAPUV)
    264    SF( Y,  Y,  x,  x,  Y,  x,  x,  x, 60,    x,   YCRCB_SWAPY)
    265    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   DXT1_RGB)
    266 /* smpl filt shad CK  RT  AB  VB  SO  color ccs_e */
    267    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   FXT1)
    268    SF(75, 75,  x,  x,  x,  x,  Y,  x,  x,    x,   R8G8B8_UNORM)
    269    SF(75, 75,  x,  x,  x,  x,  Y,  x,  x,    x,   R8G8B8_SNORM)
    270    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R8G8B8_SSCALED)
    271    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R8G8B8_USCALED)
    272    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R64G64B64A64_FLOAT)
    273    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R64G64B64_FLOAT)
    274    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   BC4_SNORM)
    275    SF( Y,  Y,  x,  x,  x,  x,  x,  x,  x,    x,   BC5_SNORM)
    276    SF(50, 50,  x,  x,  x,  x, 60,  x,  x,    x,   R16G16B16_FLOAT)
    277    SF(75, 75,  x,  x,  x,  x,  Y,  x,  x,    x,   R16G16B16_UNORM)
    278    SF(75, 75,  x,  x,  x,  x,  Y,  x,  x,    x,   R16G16B16_SNORM)
    279    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R16G16B16_SSCALED)
    280    SF( x,  x,  x,  x,  x,  x,  Y,  x,  x,    x,   R16G16B16_USCALED)
    281    SF(70, 70,  x,  x,  x,  x,  x,  x,  x,    x,   BC6H_SF16)
    282    SF(70, 70,  x,  x,  x,  x,  x,  x,  x,    x,   BC7_UNORM)
    283    SF(70, 70,  x,  x,  x,  x,  x,  x,  x,    x,   BC7_UNORM_SRGB)
    284    SF(70, 70,  x,  x,  x,  x,  x,  x,  x,    x,   BC6H_UF16)
    285    SF( x,  x,  x,  x,  x,  x,  x,  x,  x,    x,   PLANAR_420_8)
    286    SF(75, 75,  x,  x,  x,  x,  x,  x,  x,    x,   R8G8B8_UNORM_SRGB)
    287    SF(80, 80,  x,  x,  x,  x,  x,  x,  x,    x,   ETC1_RGB8)
    288    SF(80, 80,  x,  x,  x,  x,  x,  x,  x,    x,   ETC2_RGB8)
    289    SF(80, 80,  x,  x,  x,  x,  x,  x,  x,    x,   EAC_R11)
    290    SF(80, 80,  x,  x,  x,  x,  x,  x,  x,    x,   EAC_RG11)
    291    SF(80, 80,  x,  x,  x,  x,  x,  x,  x,    x,   EAC_SIGNED_R11)
    292    SF(80, 80,  x,  x,  x,  x,  x,  x,  x,    x,   EAC_SIGNED_RG11)
    293    SF(80, 80,  x,  x,  x,  x,  x,  x,  x,    x,   ETC2_SRGB8)
    294    SF(90,  x,  x,  x,  x,  x, 75,  x,  x,    x,   R16G16B16_UINT)
    295    SF(90,  x,  x,  x,  x,  x, 75,  x,  x,    x,   R16G16B16_SINT)
    296    SF( x,  x,  x,  x,  x,  x, 75,  x,  x,    x,   R32_SFIXED)
    297    SF( x,  x,  x,  x,  x,  x, 75,  x,  x,    x,   R10G10B10A2_SNORM)
    298    SF( x,  x,  x,  x,  x,  x, 75,  x,  x,    x,   R10G10B10A2_USCALED)
    299    SF( x,  x,  x,  x,  x,  x, 75,  x,  x,    x,   R10G10B10A2_SSCALED)
    300    SF( x,  x,  x,  x,  x,  x, 75,  x,  x,    x,   R10G10B10A2_SINT)
    301    SF( x,  x,  x,  x,  x,  x, 75,  x,  x,    x,   B10G10R10A2_SNORM)
    302    SF( x,  x,  x,  x,  x,  x, 75,  x,  x,    x,   B10G10R10A2_USCALED)
    303    SF( x,  x,  x,  x,  x,  x, 75,  x,  x,    x,   B10G10R10A2_SSCALED)
    304    SF( x,  x,  x,  x,  x,  x, 75,  x,  x,    x,   B10G10R10A2_UINT)
    305    SF( x,  x,  x,  x,  x,  x, 75,  x,  x,    x,   B10G10R10A2_SINT)
    306    SF( x,  x,  x,  x,  x,  x, 80,  x,  x,    x,   R64G64B64A64_PASSTHRU)
    307    SF( x,  x,  x,  x,  x,  x, 80,  x,  x,    x,   R64G64B64_PASSTHRU)
    308    SF(80, 80,  x,  x,  x,  x,  x,  x,  x,    x,   ETC2_RGB8_PTA)
    309    SF(80, 80,  x,  x,  x,  x,  x,  x,  x,    x,   ETC2_SRGB8_PTA)
    310    SF(80, 80,  x,  x,  x,  x,  x,  x,  x,    x,   ETC2_EAC_RGBA8)
    311    SF(80, 80,  x,  x,  x,  x,  x,  x,  x,    x,   ETC2_EAC_SRGB8_A8)
    312    SF(90,  x,  x,  x,  x,  x, 75,  x,  x,    x,   R8G8B8_UINT)
    313    SF(90,  x,  x,  x,  x,  x, 75,  x,  x,    x,   R8G8B8_SINT)
    314    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_4X4_FLT16)
    315    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_5X4_FLT16)
    316    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_5X5_FLT16)
    317    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_6X5_FLT16)
    318    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_6X6_FLT16)
    319    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_8X5_FLT16)
    320    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_8X6_FLT16)
    321    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_8X8_FLT16)
    322    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_10X5_FLT16)
    323    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_10X6_FLT16)
    324    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_10X8_FLT16)
    325    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_10X10_FLT16)
    326    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_12X10_FLT16)
    327    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_12X12_FLT16)
    328    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_4X4_U8SRGB)
    329    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_5X4_U8SRGB)
    330    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_5X5_U8SRGB)
    331    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_6X5_U8SRGB)
    332    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_6X6_U8SRGB)
    333    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_8X5_U8SRGB)
    334    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_8X6_U8SRGB)
    335    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_8X8_U8SRGB)
    336    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_10X5_U8SRGB)
    337    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_10X6_U8SRGB)
    338    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_10X8_U8SRGB)
    339    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_10X10_U8SRGB)
    340    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_12X10_U8SRGB)
    341    SF(90, 90,  x,  x,  x,  x,  x,  x,  x,    x,   ASTC_LDR_2D_12X12_U8SRGB)
    342 };
    343 #undef x
    344 #undef Y
    345 
    346 static unsigned
    347 format_gen(const struct gen_device_info *devinfo)
    348 {
    349    return devinfo->gen * 10 + (devinfo->is_g4x || devinfo->is_haswell) * 5;
    350 }
    351 
    352 bool
    353 isl_format_supports_rendering(const struct gen_device_info *devinfo,
    354                               enum isl_format format)
    355 {
    356    if (!format_info[format].exists)
    357       return false;
    358 
    359    return format_gen(devinfo) >= format_info[format].render_target;
    360 }
    361 
    362 bool
    363 isl_format_supports_alpha_blending(const struct gen_device_info *devinfo,
    364                                    enum isl_format format)
    365 {
    366    if (!format_info[format].exists)
    367       return false;
    368 
    369    return format_gen(devinfo) >= format_info[format].alpha_blend;
    370 }
    371 
    372 bool
    373 isl_format_supports_sampling(const struct gen_device_info *devinfo,
    374                              enum isl_format format)
    375 {
    376    if (!format_info[format].exists)
    377       return false;
    378 
    379    if (devinfo->is_baytrail) {
    380       const struct isl_format_layout *fmtl = isl_format_get_layout(format);
    381       /* Support for ETC1 and ETC2 exists on Bay Trail even though big-core
    382        * GPUs didn't get it until Broadwell.
    383        */
    384       if (fmtl->txc == ISL_TXC_ETC1 || fmtl->txc == ISL_TXC_ETC2)
    385          return true;
    386    } else if (devinfo->is_cherryview) {
    387       const struct isl_format_layout *fmtl = isl_format_get_layout(format);
    388       /* Support for ASTC exists on Cherry View even though big-core
    389        * GPUs didn't get it until Skylake.
    390        */
    391       if (fmtl->txc == ISL_TXC_ASTC)
    392          return true;
    393    }
    394 
    395    return format_gen(devinfo) >= format_info[format].sampling;
    396 }
    397 
    398 bool
    399 isl_format_supports_filtering(const struct gen_device_info *devinfo,
    400                               enum isl_format format)
    401 {
    402    if (!format_info[format].exists)
    403       return false;
    404 
    405    if (devinfo->is_baytrail) {
    406       const struct isl_format_layout *fmtl = isl_format_get_layout(format);
    407       /* Support for ETC1 and ETC2 exists on Bay Trail even though big-core
    408        * GPUs didn't get it until Broadwell.
    409        */
    410       if (fmtl->txc == ISL_TXC_ETC1 || fmtl->txc == ISL_TXC_ETC2)
    411          return true;
    412    } else if (devinfo->is_cherryview) {
    413       const struct isl_format_layout *fmtl = isl_format_get_layout(format);
    414       /* Support for ASTC exists on Cherry View even though big-core
    415        * GPUs didn't get it until Skylake.
    416        */
    417       if (fmtl->txc == ISL_TXC_ASTC)
    418          return true;
    419    }
    420 
    421    return format_gen(devinfo) >= format_info[format].filtering;
    422 }
    423 
    424 bool
    425 isl_format_supports_vertex_fetch(const struct gen_device_info *devinfo,
    426                                  enum isl_format format)
    427 {
    428    if (!format_info[format].exists)
    429       return false;
    430 
    431    /* For vertex fetch, Bay Trail supports the same set of formats as Haswell
    432     * but is a superset of Ivy Bridge.
    433     */
    434    if (devinfo->is_baytrail)
    435       return 75 >= format_info[format].input_vb;
    436 
    437    return format_gen(devinfo) >= format_info[format].input_vb;
    438 }
    439 
    440 bool
    441 isl_format_supports_lossless_compression(const struct gen_device_info *devinfo,
    442                                          enum isl_format format)
    443 {
    444    if (!format_info[format].exists)
    445       return false;
    446 
    447    return format_gen(devinfo) >= format_info[format].lossless_compression;
    448 }
    449 
    450 bool
    451 isl_format_supports_multisampling(const struct gen_device_info *devinfo,
    452                                   enum isl_format format)
    453 {
    454    /* From the Sandybridge PRM, Volume 4 Part 1 p72, SURFACE_STATE, Surface
    455     * Format:
    456     *
    457     *    If Number of Multisamples is set to a value other than
    458     *    MULTISAMPLECOUNT_1, this field cannot be set to the following
    459     *    formats:
    460     *
    461     *       - any format with greater than 64 bits per element
    462     *       - any compressed texture format (BC*)
    463     *       - any YCRCB* format
    464     *
    465     * The restriction on the format's size is removed on Broadwell.  Also,
    466     * there is an exception for HiZ which we treat as a compressed format and
    467     * is allowed to be multisampled on Broadwell and earlier.
    468     */
    469    if (format == ISL_FORMAT_HIZ) {
    470       /* On SKL+, HiZ is always single-sampled even when the primary surface
    471        * is multisampled.  See also isl_surf_get_hiz_surf().
    472        */
    473       return devinfo->gen <= 8;
    474    } else if (devinfo->gen < 8 && isl_format_get_layout(format)->bpb > 64) {
    475       return false;
    476    } else if (isl_format_is_compressed(format)) {
    477       return false;
    478    } else if (isl_format_is_yuv(format)) {
    479       return false;
    480    } else {
    481       return true;
    482    }
    483 }
    484 
    485 static inline bool
    486 isl_format_has_channel_type(enum isl_format fmt, enum isl_base_type type)
    487 {
    488    const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
    489 
    490    return fmtl->channels.r.type == type ||
    491           fmtl->channels.g.type == type ||
    492           fmtl->channels.b.type == type ||
    493           fmtl->channels.a.type == type ||
    494           fmtl->channels.l.type == type ||
    495           fmtl->channels.i.type == type ||
    496           fmtl->channels.p.type == type;
    497 }
    498 
    499 bool
    500 isl_format_has_unorm_channel(enum isl_format fmt)
    501 {
    502    return isl_format_has_channel_type(fmt, ISL_UNORM);
    503 }
    504 
    505 bool
    506 isl_format_has_snorm_channel(enum isl_format fmt)
    507 {
    508    return isl_format_has_channel_type(fmt, ISL_SNORM);
    509 }
    510 
    511 bool
    512 isl_format_has_ufloat_channel(enum isl_format fmt)
    513 {
    514    return isl_format_has_channel_type(fmt, ISL_UFLOAT);
    515 }
    516 
    517 bool
    518 isl_format_has_sfloat_channel(enum isl_format fmt)
    519 {
    520    return isl_format_has_channel_type(fmt, ISL_SFLOAT);
    521 }
    522 
    523 bool
    524 isl_format_has_uint_channel(enum isl_format fmt)
    525 {
    526    return isl_format_has_channel_type(fmt, ISL_UINT);
    527 }
    528 
    529 bool
    530 isl_format_has_sint_channel(enum isl_format fmt)
    531 {
    532    return isl_format_has_channel_type(fmt, ISL_SINT);
    533 }
    534 
    535 unsigned
    536 isl_format_get_num_channels(enum isl_format fmt)
    537 {
    538    const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
    539 
    540    assert(fmtl->channels.p.bits == 0);
    541 
    542    return (fmtl->channels.r.bits > 0) +
    543           (fmtl->channels.g.bits > 0) +
    544           (fmtl->channels.b.bits > 0) +
    545           (fmtl->channels.a.bits > 0) +
    546           (fmtl->channels.l.bits > 0) +
    547           (fmtl->channels.i.bits > 0);
    548 }
    549 
    550 uint32_t
    551 isl_format_get_depth_format(enum isl_format fmt, bool has_stencil)
    552 {
    553    switch (fmt) {
    554    default:
    555       unreachable("bad isl depth format");
    556    case ISL_FORMAT_R32_FLOAT_X8X24_TYPELESS:
    557       assert(has_stencil);
    558       return 0; /* D32_FLOAT_S8X24_UINT */
    559    case ISL_FORMAT_R32_FLOAT:
    560       assert(!has_stencil);
    561       return 1; /* D32_FLOAT */
    562    case ISL_FORMAT_R24_UNORM_X8_TYPELESS:
    563       if (has_stencil) {
    564          return 2; /* D24_UNORM_S8_UINT */
    565       } else {
    566          return 3; /* D24_UNORM_X8_UINT */
    567       }
    568    case ISL_FORMAT_R16_UNORM:
    569       assert(!has_stencil);
    570       return 5; /* D16_UNORM */
    571    }
    572 }
    573 
    574 enum isl_format
    575 isl_format_rgb_to_rgba(enum isl_format rgb)
    576 {
    577    assert(isl_format_is_rgb(rgb));
    578 
    579    switch (rgb) {
    580    case ISL_FORMAT_R32G32B32_FLOAT:    return ISL_FORMAT_R32G32B32A32_FLOAT;
    581    case ISL_FORMAT_R32G32B32_SINT:     return ISL_FORMAT_R32G32B32A32_SINT;
    582    case ISL_FORMAT_R32G32B32_UINT:     return ISL_FORMAT_R32G32B32A32_UINT;
    583    case ISL_FORMAT_R32G32B32_UNORM:    return ISL_FORMAT_R32G32B32A32_UNORM;
    584    case ISL_FORMAT_R32G32B32_SNORM:    return ISL_FORMAT_R32G32B32A32_SNORM;
    585    case ISL_FORMAT_R32G32B32_SSCALED:  return ISL_FORMAT_R32G32B32A32_SSCALED;
    586    case ISL_FORMAT_R32G32B32_USCALED:  return ISL_FORMAT_R32G32B32A32_USCALED;
    587    case ISL_FORMAT_R32G32B32_SFIXED:   return ISL_FORMAT_R32G32B32A32_SFIXED;
    588    case ISL_FORMAT_R8G8B8_UNORM:       return ISL_FORMAT_R8G8B8A8_UNORM;
    589    case ISL_FORMAT_R8G8B8_SNORM:       return ISL_FORMAT_R8G8B8A8_SNORM;
    590    case ISL_FORMAT_R8G8B8_SSCALED:     return ISL_FORMAT_R8G8B8A8_SSCALED;
    591    case ISL_FORMAT_R8G8B8_USCALED:     return ISL_FORMAT_R8G8B8A8_USCALED;
    592    case ISL_FORMAT_R16G16B16_FLOAT:    return ISL_FORMAT_R16G16B16A16_FLOAT;
    593    case ISL_FORMAT_R16G16B16_UNORM:    return ISL_FORMAT_R16G16B16A16_UNORM;
    594    case ISL_FORMAT_R16G16B16_SNORM:    return ISL_FORMAT_R16G16B16A16_SNORM;
    595    case ISL_FORMAT_R16G16B16_SSCALED:  return ISL_FORMAT_R16G16B16A16_SSCALED;
    596    case ISL_FORMAT_R16G16B16_USCALED:  return ISL_FORMAT_R16G16B16A16_USCALED;
    597    case ISL_FORMAT_R8G8B8_UNORM_SRGB:  return ISL_FORMAT_R8G8B8A8_UNORM_SRGB;
    598    case ISL_FORMAT_R16G16B16_UINT:     return ISL_FORMAT_R16G16B16A16_UINT;
    599    case ISL_FORMAT_R16G16B16_SINT:     return ISL_FORMAT_R16G16B16A16_SINT;
    600    case ISL_FORMAT_R8G8B8_UINT:        return ISL_FORMAT_R8G8B8A8_UINT;
    601    case ISL_FORMAT_R8G8B8_SINT:        return ISL_FORMAT_R8G8B8A8_SINT;
    602    default:
    603       return ISL_FORMAT_UNSUPPORTED;
    604    }
    605 }
    606 
    607 enum isl_format
    608 isl_format_rgb_to_rgbx(enum isl_format rgb)
    609 {
    610    assert(isl_format_is_rgb(rgb));
    611 
    612    switch (rgb) {
    613    case ISL_FORMAT_R32G32B32_FLOAT:
    614       return ISL_FORMAT_R32G32B32X32_FLOAT;
    615    case ISL_FORMAT_R16G16B16_UNORM:
    616       return ISL_FORMAT_R16G16B16X16_UNORM;
    617    case ISL_FORMAT_R16G16B16_FLOAT:
    618       return ISL_FORMAT_R16G16B16X16_FLOAT;
    619    case ISL_FORMAT_R8G8B8_UNORM:
    620       return ISL_FORMAT_R8G8B8X8_UNORM;
    621    case ISL_FORMAT_R8G8B8_UNORM_SRGB:
    622       return ISL_FORMAT_R8G8B8X8_UNORM_SRGB;
    623    default:
    624       return ISL_FORMAT_UNSUPPORTED;
    625    }
    626 }
    627