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