1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
4 * Copyright (c) 2008-2010 VMware, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29
30 /**
31 * Mesa / Gallium format conversion and format selection code.
32 * \author Brian Paul
33 */
34
35
36 #include "main/context.h"
37 #include "main/enums.h"
38 #include "main/formats.h"
39 #include "main/glformats.h"
40 #include "main/texcompress.h"
41 #include "main/texgetimage.h"
42 #include "main/teximage.h"
43 #include "main/texstore.h"
44 #include "main/image.h"
45 #include "main/macros.h"
46 #include "main/formatquery.h"
47
48 #include "pipe/p_context.h"
49 #include "pipe/p_defines.h"
50 #include "pipe/p_screen.h"
51 #include "util/format/u_format.h"
52 #include "st_cb_texture.h"
53 #include "st_context.h"
54 #include "st_format.h"
55 #include "st_texture.h"
56
57
58 /**
59 * Translate Mesa format to Gallium format.
60 */
61 enum pipe_format
st_mesa_format_to_pipe_format(const struct st_context * st,mesa_format mesaFormat)62 st_mesa_format_to_pipe_format(const struct st_context *st,
63 mesa_format mesaFormat)
64 {
65 struct pipe_screen *screen = st->pipe->screen;
66
67 /* The destination RGBA format mustn't be changed, because it's also
68 * a destination format of the unpack/decompression function.
69 */
70 if (mesaFormat == MESA_FORMAT_ETC1_RGB8 && !st->has_etc1)
71 return PIPE_FORMAT_R8G8B8A8_UNORM;
72
73 /* ETC2 formats are emulated as uncompressed ones.
74 * The destination formats mustn't be changed, because they are also
75 * destination formats of the unpack/decompression function.
76 */
77 if (_mesa_is_format_etc2(mesaFormat) && !st->has_etc2) {
78 bool has_bgra_srgb = screen->is_format_supported(screen,
79 PIPE_FORMAT_B8G8R8A8_SRGB,
80 PIPE_TEXTURE_2D, 0, 0,
81 PIPE_BIND_SAMPLER_VIEW);
82
83 switch (mesaFormat) {
84 case MESA_FORMAT_ETC2_RGB8:
85 return PIPE_FORMAT_R8G8B8A8_UNORM;
86 case MESA_FORMAT_ETC2_SRGB8:
87 return has_bgra_srgb ? PIPE_FORMAT_B8G8R8A8_SRGB : PIPE_FORMAT_R8G8B8A8_SRGB;
88 case MESA_FORMAT_ETC2_RGBA8_EAC:
89 return PIPE_FORMAT_R8G8B8A8_UNORM;
90 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
91 return has_bgra_srgb ? PIPE_FORMAT_B8G8R8A8_SRGB : PIPE_FORMAT_R8G8B8A8_SRGB;
92 case MESA_FORMAT_ETC2_R11_EAC:
93 return PIPE_FORMAT_R16_UNORM;
94 case MESA_FORMAT_ETC2_RG11_EAC:
95 return PIPE_FORMAT_R16G16_UNORM;
96 case MESA_FORMAT_ETC2_SIGNED_R11_EAC:
97 return PIPE_FORMAT_R16_SNORM;
98 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC:
99 return PIPE_FORMAT_R16G16_SNORM;
100 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:
101 return PIPE_FORMAT_R8G8B8A8_UNORM;
102 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
103 return has_bgra_srgb ? PIPE_FORMAT_B8G8R8A8_SRGB : PIPE_FORMAT_R8G8B8A8_SRGB;
104 default:
105 unreachable("Unknown ETC2 format");
106 }
107 }
108
109 if (st_astc_format_fallback(st, mesaFormat)) {
110 if (_mesa_is_format_srgb(mesaFormat))
111 return PIPE_FORMAT_R8G8B8A8_SRGB;
112 else
113 return PIPE_FORMAT_R8G8B8A8_UNORM;
114 }
115
116 return mesaFormat;
117 }
118
119
120 /**
121 * Translate Gallium format to Mesa format.
122 */
123 mesa_format
st_pipe_format_to_mesa_format(enum pipe_format format)124 st_pipe_format_to_mesa_format(enum pipe_format format)
125 {
126 mesa_format mf = format;
127 if (!_mesa_get_format_name(mf))
128 return MESA_FORMAT_NONE;
129 return mf;
130 }
131
132 /**
133 * Map GL texture formats to Gallium pipe formats.
134 */
135 struct format_mapping
136 {
137 GLenum glFormats[18]; /**< list of GLenum formats, 0-terminated */
138 enum pipe_format pipeFormats[14]; /**< list of pipe formats, 0-terminated */
139 };
140
141
142 #define DEFAULT_RGBA_FORMATS \
143 PIPE_FORMAT_R8G8B8A8_UNORM, \
144 PIPE_FORMAT_B8G8R8A8_UNORM, \
145 PIPE_FORMAT_A8R8G8B8_UNORM, \
146 PIPE_FORMAT_A8B8G8R8_UNORM, \
147 0
148
149 #define DEFAULT_RGB_FORMATS \
150 PIPE_FORMAT_R8G8B8X8_UNORM, \
151 PIPE_FORMAT_B8G8R8X8_UNORM, \
152 PIPE_FORMAT_X8R8G8B8_UNORM, \
153 PIPE_FORMAT_X8B8G8R8_UNORM, \
154 PIPE_FORMAT_B5G6R5_UNORM, \
155 DEFAULT_RGBA_FORMATS
156
157 #define DEFAULT_SRGBA_FORMATS \
158 PIPE_FORMAT_R8G8B8A8_SRGB, \
159 PIPE_FORMAT_B8G8R8A8_SRGB, \
160 PIPE_FORMAT_A8R8G8B8_SRGB, \
161 PIPE_FORMAT_A8B8G8R8_SRGB, \
162 0
163
164 #define DEFAULT_DEPTH_FORMATS \
165 PIPE_FORMAT_Z24X8_UNORM, \
166 PIPE_FORMAT_X8Z24_UNORM, \
167 PIPE_FORMAT_Z16_UNORM, \
168 PIPE_FORMAT_Z24_UNORM_S8_UINT, \
169 PIPE_FORMAT_S8_UINT_Z24_UNORM, \
170 0
171
172 #define DEFAULT_SNORM8_RGBA_FORMATS \
173 PIPE_FORMAT_R8G8B8A8_SNORM, \
174 0
175
176 #define DEFAULT_UNORM16_RGBA_FORMATS \
177 PIPE_FORMAT_R16G16B16A16_UNORM, \
178 DEFAULT_RGBA_FORMATS
179
180
181 /**
182 * This table maps OpenGL texture format enums to Gallium pipe_format enums.
183 * Multiple GL enums might map to multiple pipe_formats.
184 * The first pipe format in the list that's supported is the one that's chosen.
185 */
186 static const struct format_mapping format_map[] = {
187 /* Basic RGB, RGBA formats */
188 {
189 { GL_RGB10, 0 },
190 { PIPE_FORMAT_R10G10B10X2_UNORM, PIPE_FORMAT_B10G10R10X2_UNORM,
191 PIPE_FORMAT_R10G10B10A2_UNORM, PIPE_FORMAT_B10G10R10A2_UNORM,
192 DEFAULT_RGB_FORMATS }
193 },
194 {
195 { GL_RGB10_A2, 0 },
196 { PIPE_FORMAT_R10G10B10A2_UNORM, PIPE_FORMAT_B10G10R10A2_UNORM,
197 DEFAULT_RGBA_FORMATS }
198 },
199 {
200 { 4, GL_RGBA, GL_RGBA8, 0 },
201 { PIPE_FORMAT_R8G8B8A8_UNORM, DEFAULT_RGBA_FORMATS }
202 },
203 {
204 { GL_BGRA, 0 },
205 { DEFAULT_RGBA_FORMATS }
206 },
207 {
208 { 3, GL_RGB, GL_RGB8, 0 },
209 { PIPE_FORMAT_R8G8B8X8_UNORM, DEFAULT_RGB_FORMATS }
210 },
211 {
212 { GL_RGB12, GL_RGB16, 0 },
213 { PIPE_FORMAT_R16G16B16X16_UNORM, PIPE_FORMAT_R16G16B16A16_UNORM,
214 DEFAULT_RGB_FORMATS }
215 },
216 {
217 { GL_RGBA12, GL_RGBA16, 0 },
218 { PIPE_FORMAT_R16G16B16A16_UNORM, DEFAULT_RGBA_FORMATS }
219 },
220 {
221 { GL_RGBA4, GL_RGBA2, 0 },
222 { PIPE_FORMAT_B4G4R4A4_UNORM, PIPE_FORMAT_A4B4G4R4_UNORM,
223 DEFAULT_RGBA_FORMATS }
224 },
225 {
226 { GL_RGB5_A1, 0 },
227 { PIPE_FORMAT_B5G5R5A1_UNORM, PIPE_FORMAT_A1B5G5R5_UNORM,
228 DEFAULT_RGBA_FORMATS }
229 },
230 {
231 { GL_R3_G3_B2, 0 },
232 { PIPE_FORMAT_B2G3R3_UNORM, PIPE_FORMAT_R3G3B2_UNORM,
233 PIPE_FORMAT_B5G6R5_UNORM, PIPE_FORMAT_B5G5R5A1_UNORM,
234 DEFAULT_RGB_FORMATS }
235 },
236 {
237 { GL_RGB4, 0 },
238 { PIPE_FORMAT_B4G4R4X4_UNORM, PIPE_FORMAT_B4G4R4A4_UNORM,
239 PIPE_FORMAT_A4B4G4R4_UNORM,
240 DEFAULT_RGB_FORMATS }
241 },
242 {
243 { GL_RGB5, 0 },
244 { PIPE_FORMAT_B5G5R5X1_UNORM, PIPE_FORMAT_X1B5G5R5_UNORM,
245 PIPE_FORMAT_B5G5R5A1_UNORM, PIPE_FORMAT_A1B5G5R5_UNORM,
246 DEFAULT_RGB_FORMATS }
247 },
248 {
249 { GL_RGB565, 0 },
250 { PIPE_FORMAT_B5G6R5_UNORM, DEFAULT_RGB_FORMATS }
251 },
252
253 /* basic Alpha formats */
254 {
255 { GL_ALPHA12, GL_ALPHA16, 0 },
256 { PIPE_FORMAT_A16_UNORM, PIPE_FORMAT_R16G16B16A16_UNORM,
257 PIPE_FORMAT_A8_UNORM, DEFAULT_RGBA_FORMATS }
258 },
259 {
260 { GL_ALPHA, GL_ALPHA4, GL_ALPHA8, GL_COMPRESSED_ALPHA, 0 },
261 { PIPE_FORMAT_A8_UNORM, DEFAULT_RGBA_FORMATS }
262 },
263
264 /* basic Luminance formats */
265 {
266 { GL_LUMINANCE12, GL_LUMINANCE16, 0 },
267 { PIPE_FORMAT_L16_UNORM, PIPE_FORMAT_R16G16B16A16_UNORM,
268 PIPE_FORMAT_L8_UNORM, DEFAULT_RGB_FORMATS }
269 },
270 {
271 { 1, GL_LUMINANCE, GL_LUMINANCE4, GL_LUMINANCE8, 0 },
272 { PIPE_FORMAT_L8_UNORM, PIPE_FORMAT_L8A8_UNORM, DEFAULT_RGB_FORMATS }
273 },
274
275 /* basic Luminance/Alpha formats */
276 {
277 { GL_LUMINANCE12_ALPHA4, GL_LUMINANCE12_ALPHA12,
278 GL_LUMINANCE16_ALPHA16, 0},
279 { PIPE_FORMAT_L16A16_UNORM, PIPE_FORMAT_R16G16B16A16_UNORM,
280 PIPE_FORMAT_L8A8_UNORM, DEFAULT_RGBA_FORMATS }
281 },
282 {
283 { 2, GL_LUMINANCE_ALPHA, GL_LUMINANCE6_ALPHA2, GL_LUMINANCE8_ALPHA8, 0 },
284 { PIPE_FORMAT_L8A8_UNORM, DEFAULT_RGBA_FORMATS }
285 },
286 {
287 { GL_LUMINANCE4_ALPHA4, 0 },
288 { PIPE_FORMAT_L4A4_UNORM, PIPE_FORMAT_L8A8_UNORM,
289 DEFAULT_RGBA_FORMATS }
290 },
291
292 /* basic Intensity formats */
293 {
294 { GL_INTENSITY12, GL_INTENSITY16, 0 },
295 { PIPE_FORMAT_I16_UNORM, PIPE_FORMAT_R16G16B16A16_UNORM,
296 PIPE_FORMAT_I8_UNORM, DEFAULT_RGBA_FORMATS }
297 },
298 {
299 { GL_INTENSITY, GL_INTENSITY4, GL_INTENSITY8,
300 GL_COMPRESSED_INTENSITY, 0 },
301 { PIPE_FORMAT_I8_UNORM, DEFAULT_RGBA_FORMATS }
302 },
303
304 /* YCbCr */
305 {
306 { GL_YCBCR_MESA, 0 },
307 { PIPE_FORMAT_UYVY, PIPE_FORMAT_YUYV, 0 }
308 },
309
310 /* compressed formats */ /* XXX PIPE_BIND_SAMPLER_VIEW only */
311 {
312 { GL_COMPRESSED_RGB, 0 },
313 { PIPE_FORMAT_DXT1_RGB, DEFAULT_RGB_FORMATS }
314 },
315 {
316 { GL_COMPRESSED_RGBA, 0 },
317 { PIPE_FORMAT_DXT5_RGBA, DEFAULT_RGBA_FORMATS }
318 },
319 {
320 { GL_RGB_S3TC, GL_RGB4_S3TC, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 0 },
321 { PIPE_FORMAT_DXT1_RGB, 0 }
322 },
323 {
324 { GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 0 },
325 { PIPE_FORMAT_DXT1_RGBA, 0 }
326 },
327 {
328 { GL_RGBA_S3TC, GL_RGBA4_S3TC, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 0 },
329 { PIPE_FORMAT_DXT3_RGBA, 0 }
330 },
331 {
332 { GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 0 },
333 { PIPE_FORMAT_DXT5_RGBA, 0 }
334 },
335
336 {
337 { GL_COMPRESSED_RGB_FXT1_3DFX, 0 },
338 { PIPE_FORMAT_FXT1_RGB, 0 }
339 },
340 {
341 { GL_COMPRESSED_RGBA_FXT1_3DFX, 0 },
342 { PIPE_FORMAT_FXT1_RGBA, 0 }
343 },
344
345 /* Depth formats */
346 {
347 { GL_DEPTH_COMPONENT16, 0 },
348 { PIPE_FORMAT_Z16_UNORM, DEFAULT_DEPTH_FORMATS }
349 },
350 {
351 { GL_DEPTH_COMPONENT24, 0 },
352 { PIPE_FORMAT_Z24X8_UNORM, PIPE_FORMAT_X8Z24_UNORM,
353 DEFAULT_DEPTH_FORMATS }
354 },
355 {
356 { GL_DEPTH_COMPONENT32, 0 },
357 { PIPE_FORMAT_Z32_UNORM, DEFAULT_DEPTH_FORMATS }
358 },
359 {
360 { GL_DEPTH_COMPONENT, 0 },
361 { DEFAULT_DEPTH_FORMATS }
362 },
363 {
364 { GL_DEPTH_COMPONENT32F, 0 },
365 { PIPE_FORMAT_Z32_FLOAT, 0 }
366 },
367
368 /* stencil formats */
369 {
370 { GL_STENCIL_INDEX, GL_STENCIL_INDEX1_EXT, GL_STENCIL_INDEX4_EXT,
371 GL_STENCIL_INDEX8_EXT, GL_STENCIL_INDEX16_EXT, 0 },
372 {
373 PIPE_FORMAT_S8_UINT, PIPE_FORMAT_Z24_UNORM_S8_UINT,
374 PIPE_FORMAT_S8_UINT_Z24_UNORM, 0
375 }
376 },
377
378 /* Depth / Stencil formats */
379 {
380 { GL_DEPTH_STENCIL_EXT, GL_DEPTH24_STENCIL8_EXT, 0 },
381 { PIPE_FORMAT_Z24_UNORM_S8_UINT, PIPE_FORMAT_S8_UINT_Z24_UNORM, 0 }
382 },
383 {
384 { GL_DEPTH32F_STENCIL8, 0 },
385 { PIPE_FORMAT_Z32_FLOAT_S8X24_UINT, 0 }
386 },
387
388 /* sRGB formats */
389 {
390 { GL_SRGB_EXT, GL_SRGB8_EXT, 0 },
391 { PIPE_FORMAT_R8G8B8X8_SRGB, PIPE_FORMAT_B8G8R8X8_SRGB,
392 DEFAULT_SRGBA_FORMATS }
393 },
394 {
395 { GL_SRGB_ALPHA_EXT, GL_SRGB8_ALPHA8_EXT, 0 },
396 { PIPE_FORMAT_R8G8B8A8_SRGB, DEFAULT_SRGBA_FORMATS }
397 },
398 {
399 { GL_COMPRESSED_SRGB_EXT, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 0 },
400 { PIPE_FORMAT_DXT1_SRGB, PIPE_FORMAT_R8G8B8X8_SRGB,
401 PIPE_FORMAT_B8G8R8X8_SRGB, DEFAULT_SRGBA_FORMATS }
402 },
403 {
404 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 0 },
405 { PIPE_FORMAT_DXT1_SRGBA, 0 }
406 },
407 {
408 { GL_COMPRESSED_SRGB_ALPHA_EXT,
409 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0 },
410 { PIPE_FORMAT_DXT3_SRGBA, DEFAULT_SRGBA_FORMATS }
411 },
412 {
413 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0 },
414 { PIPE_FORMAT_DXT5_SRGBA, 0 }
415 },
416 {
417 { GL_SLUMINANCE_ALPHA_EXT, GL_SLUMINANCE8_ALPHA8_EXT,
418 GL_COMPRESSED_SLUMINANCE_ALPHA_EXT, 0 },
419 { PIPE_FORMAT_L8A8_SRGB, DEFAULT_SRGBA_FORMATS }
420 },
421 {
422 { GL_SLUMINANCE_EXT, GL_SLUMINANCE8_EXT, GL_COMPRESSED_SLUMINANCE_EXT,
423 0 },
424 { PIPE_FORMAT_L8_SRGB, DEFAULT_SRGBA_FORMATS }
425 },
426 {
427 { GL_SR8_EXT, 0 },
428 { PIPE_FORMAT_R8_SRGB, 0 }
429 },
430
431 /* 16-bit float formats */
432 {
433 { GL_RGBA16F_ARB, 0 },
434 { PIPE_FORMAT_R16G16B16A16_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
435 },
436 {
437 { GL_RGB16F_ARB, 0 },
438 { PIPE_FORMAT_R16G16B16_FLOAT, PIPE_FORMAT_R16G16B16X16_FLOAT,
439 PIPE_FORMAT_R16G16B16A16_FLOAT,
440 PIPE_FORMAT_R32G32B32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
441 },
442 {
443 { GL_LUMINANCE_ALPHA16F_ARB, 0 },
444 { PIPE_FORMAT_L16A16_FLOAT, PIPE_FORMAT_R16G16B16A16_FLOAT,
445 PIPE_FORMAT_L32A32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
446 },
447 {
448 { GL_ALPHA16F_ARB, 0 },
449 { PIPE_FORMAT_A16_FLOAT, PIPE_FORMAT_L16A16_FLOAT,
450 PIPE_FORMAT_A32_FLOAT, PIPE_FORMAT_R16G16B16A16_FLOAT,
451 PIPE_FORMAT_L32A32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
452 },
453 {
454 { GL_INTENSITY16F_ARB, 0 },
455 { PIPE_FORMAT_I16_FLOAT, PIPE_FORMAT_L16A16_FLOAT,
456 PIPE_FORMAT_I32_FLOAT, PIPE_FORMAT_R16G16B16A16_FLOAT,
457 PIPE_FORMAT_L32A32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
458 },
459 {
460 { GL_LUMINANCE16F_ARB, 0 },
461 { PIPE_FORMAT_L16_FLOAT, PIPE_FORMAT_L16A16_FLOAT,
462 PIPE_FORMAT_L32_FLOAT, PIPE_FORMAT_R16G16B16A16_FLOAT,
463 PIPE_FORMAT_L32A32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
464 },
465 {
466 { GL_R16F, 0 },
467 { PIPE_FORMAT_R16_FLOAT, PIPE_FORMAT_R16G16_FLOAT,
468 PIPE_FORMAT_R32_FLOAT, PIPE_FORMAT_R16G16B16A16_FLOAT,
469 PIPE_FORMAT_R32G32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
470 },
471 {
472 { GL_RG16F, 0 },
473 { PIPE_FORMAT_R16G16_FLOAT, PIPE_FORMAT_R16G16B16A16_FLOAT,
474 PIPE_FORMAT_R32G32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
475 },
476
477 /* 32-bit float formats */
478 {
479 { GL_RGBA32F_ARB, 0 },
480 { PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
481 },
482 {
483 { GL_RGB32F_ARB, 0 },
484 { PIPE_FORMAT_R32G32B32_FLOAT, PIPE_FORMAT_R32G32B32X32_FLOAT,
485 PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
486 },
487 {
488 { GL_LUMINANCE_ALPHA32F_ARB, 0 },
489 { PIPE_FORMAT_L32A32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
490 },
491 {
492 { GL_ALPHA32F_ARB, 0 },
493 { PIPE_FORMAT_A32_FLOAT, PIPE_FORMAT_L32A32_FLOAT,
494 PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
495 },
496 {
497 { GL_INTENSITY32F_ARB, 0 },
498 { PIPE_FORMAT_I32_FLOAT, PIPE_FORMAT_L32A32_FLOAT,
499 PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
500 },
501 {
502 { GL_LUMINANCE32F_ARB, 0 },
503 { PIPE_FORMAT_L32_FLOAT, PIPE_FORMAT_L32A32_FLOAT,
504 PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
505 },
506 {
507 { GL_R32F, 0 },
508 { PIPE_FORMAT_R32_FLOAT, PIPE_FORMAT_R32G32_FLOAT,
509 PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
510 },
511 {
512 { GL_RG32F, 0 },
513 { PIPE_FORMAT_R32G32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
514 },
515
516 /* R, RG formats */
517 {
518 { GL_RED, GL_R8, 0 },
519 { PIPE_FORMAT_R8_UNORM, PIPE_FORMAT_R8G8_UNORM, DEFAULT_RGBA_FORMATS }
520 },
521 {
522 { GL_RG, GL_RG8, 0 },
523 { PIPE_FORMAT_R8G8_UNORM, DEFAULT_RGBA_FORMATS }
524 },
525 {
526 { GL_R16, 0 },
527 { PIPE_FORMAT_R16_UNORM, PIPE_FORMAT_R16G16_UNORM,
528 DEFAULT_UNORM16_RGBA_FORMATS }
529 },
530 {
531 { GL_RG16, 0 },
532 { PIPE_FORMAT_R16G16_UNORM, DEFAULT_UNORM16_RGBA_FORMATS }
533 },
534
535 /* compressed R, RG formats */
536 {
537 { GL_COMPRESSED_RED, GL_COMPRESSED_RED_RGTC1, 0 },
538 { PIPE_FORMAT_RGTC1_UNORM, PIPE_FORMAT_R8_UNORM, DEFAULT_RGBA_FORMATS }
539 },
540 {
541 { GL_COMPRESSED_SIGNED_RED_RGTC1, 0 },
542 { PIPE_FORMAT_RGTC1_SNORM, DEFAULT_SNORM8_RGBA_FORMATS }
543 },
544 {
545 { GL_COMPRESSED_RG, GL_COMPRESSED_RG_RGTC2, 0 },
546 { PIPE_FORMAT_RGTC2_UNORM, PIPE_FORMAT_R8G8_UNORM, DEFAULT_RGBA_FORMATS }
547 },
548 {
549 { GL_COMPRESSED_SIGNED_RG_RGTC2, 0 },
550 { PIPE_FORMAT_RGTC2_SNORM, DEFAULT_SNORM8_RGBA_FORMATS }
551 },
552 {
553 { GL_COMPRESSED_LUMINANCE, GL_COMPRESSED_LUMINANCE_LATC1_EXT, 0 },
554 { PIPE_FORMAT_LATC1_UNORM, PIPE_FORMAT_L8_UNORM, DEFAULT_RGBA_FORMATS }
555 },
556 {
557 { GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT, 0 },
558 { PIPE_FORMAT_LATC1_SNORM, DEFAULT_SNORM8_RGBA_FORMATS }
559 },
560 {
561 { GL_COMPRESSED_LUMINANCE_ALPHA, GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT,
562 GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, 0 },
563 { PIPE_FORMAT_LATC2_UNORM, PIPE_FORMAT_L8A8_UNORM, DEFAULT_RGBA_FORMATS }
564 },
565 {
566 { GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT, 0 },
567 { PIPE_FORMAT_LATC2_SNORM, DEFAULT_SNORM8_RGBA_FORMATS }
568 },
569
570 /* ETC1 */
571 {
572 { GL_ETC1_RGB8_OES, 0 },
573 { PIPE_FORMAT_ETC1_RGB8, 0 }
574 },
575
576 /* ETC2 */
577 {
578 { GL_COMPRESSED_RGB8_ETC2, 0 },
579 { PIPE_FORMAT_ETC2_RGB8, 0 }
580 },
581 {
582 { GL_COMPRESSED_SRGB8_ETC2, 0 },
583 { PIPE_FORMAT_ETC2_SRGB8, 0 }
584 },
585 {
586 { GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 0 },
587 { PIPE_FORMAT_ETC2_RGB8A1, 0 }
588 },
589 {
590 { GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 0 },
591 { PIPE_FORMAT_ETC2_SRGB8A1, 0 }
592 },
593 {
594 { GL_COMPRESSED_RGBA8_ETC2_EAC, 0 },
595 { PIPE_FORMAT_ETC2_RGBA8, 0 }
596 },
597 {
598 { GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 0 },
599 { PIPE_FORMAT_ETC2_SRGBA8, 0 }
600 },
601 {
602 { GL_COMPRESSED_R11_EAC, 0 },
603 { PIPE_FORMAT_ETC2_R11_UNORM, 0 }
604 },
605 {
606 { GL_COMPRESSED_SIGNED_R11_EAC, 0 },
607 { PIPE_FORMAT_ETC2_R11_SNORM, 0 }
608 },
609 {
610 { GL_COMPRESSED_RG11_EAC, 0 },
611 { PIPE_FORMAT_ETC2_RG11_UNORM, 0 }
612 },
613 {
614 { GL_COMPRESSED_SIGNED_RG11_EAC, 0 },
615 { PIPE_FORMAT_ETC2_RG11_SNORM, 0 }
616 },
617
618 /* BPTC */
619 {
620 { GL_COMPRESSED_RGBA_BPTC_UNORM, 0 },
621 { PIPE_FORMAT_BPTC_RGBA_UNORM, 0 },
622 },
623 {
624 { GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, 0 },
625 { PIPE_FORMAT_BPTC_SRGBA, 0 },
626 },
627 {
628 { GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, 0 },
629 { PIPE_FORMAT_BPTC_RGB_FLOAT, 0 },
630 },
631 {
632 { GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, 0 },
633 { PIPE_FORMAT_BPTC_RGB_UFLOAT, 0 },
634 },
635
636 /* ASTC */
637 {
638 { GL_COMPRESSED_RGBA_ASTC_4x4_KHR, 0 },
639 { PIPE_FORMAT_ASTC_4x4, 0},
640 },
641 {
642 { GL_COMPRESSED_RGBA_ASTC_5x4_KHR, 0 },
643 { PIPE_FORMAT_ASTC_5x4, 0},
644 },
645 {
646 { GL_COMPRESSED_RGBA_ASTC_5x5_KHR, 0 },
647 { PIPE_FORMAT_ASTC_5x5, 0},
648 },
649 {
650 { GL_COMPRESSED_RGBA_ASTC_6x5_KHR, 0 },
651 { PIPE_FORMAT_ASTC_6x5, 0},
652 },
653 {
654 { GL_COMPRESSED_RGBA_ASTC_6x6_KHR, 0 },
655 { PIPE_FORMAT_ASTC_6x6, 0},
656 },
657 {
658 { GL_COMPRESSED_RGBA_ASTC_8x5_KHR, 0 },
659 { PIPE_FORMAT_ASTC_8x5, 0},
660 },
661 {
662 { GL_COMPRESSED_RGBA_ASTC_8x6_KHR, 0 },
663 { PIPE_FORMAT_ASTC_8x6, 0},
664 },
665 {
666 { GL_COMPRESSED_RGBA_ASTC_8x8_KHR, 0 },
667 { PIPE_FORMAT_ASTC_8x8, 0},
668 },
669 {
670 { GL_COMPRESSED_RGBA_ASTC_10x5_KHR, 0 },
671 { PIPE_FORMAT_ASTC_10x5, 0},
672 },
673 {
674 { GL_COMPRESSED_RGBA_ASTC_10x6_KHR, 0 },
675 { PIPE_FORMAT_ASTC_10x6, 0},
676 },
677 {
678 { GL_COMPRESSED_RGBA_ASTC_10x8_KHR, 0 },
679 { PIPE_FORMAT_ASTC_10x8, 0},
680 },
681 {
682 { GL_COMPRESSED_RGBA_ASTC_10x10_KHR, 0 },
683 { PIPE_FORMAT_ASTC_10x10, 0},
684 },
685 {
686 { GL_COMPRESSED_RGBA_ASTC_12x10_KHR, 0 },
687 { PIPE_FORMAT_ASTC_12x10, 0},
688 },
689 {
690 { GL_COMPRESSED_RGBA_ASTC_12x12_KHR, 0 },
691 { PIPE_FORMAT_ASTC_12x12, 0},
692 },
693
694 {
695 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, 0 },
696 { PIPE_FORMAT_ASTC_4x4_SRGB, 0},
697 },
698 {
699 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, 0 },
700 { PIPE_FORMAT_ASTC_5x4_SRGB, 0},
701 },
702 {
703 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, 0 },
704 { PIPE_FORMAT_ASTC_5x5_SRGB, 0},
705 },
706 {
707 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, 0 },
708 { PIPE_FORMAT_ASTC_6x5_SRGB, 0},
709 },
710 {
711 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, 0 },
712 { PIPE_FORMAT_ASTC_6x6_SRGB, 0},
713 },
714 {
715 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, 0 },
716 { PIPE_FORMAT_ASTC_8x5_SRGB, 0},
717 },
718 {
719 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, 0 },
720 { PIPE_FORMAT_ASTC_8x6_SRGB, 0},
721 },
722 {
723 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, 0 },
724 { PIPE_FORMAT_ASTC_8x8_SRGB, 0},
725 },
726 {
727 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, 0 },
728 { PIPE_FORMAT_ASTC_10x5_SRGB, 0},
729 },
730 {
731 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, 0 },
732 { PIPE_FORMAT_ASTC_10x6_SRGB, 0},
733 },
734 {
735 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, 0 },
736 { PIPE_FORMAT_ASTC_10x8_SRGB, 0},
737 },
738 {
739 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, 0 },
740 { PIPE_FORMAT_ASTC_10x10_SRGB, 0},
741 },
742 {
743 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, 0 },
744 { PIPE_FORMAT_ASTC_12x10_SRGB, 0},
745 },
746 {
747 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, 0 },
748 { PIPE_FORMAT_ASTC_12x12_SRGB, 0},
749 },
750
751 /* signed/unsigned integer formats.
752 */
753 {
754 { GL_RGBA_INTEGER_EXT,
755 GL_BGRA_INTEGER_EXT,
756 GL_RGBA8I_EXT, 0 },
757 { PIPE_FORMAT_R8G8B8A8_SINT, 0 }
758 },
759 {
760 { GL_RGB_INTEGER_EXT,
761 GL_BGR_INTEGER_EXT,
762 GL_RGB8I_EXT,
763 GL_BLUE_INTEGER_EXT, 0 },
764 { PIPE_FORMAT_R8G8B8_SINT, PIPE_FORMAT_R8G8B8X8_SINT,
765 PIPE_FORMAT_R8G8B8A8_SINT, 0 }
766 },
767 {
768 { GL_ALPHA_INTEGER_EXT,
769 GL_ALPHA8I_EXT, 0 },
770 { PIPE_FORMAT_A8_SINT, PIPE_FORMAT_R8G8B8A8_SINT, 0 }
771 },
772 {
773 { GL_ALPHA16I_EXT, 0 },
774 { PIPE_FORMAT_A16_SINT, PIPE_FORMAT_R16G16B16A16_SINT, 0 }
775 },
776 {
777 { GL_ALPHA32I_EXT, 0 },
778 { PIPE_FORMAT_A32_SINT, PIPE_FORMAT_R32G32B32A32_SINT, 0 }
779 },
780 {
781 { GL_ALPHA8UI_EXT, 0 },
782 { PIPE_FORMAT_A8_UINT, PIPE_FORMAT_R8G8B8A8_UINT, 0 }
783 },
784 {
785 { GL_ALPHA16UI_EXT, 0 },
786 { PIPE_FORMAT_A16_UINT, PIPE_FORMAT_R16G16B16A16_UINT, 0 }
787 },
788 {
789 { GL_ALPHA32UI_EXT, 0 },
790 { PIPE_FORMAT_A32_UINT, PIPE_FORMAT_R32G32B32A32_UINT, 0 }
791 },
792 {
793 { GL_INTENSITY8I_EXT, 0 },
794 { PIPE_FORMAT_I8_SINT, PIPE_FORMAT_R8G8B8A8_SINT, 0 }
795 },
796 {
797 { GL_INTENSITY16I_EXT, 0 },
798 { PIPE_FORMAT_I16_SINT, PIPE_FORMAT_R16G16B16A16_SINT, 0 }
799 },
800 {
801 { GL_INTENSITY32I_EXT, 0 },
802 { PIPE_FORMAT_I32_SINT, PIPE_FORMAT_R32G32B32A32_SINT, 0 }
803 },
804 {
805 { GL_INTENSITY8UI_EXT, 0 },
806 { PIPE_FORMAT_I8_UINT, PIPE_FORMAT_R8G8B8A8_UINT, 0 }
807 },
808 {
809 { GL_INTENSITY16UI_EXT, 0 },
810 { PIPE_FORMAT_I16_UINT, PIPE_FORMAT_R16G16B16A16_UINT, 0 }
811 },
812 {
813 { GL_INTENSITY32UI_EXT, 0 },
814 { PIPE_FORMAT_I32_UINT, PIPE_FORMAT_R32G32B32A32_UINT, 0 }
815 },
816 {
817 { GL_LUMINANCE8I_EXT, 0 },
818 { PIPE_FORMAT_L8_SINT, PIPE_FORMAT_R8G8B8A8_SINT, 0 }
819 },
820 {
821 { GL_LUMINANCE16I_EXT, 0 },
822 { PIPE_FORMAT_L16_SINT, PIPE_FORMAT_R16G16B16A16_SINT, 0 }
823 },
824 {
825 { GL_LUMINANCE32I_EXT, 0 },
826 { PIPE_FORMAT_L32_SINT, PIPE_FORMAT_R32G32B32A32_SINT, 0 }
827 },
828 {
829 { GL_LUMINANCE_INTEGER_EXT,
830 GL_LUMINANCE8UI_EXT, 0 },
831 { PIPE_FORMAT_L8_UINT, PIPE_FORMAT_R8G8B8A8_UINT, 0 }
832 },
833 {
834 { GL_LUMINANCE16UI_EXT, 0 },
835 { PIPE_FORMAT_L16_UINT, PIPE_FORMAT_R16G16B16A16_UINT, 0 }
836 },
837 {
838 { GL_LUMINANCE32UI_EXT, 0 },
839 { PIPE_FORMAT_L32_UINT, PIPE_FORMAT_R32G32B32A32_UINT, 0 }
840 },
841 {
842 { GL_LUMINANCE_ALPHA_INTEGER_EXT,
843 GL_LUMINANCE_ALPHA8I_EXT, 0 },
844 { PIPE_FORMAT_L8A8_SINT, PIPE_FORMAT_R8G8B8A8_SINT, 0 }
845 },
846 {
847 { GL_LUMINANCE_ALPHA16I_EXT, 0 },
848 { PIPE_FORMAT_L16A16_SINT, PIPE_FORMAT_R16G16B16A16_SINT, 0 }
849 },
850 {
851 { GL_LUMINANCE_ALPHA32I_EXT, 0 },
852 { PIPE_FORMAT_L32A32_SINT, PIPE_FORMAT_R32G32B32A32_SINT, 0 }
853 },
854 {
855 { GL_LUMINANCE_ALPHA8UI_EXT, 0 },
856 { PIPE_FORMAT_L8A8_UINT, PIPE_FORMAT_R8G8B8A8_UINT, 0 }
857 },
858 {
859 { GL_LUMINANCE_ALPHA16UI_EXT, 0 },
860 { PIPE_FORMAT_L16A16_UINT, PIPE_FORMAT_R16G16B16A16_UINT, 0 }
861 },
862 {
863 { GL_LUMINANCE_ALPHA32UI_EXT, 0 },
864 { PIPE_FORMAT_L32A32_UINT, PIPE_FORMAT_R32G32B32A32_UINT, 0 }
865 },
866 {
867 { GL_RGB16I_EXT, 0 },
868 { PIPE_FORMAT_R16G16B16_SINT, PIPE_FORMAT_R16G16B16X16_SINT,
869 PIPE_FORMAT_R16G16B16A16_SINT, 0 },
870 },
871 {
872 { GL_RGBA16I_EXT, 0 },
873 { PIPE_FORMAT_R16G16B16A16_SINT, 0 },
874 },
875 {
876 { GL_RGB32I_EXT, 0 },
877 { PIPE_FORMAT_R32G32B32_SINT, PIPE_FORMAT_R32G32B32X32_SINT,
878 PIPE_FORMAT_R32G32B32A32_SINT, 0 },
879 },
880 {
881 { GL_RGBA32I_EXT, 0 },
882 { PIPE_FORMAT_R32G32B32A32_SINT, 0 }
883 },
884 {
885 { GL_RGBA8UI_EXT, 0 },
886 { PIPE_FORMAT_R8G8B8A8_UINT, 0 }
887 },
888 {
889 { GL_RGB8UI_EXT, 0 },
890 { PIPE_FORMAT_R8G8B8_UINT, PIPE_FORMAT_R8G8B8X8_UINT,
891 PIPE_FORMAT_R8G8B8A8_UINT, 0 }
892 },
893 {
894 { GL_RGB16UI_EXT, 0 },
895 { PIPE_FORMAT_R16G16B16_UINT, PIPE_FORMAT_R16G16B16X16_UINT,
896 PIPE_FORMAT_R16G16B16A16_UINT, 0 }
897 },
898 {
899 { GL_RGBA16UI_EXT, 0 },
900 { PIPE_FORMAT_R16G16B16A16_UINT, 0 }
901 },
902 {
903 { GL_RGB32UI_EXT, 0},
904 { PIPE_FORMAT_R32G32B32_UINT, PIPE_FORMAT_R32G32B32X32_UINT,
905 PIPE_FORMAT_R32G32B32A32_UINT, 0 }
906 },
907 {
908 { GL_RGBA32UI_EXT, 0},
909 { PIPE_FORMAT_R32G32B32A32_UINT, 0 }
910 },
911 {
912 { GL_R8I, GL_RED_INTEGER_EXT, 0},
913 { PIPE_FORMAT_R8_SINT, PIPE_FORMAT_R8G8_SINT, 0},
914 },
915 {
916 { GL_R16I, 0},
917 { PIPE_FORMAT_R16_SINT, 0},
918 },
919 {
920 { GL_R32I, 0},
921 { PIPE_FORMAT_R32_SINT, 0},
922 },
923 {
924 { GL_R8UI, 0},
925 { PIPE_FORMAT_R8_UINT, PIPE_FORMAT_R8G8_UINT, 0},
926 },
927 {
928 { GL_R16UI, 0},
929 { PIPE_FORMAT_R16_UINT, 0},
930 },
931 {
932 { GL_R32UI, 0},
933 { PIPE_FORMAT_R32_UINT, 0},
934 },
935 {
936 { GL_RG8I, GL_GREEN_INTEGER_EXT, 0},
937 { PIPE_FORMAT_R8G8_SINT, 0},
938 },
939 {
940 { GL_RG16I, 0},
941 { PIPE_FORMAT_R16G16_SINT, 0},
942 },
943 {
944 { GL_RG32I, 0},
945 { PIPE_FORMAT_R32G32_SINT, 0},
946 },
947 {
948 { GL_RG8UI, 0},
949 { PIPE_FORMAT_R8G8_UINT, 0},
950 },
951 {
952 { GL_RG16UI, 0},
953 { PIPE_FORMAT_R16G16_UINT, 0},
954 },
955 {
956 { GL_RG32UI, 0},
957 { PIPE_FORMAT_R32G32_UINT, 0},
958 },
959 /* signed normalized formats */
960 {
961 { GL_RED_SNORM, GL_R8_SNORM, 0 },
962 { PIPE_FORMAT_R8_SNORM, PIPE_FORMAT_R8G8_SNORM,
963 PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
964 },
965 {
966 { GL_R16_SNORM, 0 },
967 { PIPE_FORMAT_R16_SNORM,
968 PIPE_FORMAT_R16G16_SNORM,
969 PIPE_FORMAT_R16G16B16A16_SNORM,
970 PIPE_FORMAT_R8_SNORM,
971 PIPE_FORMAT_R8G8_SNORM,
972 PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
973 },
974 {
975 { GL_RG_SNORM, GL_RG8_SNORM, 0 },
976 { PIPE_FORMAT_R8G8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
977 },
978 {
979 { GL_RG16_SNORM, 0 },
980 { PIPE_FORMAT_R16G16_SNORM, PIPE_FORMAT_R16G16B16A16_SNORM,
981 PIPE_FORMAT_R8G8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
982 },
983 {
984 { GL_RGB_SNORM, GL_RGB8_SNORM, 0 },
985 { PIPE_FORMAT_R8G8B8X8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
986 },
987 {
988 { GL_RGBA_SNORM, GL_RGBA8_SNORM, 0 },
989 { PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
990 },
991 {
992 { GL_RGB16_SNORM, 0 },
993 { PIPE_FORMAT_R16G16B16X16_SNORM, PIPE_FORMAT_R16G16B16A16_SNORM,
994 PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
995 },
996 {
997 { GL_RGBA16_SNORM, 0 },
998 { PIPE_FORMAT_R16G16B16A16_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
999 },
1000 {
1001 { GL_ALPHA_SNORM, GL_ALPHA8_SNORM, 0 },
1002 { PIPE_FORMAT_A8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1003 },
1004 {
1005 { GL_ALPHA16_SNORM, 0 },
1006 { PIPE_FORMAT_A16_SNORM, PIPE_FORMAT_R16G16B16A16_SNORM,
1007 PIPE_FORMAT_A8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1008 },
1009 {
1010 { GL_LUMINANCE_SNORM, GL_LUMINANCE8_SNORM, 0 },
1011 { PIPE_FORMAT_L8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1012 },
1013 {
1014 { GL_LUMINANCE16_SNORM, 0 },
1015 { PIPE_FORMAT_L16_SNORM, PIPE_FORMAT_R16G16B16A16_SNORM,
1016 PIPE_FORMAT_L8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1017 },
1018 {
1019 { GL_LUMINANCE_ALPHA_SNORM, GL_LUMINANCE8_ALPHA8_SNORM, 0 },
1020 { PIPE_FORMAT_L8A8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1021 },
1022 {
1023 { GL_LUMINANCE16_ALPHA16_SNORM, 0 },
1024 { PIPE_FORMAT_L16A16_SNORM, PIPE_FORMAT_R16G16B16A16_SNORM,
1025 PIPE_FORMAT_L8A8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1026 },
1027 {
1028 { GL_INTENSITY_SNORM, GL_INTENSITY8_SNORM, 0 },
1029 { PIPE_FORMAT_I8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1030 },
1031 {
1032 { GL_INTENSITY16_SNORM, 0 },
1033 { PIPE_FORMAT_I16_SNORM, PIPE_FORMAT_R16G16B16A16_SNORM,
1034 PIPE_FORMAT_I8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1035 },
1036 {
1037 { GL_RGB9_E5, 0 },
1038 { PIPE_FORMAT_R9G9B9E5_FLOAT, 0 }
1039 },
1040 {
1041 { GL_R11F_G11F_B10F, 0 },
1042 { PIPE_FORMAT_R11G11B10_FLOAT, 0 }
1043 },
1044 {
1045 { GL_RGB10_A2UI, 0 },
1046 { PIPE_FORMAT_R10G10B10A2_UINT, PIPE_FORMAT_B10G10R10A2_UINT, 0 }
1047 },
1048 };
1049
1050
1051 /**
1052 * Return first supported format from the given list.
1053 * \param allow_dxt indicates whether it's OK to return a DXT format.
1054 */
1055 static enum pipe_format
find_supported_format(struct pipe_screen * screen,const enum pipe_format formats[],enum pipe_texture_target target,unsigned sample_count,unsigned storage_sample_count,unsigned bindings,boolean allow_dxt)1056 find_supported_format(struct pipe_screen *screen,
1057 const enum pipe_format formats[],
1058 enum pipe_texture_target target,
1059 unsigned sample_count,
1060 unsigned storage_sample_count,
1061 unsigned bindings,
1062 boolean allow_dxt)
1063 {
1064 uint i;
1065 for (i = 0; formats[i]; i++) {
1066 if (screen->is_format_supported(screen, formats[i], target,
1067 sample_count, storage_sample_count,
1068 bindings)) {
1069 if (!allow_dxt && util_format_is_s3tc(formats[i])) {
1070 /* we can't return a dxt format, continue searching */
1071 continue;
1072 }
1073
1074 return formats[i];
1075 }
1076 }
1077 return PIPE_FORMAT_NONE;
1078 }
1079
1080 /**
1081 * Given an OpenGL internalFormat value for a texture or surface, return
1082 * the best matching PIPE_FORMAT_x, or PIPE_FORMAT_NONE if there's no match.
1083 * This is called during glTexImage2D, for example.
1084 *
1085 * The bindings parameter typically has PIPE_BIND_SAMPLER_VIEW set, plus
1086 * either PIPE_BINDING_RENDER_TARGET or PIPE_BINDING_DEPTH_STENCIL if
1087 * we want render-to-texture ability.
1088 *
1089 * \param internalFormat the user value passed to glTexImage2D
1090 * \param target one of PIPE_TEXTURE_x
1091 * \param bindings bitmask of PIPE_BIND_x flags.
1092 * \param allow_dxt indicates whether it's OK to return a DXT format. This
1093 * only matters when internalFormat names a generic or
1094 * specific compressed format. And that should only happen
1095 * when we're getting called from gl[Copy]TexImage().
1096 */
1097 enum pipe_format
st_choose_format(struct st_context * st,GLenum internalFormat,GLenum format,GLenum type,enum pipe_texture_target target,unsigned sample_count,unsigned storage_sample_count,unsigned bindings,bool swap_bytes,bool allow_dxt)1098 st_choose_format(struct st_context *st, GLenum internalFormat,
1099 GLenum format, GLenum type,
1100 enum pipe_texture_target target, unsigned sample_count,
1101 unsigned storage_sample_count,
1102 unsigned bindings, bool swap_bytes, bool allow_dxt)
1103 {
1104 struct pipe_screen *screen = st->pipe->screen;
1105 unsigned i;
1106 int j;
1107 enum pipe_format pf;
1108
1109 /* can't render to compressed formats at this time */
1110 if (_mesa_is_compressed_format(st->ctx, internalFormat)
1111 && (bindings & ~PIPE_BIND_SAMPLER_VIEW)) {
1112 return PIPE_FORMAT_NONE;
1113 }
1114
1115 /* If we have an unsized internalFormat, and the driver supports a format
1116 * that exactly matches format/type such that we can just memcpy, pick that
1117 * (unless the format wouldn't still be unorm, which is the expectation for
1118 * unsized formats).
1119 */
1120 if (_mesa_is_enum_format_unsized(internalFormat) && format != 0 &&
1121 _mesa_is_type_unsigned(type)) {
1122 pf = st_choose_matching_format(st, bindings, format, type,
1123 swap_bytes);
1124
1125 if (pf != PIPE_FORMAT_NONE &&
1126 screen->is_format_supported(screen, pf, target, sample_count,
1127 storage_sample_count, bindings) &&
1128 _mesa_get_format_base_format(st_pipe_format_to_mesa_format(pf)) ==
1129 internalFormat) {
1130 goto success;
1131 }
1132 }
1133
1134 /* For an unsized GL_RGB but a 2_10_10_10 type, try to pick one of the
1135 * 2_10_10_10 formats. This is important for
1136 * GL_EXT_texture_type_2_10_10_10_EXT support, which says that these
1137 * formats are not color-renderable. Mesa's check for making those
1138 * non-color-renderable is based on our chosen format being 2101010.
1139 */
1140 if (type == GL_UNSIGNED_INT_2_10_10_10_REV) {
1141 if (internalFormat == GL_RGB)
1142 internalFormat = GL_RGB10;
1143 else if (internalFormat == GL_RGBA)
1144 internalFormat = GL_RGB10_A2;
1145 }
1146
1147 if (type == GL_UNSIGNED_SHORT_5_5_5_1) {
1148 if (internalFormat == GL_RGB)
1149 internalFormat = GL_RGB5;
1150 else if (internalFormat == GL_RGBA)
1151 internalFormat = GL_RGB5_A1;
1152 }
1153
1154 /* search table for internalFormat */
1155 for (i = 0; i < ARRAY_SIZE(format_map); i++) {
1156 const struct format_mapping *mapping = &format_map[i];
1157 for (j = 0; mapping->glFormats[j]; j++) {
1158 if (mapping->glFormats[j] == internalFormat) {
1159 /* Found the desired internal format. Find first pipe format
1160 * which is supported by the driver.
1161 */
1162 pf = find_supported_format(screen, mapping->pipeFormats,
1163 target, sample_count,
1164 storage_sample_count, bindings,
1165 allow_dxt);
1166 goto success;
1167 }
1168 }
1169 }
1170
1171 _mesa_problem(NULL, "unhandled format!\n");
1172 return PIPE_FORMAT_NONE;
1173
1174 success:
1175 if (0) {
1176 debug_printf("%s(fmt=%s, type=%s, intFmt=%s) = %s\n",
1177 __FUNCTION__,
1178 _mesa_enum_to_string(format),
1179 _mesa_enum_to_string(type),
1180 _mesa_enum_to_string(internalFormat),
1181 util_format_name(pf));
1182 }
1183 return pf;
1184 }
1185
1186
1187 /**
1188 * Called by FBO code to choose a PIPE_FORMAT_ for drawing surfaces.
1189 */
1190 enum pipe_format
st_choose_renderbuffer_format(struct st_context * st,GLenum internalFormat,unsigned sample_count,unsigned storage_sample_count)1191 st_choose_renderbuffer_format(struct st_context *st,
1192 GLenum internalFormat, unsigned sample_count,
1193 unsigned storage_sample_count)
1194 {
1195 unsigned bindings;
1196 if (_mesa_is_depth_or_stencil_format(internalFormat))
1197 bindings = PIPE_BIND_DEPTH_STENCIL;
1198 else
1199 bindings = PIPE_BIND_RENDER_TARGET;
1200 return st_choose_format(st, internalFormat, GL_NONE, GL_NONE,
1201 PIPE_TEXTURE_2D, sample_count,
1202 storage_sample_count, bindings,
1203 false, false);
1204 }
1205
1206
1207 /**
1208 * Given an OpenGL user-requested format and type, and swapBytes state,
1209 * return the format which exactly matches those parameters, so that
1210 * a memcpy-based transfer can be done.
1211 *
1212 * If no format is supported, return PIPE_FORMAT_NONE.
1213 */
1214 enum pipe_format
st_choose_matching_format(struct st_context * st,unsigned bind,GLenum format,GLenum type,GLboolean swapBytes)1215 st_choose_matching_format(struct st_context *st, unsigned bind,
1216 GLenum format, GLenum type, GLboolean swapBytes)
1217 {
1218 struct pipe_screen *screen = st->pipe->screen;
1219
1220 if (swapBytes && !_mesa_swap_bytes_in_type_enum(&type))
1221 return PIPE_FORMAT_NONE;
1222
1223 mesa_format mesa_format = _mesa_format_from_format_and_type(format, type);
1224 if (_mesa_format_is_mesa_array_format(mesa_format))
1225 mesa_format = _mesa_format_from_array_format(mesa_format);
1226 if (mesa_format != MESA_FORMAT_NONE) {
1227 enum pipe_format format = st_mesa_format_to_pipe_format(st, mesa_format);
1228 if (format != PIPE_FORMAT_NONE &&
1229 screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0, 0, bind))
1230 return format;
1231 }
1232
1233 return PIPE_FORMAT_NONE;
1234 }
1235
1236
1237 /**
1238 * Called via ctx->Driver.ChooseTextureFormat().
1239 */
1240 mesa_format
st_ChooseTextureFormat(struct gl_context * ctx,GLenum target,GLint internalFormat,GLenum format,GLenum type)1241 st_ChooseTextureFormat(struct gl_context *ctx, GLenum target,
1242 GLint internalFormat,
1243 GLenum format, GLenum type)
1244 {
1245 struct st_context *st = st_context(ctx);
1246 enum pipe_format pFormat;
1247 mesa_format mFormat;
1248 unsigned bindings;
1249 bool is_renderbuffer = false;
1250 enum pipe_texture_target pTarget;
1251
1252 if (target == GL_RENDERBUFFER) {
1253 pTarget = PIPE_TEXTURE_2D;
1254 is_renderbuffer = true;
1255 } else {
1256 pTarget = gl_target_to_pipe(target);
1257 }
1258
1259 if (target == GL_TEXTURE_1D || target == GL_TEXTURE_1D_ARRAY) {
1260 /* We don't do compression for these texture targets because of
1261 * difficulty with sub-texture updates on non-block boundaries, etc.
1262 * So change the internal format request to an uncompressed format.
1263 */
1264 internalFormat =
1265 _mesa_generic_compressed_format_to_uncompressed_format(internalFormat);
1266 }
1267
1268 /* GL textures may wind up being render targets, but we don't know
1269 * that in advance. Specify potential render target flags now for formats
1270 * that we know should always be renderable.
1271 */
1272 bindings = PIPE_BIND_SAMPLER_VIEW;
1273 if (_mesa_is_depth_or_stencil_format(internalFormat))
1274 bindings |= PIPE_BIND_DEPTH_STENCIL;
1275 else if (is_renderbuffer || internalFormat == 3 || internalFormat == 4 ||
1276 internalFormat == GL_RGB || internalFormat == GL_RGBA ||
1277 internalFormat == GL_RGBA2 ||
1278 internalFormat == GL_RGB4 || internalFormat == GL_RGBA4 ||
1279 internalFormat == GL_RGB8 || internalFormat == GL_RGBA8 ||
1280 internalFormat == GL_BGRA ||
1281 internalFormat == GL_RGB16F ||
1282 internalFormat == GL_RGBA16F ||
1283 internalFormat == GL_RGB32F ||
1284 internalFormat == GL_RGBA32F ||
1285 internalFormat == GL_RED ||
1286 internalFormat == GL_RED_SNORM ||
1287 internalFormat == GL_R8I ||
1288 internalFormat == GL_R8UI)
1289 bindings |= PIPE_BIND_RENDER_TARGET;
1290
1291 /* GLES allows the driver to choose any format which matches
1292 * the format+type combo, because GLES only supports unsized internal
1293 * formats and expects the driver to choose whatever suits it.
1294 */
1295 if (_mesa_is_gles(ctx)) {
1296 GLenum baseFormat = _mesa_base_tex_format(ctx, internalFormat);
1297 GLenum basePackFormat = _mesa_base_pack_format(format);
1298 GLenum iformat = internalFormat;
1299
1300 /* Treat GL_BGRA as GL_RGBA. */
1301 if (iformat == GL_BGRA)
1302 iformat = GL_RGBA;
1303
1304 /* Check if the internalformat is unsized and compatible
1305 * with the "format".
1306 */
1307 if (iformat == baseFormat && iformat == basePackFormat) {
1308 pFormat = st_choose_matching_format(st, bindings, format, type,
1309 ctx->Unpack.SwapBytes);
1310
1311 if (pFormat != PIPE_FORMAT_NONE)
1312 return st_pipe_format_to_mesa_format(pFormat);
1313
1314 if (!is_renderbuffer) {
1315 /* try choosing format again, this time without render
1316 * target bindings.
1317 */
1318 pFormat = st_choose_matching_format(st, PIPE_BIND_SAMPLER_VIEW,
1319 format, type,
1320 ctx->Unpack.SwapBytes);
1321 if (pFormat != PIPE_FORMAT_NONE)
1322 return st_pipe_format_to_mesa_format(pFormat);
1323 }
1324 }
1325 }
1326
1327 pFormat = st_choose_format(st, internalFormat, format, type,
1328 pTarget, 0, 0, bindings,
1329 ctx->Unpack.SwapBytes, true);
1330
1331 if (pFormat == PIPE_FORMAT_NONE && !is_renderbuffer) {
1332 /* try choosing format again, this time without render target bindings */
1333 pFormat = st_choose_format(st, internalFormat, format, type,
1334 pTarget, 0, 0, PIPE_BIND_SAMPLER_VIEW,
1335 ctx->Unpack.SwapBytes, true);
1336 }
1337
1338 if (pFormat == PIPE_FORMAT_NONE) {
1339 mFormat = _mesa_glenum_to_compressed_format(internalFormat);
1340 if (st_compressed_format_fallback(st, mFormat))
1341 return mFormat;
1342
1343 /* no luck at all */
1344 return MESA_FORMAT_NONE;
1345 }
1346
1347 mFormat = st_pipe_format_to_mesa_format(pFormat);
1348
1349 /* Debugging aid */
1350 if (0) {
1351 debug_printf("%s(intFormat=%s, format=%s, type=%s) -> %s, %s\n",
1352 __func__,
1353 _mesa_enum_to_string(internalFormat),
1354 _mesa_enum_to_string(format),
1355 _mesa_enum_to_string(type),
1356 util_format_name(pFormat),
1357 _mesa_get_format_name(mFormat));
1358 }
1359
1360 return mFormat;
1361 }
1362
1363
1364 /**
1365 * Called via ctx->Driver.QueryInternalFormat().
1366 */
1367 static size_t
st_QuerySamplesForFormat(struct gl_context * ctx,GLenum target,GLenum internalFormat,int samples[16])1368 st_QuerySamplesForFormat(struct gl_context *ctx, GLenum target,
1369 GLenum internalFormat, int samples[16])
1370 {
1371 struct st_context *st = st_context(ctx);
1372 enum pipe_format format;
1373 unsigned i, bind, num_sample_counts = 0;
1374
1375 (void) target;
1376
1377 if (_mesa_is_depth_or_stencil_format(internalFormat))
1378 bind = PIPE_BIND_DEPTH_STENCIL;
1379 else
1380 bind = PIPE_BIND_RENDER_TARGET;
1381
1382 /* If an sRGB framebuffer is unsupported, sRGB formats behave like linear
1383 * formats.
1384 */
1385 if (!ctx->Extensions.EXT_sRGB) {
1386 internalFormat = _mesa_get_linear_internalformat(internalFormat);
1387 }
1388
1389 /* Set sample counts in descending order. */
1390 for (i = 16; i > 1; i--) {
1391 format = st_choose_format(st, internalFormat, GL_NONE, GL_NONE,
1392 PIPE_TEXTURE_2D, i, i, bind,
1393 false, false);
1394
1395 if (format != PIPE_FORMAT_NONE) {
1396 samples[num_sample_counts++] = i;
1397 }
1398 }
1399
1400 if (!num_sample_counts) {
1401 samples[num_sample_counts++] = 1;
1402 }
1403
1404 return num_sample_counts;
1405 }
1406
1407
1408 /**
1409 * ARB_internalformat_query2 driver hook.
1410 */
1411 void
st_QueryInternalFormat(struct gl_context * ctx,GLenum target,GLenum internalFormat,GLenum pname,GLint * params)1412 st_QueryInternalFormat(struct gl_context *ctx, GLenum target,
1413 GLenum internalFormat, GLenum pname, GLint *params)
1414 {
1415 struct st_context *st = st_context(ctx);
1416 /* The API entry-point gives us a temporary params buffer that is non-NULL
1417 * and guaranteed to have at least 16 elements.
1418 */
1419 assert(params != NULL);
1420
1421 switch (pname) {
1422 case GL_SAMPLES:
1423 st_QuerySamplesForFormat(ctx, target, internalFormat, params);
1424 break;
1425
1426 case GL_NUM_SAMPLE_COUNTS: {
1427 int samples[16];
1428 size_t num_samples;
1429 num_samples = st_QuerySamplesForFormat(ctx, target, internalFormat,
1430 samples);
1431 params[0] = (GLint) num_samples;
1432 break;
1433 }
1434 case GL_INTERNALFORMAT_PREFERRED: {
1435 params[0] = GL_NONE;
1436
1437 /* We need to resolve an internal format that is compatible with
1438 * the passed internal format, and optimal to the driver. By now,
1439 * we just validate that the passed internal format is supported by
1440 * the driver, and if so return the same internal format, otherwise
1441 * return GL_NONE.
1442 */
1443 unsigned bindings;
1444 if (_mesa_is_depth_or_stencil_format(internalFormat))
1445 bindings = PIPE_BIND_DEPTH_STENCIL;
1446 else
1447 bindings = PIPE_BIND_RENDER_TARGET;
1448 enum pipe_format pformat = st_choose_format(st,
1449 internalFormat,
1450 GL_NONE,
1451 GL_NONE,
1452 PIPE_TEXTURE_2D, 0, 0,
1453 bindings,
1454 false, false);
1455 if (pformat)
1456 params[0] = internalFormat;
1457 break;
1458 }
1459 default:
1460 /* For the rest of the pnames, we call back the Mesa's default
1461 * function for drivers that don't implement ARB_internalformat_query2.
1462 */
1463 _mesa_query_internal_format_default(ctx, target, internalFormat, pname,
1464 params);
1465 }
1466 }
1467
1468
1469 /**
1470 * This is used for translating texture border color and the clear
1471 * color. For example, the clear color is interpreted according to
1472 * the renderbuffer's base format. For example, if clearing a
1473 * GL_LUMINANCE buffer, we'll return colorOut[0] = colorOut[1] =
1474 * colorOut[2] = colorIn[0].
1475 * Similarly for texture border colors.
1476 */
1477 void
st_translate_color(const union gl_color_union * colorIn,union pipe_color_union * colorOut,GLenum baseFormat,GLboolean is_integer)1478 st_translate_color(const union gl_color_union *colorIn,
1479 union pipe_color_union *colorOut,
1480 GLenum baseFormat, GLboolean is_integer)
1481 {
1482 if (is_integer) {
1483 const int *in = colorIn->i;
1484 int *out = colorOut->i;
1485
1486 switch (baseFormat) {
1487 case GL_RED:
1488 out[0] = in[0];
1489 out[1] = 0;
1490 out[2] = 0;
1491 out[3] = 1;
1492 break;
1493 case GL_RG:
1494 out[0] = in[0];
1495 out[1] = in[1];
1496 out[2] = 0;
1497 out[3] = 1;
1498 break;
1499 case GL_RGB:
1500 out[0] = in[0];
1501 out[1] = in[1];
1502 out[2] = in[2];
1503 out[3] = 1;
1504 break;
1505 case GL_ALPHA:
1506 out[0] = out[1] = out[2] = 0;
1507 out[3] = in[3];
1508 break;
1509 case GL_LUMINANCE:
1510 out[0] = out[1] = out[2] = in[0];
1511 out[3] = 1;
1512 break;
1513 case GL_LUMINANCE_ALPHA:
1514 out[0] = out[1] = out[2] = in[0];
1515 out[3] = in[3];
1516 break;
1517 case GL_INTENSITY:
1518 out[0] = out[1] = out[2] = out[3] = in[0];
1519 break;
1520 default:
1521 COPY_4V(out, in);
1522 }
1523 }
1524 else {
1525 const float *in = colorIn->f;
1526 float *out = colorOut->f;
1527
1528 switch (baseFormat) {
1529 case GL_RED:
1530 out[0] = in[0];
1531 out[1] = 0.0F;
1532 out[2] = 0.0F;
1533 out[3] = 1.0F;
1534 break;
1535 case GL_RG:
1536 out[0] = in[0];
1537 out[1] = in[1];
1538 out[2] = 0.0F;
1539 out[3] = 1.0F;
1540 break;
1541 case GL_RGB:
1542 out[0] = in[0];
1543 out[1] = in[1];
1544 out[2] = in[2];
1545 out[3] = 1.0F;
1546 break;
1547 case GL_ALPHA:
1548 out[0] = out[1] = out[2] = 0.0F;
1549 out[3] = in[3];
1550 break;
1551 case GL_LUMINANCE:
1552 out[0] = out[1] = out[2] = in[0];
1553 out[3] = 1.0F;
1554 break;
1555 case GL_LUMINANCE_ALPHA:
1556 out[0] = out[1] = out[2] = in[0];
1557 out[3] = in[3];
1558 break;
1559 /* Stencil border is tricky on some hw. Help drivers a little here. */
1560 case GL_STENCIL_INDEX:
1561 case GL_INTENSITY:
1562 out[0] = out[1] = out[2] = out[3] = in[0];
1563 break;
1564 default:
1565 COPY_4V(out, in);
1566 }
1567 }
1568 }
1569