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