xref: /aosp_15_r20/external/mesa3d/src/intel/isl/isl_format.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 "isl_priv.h"
28 #include "dev/intel_device_info.h"
29 
30 #include "util/macros.h" /* Needed for MAX3 and MAX2 for format_rgb9e5 */
31 
32 #include "util/format/format_utils.h"
33 #include "util/format_r11g11b10f.h"
34 #include "util/format_rgb9e5.h"
35 #include "util/format_srgb.h"
36 #include "util/half_float.h"
37 #include "util/rounding.h"
38 #include "util/u_math.h"
39 
40 struct surface_format_info {
41    bool exists;
42    /* These fields must fit the largest verx10 value. */
43    uint16_t sampling;
44    uint16_t filtering;
45    uint16_t shadow_compare;
46    uint16_t chroma_key;
47    uint16_t render_target;
48    uint16_t alpha_blend;
49    uint16_t input_vb;
50    uint16_t streamed_output_vb;
51    uint16_t color_processing;
52    uint16_t typed_write;
53    uint16_t typed_read;
54    uint16_t typed_atomics;
55    uint16_t ccs_e;
56 };
57 
58 /* This macro allows us to write the table almost as it appears in the PRM,
59  * while restructuring it to turn it into the C code we want.
60  */
61 #define SF(sampl, filt, shad, ck, rt, ab, vb, so, color, tw, tr, ccs_e, ta, sf) \
62    [ISL_FORMAT_##sf] = { true, sampl, filt, shad, ck, rt, ab, vb, so, color, tw, tr, ta, ccs_e},
63 
64 #define Y 0
65 #define x 0xFFFF
66 /**
67  * This is the table of support for surface (texture, renderbuffer, and vertex
68  * buffer, but not depthbuffer) formats across the various hardware generations.
69  *
70  * The table is formatted to match the documentation, except that the docs have
71  * this ridiculous mapping of Y[*+~^#&] for "supported on DevWhatever".  To put
72  * it in our table, here's the mapping:
73  *
74  * Y*: 45
75  * Y+: 45 (g45/gm45)
76  * Y~: 50 (gfx5)
77  * Y^: 60 (gfx6)
78  * Y#: 70 (gfx7)
79  *
80  * The abbreviations in the header below are:
81  * smpl  - Sampling Engine
82  * filt  - Sampling Engine Filtering
83  * shad  - Sampling Engine Shadow Map
84  * CK    - Sampling Engine Chroma Key
85  * RT    - Render Target
86  * AB    - Alpha Blend Render Target
87  * VB    - Input Vertex Buffer
88  * SO    - Steamed Output Vertex Buffers (transform feedback)
89  * color - Color Processing
90  * TW    - Typed Write
91  * TR    - Typed Read
92  * ccs_e - Lossless Compression Support (gfx9+ only)
93  * sf    - Surface Format
94  * TA    - Typed Atomics
95  *
96  * See page 88 of the Sandybridge PRM VOL4_Part1 PDF.
97  *
98  * As of Ivybridge, the columns are no longer in that table and the
99  * information can be found spread across:
100  *
101  * - VOL2_Part1 section 2.5.11 Format Conversion (vertex fetch).
102  * - VOL4_Part1 section 2.12.2.1.2 Sampler Output Channel Mapping.
103  * - VOL4_Part1 section 3.9.11 Render Target Write.
104  * - Render Target Surface Types [SKL+]
105  */
106 static const struct surface_format_info format_info[] = {
107 /*    smpl filt  shad  CK   RT   AB   VB   SO color TW   TR  ccs_e  TA */
108    SF(  Y,  50,   x,   x,   Y,   Y,   Y,   Y,   x,  70,  90,  90,    x,  R32G32B32A32_FLOAT)
109    SF(  Y,   x,   x,   x,   Y,   x,   Y,   Y,   x,  70,  90,  90,    x,  R32G32B32A32_SINT)
110    SF(  Y,   x,   x,   x,   Y,   x,   Y,   Y,   x,  70,  90,  90,    x,  R32G32B32A32_UINT)
111    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32G32B32A32_UNORM)
112    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32G32B32A32_SNORM)
113    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R64G64_FLOAT)
114    SF(  Y,  50,   x,   x, 110, 110,   x,   x,   x,   x,   x, 110,    x,  R32G32B32X32_FLOAT)
115    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32G32B32A32_SSCALED)
116    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32G32B32A32_USCALED)
117    SF(  x,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  R32G32B32A32_SFIXED)
118    SF(  x,   x,   x,   x,   x,   x,  80,   x,   x,   x,   x,   x,    x,  R64G64_PASSTHRU)
119    SF(  Y,  50,   x,   x,   x,   x,   Y,   Y,   x,   x,   x,   x,    x,  R32G32B32_FLOAT)
120    SF(  Y,   x,   x,   x,   x,   x,   Y,   Y,   x,   x,   x,   x,    x,  R32G32B32_SINT)
121    SF(  Y,   x,   x,   x,   x,   x,   Y,   Y,   x,   x,   x,   x,    x,  R32G32B32_UINT)
122    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32G32B32_UNORM)
123    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32G32B32_SNORM)
124    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32G32B32_SSCALED)
125    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32G32B32_USCALED)
126    SF(  x,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  R32G32B32_SFIXED)
127    SF(  Y,   Y,   x,   x,   Y,  45,   Y,   x,  60,  70, 110,  90,    x,  R16G16B16A16_UNORM)
128    SF(  Y,   Y,   x,   x,   Y,  60,   Y,   x,   x,  70, 110,  90,    x,  R16G16B16A16_SNORM)
129    SF(  Y,   x,   x,   x,   Y,   x,   Y,   x,   x,  70,  90,  90,    x,  R16G16B16A16_SINT)
130    SF(  Y,   x,   x,   x,   Y,   x,   Y,   x,   x,  70,  75,  90,    x,  R16G16B16A16_UINT)
131    SF(  Y,   Y,   x,   x,   Y,   Y,   Y,   x,   x,  70,  90,  90,    x,  R16G16B16A16_FLOAT)
132    SF(  Y,  50,   x,   x,   Y,   Y,   Y,   Y,   x,  70,  90,  90,    x,  R32G32_FLOAT)
133    SF(  Y,  70,   x,   x,   Y,   Y,   Y,   Y,   x,   x,   x,   x,    x,  R32G32_FLOAT_LD)
134    SF(  Y,   x,   x,   x,   Y,   x,   Y,   Y,   x,  70,  90,  90,    x,  R32G32_SINT)
135    SF(  Y,   x,   x,   x,   Y,   x,   Y,   Y,   x,  70,  90,  90,    x,  R32G32_UINT)
136    SF(  Y,  50,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  R32_FLOAT_X8X24_TYPELESS)
137    SF(  Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  X32_TYPELESS_G8X24_UINT)
138    SF(  Y,  50,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L32A32_FLOAT)
139    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32G32_UNORM)
140    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32G32_SNORM)
141    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,   90,  R64_FLOAT)
142    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  R16G16B16X16_UNORM)
143    SF(  Y,   Y,   x,   x,  90,  90,   x,   x,   x,   x,   x,  90,    x,  R16G16B16X16_FLOAT)
144    SF(  Y,  50,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  A32X32_FLOAT)
145    SF(  Y,  50,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L32X32_FLOAT)
146    SF(  Y,  50,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  I32X32_FLOAT)
147    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R16G16B16A16_SSCALED)
148    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R16G16B16A16_USCALED)
149    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32G32_SSCALED)
150    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32G32_USCALED)
151    SF(  x,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  R32G32_SFIXED)
152    SF(  x,   x,   x,   x,   x,   x,  80,   x,   x,   x,   x,   x,   90,  R64_PASSTHRU)
153    SF(  Y,   Y,   x,   Y,   Y,   Y,   Y,   x,  60,  70, 125,  90,    x,  B8G8R8A8_UNORM)
154    SF(  Y,   Y,   x,   x,   Y,   Y,   x,   x,   x,   x,   x, 110,    x,  B8G8R8A8_UNORM_SRGB)
155 /*    smpl filt  shad  CK   RT   AB   VB   SO color TW   TR  ccs_e  TA */
156    SF(  Y,   Y,   x,   x,   Y,   Y,   Y,   x,  60,  70, 125, 110,    x,  R10G10B10A2_UNORM)
157    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,  60,   x,   x, 120,    x,  R10G10B10A2_UNORM_SRGB)
158    SF(  Y,   x,   x,   x,   Y,   x,   Y,   x,   x,  70, 125, 110,    x,  R10G10B10A2_UINT)
159    SF(  Y,   Y,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R10G10B10_SNORM_A2_UNORM)
160    SF(  Y,   Y,   x,   x,   Y,   Y,   Y,   x,  60,  70, 110,  90,    x,  R8G8B8A8_UNORM)
161    SF(  Y,   Y,   x,   x,   Y,   Y,   x,   x,  60,   x,   x, 110,    x,  R8G8B8A8_UNORM_SRGB)
162    SF(  Y,   Y,   x,   x,   Y,  60,   Y,   x,   x,  70, 110,  90,    x,  R8G8B8A8_SNORM)
163    SF(  Y,   x,   x,   x,   Y,   x,   Y,   x,   x,  70,  90,  90,    x,  R8G8B8A8_SINT)
164    SF(  Y,   x,   x,   x,   Y,   x,   Y,   x,   x,  70,  75,  90,    x,  R8G8B8A8_UINT)
165    SF(  Y,   Y,   x,   x,   Y,  45,   Y,   x,   x,  70, 110,  90,    x,  R16G16_UNORM)
166    SF(  Y,   Y,   x,   x,   Y,  60,   Y,   x,   x,  70, 110,  90,    x,  R16G16_SNORM)
167    SF(  Y,   x,   x,   x,   Y,   x,   Y,   x,   x,  70,  90,  90,    x,  R16G16_SINT)
168    SF(  Y,   x,   x,   x,   Y,   x,   Y,   x,   x,  70,  75,  90,    x,  R16G16_UINT)
169    SF(  Y,   Y,   x,   x,   Y,   Y,   Y,   x,   x,  70,  90,  90,    x,  R16G16_FLOAT)
170    SF(  Y,   Y,   x,   x,   Y,   Y,  75,   x,  60,  70, 125, 110,    x,  B10G10R10A2_UNORM)
171    SF(  Y,   Y,   x,   x,   Y,   Y,   x,   x,  60,   x,   x, 110,    x,  B10G10R10A2_UNORM_SRGB)
172    SF(  Y,   Y,   x,   x,   Y,   Y,   Y,   x,   x,  70, 125, 110,    x,  R11G11B10_FLOAT)
173    SF(120, 120,   x,   x, 120, 120,   x,   x,   x, 125, 125, 120,    x,  R10G10B10_FLOAT_A2_UNORM)
174    SF(  Y,   x,   x,   x,   Y,   x,   Y,   Y,   x,  70,  70,  90,   70,  R32_SINT)
175    SF(  Y,   x,   x,   x,   Y,   x,   Y,   Y,   x,  70,  70,  90,   70,  R32_UINT)
176    SF(  Y,  50,   Y,   x,   Y,   Y,   Y,   Y,   x,  70,  70,  90,  110,  R32_FLOAT)
177    SF(  Y,  50,   Y,   x,   x,   x,   x,   x,   x,   x,   x, 120,    x,  R24_UNORM_X8_TYPELESS)
178    SF(  Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  X24_TYPELESS_G8_UINT)
179    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L16A16_UNORM)
180    SF(  Y,  50,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  I24X8_UNORM)
181    SF(  Y,  50,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L24X8_UNORM)
182    SF(  Y,  50,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  A24X8_UNORM)
183    SF(  Y,  50,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  I32_FLOAT)
184    SF(  Y,  50,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L32_FLOAT)
185    SF(  Y,  50,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  A32_FLOAT)
186    SF(  Y,   Y,   x,   Y,  80,  80,   x,   x,  60,   x,   x,  90,    x,  B8G8R8X8_UNORM)
187    SF(  Y,   Y,   x,   x,  80,  80,   x,   x,   x,   x,   x, 110,    x,  B8G8R8X8_UNORM_SRGB)
188    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  R8G8B8X8_UNORM)
189    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  R8G8B8X8_UNORM_SRGB)
190    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  R9G9B9E5_SHAREDEXP)
191    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  B10G10R10X2_UNORM)
192    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L16A16_FLOAT)
193    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32_UNORM)
194    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32_SNORM)
195 /*    smpl filt  shad  CK   RT   AB   VB   SO color TW   TR  ccs_e  TA */
196    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R10G10B10X2_USCALED)
197    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R8G8B8A8_SSCALED)
198    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R8G8B8A8_USCALED)
199    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R16G16_SSCALED)
200    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R16G16_USCALED)
201    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32_SSCALED)
202    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R32_USCALED)
203    SF(  Y,   Y,   x,   Y,   Y,   Y,   x,   x,   x,  70,   x, 120,    x,  B5G6R5_UNORM)
204    SF(  Y,   Y,   x,   x,   Y,   Y,   x,   x,   x,   x,   x, 120,    x,  B5G6R5_UNORM_SRGB)
205    SF(  Y,   Y,   x,   Y,   Y,   Y,   x,   x,   x,  70,   x, 120,    x,  B5G5R5A1_UNORM)
206    SF(  Y,   Y,   x,   x,   Y,   Y,   x,   x,   x,   x,   x, 120,    x,  B5G5R5A1_UNORM_SRGB)
207    SF(  Y,   Y,   x,   Y,   Y,   Y,   x,   x,   x,  70,   x, 120,    x,  B4G4R4A4_UNORM)
208    SF(  Y,   Y,   x,   x,   Y,   Y,   x,   x,   x,   x,   x, 120,    x,  B4G4R4A4_UNORM_SRGB)
209    SF(  Y,   Y,   x,   x,   Y,   Y,   Y,   x,   x,  70, 110, 120,    x,  R8G8_UNORM)
210    SF(  Y,   Y,   x,   Y,   Y,  60,   Y,   x,   x,  70, 110, 120,    x,  R8G8_SNORM)
211    SF(  Y,   x,   x,   x,   Y,   x,   Y,   x,   x,  70,  90, 120,    x,  R8G8_SINT)
212    SF(  Y,   x,   x,   x,   Y,   x,   Y,   x,   x,  70,  75, 120,    x,  R8G8_UINT)
213    SF(  Y,   Y,   Y,   x,   Y,  45,   Y,   x,  70,  70, 110, 120,    x,  R16_UNORM)
214    SF(  Y,   Y,   x,   x,   Y,  60,   Y,   x,   x,  70, 110, 120,    x,  R16_SNORM)
215    SF(  Y,   x,   x,   x,   Y,   x,   Y,   x,   x,  70,  90, 120,  120,  R16_SINT)
216    SF(  Y,   x,   x,   x,   Y,   x,   Y,   x,   x,  70,  75, 120,  120,  R16_UINT)
217    SF(  Y,   Y,   x,   x,   Y,   Y,   Y,   x,   x,  70,  90, 120,  120,  R16_FLOAT)
218    SF( 50,  50,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  A8P8_UNORM_PALETTE0)
219    SF( 50,  50,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  A8P8_UNORM_PALETTE1)
220    SF(  Y,   Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  I16_UNORM)
221    SF(  Y,   Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L16_UNORM)
222    SF(  Y,   Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  A16_UNORM)
223    SF(  Y,   Y,   x,   Y,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L8A8_UNORM)
224    SF(  Y,   Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  I16_FLOAT)
225    SF(  Y,   Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L16_FLOAT)
226    SF(  Y,   Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  A16_FLOAT)
227    SF( 45,  45,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L8A8_UNORM_SRGB)
228    SF(  Y,   Y,   x,   Y,   x,   x,   x,   x,   x,   x,   x,   x,    x,  R5G5_SNORM_B6_UNORM)
229    SF(  x,   x,   x,   x,   Y,   Y,   x,   x,   x,  70,   x, 120,    x,  B5G5R5X1_UNORM)
230    SF(  x,   x,   x,   x,   Y,   Y,   x,   x,   x,   x,   x, 120,    x,  B5G5R5X1_UNORM_SRGB)
231    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R8G8_SSCALED)
232    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R8G8_USCALED)
233 /*    smpl filt  shad  CK   RT   AB   VB   SO color TW   TR  ccs_e  TA */
234    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R16_SSCALED)
235    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R16_USCALED)
236    SF( 50,  50,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  P8A8_UNORM_PALETTE0)
237    SF( 50,  50,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  P8A8_UNORM_PALETTE1)
238    SF(120, 120,   x,   x, 120, 120,   x,   x,   x,   x,   x, 120,    x,  A1B5G5R5_UNORM)
239    /* According to the PRM, A4B4G4R4_UNORM isn't supported until Sky Lake
240     * but empirical testing indicates that at least sampling works just fine
241     * on Broadwell.
242     */
243    SF( 80,  80,   x,   x,  90, 120,   x,   x,   x,   x,   x, 120,    x,  A4B4G4R4_UNORM)
244    SF( 90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L8A8_UINT)
245    SF( 90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L8A8_SINT)
246    SF(  Y,   Y,   x,  45,   Y,   Y,   Y,   x,   x,  70, 110, 120,    x,  R8_UNORM)
247    SF(  Y,   Y,   x,   x,   Y,  60,   Y,   x,   x,  70, 110, 120,    x,  R8_SNORM)
248    SF(  Y,   x,   x,   x,   Y,   x,   Y,   x,   x,  70,  90, 120,    x,  R8_SINT)
249    SF(  Y,   x,   x,   x,   Y,   x,   Y,   x,   x,  70,  75, 120,    x,  R8_UINT)
250    SF(  Y,   Y,   x,   Y,   Y,   Y,   x,   x,   x,  70, 110, 120,    x,  A8_UNORM)
251    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  I8_UNORM)
252    SF(  Y,   Y,   x,   Y,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L8_UNORM)
253    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  P4A4_UNORM_PALETTE0)
254    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  A4P4_UNORM_PALETTE0)
255    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R8_SSCALED)
256    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R8_USCALED)
257    SF( 45,  45,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  P8_UNORM_PALETTE0)
258    SF( 45,  45,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L8_UNORM_SRGB)
259    SF( 45,  45,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  P8_UNORM_PALETTE1)
260    SF( 45,  45,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  P4A4_UNORM_PALETTE1)
261    SF( 45,  45,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  A4P4_UNORM_PALETTE1)
262    SF(  x,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  Y8_UNORM)
263    SF( 90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L8_UINT)
264    SF( 90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  L8_SINT)
265    SF( 90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  I8_UINT)
266    SF( 90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  I8_SINT)
267    SF( 45,  45,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  DXT1_RGB_SRGB)
268    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  R1_UNORM)
269    SF(  Y,   Y,   x,   Y,   Y,   x,   x,   x,  60,   x,   x, 120,    x,  YCRCB_NORMAL)
270    SF(  Y,   Y,   x,   Y,   Y,   x,   x,   x,  60,   x,   x,   x,    x,  YCRCB_SWAPUVY)
271    SF( 45,  45,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  P2_UNORM_PALETTE0)
272    SF( 45,  45,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  P2_UNORM_PALETTE1)
273    SF(  Y,   Y,   x,   Y,   x,   x,   x,   x,   x,   x,   x,   x,    x,  BC1_UNORM)
274    SF(  Y,   Y,   x,   Y,   x,   x,   x,   x,   x,   x,   x,   x,    x,  BC2_UNORM)
275    SF(  Y,   Y,   x,   Y,   x,   x,   x,   x,   x,   x,   x,   x,    x,  BC3_UNORM)
276    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  BC4_UNORM)
277    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  BC5_UNORM)
278    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  BC1_UNORM_SRGB)
279    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  BC2_UNORM_SRGB)
280    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  BC3_UNORM_SRGB)
281    SF(  Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  MONO8)
282    SF(  Y,   Y,   x,   x,   Y,   x,   x,   x,  60,   x,   x,   x,    x,  YCRCB_SWAPUV)
283    SF(  Y,   Y,   x,   x,   Y,   x,   x,   x,  60,   x,   x, 120,    x,  YCRCB_SWAPY)
284    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  DXT1_RGB)
285 /*    smpl filt  shad  CK   RT   AB   VB   SO color TW   TR  ccs_e  TA */
286    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  FXT1)
287    SF( 75,  75,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R8G8B8_UNORM)
288    SF( 75,  75,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R8G8B8_SNORM)
289    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R8G8B8_SSCALED)
290    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R8G8B8_USCALED)
291    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R64G64B64A64_FLOAT)
292    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R64G64B64_FLOAT)
293    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  BC4_SNORM)
294    SF(  Y,   Y,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  BC5_SNORM)
295    SF( 50,  50,   x,   x,   x,   x,  60,   x,   x,   x,   x,   x,    x,  R16G16B16_FLOAT)
296    SF( 75,  75,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R16G16B16_UNORM)
297    SF( 75,  75,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R16G16B16_SNORM)
298    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R16G16B16_SSCALED)
299    SF(  x,   x,   x,   x,   x,   x,   Y,   x,   x,   x,   x,   x,    x,  R16G16B16_USCALED)
300    SF( 70,  70,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  BC6H_SF16)
301    SF( 70,  70,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  BC7_UNORM)
302    SF( 70,  70,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  BC7_UNORM_SRGB)
303    SF( 70,  70,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  BC6H_UF16)
304    SF(  x,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  PLANAR_420_8)
305    /* The format enum for R8G8B8_UNORM_SRGB first shows up in the HSW PRM but
306     * empirical testing indicates that it doesn't actually sRGB decode and
307     * acts identical to R8G8B8_UNORM.  It does work on gfx8+.
308     */
309    SF( 80,  80,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  R8G8B8_UNORM_SRGB)
310    SF( 80,  80,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ETC1_RGB8)
311    SF( 80,  80,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ETC2_RGB8)
312    SF( 80,  80,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  EAC_R11)
313    SF( 80,  80,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  EAC_RG11)
314    SF( 80,  80,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  EAC_SIGNED_R11)
315    SF( 80,  80,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  EAC_SIGNED_RG11)
316    SF( 80,  80,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ETC2_SRGB8)
317    SF( 90,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  R16G16B16_UINT)
318    SF( 90,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  R16G16B16_SINT)
319    SF(  x,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  R32_SFIXED)
320    SF(  x,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  R10G10B10A2_SNORM)
321    SF(  x,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  R10G10B10A2_USCALED)
322    SF(  x,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  R10G10B10A2_SSCALED)
323    SF(  x,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  R10G10B10A2_SINT)
324    SF(  x,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  B10G10R10A2_SNORM)
325    SF(  x,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  B10G10R10A2_USCALED)
326    SF(  x,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  B10G10R10A2_SSCALED)
327    SF(  x,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  B10G10R10A2_UINT)
328    SF(  x,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  B10G10R10A2_SINT)
329    SF(  x,   x,   x,   x,   x,   x,  80,   x,   x,   x,   x,   x,    x,  R64G64B64A64_PASSTHRU)
330    SF(  x,   x,   x,   x,   x,   x,  80,   x,   x,   x,   x,   x,    x,  R64G64B64_PASSTHRU)
331    SF( 80,  80,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ETC2_RGB8_PTA)
332    SF( 80,  80,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ETC2_SRGB8_PTA)
333    SF( 80,  80,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ETC2_EAC_RGBA8)
334    SF( 80,  80,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ETC2_EAC_SRGB8_A8)
335    SF( 90,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  R8G8B8_UINT)
336    SF( 90,   x,   x,   x,   x,   x,  75,   x,   x,   x,   x,   x,    x,  R8G8B8_SINT)
337    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_4X4_FLT16)
338    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_5X4_FLT16)
339    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_5X5_FLT16)
340    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_6X5_FLT16)
341    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_6X6_FLT16)
342    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_8X5_FLT16)
343    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_8X6_FLT16)
344    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_8X8_FLT16)
345    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_10X5_FLT16)
346    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_10X6_FLT16)
347    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_10X8_FLT16)
348    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_10X10_FLT16)
349    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_12X10_FLT16)
350    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_12X12_FLT16)
351    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_4X4_U8SRGB)
352    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_5X4_U8SRGB)
353    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_5X5_U8SRGB)
354    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_6X5_U8SRGB)
355    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_6X6_U8SRGB)
356    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_8X5_U8SRGB)
357    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_8X6_U8SRGB)
358    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_8X8_U8SRGB)
359    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_10X5_U8SRGB)
360    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_10X6_U8SRGB)
361    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_10X8_U8SRGB)
362    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_10X10_U8SRGB)
363    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_12X10_U8SRGB)
364    SF( 90,  90,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_LDR_2D_12X12_U8SRGB)
365    SF(110, 110,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_HDR_2D_4X4_FLT16)
366    SF(110, 110,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_HDR_2D_5X4_FLT16)
367    SF(110, 110,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_HDR_2D_5X5_FLT16)
368    SF(110, 110,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_HDR_2D_6X5_FLT16)
369    SF(110, 110,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_HDR_2D_6X6_FLT16)
370    SF(110, 110,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_HDR_2D_8X5_FLT16)
371    SF(110, 110,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_HDR_2D_8X6_FLT16)
372    SF(110, 110,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_HDR_2D_8X8_FLT16)
373    SF(110, 110,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_HDR_2D_10X5_FLT16)
374    SF(110, 110,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_HDR_2D_10X6_FLT16)
375    SF(110, 110,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_HDR_2D_10X8_FLT16)
376    SF(110, 110,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_HDR_2D_10X10_FLT16)
377    SF(110, 110,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_HDR_2D_12X10_FLT16)
378    SF(110, 110,   x,   x,   x,   x,   x,   x,   x,   x,   x,   x,    x,  ASTC_HDR_2D_12X12_FLT16)
379 };
380 #undef x
381 #undef Y
382 
383 
384 enum isl_format
isl_format_for_pipe_format(enum pipe_format pf)385 isl_format_for_pipe_format(enum pipe_format pf)
386 {
387    static const enum isl_format table[PIPE_FORMAT_COUNT] = {
388       [0 ... PIPE_FORMAT_COUNT-1] = ISL_FORMAT_UNSUPPORTED,
389 
390       [PIPE_FORMAT_B8G8R8A8_UNORM]          = ISL_FORMAT_B8G8R8A8_UNORM,
391       [PIPE_FORMAT_B8G8R8X8_UNORM]          = ISL_FORMAT_B8G8R8X8_UNORM,
392       [PIPE_FORMAT_B5G5R5A1_UNORM]          = ISL_FORMAT_B5G5R5A1_UNORM,
393       [PIPE_FORMAT_B4G4R4A4_UNORM]          = ISL_FORMAT_B4G4R4A4_UNORM,
394       [PIPE_FORMAT_B5G6R5_UNORM]            = ISL_FORMAT_B5G6R5_UNORM,
395       [PIPE_FORMAT_R10G10B10A2_UNORM]       = ISL_FORMAT_R10G10B10A2_UNORM,
396 
397       [PIPE_FORMAT_Z16_UNORM]               = ISL_FORMAT_R16_UNORM,
398       [PIPE_FORMAT_Z32_UNORM]               = ISL_FORMAT_R32_UNORM,
399       [PIPE_FORMAT_Z32_FLOAT]               = ISL_FORMAT_R32_FLOAT,
400 
401       /* We translate the combined depth/stencil formats to depth only here */
402       [PIPE_FORMAT_Z24_UNORM_S8_UINT]       = ISL_FORMAT_R24_UNORM_X8_TYPELESS,
403       [PIPE_FORMAT_Z24X8_UNORM]             = ISL_FORMAT_R24_UNORM_X8_TYPELESS,
404       [PIPE_FORMAT_Z32_FLOAT_S8X24_UINT]    = ISL_FORMAT_R32_FLOAT,
405 
406       [PIPE_FORMAT_S8_UINT]                 = ISL_FORMAT_R8_UINT,
407       [PIPE_FORMAT_X24S8_UINT]              = ISL_FORMAT_R8_UINT,
408       [PIPE_FORMAT_X32_S8X24_UINT]          = ISL_FORMAT_R8_UINT,
409 
410       [PIPE_FORMAT_R64_FLOAT]               = ISL_FORMAT_R64_FLOAT,
411       [PIPE_FORMAT_R64G64_FLOAT]            = ISL_FORMAT_R64G64_FLOAT,
412       [PIPE_FORMAT_R64G64B64_FLOAT]         = ISL_FORMAT_R64G64B64_FLOAT,
413       [PIPE_FORMAT_R64G64B64A64_FLOAT]      = ISL_FORMAT_R64G64B64A64_FLOAT,
414       [PIPE_FORMAT_R32_FLOAT]               = ISL_FORMAT_R32_FLOAT,
415       [PIPE_FORMAT_R32G32_FLOAT]            = ISL_FORMAT_R32G32_FLOAT,
416       [PIPE_FORMAT_R32G32B32_FLOAT]         = ISL_FORMAT_R32G32B32_FLOAT,
417       [PIPE_FORMAT_R32G32B32A32_FLOAT]      = ISL_FORMAT_R32G32B32A32_FLOAT,
418       [PIPE_FORMAT_R32_UNORM]               = ISL_FORMAT_R32_UNORM,
419       [PIPE_FORMAT_R32G32_UNORM]            = ISL_FORMAT_R32G32_UNORM,
420       [PIPE_FORMAT_R32G32B32_UNORM]         = ISL_FORMAT_R32G32B32_UNORM,
421       [PIPE_FORMAT_R32G32B32A32_UNORM]      = ISL_FORMAT_R32G32B32A32_UNORM,
422       [PIPE_FORMAT_R32_USCALED]             = ISL_FORMAT_R32_USCALED,
423       [PIPE_FORMAT_R32G32_USCALED]          = ISL_FORMAT_R32G32_USCALED,
424       [PIPE_FORMAT_R32G32B32_USCALED]       = ISL_FORMAT_R32G32B32_USCALED,
425       [PIPE_FORMAT_R32G32B32A32_USCALED]    = ISL_FORMAT_R32G32B32A32_USCALED,
426       [PIPE_FORMAT_R32_SNORM]               = ISL_FORMAT_R32_SNORM,
427       [PIPE_FORMAT_R32G32_SNORM]            = ISL_FORMAT_R32G32_SNORM,
428       [PIPE_FORMAT_R32G32B32_SNORM]         = ISL_FORMAT_R32G32B32_SNORM,
429       [PIPE_FORMAT_R32G32B32A32_SNORM]      = ISL_FORMAT_R32G32B32A32_SNORM,
430       [PIPE_FORMAT_R32_SSCALED]             = ISL_FORMAT_R32_SSCALED,
431       [PIPE_FORMAT_R32G32_SSCALED]          = ISL_FORMAT_R32G32_SSCALED,
432       [PIPE_FORMAT_R32G32B32_SSCALED]       = ISL_FORMAT_R32G32B32_SSCALED,
433       [PIPE_FORMAT_R32G32B32A32_SSCALED]    = ISL_FORMAT_R32G32B32A32_SSCALED,
434       [PIPE_FORMAT_R16_UNORM]               = ISL_FORMAT_R16_UNORM,
435       [PIPE_FORMAT_R16G16_UNORM]            = ISL_FORMAT_R16G16_UNORM,
436       [PIPE_FORMAT_R16G16B16_UNORM]         = ISL_FORMAT_R16G16B16_UNORM,
437       [PIPE_FORMAT_R16G16B16A16_UNORM]      = ISL_FORMAT_R16G16B16A16_UNORM,
438       [PIPE_FORMAT_R16_USCALED]             = ISL_FORMAT_R16_USCALED,
439       [PIPE_FORMAT_R16G16_USCALED]          = ISL_FORMAT_R16G16_USCALED,
440       [PIPE_FORMAT_R16G16B16_USCALED]       = ISL_FORMAT_R16G16B16_USCALED,
441       [PIPE_FORMAT_R16G16B16A16_USCALED]    = ISL_FORMAT_R16G16B16A16_USCALED,
442       [PIPE_FORMAT_R16_SNORM]               = ISL_FORMAT_R16_SNORM,
443       [PIPE_FORMAT_R16G16_SNORM]            = ISL_FORMAT_R16G16_SNORM,
444       [PIPE_FORMAT_R16G16B16_SNORM]         = ISL_FORMAT_R16G16B16_SNORM,
445       [PIPE_FORMAT_R16G16B16A16_SNORM]      = ISL_FORMAT_R16G16B16A16_SNORM,
446       [PIPE_FORMAT_R16_SSCALED]             = ISL_FORMAT_R16_SSCALED,
447       [PIPE_FORMAT_R16G16_SSCALED]          = ISL_FORMAT_R16G16_SSCALED,
448       [PIPE_FORMAT_R16G16B16_SSCALED]       = ISL_FORMAT_R16G16B16_SSCALED,
449       [PIPE_FORMAT_R16G16B16A16_SSCALED]    = ISL_FORMAT_R16G16B16A16_SSCALED,
450       [PIPE_FORMAT_R8_UNORM]                = ISL_FORMAT_R8_UNORM,
451       [PIPE_FORMAT_R8G8_UNORM]              = ISL_FORMAT_R8G8_UNORM,
452       [PIPE_FORMAT_R8G8B8_UNORM]            = ISL_FORMAT_R8G8B8_UNORM,
453       [PIPE_FORMAT_R8G8B8A8_UNORM]          = ISL_FORMAT_R8G8B8A8_UNORM,
454       [PIPE_FORMAT_R8_USCALED]              = ISL_FORMAT_R8_USCALED,
455       [PIPE_FORMAT_R8G8_USCALED]            = ISL_FORMAT_R8G8_USCALED,
456       [PIPE_FORMAT_R8G8B8_USCALED]          = ISL_FORMAT_R8G8B8_USCALED,
457       [PIPE_FORMAT_R8G8B8A8_USCALED]        = ISL_FORMAT_R8G8B8A8_USCALED,
458       [PIPE_FORMAT_R8_SNORM]                = ISL_FORMAT_R8_SNORM,
459       [PIPE_FORMAT_R8G8_SNORM]              = ISL_FORMAT_R8G8_SNORM,
460       [PIPE_FORMAT_R8G8B8_SNORM]            = ISL_FORMAT_R8G8B8_SNORM,
461       [PIPE_FORMAT_R8G8B8A8_SNORM]          = ISL_FORMAT_R8G8B8A8_SNORM,
462       [PIPE_FORMAT_R8_SSCALED]              = ISL_FORMAT_R8_SSCALED,
463       [PIPE_FORMAT_R8G8_SSCALED]            = ISL_FORMAT_R8G8_SSCALED,
464       [PIPE_FORMAT_R8G8B8_SSCALED]          = ISL_FORMAT_R8G8B8_SSCALED,
465       [PIPE_FORMAT_R8G8B8A8_SSCALED]        = ISL_FORMAT_R8G8B8A8_SSCALED,
466       [PIPE_FORMAT_R32_FIXED]               = ISL_FORMAT_R32_SFIXED,
467       [PIPE_FORMAT_R32G32_FIXED]            = ISL_FORMAT_R32G32_SFIXED,
468       [PIPE_FORMAT_R32G32B32_FIXED]         = ISL_FORMAT_R32G32B32_SFIXED,
469       [PIPE_FORMAT_R32G32B32A32_FIXED]      = ISL_FORMAT_R32G32B32A32_SFIXED,
470       [PIPE_FORMAT_R16_FLOAT]               = ISL_FORMAT_R16_FLOAT,
471       [PIPE_FORMAT_R16G16_FLOAT]            = ISL_FORMAT_R16G16_FLOAT,
472       [PIPE_FORMAT_R16G16B16_FLOAT]         = ISL_FORMAT_R16G16B16_FLOAT,
473       [PIPE_FORMAT_R16G16B16A16_FLOAT]      = ISL_FORMAT_R16G16B16A16_FLOAT,
474 
475       [PIPE_FORMAT_R8G8B8_SRGB]             = ISL_FORMAT_R8G8B8_UNORM_SRGB,
476       [PIPE_FORMAT_B8G8R8A8_SRGB]           = ISL_FORMAT_B8G8R8A8_UNORM_SRGB,
477       [PIPE_FORMAT_B8G8R8X8_SRGB]           = ISL_FORMAT_B8G8R8X8_UNORM_SRGB,
478       [PIPE_FORMAT_R8G8B8A8_SRGB]           = ISL_FORMAT_R8G8B8A8_UNORM_SRGB,
479 
480       [PIPE_FORMAT_DXT1_RGB]                = ISL_FORMAT_BC1_UNORM,
481       [PIPE_FORMAT_DXT1_RGBA]               = ISL_FORMAT_BC1_UNORM,
482       [PIPE_FORMAT_DXT3_RGBA]               = ISL_FORMAT_BC2_UNORM,
483       [PIPE_FORMAT_DXT5_RGBA]               = ISL_FORMAT_BC3_UNORM,
484 
485       [PIPE_FORMAT_DXT1_SRGB]               = ISL_FORMAT_BC1_UNORM_SRGB,
486       [PIPE_FORMAT_DXT1_SRGBA]              = ISL_FORMAT_BC1_UNORM_SRGB,
487       [PIPE_FORMAT_DXT3_SRGBA]              = ISL_FORMAT_BC2_UNORM_SRGB,
488       [PIPE_FORMAT_DXT5_SRGBA]              = ISL_FORMAT_BC3_UNORM_SRGB,
489 
490       [PIPE_FORMAT_RGTC1_UNORM]             = ISL_FORMAT_BC4_UNORM,
491       [PIPE_FORMAT_RGTC1_SNORM]             = ISL_FORMAT_BC4_SNORM,
492       [PIPE_FORMAT_RGTC2_UNORM]             = ISL_FORMAT_BC5_UNORM,
493       [PIPE_FORMAT_RGTC2_SNORM]             = ISL_FORMAT_BC5_SNORM,
494 
495       [PIPE_FORMAT_R10G10B10A2_USCALED]     = ISL_FORMAT_R10G10B10A2_USCALED,
496       [PIPE_FORMAT_R11G11B10_FLOAT]         = ISL_FORMAT_R11G11B10_FLOAT,
497       [PIPE_FORMAT_R9G9B9E5_FLOAT]          = ISL_FORMAT_R9G9B9E5_SHAREDEXP,
498       [PIPE_FORMAT_R1_UNORM]                = ISL_FORMAT_R1_UNORM,
499       [PIPE_FORMAT_R10G10B10X2_USCALED]     = ISL_FORMAT_R10G10B10X2_USCALED,
500       [PIPE_FORMAT_B10G10R10A2_UNORM]       = ISL_FORMAT_B10G10R10A2_UNORM,
501       [PIPE_FORMAT_R8G8B8X8_UNORM]          = ISL_FORMAT_R8G8B8X8_UNORM,
502 
503       /* Just use red formats for these - they're actually renderable,
504        * and faster to sample than the legacy L/I/A/LA formats.
505        */
506       [PIPE_FORMAT_I8_UNORM]                = ISL_FORMAT_R8_UNORM,
507       [PIPE_FORMAT_I8_UINT]                 = ISL_FORMAT_R8_UINT,
508       [PIPE_FORMAT_I8_SINT]                 = ISL_FORMAT_R8_SINT,
509       [PIPE_FORMAT_I8_SNORM]                = ISL_FORMAT_R8_SNORM,
510       [PIPE_FORMAT_I16_UINT]                = ISL_FORMAT_R16_UINT,
511       [PIPE_FORMAT_I16_UNORM]               = ISL_FORMAT_R16_UNORM,
512       [PIPE_FORMAT_I16_SINT]                = ISL_FORMAT_R16_SINT,
513       [PIPE_FORMAT_I16_SNORM]               = ISL_FORMAT_R16_SNORM,
514       [PIPE_FORMAT_I16_FLOAT]               = ISL_FORMAT_R16_FLOAT,
515       [PIPE_FORMAT_I32_UINT]                = ISL_FORMAT_R32_UINT,
516       [PIPE_FORMAT_I32_SINT]                = ISL_FORMAT_R32_SINT,
517       [PIPE_FORMAT_I32_FLOAT]               = ISL_FORMAT_R32_FLOAT,
518 
519       [PIPE_FORMAT_L8_UINT]                 = ISL_FORMAT_R8_UINT,
520       [PIPE_FORMAT_L8_UNORM]                = ISL_FORMAT_R8_UNORM,
521       [PIPE_FORMAT_L8_SINT]                 = ISL_FORMAT_R8_SINT,
522       [PIPE_FORMAT_L8_SNORM]                = ISL_FORMAT_R8_SNORM,
523       [PIPE_FORMAT_L16_UINT]                = ISL_FORMAT_R16_UINT,
524       [PIPE_FORMAT_L16_UNORM]               = ISL_FORMAT_R16_UNORM,
525       [PIPE_FORMAT_L16_SINT]                = ISL_FORMAT_R16_SINT,
526       [PIPE_FORMAT_L16_SNORM]               = ISL_FORMAT_R16_SNORM,
527       [PIPE_FORMAT_L16_FLOAT]               = ISL_FORMAT_R16_FLOAT,
528       [PIPE_FORMAT_L32_UINT]                = ISL_FORMAT_R32_UINT,
529       [PIPE_FORMAT_L32_SINT]                = ISL_FORMAT_R32_SINT,
530       [PIPE_FORMAT_L32_FLOAT]               = ISL_FORMAT_R32_FLOAT,
531 
532       /* We also map alpha and luminance-alpha formats to red as well,
533        * though most of these (other than A8_UNORM) will be non-renderable.
534        */
535       [PIPE_FORMAT_A8_UINT]                 = ISL_FORMAT_R8_UINT,
536       [PIPE_FORMAT_A8_UNORM]                = ISL_FORMAT_R8_UNORM,
537       [PIPE_FORMAT_A8_SINT]                 = ISL_FORMAT_R8_SINT,
538       [PIPE_FORMAT_A8_SNORM]                = ISL_FORMAT_R8_SNORM,
539       [PIPE_FORMAT_A16_UINT]                = ISL_FORMAT_R16_UINT,
540       [PIPE_FORMAT_A16_UNORM]               = ISL_FORMAT_R16_UNORM,
541       [PIPE_FORMAT_A16_SINT]                = ISL_FORMAT_R16_SINT,
542       [PIPE_FORMAT_A16_SNORM]               = ISL_FORMAT_R16_SNORM,
543       [PIPE_FORMAT_A16_FLOAT]               = ISL_FORMAT_R16_FLOAT,
544       [PIPE_FORMAT_A32_UINT]                = ISL_FORMAT_R32_UINT,
545       [PIPE_FORMAT_A32_SINT]                = ISL_FORMAT_R32_SINT,
546       [PIPE_FORMAT_A32_FLOAT]               = ISL_FORMAT_R32_FLOAT,
547 
548       [PIPE_FORMAT_L8A8_UINT]               = ISL_FORMAT_R8G8_UINT,
549       [PIPE_FORMAT_L8A8_UNORM]              = ISL_FORMAT_R8G8_UNORM,
550       [PIPE_FORMAT_L8A8_SINT]               = ISL_FORMAT_R8G8_SINT,
551       [PIPE_FORMAT_L8A8_SNORM]              = ISL_FORMAT_R8G8_SNORM,
552       [PIPE_FORMAT_L16A16_UINT]             = ISL_FORMAT_R16G16_UINT,
553       [PIPE_FORMAT_L16A16_UNORM]            = ISL_FORMAT_R16G16_UNORM,
554       [PIPE_FORMAT_L16A16_SINT]             = ISL_FORMAT_R16G16_SINT,
555       [PIPE_FORMAT_L16A16_SNORM]            = ISL_FORMAT_R16G16_SNORM,
556       [PIPE_FORMAT_L16A16_FLOAT]            = ISL_FORMAT_R16G16_FLOAT,
557       [PIPE_FORMAT_L32A32_UINT]             = ISL_FORMAT_R32G32_UINT,
558       [PIPE_FORMAT_L32A32_SINT]             = ISL_FORMAT_R32G32_SINT,
559       [PIPE_FORMAT_L32A32_FLOAT]            = ISL_FORMAT_R32G32_FLOAT,
560 
561       /* Sadly, we have to use luminance[-alpha] formats for sRGB decoding. */
562       [PIPE_FORMAT_R8_SRGB]                 = ISL_FORMAT_L8_UNORM_SRGB,
563       [PIPE_FORMAT_L8_SRGB]                 = ISL_FORMAT_L8_UNORM_SRGB,
564       [PIPE_FORMAT_L8A8_SRGB]               = ISL_FORMAT_L8A8_UNORM_SRGB,
565 
566       [PIPE_FORMAT_R10G10B10A2_SSCALED]     = ISL_FORMAT_R10G10B10A2_SSCALED,
567       [PIPE_FORMAT_R10G10B10A2_SNORM]       = ISL_FORMAT_R10G10B10A2_SNORM,
568 
569       [PIPE_FORMAT_B10G10R10A2_USCALED]     = ISL_FORMAT_B10G10R10A2_USCALED,
570       [PIPE_FORMAT_B10G10R10A2_SSCALED]     = ISL_FORMAT_B10G10R10A2_SSCALED,
571       [PIPE_FORMAT_B10G10R10A2_SNORM]       = ISL_FORMAT_B10G10R10A2_SNORM,
572 
573       [PIPE_FORMAT_R8_UINT]                 = ISL_FORMAT_R8_UINT,
574       [PIPE_FORMAT_R8G8_UINT]               = ISL_FORMAT_R8G8_UINT,
575       [PIPE_FORMAT_R8G8B8_UINT]             = ISL_FORMAT_R8G8B8_UINT,
576       [PIPE_FORMAT_R8G8B8A8_UINT]           = ISL_FORMAT_R8G8B8A8_UINT,
577 
578       [PIPE_FORMAT_R8_SINT]                 = ISL_FORMAT_R8_SINT,
579       [PIPE_FORMAT_R8G8_SINT]               = ISL_FORMAT_R8G8_SINT,
580       [PIPE_FORMAT_R8G8B8_SINT]             = ISL_FORMAT_R8G8B8_SINT,
581       [PIPE_FORMAT_R8G8B8A8_SINT]           = ISL_FORMAT_R8G8B8A8_SINT,
582 
583       [PIPE_FORMAT_R16_UINT]                = ISL_FORMAT_R16_UINT,
584       [PIPE_FORMAT_R16G16_UINT]             = ISL_FORMAT_R16G16_UINT,
585       [PIPE_FORMAT_R16G16B16_UINT]          = ISL_FORMAT_R16G16B16_UINT,
586       [PIPE_FORMAT_R16G16B16A16_UINT]       = ISL_FORMAT_R16G16B16A16_UINT,
587 
588       [PIPE_FORMAT_R16_SINT]                = ISL_FORMAT_R16_SINT,
589       [PIPE_FORMAT_R16G16_SINT]             = ISL_FORMAT_R16G16_SINT,
590       [PIPE_FORMAT_R16G16B16_SINT]          = ISL_FORMAT_R16G16B16_SINT,
591       [PIPE_FORMAT_R16G16B16A16_SINT]       = ISL_FORMAT_R16G16B16A16_SINT,
592 
593       [PIPE_FORMAT_R32_UINT]                = ISL_FORMAT_R32_UINT,
594       [PIPE_FORMAT_R32G32_UINT]             = ISL_FORMAT_R32G32_UINT,
595       [PIPE_FORMAT_R32G32B32_UINT]          = ISL_FORMAT_R32G32B32_UINT,
596       [PIPE_FORMAT_R32G32B32A32_UINT]       = ISL_FORMAT_R32G32B32A32_UINT,
597 
598       [PIPE_FORMAT_R32_SINT]                = ISL_FORMAT_R32_SINT,
599       [PIPE_FORMAT_R32G32_SINT]             = ISL_FORMAT_R32G32_SINT,
600       [PIPE_FORMAT_R32G32B32_SINT]          = ISL_FORMAT_R32G32B32_SINT,
601       [PIPE_FORMAT_R32G32B32A32_SINT]       = ISL_FORMAT_R32G32B32A32_SINT,
602 
603       [PIPE_FORMAT_B10G10R10A2_UINT]        = ISL_FORMAT_B10G10R10A2_UINT,
604 
605       [PIPE_FORMAT_ETC1_RGB8]               = ISL_FORMAT_ETC1_RGB8,
606 
607       /* The formats say YCrCb, but there's no colorspace conversion. */
608       [PIPE_FORMAT_R8G8_R8B8_UNORM]         = ISL_FORMAT_YCRCB_NORMAL,
609       [PIPE_FORMAT_G8R8_B8R8_UNORM]         = ISL_FORMAT_YCRCB_SWAPY,
610 
611       /* We map these formats to help configure media compression. */
612       [PIPE_FORMAT_YUYV]                    = ISL_FORMAT_YCRCB_NORMAL,
613       [PIPE_FORMAT_UYVY]                    = ISL_FORMAT_YCRCB_SWAPY,
614       [PIPE_FORMAT_NV12]                    = ISL_FORMAT_PLANAR_420_8,
615       [PIPE_FORMAT_P010]                    = ISL_FORMAT_PLANAR_420_10,
616       [PIPE_FORMAT_P012]                    = ISL_FORMAT_PLANAR_420_12,
617       [PIPE_FORMAT_P016]                    = ISL_FORMAT_PLANAR_420_16,
618 
619       [PIPE_FORMAT_R8G8B8X8_SRGB]           = ISL_FORMAT_R8G8B8X8_UNORM_SRGB,
620       [PIPE_FORMAT_B10G10R10X2_UNORM]       = ISL_FORMAT_B10G10R10X2_UNORM,
621       [PIPE_FORMAT_R16G16B16X16_UNORM]      = ISL_FORMAT_R16G16B16X16_UNORM,
622       [PIPE_FORMAT_R16G16B16X16_FLOAT]      = ISL_FORMAT_R16G16B16X16_FLOAT,
623       [PIPE_FORMAT_R32G32B32X32_FLOAT]      = ISL_FORMAT_R32G32B32X32_FLOAT,
624 
625       [PIPE_FORMAT_R10G10B10A2_UINT]        = ISL_FORMAT_R10G10B10A2_UINT,
626 
627       [PIPE_FORMAT_B5G6R5_SRGB]             = ISL_FORMAT_B5G6R5_UNORM_SRGB,
628 
629       [PIPE_FORMAT_BPTC_RGBA_UNORM]         = ISL_FORMAT_BC7_UNORM,
630       [PIPE_FORMAT_BPTC_SRGBA]              = ISL_FORMAT_BC7_UNORM_SRGB,
631       [PIPE_FORMAT_BPTC_RGB_FLOAT]          = ISL_FORMAT_BC6H_SF16,
632       [PIPE_FORMAT_BPTC_RGB_UFLOAT]         = ISL_FORMAT_BC6H_UF16,
633 
634       [PIPE_FORMAT_ETC2_RGB8]               = ISL_FORMAT_ETC2_RGB8,
635       [PIPE_FORMAT_ETC2_SRGB8]              = ISL_FORMAT_ETC2_SRGB8,
636       [PIPE_FORMAT_ETC2_RGB8A1]             = ISL_FORMAT_ETC2_RGB8_PTA,
637       [PIPE_FORMAT_ETC2_SRGB8A1]            = ISL_FORMAT_ETC2_SRGB8_PTA,
638       [PIPE_FORMAT_ETC2_RGBA8]              = ISL_FORMAT_ETC2_EAC_RGBA8,
639       [PIPE_FORMAT_ETC2_SRGBA8]             = ISL_FORMAT_ETC2_EAC_SRGB8_A8,
640       [PIPE_FORMAT_ETC2_R11_UNORM]          = ISL_FORMAT_EAC_R11,
641       [PIPE_FORMAT_ETC2_R11_SNORM]          = ISL_FORMAT_EAC_SIGNED_R11,
642       [PIPE_FORMAT_ETC2_RG11_UNORM]         = ISL_FORMAT_EAC_RG11,
643       [PIPE_FORMAT_ETC2_RG11_SNORM]         = ISL_FORMAT_EAC_SIGNED_RG11,
644 
645       [PIPE_FORMAT_FXT1_RGB]                = ISL_FORMAT_FXT1,
646       [PIPE_FORMAT_FXT1_RGBA]               = ISL_FORMAT_FXT1,
647 
648       [PIPE_FORMAT_ASTC_4x4]                = ISL_FORMAT_ASTC_LDR_2D_4X4_FLT16,
649       [PIPE_FORMAT_ASTC_5x4]                = ISL_FORMAT_ASTC_LDR_2D_5X4_FLT16,
650       [PIPE_FORMAT_ASTC_5x5]                = ISL_FORMAT_ASTC_LDR_2D_5X5_FLT16,
651       [PIPE_FORMAT_ASTC_6x5]                = ISL_FORMAT_ASTC_LDR_2D_6X5_FLT16,
652       [PIPE_FORMAT_ASTC_6x6]                = ISL_FORMAT_ASTC_LDR_2D_6X6_FLT16,
653       [PIPE_FORMAT_ASTC_8x5]                = ISL_FORMAT_ASTC_LDR_2D_8X5_FLT16,
654       [PIPE_FORMAT_ASTC_8x6]                = ISL_FORMAT_ASTC_LDR_2D_8X6_FLT16,
655       [PIPE_FORMAT_ASTC_8x8]                = ISL_FORMAT_ASTC_LDR_2D_8X8_FLT16,
656       [PIPE_FORMAT_ASTC_10x5]               = ISL_FORMAT_ASTC_LDR_2D_10X5_FLT16,
657       [PIPE_FORMAT_ASTC_10x6]               = ISL_FORMAT_ASTC_LDR_2D_10X6_FLT16,
658       [PIPE_FORMAT_ASTC_10x8]               = ISL_FORMAT_ASTC_LDR_2D_10X8_FLT16,
659       [PIPE_FORMAT_ASTC_10x10]              = ISL_FORMAT_ASTC_LDR_2D_10X10_FLT16,
660       [PIPE_FORMAT_ASTC_12x10]              = ISL_FORMAT_ASTC_LDR_2D_12X10_FLT16,
661       [PIPE_FORMAT_ASTC_12x12]              = ISL_FORMAT_ASTC_LDR_2D_12X12_FLT16,
662 
663       [PIPE_FORMAT_ASTC_4x4_SRGB]           = ISL_FORMAT_ASTC_LDR_2D_4X4_U8SRGB,
664       [PIPE_FORMAT_ASTC_5x4_SRGB]           = ISL_FORMAT_ASTC_LDR_2D_5X4_U8SRGB,
665       [PIPE_FORMAT_ASTC_5x5_SRGB]           = ISL_FORMAT_ASTC_LDR_2D_5X5_U8SRGB,
666       [PIPE_FORMAT_ASTC_6x5_SRGB]           = ISL_FORMAT_ASTC_LDR_2D_6X5_U8SRGB,
667       [PIPE_FORMAT_ASTC_6x6_SRGB]           = ISL_FORMAT_ASTC_LDR_2D_6X6_U8SRGB,
668       [PIPE_FORMAT_ASTC_8x5_SRGB]           = ISL_FORMAT_ASTC_LDR_2D_8X5_U8SRGB,
669       [PIPE_FORMAT_ASTC_8x6_SRGB]           = ISL_FORMAT_ASTC_LDR_2D_8X6_U8SRGB,
670       [PIPE_FORMAT_ASTC_8x8_SRGB]           = ISL_FORMAT_ASTC_LDR_2D_8X8_U8SRGB,
671       [PIPE_FORMAT_ASTC_10x5_SRGB]          = ISL_FORMAT_ASTC_LDR_2D_10X5_U8SRGB,
672       [PIPE_FORMAT_ASTC_10x6_SRGB]          = ISL_FORMAT_ASTC_LDR_2D_10X6_U8SRGB,
673       [PIPE_FORMAT_ASTC_10x8_SRGB]          = ISL_FORMAT_ASTC_LDR_2D_10X8_U8SRGB,
674       [PIPE_FORMAT_ASTC_10x10_SRGB]         = ISL_FORMAT_ASTC_LDR_2D_10X10_U8SRGB,
675       [PIPE_FORMAT_ASTC_12x10_SRGB]         = ISL_FORMAT_ASTC_LDR_2D_12X10_U8SRGB,
676       [PIPE_FORMAT_ASTC_12x12_SRGB]         = ISL_FORMAT_ASTC_LDR_2D_12X12_U8SRGB,
677 
678       [PIPE_FORMAT_A1B5G5R5_UNORM]          = ISL_FORMAT_A1B5G5R5_UNORM,
679 
680       /* We support these so that we know the API expects no alpha channel.
681        * Otherwise, the state tracker would just give us a format with alpha
682        * and we wouldn't know to override the swizzle to 1.
683        */
684       [PIPE_FORMAT_R16G16B16X16_UINT]       = ISL_FORMAT_R16G16B16A16_UINT,
685       [PIPE_FORMAT_R16G16B16X16_SINT]       = ISL_FORMAT_R16G16B16A16_SINT,
686       [PIPE_FORMAT_R32G32B32X32_UINT]       = ISL_FORMAT_R32G32B32A32_UINT,
687       [PIPE_FORMAT_R32G32B32X32_SINT]       = ISL_FORMAT_R32G32B32A32_SINT,
688       [PIPE_FORMAT_R10G10B10X2_SNORM]       = ISL_FORMAT_R10G10B10A2_SNORM,
689    };
690    assert(pf < PIPE_FORMAT_COUNT);
691    return table[pf];
692 }
693 
694 static bool
format_info_exists(enum isl_format format)695 format_info_exists(enum isl_format format)
696 {
697    assert(format != ISL_FORMAT_UNSUPPORTED);
698    assert(format < ISL_NUM_FORMATS);
699    return format < ARRAY_SIZE(format_info) && format_info[format].exists;
700 }
701 
702 bool
isl_format_supports_rendering(const struct intel_device_info * devinfo,enum isl_format format)703 isl_format_supports_rendering(const struct intel_device_info *devinfo,
704                               enum isl_format format)
705 {
706    if (!format_info_exists(format))
707       return false;
708 
709    /* If this fails, then we need to update struct surface_format_info */
710    assert(devinfo->verx10 <
711           (1ul << (8 * sizeof(format_info[format].render_target))));
712    return devinfo->verx10 >= format_info[format].render_target;
713 }
714 
715 bool
isl_format_supports_alpha_blending(const struct intel_device_info * devinfo,enum isl_format format)716 isl_format_supports_alpha_blending(const struct intel_device_info *devinfo,
717                                    enum isl_format format)
718 {
719    if (!format_info_exists(format))
720       return false;
721 
722    return devinfo->verx10 >= format_info[format].alpha_blend;
723 }
724 
725 bool
isl_format_supports_sampling(const struct intel_device_info * devinfo,enum isl_format format)726 isl_format_supports_sampling(const struct intel_device_info *devinfo,
727                              enum isl_format format)
728 {
729    if (!format_info_exists(format))
730       return false;
731 
732    if (devinfo->platform == INTEL_PLATFORM_BYT) {
733       const struct isl_format_layout *fmtl = isl_format_get_layout(format);
734       /* Support for ETC1 and ETC2 exists on Bay Trail even though big-core
735        * GPUs didn't get it until Broadwell.
736        */
737       if (fmtl->txc == ISL_TXC_ETC1 || fmtl->txc == ISL_TXC_ETC2)
738          return true;
739    } else if (devinfo->platform == INTEL_PLATFORM_CHV) {
740       /* Support for ASTC LDR theoretically exists on Cherry View even though
741        * big-core GPUs didn't get it until Skylake.  However, it's fairly
742        * badly broken and requires some nasty workarounds which no Mesa driver
743        * has ever implemented.
744        */
745    } else if (intel_device_info_is_9lp(devinfo)) {
746       const struct isl_format_layout *fmtl = isl_format_get_layout(format);
747       /* Support for ASTC HDR exists on Broxton even though big-core
748        * GPUs didn't get it until Cannonlake.
749        */
750       if (fmtl->txc == ISL_TXC_ASTC)
751          return true;
752    } else if (devinfo->verx10 >= 125) {
753       const struct isl_format_layout *fmtl = isl_format_get_layout(format);
754       /* ASTC & FXT1 support was removed from the hardware on Gfx12.5.
755        * Annoyingly, our format_info table doesn't have a concept of things
756        * being removed so we handle it as yet another special case.
757        *
758        * See HSD 1408144932 (ASTC), 1407633611 (FXT1)
759        *
760        */
761       if (fmtl->txc == ISL_TXC_ASTC || fmtl->txc == ISL_TXC_FXT1)
762          return false;
763    }
764 
765    return devinfo->verx10 >= format_info[format].sampling;
766 }
767 
768 bool
isl_format_supports_filtering(const struct intel_device_info * devinfo,enum isl_format format)769 isl_format_supports_filtering(const struct intel_device_info *devinfo,
770                               enum isl_format format)
771 {
772    if (!format_info_exists(format))
773       return false;
774 
775    if (isl_format_is_compressed(format)) {
776       assert(format_info[format].filtering == format_info[format].sampling);
777       return isl_format_supports_sampling(devinfo, format);
778    }
779 
780    return devinfo->verx10 >= format_info[format].filtering;
781 }
782 
783 bool
isl_format_supports_vertex_fetch(const struct intel_device_info * devinfo,enum isl_format format)784 isl_format_supports_vertex_fetch(const struct intel_device_info *devinfo,
785                                  enum isl_format format)
786 {
787    if (!format_info_exists(format))
788       return false;
789 
790    /* For vertex fetch, Bay Trail supports the same set of formats as Haswell
791     * but is a superset of Ivy Bridge.
792     */
793    if (devinfo->platform == INTEL_PLATFORM_BYT)
794       return 75 >= format_info[format].input_vb;
795 
796    return devinfo->verx10 >= format_info[format].input_vb;
797 }
798 
799 /**
800  * Returns true if the given format can support typed writes.
801  */
802 bool
isl_format_supports_typed_writes(const struct intel_device_info * devinfo,enum isl_format format)803 isl_format_supports_typed_writes(const struct intel_device_info *devinfo,
804                                  enum isl_format format)
805 {
806    if (!format_info_exists(format))
807       return false;
808 
809    return devinfo->verx10 >= format_info[format].typed_write;
810 }
811 
812 /**
813  * Returns true if the given format can support typed atomics.
814  */
815 bool
isl_format_supports_typed_atomics(const struct intel_device_info * devinfo,enum isl_format format)816 isl_format_supports_typed_atomics(const struct intel_device_info *devinfo,
817                                   enum isl_format format)
818 {
819    if (!format_info_exists(format))
820       return false;
821 
822    return devinfo->verx10 >= format_info[format].typed_atomics;
823 }
824 
825 /**
826  * Returns true if the given format can support typed reads with format
827  * conversion fully handled by hardware.  On Sky Lake, all formats which are
828  * supported for typed writes also support typed reads but some of them return
829  * the raw image data and don't provide format conversion.
830  *
831  * For anyone looking to find this data in the PRM, the easiest way to find
832  * format tables is to search for R11G11B10.  There are only a few
833  * occurrences.
834  */
835 bool
isl_format_supports_typed_reads(const struct intel_device_info * devinfo,enum isl_format format)836 isl_format_supports_typed_reads(const struct intel_device_info *devinfo,
837                                 enum isl_format format)
838 {
839    if (!format_info_exists(format))
840       return false;
841 
842    return devinfo->verx10 >= format_info[format].typed_read;
843 }
844 
845 /**
846  * Returns true if the given format can support single-sample fast clears.
847  * This function only checks the format.  In order to determine if a surface
848  * supports CCS_E, several other factors need to be considered such as tiling
849  * and sample count.  See isl_surf_get_ccs_surf for details.
850  */
851 bool
isl_format_supports_ccs_d(const struct intel_device_info * devinfo,enum isl_format format)852 isl_format_supports_ccs_d(const struct intel_device_info *devinfo,
853                           enum isl_format format)
854 {
855    /* Clear-only compression was first added on Ivy Bridge and was last
856     * implemented on Ice lake (see BSpec: 43862).
857     */
858    if (devinfo->ver < 7 || devinfo->ver > 11)
859       return false;
860 
861    if (!isl_format_supports_rendering(devinfo, format))
862       return false;
863 
864    const struct isl_format_layout *fmtl = isl_format_get_layout(format);
865 
866    /* From the Ivy Bridge PRM, Vol2 Part1 11.7 "MCS Buffer for Render
867     * Target(s)", beneath the "Fast Color Clear" bullet (p326):
868     *
869     *     - MCS buffer for non-MSRT is supported only for RT formats 32bpp,
870     *       64bpp, and 128bpp.
871     */
872    return fmtl->bpb == 32 || fmtl->bpb == 64 || fmtl->bpb == 128;
873 }
874 
875 /**
876  * Returns true if the given format can support single-sample color
877  * compression.  This function only checks the format.  In order to determine
878  * if a surface supports CCS_E, several other factors need to be considered
879  * such as tiling and sample count.  See isl_surf_get_ccs_surf for details.
880  */
881 bool
isl_format_supports_ccs_e(const struct intel_device_info * devinfo,enum isl_format format)882 isl_format_supports_ccs_e(const struct intel_device_info *devinfo,
883                           enum isl_format format)
884 {
885    if (!format_info_exists(format))
886       return false;
887 
888    /* On Xe2+ platforms, it doesn't matter that if a format can be
889     * compressed or not. Formats are given CMF encodings as a hint
890     * to hardware to reach the best compression ratio. When the CMF
891     * value is not the one for a format in the spec or a format's CMF
892     * encoding is unknown, the compressed ratio can be less optimistic,
893     * but no corruption should happen per hardware design.
894     */
895    if (devinfo->ver >= 20)
896       return true;
897 
898    /* For simplicity, only report that a format supports CCS_E if blorp can
899     * perform bit-for-bit copies with an image of that format while compressed.
900     * Unfortunately, R11G11B10_FLOAT is in a compression class of its own, and
901     * on ICL, there is no way to copy to/from it which doesn't potentially
902     * loose data if one of the bit patterns being copied isn't valid finite
903     * floats.
904     */
905    if (devinfo->ver == 11 && format == ISL_FORMAT_R11G11B10_FLOAT)
906       return false;
907 
908    return devinfo->verx10 >= format_info[format].ccs_e;
909 }
910 
911 bool
isl_format_supports_multisampling(const struct intel_device_info * devinfo,enum isl_format format)912 isl_format_supports_multisampling(const struct intel_device_info *devinfo,
913                                   enum isl_format format)
914 {
915    /* From the Sandybridge PRM, Volume 4 Part 1 p72, SURFACE_STATE, Surface
916     * Format:
917     *
918     *    If Number of Multisamples is set to a value other than
919     *    MULTISAMPLECOUNT_1, this field cannot be set to the following
920     *    formats:
921     *
922     *       - any format with greater than 64 bits per element
923     *       - any compressed texture format (BC*)
924     *       - any YCRCB* format
925     *
926     * The restriction on the format's size is removed on Broadwell. Moreover,
927     * empirically it looks that even IvyBridge can handle multisampled surfaces
928     * with format sizes all the way to 128-bits (RGBA32F, RGBA32I, RGBA32UI).
929     *
930     * Also, there is an exception for HiZ which we treat as a compressed
931     * format and is allowed to be multisampled on Broadwell and earlier.
932     */
933    if (format == ISL_FORMAT_HIZ) {
934       /* On SKL+, HiZ is always single-sampled even when the primary surface
935        * is multisampled.  See also isl_surf_get_hiz_surf().
936        */
937       return devinfo->ver <= 8;
938    } else if (devinfo->ver == 7 && isl_format_has_sint_channel(format)) {
939       /* From the Ivy Bridge PRM, Vol4 Part1 p73 ("Number of Multisamples"):
940        *
941        *   This field must be set to MULTISAMPLECOUNT_1 for SINT MSRTs when
942        *   all RT channels are not written
943        *
944        * From the Ivy Bridge PRM, Vol4 Part1 p77 ("MCS Enable"):
945        *
946        *   This field must be set to 0 for all SINT MSRTs when all RT channels
947        *   are not written
948        *
949        * Disable multisampling support now as we don't handle the case when
950        * one of the render target channels is disabled.
951        */
952       return false;
953    } else if (devinfo->ver < 7 && isl_format_get_layout(format)->bpb > 64) {
954       return false;
955    } else if (isl_format_is_compressed(format)) {
956       return false;
957    } else if (isl_format_is_yuv(format)) {
958       return false;
959    } else {
960       return true;
961    }
962 }
963 
964 /**
965  * Returns true if the two formats are component size compatible meaning that
966  * each component from one format has the same number of bits as the other
967  * format.
968  *
969  * This is useful to check whether an image used with 2 different formats can
970  * be fast cleared with a non 0 clear color.
971  */
972 bool
isl_formats_have_same_bits_per_channel(enum isl_format format1,enum isl_format format2)973 isl_formats_have_same_bits_per_channel(enum isl_format format1,
974                                        enum isl_format format2)
975 {
976    const struct isl_format_layout *fmtl1 = isl_format_get_layout(format1);
977    const struct isl_format_layout *fmtl2 = isl_format_get_layout(format2);
978 
979    return fmtl1->channels.r.bits == fmtl2->channels.r.bits &&
980           fmtl1->channels.g.bits == fmtl2->channels.g.bits &&
981           fmtl1->channels.b.bits == fmtl2->channels.b.bits &&
982           fmtl1->channels.a.bits == fmtl2->channels.a.bits &&
983           fmtl1->channels.l.bits == fmtl2->channels.l.bits &&
984           fmtl1->channels.i.bits == fmtl2->channels.i.bits &&
985           fmtl1->channels.p.bits == fmtl2->channels.p.bits;
986 }
987 
988 /**
989  * Returns true if the two formats are "CCS_E compatible" meaning that you can
990  * render in one format with CCS_E enabled and then texture using the other
991  * format without needing a resolve.
992  *
993  * Note: Even if the formats are compatible, special care must be taken if a
994  * clear color is involved because the encoding of the clear color is heavily
995  * format-dependent.
996  */
997 bool
isl_formats_are_ccs_e_compatible(const struct intel_device_info * devinfo,enum isl_format format1,enum isl_format format2)998 isl_formats_are_ccs_e_compatible(const struct intel_device_info *devinfo,
999                                  enum isl_format format1,
1000                                  enum isl_format format2)
1001 {
1002    /* They must support CCS_E */
1003    if (!isl_format_supports_ccs_e(devinfo, format1) ||
1004        !isl_format_supports_ccs_e(devinfo, format2))
1005       return false;
1006 
1007    /* On TGL+, drivers may specify a compression format independently from the
1008     * surface format. So, even if the surface format changes, hardware is
1009     * still able to determine how to access the CCS.
1010     */
1011    if (devinfo->ver >= 12)
1012       return true;
1013 
1014    /* The compression used by CCS is not dependent on the actual data encoding
1015     * of the format but only depends on the bit-layout of the channels.
1016     */
1017    return isl_formats_have_same_bits_per_channel(format1, format2);
1018 }
1019 
1020 static bool
isl_format_has_channel_type(enum isl_format fmt,enum isl_base_type type)1021 isl_format_has_channel_type(enum isl_format fmt, enum isl_base_type type)
1022 {
1023    const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
1024 
1025    return fmtl->channels.r.type == type ||
1026           fmtl->channels.g.type == type ||
1027           fmtl->channels.b.type == type ||
1028           fmtl->channels.a.type == type ||
1029           fmtl->channels.l.type == type ||
1030           fmtl->channels.i.type == type ||
1031           fmtl->channels.p.type == type;
1032 }
1033 
1034 bool
isl_format_has_unorm_channel(enum isl_format fmt)1035 isl_format_has_unorm_channel(enum isl_format fmt)
1036 {
1037    return isl_format_has_channel_type(fmt, ISL_UNORM);
1038 }
1039 
1040 bool
isl_format_has_snorm_channel(enum isl_format fmt)1041 isl_format_has_snorm_channel(enum isl_format fmt)
1042 {
1043    return isl_format_has_channel_type(fmt, ISL_SNORM);
1044 }
1045 
1046 bool
isl_format_has_ufloat_channel(enum isl_format fmt)1047 isl_format_has_ufloat_channel(enum isl_format fmt)
1048 {
1049    return isl_format_has_channel_type(fmt, ISL_UFLOAT);
1050 }
1051 
1052 bool
isl_format_has_sfloat_channel(enum isl_format fmt)1053 isl_format_has_sfloat_channel(enum isl_format fmt)
1054 {
1055    return isl_format_has_channel_type(fmt, ISL_SFLOAT);
1056 }
1057 
1058 bool
isl_format_has_uint_channel(enum isl_format fmt)1059 isl_format_has_uint_channel(enum isl_format fmt)
1060 {
1061    return isl_format_has_channel_type(fmt, ISL_UINT);
1062 }
1063 
1064 bool
isl_format_has_sint_channel(enum isl_format fmt)1065 isl_format_has_sint_channel(enum isl_format fmt)
1066 {
1067    return isl_format_has_channel_type(fmt, ISL_SINT);
1068 }
1069 
1070 bool
isl_format_has_color_component(enum isl_format fmt,int component)1071 isl_format_has_color_component(enum isl_format fmt, int component)
1072 {
1073    const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
1074    const uint8_t intensity = fmtl->channels.i.bits;
1075    const uint8_t luminance = fmtl->channels.l.bits;
1076 
1077    switch (component) {
1078    case 0:
1079       return (fmtl->channels.r.bits + intensity + luminance) > 0;
1080    case 1:
1081       return (fmtl->channels.g.bits + intensity + luminance) > 0;
1082    case 2:
1083       return (fmtl->channels.b.bits + intensity + luminance) > 0;
1084    case 3:
1085       return (fmtl->channels.a.bits + intensity) > 0;
1086    default:
1087       assert(!"Invalid color component: must be 0..3");
1088       return false;
1089    }
1090 }
1091 
1092 unsigned
isl_format_get_num_channels(enum isl_format fmt)1093 isl_format_get_num_channels(enum isl_format fmt)
1094 {
1095    const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
1096 
1097    assert(fmtl->channels.p.bits == 0);
1098 
1099    return (fmtl->channels.r.bits > 0) +
1100           (fmtl->channels.g.bits > 0) +
1101           (fmtl->channels.b.bits > 0) +
1102           (fmtl->channels.a.bits > 0) +
1103           (fmtl->channels.l.bits > 0) +
1104           (fmtl->channels.i.bits > 0);
1105 }
1106 
1107 uint32_t
isl_format_get_depth_format(enum isl_format fmt,bool has_stencil)1108 isl_format_get_depth_format(enum isl_format fmt, bool has_stencil)
1109 {
1110    switch (fmt) {
1111    default:
1112       unreachable("bad isl depth format");
1113    case ISL_FORMAT_R32_FLOAT_X8X24_TYPELESS:
1114       assert(has_stencil);
1115       return 0; /* D32_FLOAT_S8X24_UINT */
1116    case ISL_FORMAT_R32_FLOAT:
1117       assert(!has_stencil);
1118       return 1; /* D32_FLOAT */
1119    case ISL_FORMAT_R24_UNORM_X8_TYPELESS:
1120       if (has_stencil) {
1121          return 2; /* D24_UNORM_S8_UINT */
1122       } else {
1123          return 3; /* D24_UNORM_X8_UINT */
1124       }
1125    case ISL_FORMAT_R16_UNORM:
1126       assert(!has_stencil);
1127       return 5; /* D16_UNORM */
1128    }
1129 }
1130 
1131 enum isl_format
isl_format_rgb_to_rgba(enum isl_format rgb)1132 isl_format_rgb_to_rgba(enum isl_format rgb)
1133 {
1134    assert(isl_format_is_rgb(rgb));
1135 
1136    switch (rgb) {
1137    case ISL_FORMAT_R32G32B32_FLOAT:    return ISL_FORMAT_R32G32B32A32_FLOAT;
1138    case ISL_FORMAT_R32G32B32_SINT:     return ISL_FORMAT_R32G32B32A32_SINT;
1139    case ISL_FORMAT_R32G32B32_UINT:     return ISL_FORMAT_R32G32B32A32_UINT;
1140    case ISL_FORMAT_R32G32B32_UNORM:    return ISL_FORMAT_R32G32B32A32_UNORM;
1141    case ISL_FORMAT_R32G32B32_SNORM:    return ISL_FORMAT_R32G32B32A32_SNORM;
1142    case ISL_FORMAT_R32G32B32_SSCALED:  return ISL_FORMAT_R32G32B32A32_SSCALED;
1143    case ISL_FORMAT_R32G32B32_USCALED:  return ISL_FORMAT_R32G32B32A32_USCALED;
1144    case ISL_FORMAT_R32G32B32_SFIXED:   return ISL_FORMAT_R32G32B32A32_SFIXED;
1145    case ISL_FORMAT_R8G8B8_UNORM:       return ISL_FORMAT_R8G8B8A8_UNORM;
1146    case ISL_FORMAT_R8G8B8_SNORM:       return ISL_FORMAT_R8G8B8A8_SNORM;
1147    case ISL_FORMAT_R8G8B8_SSCALED:     return ISL_FORMAT_R8G8B8A8_SSCALED;
1148    case ISL_FORMAT_R8G8B8_USCALED:     return ISL_FORMAT_R8G8B8A8_USCALED;
1149    case ISL_FORMAT_R16G16B16_FLOAT:    return ISL_FORMAT_R16G16B16A16_FLOAT;
1150    case ISL_FORMAT_R16G16B16_UNORM:    return ISL_FORMAT_R16G16B16A16_UNORM;
1151    case ISL_FORMAT_R16G16B16_SNORM:    return ISL_FORMAT_R16G16B16A16_SNORM;
1152    case ISL_FORMAT_R16G16B16_SSCALED:  return ISL_FORMAT_R16G16B16A16_SSCALED;
1153    case ISL_FORMAT_R16G16B16_USCALED:  return ISL_FORMAT_R16G16B16A16_USCALED;
1154    case ISL_FORMAT_R8G8B8_UNORM_SRGB:  return ISL_FORMAT_R8G8B8A8_UNORM_SRGB;
1155    case ISL_FORMAT_R16G16B16_UINT:     return ISL_FORMAT_R16G16B16A16_UINT;
1156    case ISL_FORMAT_R16G16B16_SINT:     return ISL_FORMAT_R16G16B16A16_SINT;
1157    case ISL_FORMAT_R8G8B8_UINT:        return ISL_FORMAT_R8G8B8A8_UINT;
1158    case ISL_FORMAT_R8G8B8_SINT:        return ISL_FORMAT_R8G8B8A8_SINT;
1159    default:
1160       return ISL_FORMAT_UNSUPPORTED;
1161    }
1162 }
1163 
1164 enum isl_format
isl_format_rgb_to_rgbx(enum isl_format rgb)1165 isl_format_rgb_to_rgbx(enum isl_format rgb)
1166 {
1167    assert(isl_format_is_rgb(rgb));
1168 
1169    switch (rgb) {
1170    case ISL_FORMAT_R32G32B32_FLOAT:
1171       return ISL_FORMAT_R32G32B32X32_FLOAT;
1172    case ISL_FORMAT_R16G16B16_UNORM:
1173       return ISL_FORMAT_R16G16B16X16_UNORM;
1174    case ISL_FORMAT_R16G16B16_FLOAT:
1175       return ISL_FORMAT_R16G16B16X16_FLOAT;
1176    case ISL_FORMAT_R8G8B8_UNORM:
1177       return ISL_FORMAT_R8G8B8X8_UNORM;
1178    case ISL_FORMAT_R8G8B8_UNORM_SRGB:
1179       return ISL_FORMAT_R8G8B8X8_UNORM_SRGB;
1180    default:
1181       return ISL_FORMAT_UNSUPPORTED;
1182    }
1183 }
1184 
1185 enum isl_format
isl_format_rgbx_to_rgba(enum isl_format rgbx)1186 isl_format_rgbx_to_rgba(enum isl_format rgbx)
1187 {
1188    assert(isl_format_is_rgbx(rgbx));
1189 
1190    switch (rgbx) {
1191    case ISL_FORMAT_R32G32B32X32_FLOAT:
1192       return ISL_FORMAT_R32G32B32A32_FLOAT;
1193    case ISL_FORMAT_R16G16B16X16_UNORM:
1194       return ISL_FORMAT_R16G16B16A16_UNORM;
1195    case ISL_FORMAT_R16G16B16X16_FLOAT:
1196       return ISL_FORMAT_R16G16B16A16_FLOAT;
1197    case ISL_FORMAT_B8G8R8X8_UNORM:
1198       return ISL_FORMAT_B8G8R8A8_UNORM;
1199    case ISL_FORMAT_B8G8R8X8_UNORM_SRGB:
1200       return ISL_FORMAT_B8G8R8A8_UNORM_SRGB;
1201    case ISL_FORMAT_R8G8B8X8_UNORM:
1202       return ISL_FORMAT_R8G8B8A8_UNORM;
1203    case ISL_FORMAT_R8G8B8X8_UNORM_SRGB:
1204       return ISL_FORMAT_R8G8B8A8_UNORM_SRGB;
1205    case ISL_FORMAT_B10G10R10X2_UNORM:
1206       return ISL_FORMAT_B10G10R10A2_UNORM;
1207    case ISL_FORMAT_B5G5R5X1_UNORM:
1208       return ISL_FORMAT_B5G5R5A1_UNORM;
1209    case ISL_FORMAT_B5G5R5X1_UNORM_SRGB:
1210       return ISL_FORMAT_B5G5R5A1_UNORM_SRGB;
1211    default:
1212       assert(!"Invalid RGBX format");
1213       return rgbx;
1214    }
1215 }
1216 
1217 /*
1218  * Xe2 allows route of LD messages from Sampler to LSC to improve performance
1219  * when some restrictions are met, here checking the format restrictions.
1220  *
1221  * RENDER_SURFACE_STATE::Enable Sampler Route to LSC:
1222  *   "The Surface Format is one of the following:
1223  *
1224  *     R8_UNORM, R8G8_UNORM, R16_UNORM, R16G16_UNORM, R16G16B16A16_UNORM
1225  *     R16_FLOAT, R16G16_FLOAT, R16G16B16A16_FLOAT
1226  *     R32_FLOAT, R32G32_FLOAT, R32G32B32A32_FLOAT, R32_UINT, R32G32_UINT, R32G32B32A32_UINT
1227  *     R10G10B10A2_UNORM, R11G11B10_FLOAT
1228  *   "
1229  */
1230 bool
isl_format_support_sampler_route_to_lsc(enum isl_format fmt)1231 isl_format_support_sampler_route_to_lsc(enum isl_format fmt)
1232 {
1233    switch (fmt) {
1234    case ISL_FORMAT_R8_UNORM:
1235    case ISL_FORMAT_R8G8_UNORM:
1236    case ISL_FORMAT_R16_UNORM:
1237    case ISL_FORMAT_R16G16_UNORM:
1238    case ISL_FORMAT_R16G16B16A16_UNORM:
1239    case ISL_FORMAT_R16_FLOAT:
1240    case ISL_FORMAT_R16G16_FLOAT:
1241    case ISL_FORMAT_R16G16B16A16_FLOAT:
1242    case ISL_FORMAT_R32_FLOAT:
1243    case ISL_FORMAT_R32G32_FLOAT:
1244    case ISL_FORMAT_R32G32B32A32_FLOAT:
1245    case ISL_FORMAT_R32_UINT:
1246    case ISL_FORMAT_R32G32_UINT:
1247    case ISL_FORMAT_R32G32B32A32_UINT:
1248    case ISL_FORMAT_R10G10B10A2_UNORM:
1249    case ISL_FORMAT_R11G11B10_FLOAT:
1250       return true;
1251    default:
1252       return false;
1253    }
1254 }
1255 
1256 static inline void
pack_channel(const union isl_color_value * value,unsigned i,const struct isl_channel_layout * layout,enum isl_colorspace colorspace,uint32_t data_out[4])1257 pack_channel(const union isl_color_value *value, unsigned i,
1258              const struct isl_channel_layout *layout,
1259              enum isl_colorspace colorspace,
1260              uint32_t data_out[4])
1261 {
1262    if (layout->type == ISL_VOID)
1263       return;
1264 
1265    if (colorspace == ISL_COLORSPACE_SRGB)
1266       assert(layout->type == ISL_UNORM);
1267 
1268    uint32_t packed;
1269    switch (layout->type) {
1270    case ISL_UNORM:
1271       if (colorspace == ISL_COLORSPACE_SRGB) {
1272          if (layout->bits == 8) {
1273             packed = util_format_linear_float_to_srgb_8unorm(value->f32[i]);
1274          } else {
1275             float srgb = util_format_linear_to_srgb_float(value->f32[i]);
1276             packed = _mesa_float_to_unorm(srgb, layout->bits);
1277          }
1278       } else {
1279          packed = _mesa_float_to_unorm(value->f32[i], layout->bits);
1280       }
1281       break;
1282    case ISL_SNORM:
1283       packed = _mesa_float_to_snorm(value->f32[i], layout->bits);
1284       break;
1285    case ISL_SFLOAT:
1286       assert(layout->bits == 16 || layout->bits == 32);
1287       if (layout->bits == 16) {
1288          packed = _mesa_float_to_half(value->f32[i]);
1289       } else {
1290          packed = value->u32[i];
1291       }
1292       break;
1293    case ISL_UINT:
1294       packed = MIN(value->u32[i], u_uintN_max(layout->bits));
1295       break;
1296    case ISL_SINT:
1297       packed = CLAMP(value->i32[i], u_intN_min(layout->bits),
1298                      u_intN_max(layout->bits));
1299       break;
1300 
1301    default:
1302       unreachable("Invalid channel type");
1303    }
1304 
1305    unsigned dword = layout->start_bit / 32;
1306    unsigned bit = layout->start_bit % 32;
1307    assert(bit + layout->bits <= 32);
1308    data_out[dword] |= (packed & u_uintN_max(layout->bits)) << bit;
1309 }
1310 
1311 /**
1312  * Take an isl_color_value and pack it into the actual bits as specified by
1313  * the isl_format.  This function is very slow for a format conversion
1314  * function but should be fine for a single pixel worth of data.
1315  */
1316 void
isl_color_value_pack(const union isl_color_value * value,enum isl_format format,uint32_t * data_out)1317 isl_color_value_pack(const union isl_color_value *value,
1318                      enum isl_format format,
1319                      uint32_t *data_out)
1320 {
1321    const struct isl_format_layout *fmtl = isl_format_get_layout(format);
1322    assert(fmtl->colorspace == ISL_COLORSPACE_LINEAR ||
1323           fmtl->colorspace == ISL_COLORSPACE_SRGB);
1324    assert(!isl_format_is_compressed(format));
1325 
1326    memset(data_out, 0, isl_align(fmtl->bpb, 32) / 8);
1327 
1328    if (format == ISL_FORMAT_R9G9B9E5_SHAREDEXP) {
1329       data_out[0] = float3_to_rgb9e5(value->f32);
1330       return;
1331    } else if (format == ISL_FORMAT_R11G11B10_FLOAT) {
1332       data_out[0] = float3_to_r11g11b10f(value->f32);
1333       return;
1334    }
1335 
1336    pack_channel(value, 0, &fmtl->channels.r, fmtl->colorspace, data_out);
1337    pack_channel(value, 1, &fmtl->channels.g, fmtl->colorspace, data_out);
1338    pack_channel(value, 2, &fmtl->channels.b, fmtl->colorspace, data_out);
1339    pack_channel(value, 3, &fmtl->channels.a, ISL_COLORSPACE_LINEAR, data_out);
1340    pack_channel(value, 0, &fmtl->channels.l, fmtl->colorspace, data_out);
1341    pack_channel(value, 0, &fmtl->channels.i, ISL_COLORSPACE_LINEAR, data_out);
1342    assert(fmtl->channels.p.bits == 0);
1343 }
1344 
1345 static inline void
unpack_channel(union isl_color_value * value,unsigned start,unsigned count,const struct isl_channel_layout * layout,enum isl_colorspace colorspace,const uint32_t * data_in)1346 unpack_channel(union isl_color_value *value,
1347                unsigned start, unsigned count,
1348                const struct isl_channel_layout *layout,
1349                enum isl_colorspace colorspace,
1350                const uint32_t *data_in)
1351 {
1352    if (layout->type == ISL_VOID)
1353       return;
1354 
1355    unsigned dword = layout->start_bit / 32;
1356    unsigned bit = layout->start_bit % 32;
1357    assert(bit + layout->bits <= 32);
1358    uint32_t packed = (data_in[dword] >> bit) & u_uintN_max(layout->bits);
1359 
1360    union {
1361       uint32_t u32;
1362       float f32;
1363    } unpacked;
1364 
1365    if (colorspace == ISL_COLORSPACE_SRGB)
1366       assert(layout->type == ISL_UNORM);
1367 
1368    switch (layout->type) {
1369    case ISL_UNORM:
1370       if (colorspace == ISL_COLORSPACE_SRGB) {
1371          if (layout->bits == 8) {
1372             unpacked.f32 = util_format_srgb_8unorm_to_linear_float(packed);
1373          } else {
1374             float srgb = _mesa_unorm_to_float(packed, layout->bits);
1375             unpacked.f32 = util_format_srgb_to_linear_float(srgb);
1376          }
1377       } else {
1378          unpacked.f32 = _mesa_unorm_to_float(packed, layout->bits);
1379       }
1380       break;
1381    case ISL_SNORM:
1382       unpacked.f32 = _mesa_snorm_to_float(util_sign_extend(packed, layout->bits),
1383                                           layout->bits);
1384       break;
1385    case ISL_SFLOAT:
1386       assert(layout->bits == 16 || layout->bits == 32);
1387       if (layout->bits == 16) {
1388          unpacked.f32 = _mesa_half_to_float(packed);
1389       } else {
1390          unpacked.u32 = packed;
1391       }
1392       break;
1393    case ISL_UINT:
1394       unpacked.u32 = packed;
1395       break;
1396    case ISL_SINT:
1397       unpacked.u32 = util_sign_extend(packed, layout->bits);
1398       break;
1399 
1400    default:
1401       unreachable("Invalid channel type");
1402    }
1403 
1404    for (unsigned i = 0; i < count; i++)
1405       value->u32[start + i] = unpacked.u32;
1406 }
1407 
1408 /**
1409  * Unpack an isl_color_value from the actual bits as specified by
1410  * the isl_format.  This function is very slow for a format conversion
1411  * function but should be fine for a single pixel worth of data.
1412  */
1413 void
isl_color_value_unpack(union isl_color_value * value,enum isl_format format,const uint32_t * data_in)1414 isl_color_value_unpack(union isl_color_value *value,
1415                        enum isl_format format,
1416                        const uint32_t *data_in)
1417 {
1418    const struct isl_format_layout *fmtl = isl_format_get_layout(format);
1419    assert(fmtl->colorspace == ISL_COLORSPACE_LINEAR ||
1420           fmtl->colorspace == ISL_COLORSPACE_SRGB);
1421    assert(!isl_format_is_compressed(format));
1422 
1423    /* Default to opaque black. */
1424    memset(value, 0, sizeof(*value));
1425    if (isl_format_has_int_channel(format)) {
1426       value->u32[3] = 1u;
1427    } else {
1428       value->f32[3] = 1.0f;
1429    }
1430 
1431    if (format == ISL_FORMAT_R9G9B9E5_SHAREDEXP) {
1432       rgb9e5_to_float3(data_in[0], value->f32);
1433       return;
1434    } else if (format == ISL_FORMAT_R11G11B10_FLOAT) {
1435       r11g11b10f_to_float3(data_in[0], value->f32);
1436       return;
1437    }
1438 
1439    unpack_channel(value, 0, 1, &fmtl->channels.r, fmtl->colorspace, data_in);
1440    unpack_channel(value, 1, 1, &fmtl->channels.g, fmtl->colorspace, data_in);
1441    unpack_channel(value, 2, 1, &fmtl->channels.b, fmtl->colorspace, data_in);
1442    unpack_channel(value, 3, 1, &fmtl->channels.a, ISL_COLORSPACE_LINEAR, data_in);
1443    unpack_channel(value, 0, 3, &fmtl->channels.l, fmtl->colorspace, data_in);
1444    unpack_channel(value, 0, 4, &fmtl->channels.i, ISL_COLORSPACE_LINEAR, data_in);
1445    assert(fmtl->channels.p.bits == 0);
1446 }
1447