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