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