1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (c) 2011 VMware, Inc.
5 * Copyright (c) 2014 Intel Corporation.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /**
28 * Color, depth, stencil packing functions.
29 * Used to pack basic color, depth and stencil formats to specific
30 * hardware formats.
31 *
32 * There are both per-pixel and per-row packing functions:
33 * - The former will be used by swrast to write values to the color, depth,
34 * stencil buffers when drawing points, lines and masked spans.
35 * - The later will be used for image-oriented functions like glDrawPixels,
36 * glAccum, and glTexImage.
37 */
38
39 #include <stdint.h>
40
41 #include "format_pack.h"
42 #include "format_utils.h"
43 #include "macros.h"
44 #include "util/format_rgb9e5.h"
45 #include "util/format_r11g11b10f.h"
46 #include "util/format_srgb.h"
47
48 #define UNPACK(SRC, OFFSET, BITS) (((SRC) >> (OFFSET)) & MAX_UINT(BITS))
49 #define PACK(SRC, OFFSET, BITS) (((SRC) & MAX_UINT(BITS)) << (OFFSET))
50
51
52
53 /* ubyte packing functions */
54
55
56 static inline void
pack_ubyte_a8b8g8r8_unorm(const uint8_t src[4],void * dst)57 pack_ubyte_a8b8g8r8_unorm(const uint8_t src[4], void *dst)
58 {
59
60
61 uint8_t a =
62 _mesa_unorm_to_unorm(src[3], 8, 8);
63
64
65 uint8_t b =
66 _mesa_unorm_to_unorm(src[2], 8, 8);
67
68
69 uint8_t g =
70 _mesa_unorm_to_unorm(src[1], 8, 8);
71
72
73 uint8_t r =
74 _mesa_unorm_to_unorm(src[0], 8, 8);
75
76 uint32_t d = 0;
77 d |= PACK(a, 0, 8);
78 d |= PACK(b, 8, 8);
79 d |= PACK(g, 16, 8);
80 d |= PACK(r, 24, 8);
81 (*(uint32_t *)dst) = d;
82 }
83
84 static inline void
pack_ubyte_x8b8g8r8_unorm(const uint8_t src[4],void * dst)85 pack_ubyte_x8b8g8r8_unorm(const uint8_t src[4], void *dst)
86 {
87
88
89
90 uint8_t b =
91 _mesa_unorm_to_unorm(src[2], 8, 8);
92
93
94 uint8_t g =
95 _mesa_unorm_to_unorm(src[1], 8, 8);
96
97
98 uint8_t r =
99 _mesa_unorm_to_unorm(src[0], 8, 8);
100
101 uint32_t d = 0;
102 d |= PACK(b, 8, 8);
103 d |= PACK(g, 16, 8);
104 d |= PACK(r, 24, 8);
105 (*(uint32_t *)dst) = d;
106 }
107
108 static inline void
pack_ubyte_r8g8b8a8_unorm(const uint8_t src[4],void * dst)109 pack_ubyte_r8g8b8a8_unorm(const uint8_t src[4], void *dst)
110 {
111
112
113 uint8_t r =
114 _mesa_unorm_to_unorm(src[0], 8, 8);
115
116
117 uint8_t g =
118 _mesa_unorm_to_unorm(src[1], 8, 8);
119
120
121 uint8_t b =
122 _mesa_unorm_to_unorm(src[2], 8, 8);
123
124
125 uint8_t a =
126 _mesa_unorm_to_unorm(src[3], 8, 8);
127
128 uint32_t d = 0;
129 d |= PACK(r, 0, 8);
130 d |= PACK(g, 8, 8);
131 d |= PACK(b, 16, 8);
132 d |= PACK(a, 24, 8);
133 (*(uint32_t *)dst) = d;
134 }
135
136 static inline void
pack_ubyte_r8g8b8x8_unorm(const uint8_t src[4],void * dst)137 pack_ubyte_r8g8b8x8_unorm(const uint8_t src[4], void *dst)
138 {
139
140
141 uint8_t r =
142 _mesa_unorm_to_unorm(src[0], 8, 8);
143
144
145 uint8_t g =
146 _mesa_unorm_to_unorm(src[1], 8, 8);
147
148
149 uint8_t b =
150 _mesa_unorm_to_unorm(src[2], 8, 8);
151
152
153 uint32_t d = 0;
154 d |= PACK(r, 0, 8);
155 d |= PACK(g, 8, 8);
156 d |= PACK(b, 16, 8);
157 (*(uint32_t *)dst) = d;
158 }
159
160 static inline void
pack_ubyte_b8g8r8a8_unorm(const uint8_t src[4],void * dst)161 pack_ubyte_b8g8r8a8_unorm(const uint8_t src[4], void *dst)
162 {
163
164
165 uint8_t b =
166 _mesa_unorm_to_unorm(src[2], 8, 8);
167
168
169 uint8_t g =
170 _mesa_unorm_to_unorm(src[1], 8, 8);
171
172
173 uint8_t r =
174 _mesa_unorm_to_unorm(src[0], 8, 8);
175
176
177 uint8_t a =
178 _mesa_unorm_to_unorm(src[3], 8, 8);
179
180 uint32_t d = 0;
181 d |= PACK(b, 0, 8);
182 d |= PACK(g, 8, 8);
183 d |= PACK(r, 16, 8);
184 d |= PACK(a, 24, 8);
185 (*(uint32_t *)dst) = d;
186 }
187
188 static inline void
pack_ubyte_b8g8r8x8_unorm(const uint8_t src[4],void * dst)189 pack_ubyte_b8g8r8x8_unorm(const uint8_t src[4], void *dst)
190 {
191
192
193 uint8_t b =
194 _mesa_unorm_to_unorm(src[2], 8, 8);
195
196
197 uint8_t g =
198 _mesa_unorm_to_unorm(src[1], 8, 8);
199
200
201 uint8_t r =
202 _mesa_unorm_to_unorm(src[0], 8, 8);
203
204
205 uint32_t d = 0;
206 d |= PACK(b, 0, 8);
207 d |= PACK(g, 8, 8);
208 d |= PACK(r, 16, 8);
209 (*(uint32_t *)dst) = d;
210 }
211
212 static inline void
pack_ubyte_a8r8g8b8_unorm(const uint8_t src[4],void * dst)213 pack_ubyte_a8r8g8b8_unorm(const uint8_t src[4], void *dst)
214 {
215
216
217 uint8_t a =
218 _mesa_unorm_to_unorm(src[3], 8, 8);
219
220
221 uint8_t r =
222 _mesa_unorm_to_unorm(src[0], 8, 8);
223
224
225 uint8_t g =
226 _mesa_unorm_to_unorm(src[1], 8, 8);
227
228
229 uint8_t b =
230 _mesa_unorm_to_unorm(src[2], 8, 8);
231
232 uint32_t d = 0;
233 d |= PACK(a, 0, 8);
234 d |= PACK(r, 8, 8);
235 d |= PACK(g, 16, 8);
236 d |= PACK(b, 24, 8);
237 (*(uint32_t *)dst) = d;
238 }
239
240 static inline void
pack_ubyte_x8r8g8b8_unorm(const uint8_t src[4],void * dst)241 pack_ubyte_x8r8g8b8_unorm(const uint8_t src[4], void *dst)
242 {
243
244
245
246 uint8_t r =
247 _mesa_unorm_to_unorm(src[0], 8, 8);
248
249
250 uint8_t g =
251 _mesa_unorm_to_unorm(src[1], 8, 8);
252
253
254 uint8_t b =
255 _mesa_unorm_to_unorm(src[2], 8, 8);
256
257 uint32_t d = 0;
258 d |= PACK(r, 8, 8);
259 d |= PACK(g, 16, 8);
260 d |= PACK(b, 24, 8);
261 (*(uint32_t *)dst) = d;
262 }
263
264 static inline void
pack_ubyte_b5g6r5_unorm(const uint8_t src[4],void * dst)265 pack_ubyte_b5g6r5_unorm(const uint8_t src[4], void *dst)
266 {
267
268
269 uint8_t b =
270 _mesa_unorm_to_unorm(src[2], 8, 5);
271
272
273 uint8_t g =
274 _mesa_unorm_to_unorm(src[1], 8, 6);
275
276
277 uint8_t r =
278 _mesa_unorm_to_unorm(src[0], 8, 5);
279
280 uint16_t d = 0;
281 d |= PACK(b, 0, 5);
282 d |= PACK(g, 5, 6);
283 d |= PACK(r, 11, 5);
284 (*(uint16_t *)dst) = d;
285 }
286
287 static inline void
pack_ubyte_r5g6b5_unorm(const uint8_t src[4],void * dst)288 pack_ubyte_r5g6b5_unorm(const uint8_t src[4], void *dst)
289 {
290
291
292 uint8_t r =
293 _mesa_unorm_to_unorm(src[0], 8, 5);
294
295
296 uint8_t g =
297 _mesa_unorm_to_unorm(src[1], 8, 6);
298
299
300 uint8_t b =
301 _mesa_unorm_to_unorm(src[2], 8, 5);
302
303 uint16_t d = 0;
304 d |= PACK(r, 0, 5);
305 d |= PACK(g, 5, 6);
306 d |= PACK(b, 11, 5);
307 (*(uint16_t *)dst) = d;
308 }
309
310 static inline void
pack_ubyte_b4g4r4a4_unorm(const uint8_t src[4],void * dst)311 pack_ubyte_b4g4r4a4_unorm(const uint8_t src[4], void *dst)
312 {
313
314
315 uint8_t b =
316 _mesa_unorm_to_unorm(src[2], 8, 4);
317
318
319 uint8_t g =
320 _mesa_unorm_to_unorm(src[1], 8, 4);
321
322
323 uint8_t r =
324 _mesa_unorm_to_unorm(src[0], 8, 4);
325
326
327 uint8_t a =
328 _mesa_unorm_to_unorm(src[3], 8, 4);
329
330 uint16_t d = 0;
331 d |= PACK(b, 0, 4);
332 d |= PACK(g, 4, 4);
333 d |= PACK(r, 8, 4);
334 d |= PACK(a, 12, 4);
335 (*(uint16_t *)dst) = d;
336 }
337
338 static inline void
pack_ubyte_b4g4r4x4_unorm(const uint8_t src[4],void * dst)339 pack_ubyte_b4g4r4x4_unorm(const uint8_t src[4], void *dst)
340 {
341
342
343 uint8_t b =
344 _mesa_unorm_to_unorm(src[2], 8, 4);
345
346
347 uint8_t g =
348 _mesa_unorm_to_unorm(src[1], 8, 4);
349
350
351 uint8_t r =
352 _mesa_unorm_to_unorm(src[0], 8, 4);
353
354
355 uint16_t d = 0;
356 d |= PACK(b, 0, 4);
357 d |= PACK(g, 4, 4);
358 d |= PACK(r, 8, 4);
359 (*(uint16_t *)dst) = d;
360 }
361
362 static inline void
pack_ubyte_a4r4g4b4_unorm(const uint8_t src[4],void * dst)363 pack_ubyte_a4r4g4b4_unorm(const uint8_t src[4], void *dst)
364 {
365
366
367 uint8_t a =
368 _mesa_unorm_to_unorm(src[3], 8, 4);
369
370
371 uint8_t r =
372 _mesa_unorm_to_unorm(src[0], 8, 4);
373
374
375 uint8_t g =
376 _mesa_unorm_to_unorm(src[1], 8, 4);
377
378
379 uint8_t b =
380 _mesa_unorm_to_unorm(src[2], 8, 4);
381
382 uint16_t d = 0;
383 d |= PACK(a, 0, 4);
384 d |= PACK(r, 4, 4);
385 d |= PACK(g, 8, 4);
386 d |= PACK(b, 12, 4);
387 (*(uint16_t *)dst) = d;
388 }
389
390 static inline void
pack_ubyte_a1b5g5r5_unorm(const uint8_t src[4],void * dst)391 pack_ubyte_a1b5g5r5_unorm(const uint8_t src[4], void *dst)
392 {
393
394
395 uint8_t a =
396 _mesa_unorm_to_unorm(src[3], 8, 1);
397
398
399 uint8_t b =
400 _mesa_unorm_to_unorm(src[2], 8, 5);
401
402
403 uint8_t g =
404 _mesa_unorm_to_unorm(src[1], 8, 5);
405
406
407 uint8_t r =
408 _mesa_unorm_to_unorm(src[0], 8, 5);
409
410 uint16_t d = 0;
411 d |= PACK(a, 0, 1);
412 d |= PACK(b, 1, 5);
413 d |= PACK(g, 6, 5);
414 d |= PACK(r, 11, 5);
415 (*(uint16_t *)dst) = d;
416 }
417
418 static inline void
pack_ubyte_x1b5g5r5_unorm(const uint8_t src[4],void * dst)419 pack_ubyte_x1b5g5r5_unorm(const uint8_t src[4], void *dst)
420 {
421
422
423
424 uint8_t b =
425 _mesa_unorm_to_unorm(src[2], 8, 5);
426
427
428 uint8_t g =
429 _mesa_unorm_to_unorm(src[1], 8, 5);
430
431
432 uint8_t r =
433 _mesa_unorm_to_unorm(src[0], 8, 5);
434
435 uint16_t d = 0;
436 d |= PACK(b, 1, 5);
437 d |= PACK(g, 6, 5);
438 d |= PACK(r, 11, 5);
439 (*(uint16_t *)dst) = d;
440 }
441
442 static inline void
pack_ubyte_b5g5r5a1_unorm(const uint8_t src[4],void * dst)443 pack_ubyte_b5g5r5a1_unorm(const uint8_t src[4], void *dst)
444 {
445
446
447 uint8_t b =
448 _mesa_unorm_to_unorm(src[2], 8, 5);
449
450
451 uint8_t g =
452 _mesa_unorm_to_unorm(src[1], 8, 5);
453
454
455 uint8_t r =
456 _mesa_unorm_to_unorm(src[0], 8, 5);
457
458
459 uint8_t a =
460 _mesa_unorm_to_unorm(src[3], 8, 1);
461
462 uint16_t d = 0;
463 d |= PACK(b, 0, 5);
464 d |= PACK(g, 5, 5);
465 d |= PACK(r, 10, 5);
466 d |= PACK(a, 15, 1);
467 (*(uint16_t *)dst) = d;
468 }
469
470 static inline void
pack_ubyte_b5g5r5x1_unorm(const uint8_t src[4],void * dst)471 pack_ubyte_b5g5r5x1_unorm(const uint8_t src[4], void *dst)
472 {
473
474
475 uint8_t b =
476 _mesa_unorm_to_unorm(src[2], 8, 5);
477
478
479 uint8_t g =
480 _mesa_unorm_to_unorm(src[1], 8, 5);
481
482
483 uint8_t r =
484 _mesa_unorm_to_unorm(src[0], 8, 5);
485
486
487 uint16_t d = 0;
488 d |= PACK(b, 0, 5);
489 d |= PACK(g, 5, 5);
490 d |= PACK(r, 10, 5);
491 (*(uint16_t *)dst) = d;
492 }
493
494 static inline void
pack_ubyte_a1r5g5b5_unorm(const uint8_t src[4],void * dst)495 pack_ubyte_a1r5g5b5_unorm(const uint8_t src[4], void *dst)
496 {
497
498
499 uint8_t a =
500 _mesa_unorm_to_unorm(src[3], 8, 1);
501
502
503 uint8_t r =
504 _mesa_unorm_to_unorm(src[0], 8, 5);
505
506
507 uint8_t g =
508 _mesa_unorm_to_unorm(src[1], 8, 5);
509
510
511 uint8_t b =
512 _mesa_unorm_to_unorm(src[2], 8, 5);
513
514 uint16_t d = 0;
515 d |= PACK(a, 0, 1);
516 d |= PACK(r, 1, 5);
517 d |= PACK(g, 6, 5);
518 d |= PACK(b, 11, 5);
519 (*(uint16_t *)dst) = d;
520 }
521
522 static inline void
pack_ubyte_l4a4_unorm(const uint8_t src[4],void * dst)523 pack_ubyte_l4a4_unorm(const uint8_t src[4], void *dst)
524 {
525
526
527 uint8_t l =
528 _mesa_unorm_to_unorm(src[0], 8, 4);
529
530
531 uint8_t a =
532 _mesa_unorm_to_unorm(src[3], 8, 4);
533
534 uint8_t d = 0;
535 d |= PACK(l, 0, 4);
536 d |= PACK(a, 4, 4);
537 (*(uint8_t *)dst) = d;
538 }
539
540 static inline void
pack_ubyte_b2g3r3_unorm(const uint8_t src[4],void * dst)541 pack_ubyte_b2g3r3_unorm(const uint8_t src[4], void *dst)
542 {
543
544
545 uint8_t b =
546 _mesa_unorm_to_unorm(src[2], 8, 2);
547
548
549 uint8_t g =
550 _mesa_unorm_to_unorm(src[1], 8, 3);
551
552
553 uint8_t r =
554 _mesa_unorm_to_unorm(src[0], 8, 3);
555
556 uint8_t d = 0;
557 d |= PACK(b, 0, 2);
558 d |= PACK(g, 2, 3);
559 d |= PACK(r, 5, 3);
560 (*(uint8_t *)dst) = d;
561 }
562
563 static inline void
pack_ubyte_b10g10r10a2_unorm(const uint8_t src[4],void * dst)564 pack_ubyte_b10g10r10a2_unorm(const uint8_t src[4], void *dst)
565 {
566
567
568 uint16_t b =
569 _mesa_unorm_to_unorm(src[2], 8, 10);
570
571
572 uint16_t g =
573 _mesa_unorm_to_unorm(src[1], 8, 10);
574
575
576 uint16_t r =
577 _mesa_unorm_to_unorm(src[0], 8, 10);
578
579
580 uint8_t a =
581 _mesa_unorm_to_unorm(src[3], 8, 2);
582
583 uint32_t d = 0;
584 d |= PACK(b, 0, 10);
585 d |= PACK(g, 10, 10);
586 d |= PACK(r, 20, 10);
587 d |= PACK(a, 30, 2);
588 (*(uint32_t *)dst) = d;
589 }
590
591 static inline void
pack_ubyte_b10g10r10x2_unorm(const uint8_t src[4],void * dst)592 pack_ubyte_b10g10r10x2_unorm(const uint8_t src[4], void *dst)
593 {
594
595
596 uint16_t b =
597 _mesa_unorm_to_unorm(src[2], 8, 10);
598
599
600 uint16_t g =
601 _mesa_unorm_to_unorm(src[1], 8, 10);
602
603
604 uint16_t r =
605 _mesa_unorm_to_unorm(src[0], 8, 10);
606
607
608 uint32_t d = 0;
609 d |= PACK(b, 0, 10);
610 d |= PACK(g, 10, 10);
611 d |= PACK(r, 20, 10);
612 (*(uint32_t *)dst) = d;
613 }
614
615 static inline void
pack_ubyte_r10g10b10a2_unorm(const uint8_t src[4],void * dst)616 pack_ubyte_r10g10b10a2_unorm(const uint8_t src[4], void *dst)
617 {
618
619
620 uint16_t r =
621 _mesa_unorm_to_unorm(src[0], 8, 10);
622
623
624 uint16_t g =
625 _mesa_unorm_to_unorm(src[1], 8, 10);
626
627
628 uint16_t b =
629 _mesa_unorm_to_unorm(src[2], 8, 10);
630
631
632 uint8_t a =
633 _mesa_unorm_to_unorm(src[3], 8, 2);
634
635 uint32_t d = 0;
636 d |= PACK(r, 0, 10);
637 d |= PACK(g, 10, 10);
638 d |= PACK(b, 20, 10);
639 d |= PACK(a, 30, 2);
640 (*(uint32_t *)dst) = d;
641 }
642
643 static inline void
pack_ubyte_r10g10b10x2_unorm(const uint8_t src[4],void * dst)644 pack_ubyte_r10g10b10x2_unorm(const uint8_t src[4], void *dst)
645 {
646
647
648 uint16_t r =
649 _mesa_unorm_to_unorm(src[0], 8, 10);
650
651
652 uint16_t g =
653 _mesa_unorm_to_unorm(src[1], 8, 10);
654
655
656 uint16_t b =
657 _mesa_unorm_to_unorm(src[2], 8, 10);
658
659
660 uint32_t d = 0;
661 d |= PACK(r, 0, 10);
662 d |= PACK(g, 10, 10);
663 d |= PACK(b, 20, 10);
664 (*(uint32_t *)dst) = d;
665 }
666
667 static inline void
pack_ubyte_r3g3b2_unorm(const uint8_t src[4],void * dst)668 pack_ubyte_r3g3b2_unorm(const uint8_t src[4], void *dst)
669 {
670
671
672 uint8_t r =
673 _mesa_unorm_to_unorm(src[0], 8, 3);
674
675
676 uint8_t g =
677 _mesa_unorm_to_unorm(src[1], 8, 3);
678
679
680 uint8_t b =
681 _mesa_unorm_to_unorm(src[2], 8, 2);
682
683 uint8_t d = 0;
684 d |= PACK(r, 0, 3);
685 d |= PACK(g, 3, 3);
686 d |= PACK(b, 6, 2);
687 (*(uint8_t *)dst) = d;
688 }
689
690 static inline void
pack_ubyte_a4b4g4r4_unorm(const uint8_t src[4],void * dst)691 pack_ubyte_a4b4g4r4_unorm(const uint8_t src[4], void *dst)
692 {
693
694
695 uint8_t a =
696 _mesa_unorm_to_unorm(src[3], 8, 4);
697
698
699 uint8_t b =
700 _mesa_unorm_to_unorm(src[2], 8, 4);
701
702
703 uint8_t g =
704 _mesa_unorm_to_unorm(src[1], 8, 4);
705
706
707 uint8_t r =
708 _mesa_unorm_to_unorm(src[0], 8, 4);
709
710 uint16_t d = 0;
711 d |= PACK(a, 0, 4);
712 d |= PACK(b, 4, 4);
713 d |= PACK(g, 8, 4);
714 d |= PACK(r, 12, 4);
715 (*(uint16_t *)dst) = d;
716 }
717
718 static inline void
pack_ubyte_r4g4b4a4_unorm(const uint8_t src[4],void * dst)719 pack_ubyte_r4g4b4a4_unorm(const uint8_t src[4], void *dst)
720 {
721
722
723 uint8_t r =
724 _mesa_unorm_to_unorm(src[0], 8, 4);
725
726
727 uint8_t g =
728 _mesa_unorm_to_unorm(src[1], 8, 4);
729
730
731 uint8_t b =
732 _mesa_unorm_to_unorm(src[2], 8, 4);
733
734
735 uint8_t a =
736 _mesa_unorm_to_unorm(src[3], 8, 4);
737
738 uint16_t d = 0;
739 d |= PACK(r, 0, 4);
740 d |= PACK(g, 4, 4);
741 d |= PACK(b, 8, 4);
742 d |= PACK(a, 12, 4);
743 (*(uint16_t *)dst) = d;
744 }
745
746 static inline void
pack_ubyte_r5g5b5a1_unorm(const uint8_t src[4],void * dst)747 pack_ubyte_r5g5b5a1_unorm(const uint8_t src[4], void *dst)
748 {
749
750
751 uint8_t r =
752 _mesa_unorm_to_unorm(src[0], 8, 5);
753
754
755 uint8_t g =
756 _mesa_unorm_to_unorm(src[1], 8, 5);
757
758
759 uint8_t b =
760 _mesa_unorm_to_unorm(src[2], 8, 5);
761
762
763 uint8_t a =
764 _mesa_unorm_to_unorm(src[3], 8, 1);
765
766 uint16_t d = 0;
767 d |= PACK(r, 0, 5);
768 d |= PACK(g, 5, 5);
769 d |= PACK(b, 10, 5);
770 d |= PACK(a, 15, 1);
771 (*(uint16_t *)dst) = d;
772 }
773
774 static inline void
pack_ubyte_a2b10g10r10_unorm(const uint8_t src[4],void * dst)775 pack_ubyte_a2b10g10r10_unorm(const uint8_t src[4], void *dst)
776 {
777
778
779 uint8_t a =
780 _mesa_unorm_to_unorm(src[3], 8, 2);
781
782
783 uint16_t b =
784 _mesa_unorm_to_unorm(src[2], 8, 10);
785
786
787 uint16_t g =
788 _mesa_unorm_to_unorm(src[1], 8, 10);
789
790
791 uint16_t r =
792 _mesa_unorm_to_unorm(src[0], 8, 10);
793
794 uint32_t d = 0;
795 d |= PACK(a, 0, 2);
796 d |= PACK(b, 2, 10);
797 d |= PACK(g, 12, 10);
798 d |= PACK(r, 22, 10);
799 (*(uint32_t *)dst) = d;
800 }
801
802 static inline void
pack_ubyte_a2r10g10b10_unorm(const uint8_t src[4],void * dst)803 pack_ubyte_a2r10g10b10_unorm(const uint8_t src[4], void *dst)
804 {
805
806
807 uint8_t a =
808 _mesa_unorm_to_unorm(src[3], 8, 2);
809
810
811 uint16_t r =
812 _mesa_unorm_to_unorm(src[0], 8, 10);
813
814
815 uint16_t g =
816 _mesa_unorm_to_unorm(src[1], 8, 10);
817
818
819 uint16_t b =
820 _mesa_unorm_to_unorm(src[2], 8, 10);
821
822 uint32_t d = 0;
823 d |= PACK(a, 0, 2);
824 d |= PACK(r, 2, 10);
825 d |= PACK(g, 12, 10);
826 d |= PACK(b, 22, 10);
827 (*(uint32_t *)dst) = d;
828 }
829
830 static inline void
pack_ubyte_a_unorm8(const uint8_t src[4],void * dst)831 pack_ubyte_a_unorm8(const uint8_t src[4], void *dst)
832 {
833
834
835 uint8_t a =
836 _mesa_unorm_to_unorm(src[3], 8, 8);
837
838 uint8_t *d = (uint8_t *)dst;
839 d[0] = a;
840 }
841
842 static inline void
pack_ubyte_a_unorm16(const uint8_t src[4],void * dst)843 pack_ubyte_a_unorm16(const uint8_t src[4], void *dst)
844 {
845
846
847 uint16_t a =
848 _mesa_unorm_to_unorm(src[3], 8, 16);
849
850 uint16_t *d = (uint16_t *)dst;
851 d[0] = a;
852 }
853
854 static inline void
pack_ubyte_l_unorm8(const uint8_t src[4],void * dst)855 pack_ubyte_l_unorm8(const uint8_t src[4], void *dst)
856 {
857
858
859 uint8_t l =
860 _mesa_unorm_to_unorm(src[0], 8, 8);
861
862 uint8_t *d = (uint8_t *)dst;
863 d[0] = l;
864 }
865
866 static inline void
pack_ubyte_l_unorm16(const uint8_t src[4],void * dst)867 pack_ubyte_l_unorm16(const uint8_t src[4], void *dst)
868 {
869
870
871 uint16_t l =
872 _mesa_unorm_to_unorm(src[0], 8, 16);
873
874 uint16_t *d = (uint16_t *)dst;
875 d[0] = l;
876 }
877
878 static inline void
pack_ubyte_la_unorm8(const uint8_t src[4],void * dst)879 pack_ubyte_la_unorm8(const uint8_t src[4], void *dst)
880 {
881
882
883 uint8_t l =
884 _mesa_unorm_to_unorm(src[0], 8, 8);
885
886
887 uint8_t a =
888 _mesa_unorm_to_unorm(src[3], 8, 8);
889
890 uint8_t *d = (uint8_t *)dst;
891 d[0] = l;
892 d[1] = a;
893 }
894
895 static inline void
pack_ubyte_la_unorm16(const uint8_t src[4],void * dst)896 pack_ubyte_la_unorm16(const uint8_t src[4], void *dst)
897 {
898
899
900 uint16_t l =
901 _mesa_unorm_to_unorm(src[0], 8, 16);
902
903
904 uint16_t a =
905 _mesa_unorm_to_unorm(src[3], 8, 16);
906
907 uint16_t *d = (uint16_t *)dst;
908 d[0] = l;
909 d[1] = a;
910 }
911
912 static inline void
pack_ubyte_i_unorm8(const uint8_t src[4],void * dst)913 pack_ubyte_i_unorm8(const uint8_t src[4], void *dst)
914 {
915
916
917 uint8_t i =
918 _mesa_unorm_to_unorm(src[0], 8, 8);
919
920 uint8_t *d = (uint8_t *)dst;
921 d[0] = i;
922 }
923
924 static inline void
pack_ubyte_i_unorm16(const uint8_t src[4],void * dst)925 pack_ubyte_i_unorm16(const uint8_t src[4], void *dst)
926 {
927
928
929 uint16_t i =
930 _mesa_unorm_to_unorm(src[0], 8, 16);
931
932 uint16_t *d = (uint16_t *)dst;
933 d[0] = i;
934 }
935
936 static inline void
pack_ubyte_r_unorm8(const uint8_t src[4],void * dst)937 pack_ubyte_r_unorm8(const uint8_t src[4], void *dst)
938 {
939
940
941 uint8_t r =
942 _mesa_unorm_to_unorm(src[0], 8, 8);
943
944 uint8_t *d = (uint8_t *)dst;
945 d[0] = r;
946 }
947
948 static inline void
pack_ubyte_r_unorm16(const uint8_t src[4],void * dst)949 pack_ubyte_r_unorm16(const uint8_t src[4], void *dst)
950 {
951
952
953 uint16_t r =
954 _mesa_unorm_to_unorm(src[0], 8, 16);
955
956 uint16_t *d = (uint16_t *)dst;
957 d[0] = r;
958 }
959
960 static inline void
pack_ubyte_rg_unorm8(const uint8_t src[4],void * dst)961 pack_ubyte_rg_unorm8(const uint8_t src[4], void *dst)
962 {
963
964
965 uint8_t r =
966 _mesa_unorm_to_unorm(src[0], 8, 8);
967
968
969 uint8_t g =
970 _mesa_unorm_to_unorm(src[1], 8, 8);
971
972 uint8_t *d = (uint8_t *)dst;
973 d[0] = r;
974 d[1] = g;
975 }
976
977 static inline void
pack_ubyte_rg_unorm16(const uint8_t src[4],void * dst)978 pack_ubyte_rg_unorm16(const uint8_t src[4], void *dst)
979 {
980
981
982 uint16_t r =
983 _mesa_unorm_to_unorm(src[0], 8, 16);
984
985
986 uint16_t g =
987 _mesa_unorm_to_unorm(src[1], 8, 16);
988
989 uint16_t *d = (uint16_t *)dst;
990 d[0] = r;
991 d[1] = g;
992 }
993
994 static inline void
pack_ubyte_bgr_unorm8(const uint8_t src[4],void * dst)995 pack_ubyte_bgr_unorm8(const uint8_t src[4], void *dst)
996 {
997
998
999 uint8_t b =
1000 _mesa_unorm_to_unorm(src[2], 8, 8);
1001
1002
1003 uint8_t g =
1004 _mesa_unorm_to_unorm(src[1], 8, 8);
1005
1006
1007 uint8_t r =
1008 _mesa_unorm_to_unorm(src[0], 8, 8);
1009
1010 uint8_t *d = (uint8_t *)dst;
1011 d[0] = b;
1012 d[1] = g;
1013 d[2] = r;
1014 }
1015
1016 static inline void
pack_ubyte_rgb_unorm8(const uint8_t src[4],void * dst)1017 pack_ubyte_rgb_unorm8(const uint8_t src[4], void *dst)
1018 {
1019
1020
1021 uint8_t r =
1022 _mesa_unorm_to_unorm(src[0], 8, 8);
1023
1024
1025 uint8_t g =
1026 _mesa_unorm_to_unorm(src[1], 8, 8);
1027
1028
1029 uint8_t b =
1030 _mesa_unorm_to_unorm(src[2], 8, 8);
1031
1032 uint8_t *d = (uint8_t *)dst;
1033 d[0] = r;
1034 d[1] = g;
1035 d[2] = b;
1036 }
1037
1038 static inline void
pack_ubyte_rgba_unorm16(const uint8_t src[4],void * dst)1039 pack_ubyte_rgba_unorm16(const uint8_t src[4], void *dst)
1040 {
1041
1042
1043 uint16_t r =
1044 _mesa_unorm_to_unorm(src[0], 8, 16);
1045
1046
1047 uint16_t g =
1048 _mesa_unorm_to_unorm(src[1], 8, 16);
1049
1050
1051 uint16_t b =
1052 _mesa_unorm_to_unorm(src[2], 8, 16);
1053
1054
1055 uint16_t a =
1056 _mesa_unorm_to_unorm(src[3], 8, 16);
1057
1058 uint16_t *d = (uint16_t *)dst;
1059 d[0] = r;
1060 d[1] = g;
1061 d[2] = b;
1062 d[3] = a;
1063 }
1064
1065 static inline void
pack_ubyte_rgbx_unorm16(const uint8_t src[4],void * dst)1066 pack_ubyte_rgbx_unorm16(const uint8_t src[4], void *dst)
1067 {
1068
1069
1070 uint16_t r =
1071 _mesa_unorm_to_unorm(src[0], 8, 16);
1072
1073
1074 uint16_t g =
1075 _mesa_unorm_to_unorm(src[1], 8, 16);
1076
1077
1078 uint16_t b =
1079 _mesa_unorm_to_unorm(src[2], 8, 16);
1080
1081
1082 uint16_t *d = (uint16_t *)dst;
1083 d[0] = r;
1084 d[1] = g;
1085 d[2] = b;
1086 }
1087
1088 static inline void
pack_ubyte_a8b8g8r8_snorm(const uint8_t src[4],void * dst)1089 pack_ubyte_a8b8g8r8_snorm(const uint8_t src[4], void *dst)
1090 {
1091
1092
1093 int8_t a =
1094 _mesa_unorm_to_snorm(src[3], 8, 8);
1095
1096
1097 int8_t b =
1098 _mesa_unorm_to_snorm(src[2], 8, 8);
1099
1100
1101 int8_t g =
1102 _mesa_unorm_to_snorm(src[1], 8, 8);
1103
1104
1105 int8_t r =
1106 _mesa_unorm_to_snorm(src[0], 8, 8);
1107
1108 uint32_t d = 0;
1109 d |= PACK(a, 0, 8);
1110 d |= PACK(b, 8, 8);
1111 d |= PACK(g, 16, 8);
1112 d |= PACK(r, 24, 8);
1113 (*(uint32_t *)dst) = d;
1114 }
1115
1116 static inline void
pack_ubyte_x8b8g8r8_snorm(const uint8_t src[4],void * dst)1117 pack_ubyte_x8b8g8r8_snorm(const uint8_t src[4], void *dst)
1118 {
1119
1120
1121
1122 int8_t b =
1123 _mesa_unorm_to_snorm(src[2], 8, 8);
1124
1125
1126 int8_t g =
1127 _mesa_unorm_to_snorm(src[1], 8, 8);
1128
1129
1130 int8_t r =
1131 _mesa_unorm_to_snorm(src[0], 8, 8);
1132
1133 uint32_t d = 0;
1134 d |= PACK(b, 8, 8);
1135 d |= PACK(g, 16, 8);
1136 d |= PACK(r, 24, 8);
1137 (*(uint32_t *)dst) = d;
1138 }
1139
1140 static inline void
pack_ubyte_r8g8b8a8_snorm(const uint8_t src[4],void * dst)1141 pack_ubyte_r8g8b8a8_snorm(const uint8_t src[4], void *dst)
1142 {
1143
1144
1145 int8_t r =
1146 _mesa_unorm_to_snorm(src[0], 8, 8);
1147
1148
1149 int8_t g =
1150 _mesa_unorm_to_snorm(src[1], 8, 8);
1151
1152
1153 int8_t b =
1154 _mesa_unorm_to_snorm(src[2], 8, 8);
1155
1156
1157 int8_t a =
1158 _mesa_unorm_to_snorm(src[3], 8, 8);
1159
1160 uint32_t d = 0;
1161 d |= PACK(r, 0, 8);
1162 d |= PACK(g, 8, 8);
1163 d |= PACK(b, 16, 8);
1164 d |= PACK(a, 24, 8);
1165 (*(uint32_t *)dst) = d;
1166 }
1167
1168 static inline void
pack_ubyte_r8g8b8x8_snorm(const uint8_t src[4],void * dst)1169 pack_ubyte_r8g8b8x8_snorm(const uint8_t src[4], void *dst)
1170 {
1171
1172
1173 int8_t r =
1174 _mesa_unorm_to_snorm(src[0], 8, 8);
1175
1176
1177 int8_t g =
1178 _mesa_unorm_to_snorm(src[1], 8, 8);
1179
1180
1181 int8_t b =
1182 _mesa_unorm_to_snorm(src[2], 8, 8);
1183
1184
1185 uint32_t d = 0;
1186 d |= PACK(r, 0, 8);
1187 d |= PACK(g, 8, 8);
1188 d |= PACK(b, 16, 8);
1189 (*(uint32_t *)dst) = d;
1190 }
1191
1192 static inline void
pack_ubyte_a_snorm8(const uint8_t src[4],void * dst)1193 pack_ubyte_a_snorm8(const uint8_t src[4], void *dst)
1194 {
1195
1196
1197 int8_t a =
1198 _mesa_unorm_to_snorm(src[3], 8, 8);
1199
1200 int8_t *d = (int8_t *)dst;
1201 d[0] = a;
1202 }
1203
1204 static inline void
pack_ubyte_a_snorm16(const uint8_t src[4],void * dst)1205 pack_ubyte_a_snorm16(const uint8_t src[4], void *dst)
1206 {
1207
1208
1209 int16_t a =
1210 _mesa_unorm_to_snorm(src[3], 8, 16);
1211
1212 int16_t *d = (int16_t *)dst;
1213 d[0] = a;
1214 }
1215
1216 static inline void
pack_ubyte_l_snorm8(const uint8_t src[4],void * dst)1217 pack_ubyte_l_snorm8(const uint8_t src[4], void *dst)
1218 {
1219
1220
1221 int8_t l =
1222 _mesa_unorm_to_snorm(src[0], 8, 8);
1223
1224 int8_t *d = (int8_t *)dst;
1225 d[0] = l;
1226 }
1227
1228 static inline void
pack_ubyte_l_snorm16(const uint8_t src[4],void * dst)1229 pack_ubyte_l_snorm16(const uint8_t src[4], void *dst)
1230 {
1231
1232
1233 int16_t l =
1234 _mesa_unorm_to_snorm(src[0], 8, 16);
1235
1236 int16_t *d = (int16_t *)dst;
1237 d[0] = l;
1238 }
1239
1240 static inline void
pack_ubyte_i_snorm8(const uint8_t src[4],void * dst)1241 pack_ubyte_i_snorm8(const uint8_t src[4], void *dst)
1242 {
1243
1244
1245 int8_t i =
1246 _mesa_unorm_to_snorm(src[0], 8, 8);
1247
1248 int8_t *d = (int8_t *)dst;
1249 d[0] = i;
1250 }
1251
1252 static inline void
pack_ubyte_i_snorm16(const uint8_t src[4],void * dst)1253 pack_ubyte_i_snorm16(const uint8_t src[4], void *dst)
1254 {
1255
1256
1257 int16_t i =
1258 _mesa_unorm_to_snorm(src[0], 8, 16);
1259
1260 int16_t *d = (int16_t *)dst;
1261 d[0] = i;
1262 }
1263
1264 static inline void
pack_ubyte_r_snorm8(const uint8_t src[4],void * dst)1265 pack_ubyte_r_snorm8(const uint8_t src[4], void *dst)
1266 {
1267
1268
1269 int8_t r =
1270 _mesa_unorm_to_snorm(src[0], 8, 8);
1271
1272 int8_t *d = (int8_t *)dst;
1273 d[0] = r;
1274 }
1275
1276 static inline void
pack_ubyte_r_snorm16(const uint8_t src[4],void * dst)1277 pack_ubyte_r_snorm16(const uint8_t src[4], void *dst)
1278 {
1279
1280
1281 int16_t r =
1282 _mesa_unorm_to_snorm(src[0], 8, 16);
1283
1284 int16_t *d = (int16_t *)dst;
1285 d[0] = r;
1286 }
1287
1288 static inline void
pack_ubyte_la_snorm8(const uint8_t src[4],void * dst)1289 pack_ubyte_la_snorm8(const uint8_t src[4], void *dst)
1290 {
1291
1292
1293 int8_t l =
1294 _mesa_unorm_to_snorm(src[0], 8, 8);
1295
1296
1297 int8_t a =
1298 _mesa_unorm_to_snorm(src[3], 8, 8);
1299
1300 int8_t *d = (int8_t *)dst;
1301 d[0] = l;
1302 d[1] = a;
1303 }
1304
1305 static inline void
pack_ubyte_la_snorm16(const uint8_t src[4],void * dst)1306 pack_ubyte_la_snorm16(const uint8_t src[4], void *dst)
1307 {
1308
1309
1310 int16_t l =
1311 _mesa_unorm_to_snorm(src[0], 8, 16);
1312
1313
1314 int16_t a =
1315 _mesa_unorm_to_snorm(src[3], 8, 16);
1316
1317 int16_t *d = (int16_t *)dst;
1318 d[0] = l;
1319 d[1] = a;
1320 }
1321
1322 static inline void
pack_ubyte_rg_snorm8(const uint8_t src[4],void * dst)1323 pack_ubyte_rg_snorm8(const uint8_t src[4], void *dst)
1324 {
1325
1326
1327 int8_t r =
1328 _mesa_unorm_to_snorm(src[0], 8, 8);
1329
1330
1331 int8_t g =
1332 _mesa_unorm_to_snorm(src[1], 8, 8);
1333
1334 int8_t *d = (int8_t *)dst;
1335 d[0] = r;
1336 d[1] = g;
1337 }
1338
1339 static inline void
pack_ubyte_rg_snorm16(const uint8_t src[4],void * dst)1340 pack_ubyte_rg_snorm16(const uint8_t src[4], void *dst)
1341 {
1342
1343
1344 int16_t r =
1345 _mesa_unorm_to_snorm(src[0], 8, 16);
1346
1347
1348 int16_t g =
1349 _mesa_unorm_to_snorm(src[1], 8, 16);
1350
1351 int16_t *d = (int16_t *)dst;
1352 d[0] = r;
1353 d[1] = g;
1354 }
1355
1356 static inline void
pack_ubyte_rgb_snorm16(const uint8_t src[4],void * dst)1357 pack_ubyte_rgb_snorm16(const uint8_t src[4], void *dst)
1358 {
1359
1360
1361 int16_t r =
1362 _mesa_unorm_to_snorm(src[0], 8, 16);
1363
1364
1365 int16_t g =
1366 _mesa_unorm_to_snorm(src[1], 8, 16);
1367
1368
1369 int16_t b =
1370 _mesa_unorm_to_snorm(src[2], 8, 16);
1371
1372 int16_t *d = (int16_t *)dst;
1373 d[0] = r;
1374 d[1] = g;
1375 d[2] = b;
1376 }
1377
1378 static inline void
pack_ubyte_rgba_snorm16(const uint8_t src[4],void * dst)1379 pack_ubyte_rgba_snorm16(const uint8_t src[4], void *dst)
1380 {
1381
1382
1383 int16_t r =
1384 _mesa_unorm_to_snorm(src[0], 8, 16);
1385
1386
1387 int16_t g =
1388 _mesa_unorm_to_snorm(src[1], 8, 16);
1389
1390
1391 int16_t b =
1392 _mesa_unorm_to_snorm(src[2], 8, 16);
1393
1394
1395 int16_t a =
1396 _mesa_unorm_to_snorm(src[3], 8, 16);
1397
1398 int16_t *d = (int16_t *)dst;
1399 d[0] = r;
1400 d[1] = g;
1401 d[2] = b;
1402 d[3] = a;
1403 }
1404
1405 static inline void
pack_ubyte_rgbx_snorm16(const uint8_t src[4],void * dst)1406 pack_ubyte_rgbx_snorm16(const uint8_t src[4], void *dst)
1407 {
1408
1409
1410 int16_t r =
1411 _mesa_unorm_to_snorm(src[0], 8, 16);
1412
1413
1414 int16_t g =
1415 _mesa_unorm_to_snorm(src[1], 8, 16);
1416
1417
1418 int16_t b =
1419 _mesa_unorm_to_snorm(src[2], 8, 16);
1420
1421
1422 int16_t *d = (int16_t *)dst;
1423 d[0] = r;
1424 d[1] = g;
1425 d[2] = b;
1426 }
1427
1428 static inline void
pack_ubyte_a8b8g8r8_srgb(const uint8_t src[4],void * dst)1429 pack_ubyte_a8b8g8r8_srgb(const uint8_t src[4], void *dst)
1430 {
1431
1432
1433 uint8_t a =
1434 _mesa_unorm_to_unorm(src[3], 8, 8);
1435
1436
1437 uint8_t b =
1438
1439 util_format_linear_to_srgb_8unorm(src[2]);
1440
1441
1442 uint8_t g =
1443
1444 util_format_linear_to_srgb_8unorm(src[1]);
1445
1446
1447 uint8_t r =
1448
1449 util_format_linear_to_srgb_8unorm(src[0]);
1450
1451 uint32_t d = 0;
1452 d |= PACK(a, 0, 8);
1453 d |= PACK(b, 8, 8);
1454 d |= PACK(g, 16, 8);
1455 d |= PACK(r, 24, 8);
1456 (*(uint32_t *)dst) = d;
1457 }
1458
1459 static inline void
pack_ubyte_b8g8r8a8_srgb(const uint8_t src[4],void * dst)1460 pack_ubyte_b8g8r8a8_srgb(const uint8_t src[4], void *dst)
1461 {
1462
1463
1464 uint8_t b =
1465
1466 util_format_linear_to_srgb_8unorm(src[2]);
1467
1468
1469 uint8_t g =
1470
1471 util_format_linear_to_srgb_8unorm(src[1]);
1472
1473
1474 uint8_t r =
1475
1476 util_format_linear_to_srgb_8unorm(src[0]);
1477
1478
1479 uint8_t a =
1480 _mesa_unorm_to_unorm(src[3], 8, 8);
1481
1482 uint32_t d = 0;
1483 d |= PACK(b, 0, 8);
1484 d |= PACK(g, 8, 8);
1485 d |= PACK(r, 16, 8);
1486 d |= PACK(a, 24, 8);
1487 (*(uint32_t *)dst) = d;
1488 }
1489
1490 static inline void
pack_ubyte_a8r8g8b8_srgb(const uint8_t src[4],void * dst)1491 pack_ubyte_a8r8g8b8_srgb(const uint8_t src[4], void *dst)
1492 {
1493
1494
1495 uint8_t a =
1496 _mesa_unorm_to_unorm(src[3], 8, 8);
1497
1498
1499 uint8_t r =
1500
1501 util_format_linear_to_srgb_8unorm(src[0]);
1502
1503
1504 uint8_t g =
1505
1506 util_format_linear_to_srgb_8unorm(src[1]);
1507
1508
1509 uint8_t b =
1510
1511 util_format_linear_to_srgb_8unorm(src[2]);
1512
1513 uint32_t d = 0;
1514 d |= PACK(a, 0, 8);
1515 d |= PACK(r, 8, 8);
1516 d |= PACK(g, 16, 8);
1517 d |= PACK(b, 24, 8);
1518 (*(uint32_t *)dst) = d;
1519 }
1520
1521 static inline void
pack_ubyte_b8g8r8x8_srgb(const uint8_t src[4],void * dst)1522 pack_ubyte_b8g8r8x8_srgb(const uint8_t src[4], void *dst)
1523 {
1524
1525
1526 uint8_t b =
1527
1528 util_format_linear_to_srgb_8unorm(src[2]);
1529
1530
1531 uint8_t g =
1532
1533 util_format_linear_to_srgb_8unorm(src[1]);
1534
1535
1536 uint8_t r =
1537
1538 util_format_linear_to_srgb_8unorm(src[0]);
1539
1540
1541 uint32_t d = 0;
1542 d |= PACK(b, 0, 8);
1543 d |= PACK(g, 8, 8);
1544 d |= PACK(r, 16, 8);
1545 (*(uint32_t *)dst) = d;
1546 }
1547
1548 static inline void
pack_ubyte_x8r8g8b8_srgb(const uint8_t src[4],void * dst)1549 pack_ubyte_x8r8g8b8_srgb(const uint8_t src[4], void *dst)
1550 {
1551
1552
1553
1554 uint8_t r =
1555
1556 util_format_linear_to_srgb_8unorm(src[0]);
1557
1558
1559 uint8_t g =
1560
1561 util_format_linear_to_srgb_8unorm(src[1]);
1562
1563
1564 uint8_t b =
1565
1566 util_format_linear_to_srgb_8unorm(src[2]);
1567
1568 uint32_t d = 0;
1569 d |= PACK(r, 8, 8);
1570 d |= PACK(g, 16, 8);
1571 d |= PACK(b, 24, 8);
1572 (*(uint32_t *)dst) = d;
1573 }
1574
1575 static inline void
pack_ubyte_r8g8b8a8_srgb(const uint8_t src[4],void * dst)1576 pack_ubyte_r8g8b8a8_srgb(const uint8_t src[4], void *dst)
1577 {
1578
1579
1580 uint8_t r =
1581
1582 util_format_linear_to_srgb_8unorm(src[0]);
1583
1584
1585 uint8_t g =
1586
1587 util_format_linear_to_srgb_8unorm(src[1]);
1588
1589
1590 uint8_t b =
1591
1592 util_format_linear_to_srgb_8unorm(src[2]);
1593
1594
1595 uint8_t a =
1596 _mesa_unorm_to_unorm(src[3], 8, 8);
1597
1598 uint32_t d = 0;
1599 d |= PACK(r, 0, 8);
1600 d |= PACK(g, 8, 8);
1601 d |= PACK(b, 16, 8);
1602 d |= PACK(a, 24, 8);
1603 (*(uint32_t *)dst) = d;
1604 }
1605
1606 static inline void
pack_ubyte_r8g8b8x8_srgb(const uint8_t src[4],void * dst)1607 pack_ubyte_r8g8b8x8_srgb(const uint8_t src[4], void *dst)
1608 {
1609
1610
1611 uint8_t r =
1612
1613 util_format_linear_to_srgb_8unorm(src[0]);
1614
1615
1616 uint8_t g =
1617
1618 util_format_linear_to_srgb_8unorm(src[1]);
1619
1620
1621 uint8_t b =
1622
1623 util_format_linear_to_srgb_8unorm(src[2]);
1624
1625
1626 uint32_t d = 0;
1627 d |= PACK(r, 0, 8);
1628 d |= PACK(g, 8, 8);
1629 d |= PACK(b, 16, 8);
1630 (*(uint32_t *)dst) = d;
1631 }
1632
1633 static inline void
pack_ubyte_x8b8g8r8_srgb(const uint8_t src[4],void * dst)1634 pack_ubyte_x8b8g8r8_srgb(const uint8_t src[4], void *dst)
1635 {
1636
1637
1638
1639 uint8_t b =
1640
1641 util_format_linear_to_srgb_8unorm(src[2]);
1642
1643
1644 uint8_t g =
1645
1646 util_format_linear_to_srgb_8unorm(src[1]);
1647
1648
1649 uint8_t r =
1650
1651 util_format_linear_to_srgb_8unorm(src[0]);
1652
1653 uint32_t d = 0;
1654 d |= PACK(b, 8, 8);
1655 d |= PACK(g, 16, 8);
1656 d |= PACK(r, 24, 8);
1657 (*(uint32_t *)dst) = d;
1658 }
1659
1660 static inline void
pack_ubyte_r_srgb8(const uint8_t src[4],void * dst)1661 pack_ubyte_r_srgb8(const uint8_t src[4], void *dst)
1662 {
1663
1664
1665 uint8_t r =
1666
1667 util_format_linear_to_srgb_8unorm(src[0]);
1668
1669 uint8_t *d = (uint8_t *)dst;
1670 d[0] = r;
1671 }
1672
1673 static inline void
pack_ubyte_l_srgb8(const uint8_t src[4],void * dst)1674 pack_ubyte_l_srgb8(const uint8_t src[4], void *dst)
1675 {
1676
1677
1678 uint8_t l =
1679 _mesa_unorm_to_unorm(src[0], 8, 8);
1680
1681 uint8_t *d = (uint8_t *)dst;
1682 d[0] = l;
1683 }
1684
1685 static inline void
pack_ubyte_la_srgb8(const uint8_t src[4],void * dst)1686 pack_ubyte_la_srgb8(const uint8_t src[4], void *dst)
1687 {
1688
1689
1690 uint8_t l =
1691 _mesa_unorm_to_unorm(src[0], 8, 8);
1692
1693
1694 uint8_t a =
1695 _mesa_unorm_to_unorm(src[3], 8, 8);
1696
1697 uint8_t *d = (uint8_t *)dst;
1698 d[0] = l;
1699 d[1] = a;
1700 }
1701
1702 static inline void
pack_ubyte_bgr_srgb8(const uint8_t src[4],void * dst)1703 pack_ubyte_bgr_srgb8(const uint8_t src[4], void *dst)
1704 {
1705
1706
1707 uint8_t b =
1708
1709 util_format_linear_to_srgb_8unorm(src[2]);
1710
1711
1712 uint8_t g =
1713
1714 util_format_linear_to_srgb_8unorm(src[1]);
1715
1716
1717 uint8_t r =
1718
1719 util_format_linear_to_srgb_8unorm(src[0]);
1720
1721 uint8_t *d = (uint8_t *)dst;
1722 d[0] = b;
1723 d[1] = g;
1724 d[2] = r;
1725 }
1726
1727 static inline void
pack_ubyte_a_float16(const uint8_t src[4],void * dst)1728 pack_ubyte_a_float16(const uint8_t src[4], void *dst)
1729 {
1730
1731
1732 uint16_t a =
1733 _mesa_unorm_to_half(src[3], 8);
1734
1735 uint16_t *d = (uint16_t *)dst;
1736 d[0] = a;
1737 }
1738
1739 static inline void
pack_ubyte_a_float32(const uint8_t src[4],void * dst)1740 pack_ubyte_a_float32(const uint8_t src[4], void *dst)
1741 {
1742
1743
1744 float a =
1745 _mesa_unorm_to_float(src[3], 8);
1746
1747 float *d = (float *)dst;
1748 d[0] = a;
1749 }
1750
1751 static inline void
pack_ubyte_l_float16(const uint8_t src[4],void * dst)1752 pack_ubyte_l_float16(const uint8_t src[4], void *dst)
1753 {
1754
1755
1756 uint16_t l =
1757 _mesa_unorm_to_half(src[0], 8);
1758
1759 uint16_t *d = (uint16_t *)dst;
1760 d[0] = l;
1761 }
1762
1763 static inline void
pack_ubyte_l_float32(const uint8_t src[4],void * dst)1764 pack_ubyte_l_float32(const uint8_t src[4], void *dst)
1765 {
1766
1767
1768 float l =
1769 _mesa_unorm_to_float(src[0], 8);
1770
1771 float *d = (float *)dst;
1772 d[0] = l;
1773 }
1774
1775 static inline void
pack_ubyte_la_float16(const uint8_t src[4],void * dst)1776 pack_ubyte_la_float16(const uint8_t src[4], void *dst)
1777 {
1778
1779
1780 uint16_t l =
1781 _mesa_unorm_to_half(src[0], 8);
1782
1783
1784 uint16_t a =
1785 _mesa_unorm_to_half(src[3], 8);
1786
1787 uint16_t *d = (uint16_t *)dst;
1788 d[0] = l;
1789 d[1] = a;
1790 }
1791
1792 static inline void
pack_ubyte_la_float32(const uint8_t src[4],void * dst)1793 pack_ubyte_la_float32(const uint8_t src[4], void *dst)
1794 {
1795
1796
1797 float l =
1798 _mesa_unorm_to_float(src[0], 8);
1799
1800
1801 float a =
1802 _mesa_unorm_to_float(src[3], 8);
1803
1804 float *d = (float *)dst;
1805 d[0] = l;
1806 d[1] = a;
1807 }
1808
1809 static inline void
pack_ubyte_i_float16(const uint8_t src[4],void * dst)1810 pack_ubyte_i_float16(const uint8_t src[4], void *dst)
1811 {
1812
1813
1814 uint16_t i =
1815 _mesa_unorm_to_half(src[0], 8);
1816
1817 uint16_t *d = (uint16_t *)dst;
1818 d[0] = i;
1819 }
1820
1821 static inline void
pack_ubyte_i_float32(const uint8_t src[4],void * dst)1822 pack_ubyte_i_float32(const uint8_t src[4], void *dst)
1823 {
1824
1825
1826 float i =
1827 _mesa_unorm_to_float(src[0], 8);
1828
1829 float *d = (float *)dst;
1830 d[0] = i;
1831 }
1832
1833 static inline void
pack_ubyte_r_float16(const uint8_t src[4],void * dst)1834 pack_ubyte_r_float16(const uint8_t src[4], void *dst)
1835 {
1836
1837
1838 uint16_t r =
1839 _mesa_unorm_to_half(src[0], 8);
1840
1841 uint16_t *d = (uint16_t *)dst;
1842 d[0] = r;
1843 }
1844
1845 static inline void
pack_ubyte_r_float32(const uint8_t src[4],void * dst)1846 pack_ubyte_r_float32(const uint8_t src[4], void *dst)
1847 {
1848
1849
1850 float r =
1851 _mesa_unorm_to_float(src[0], 8);
1852
1853 float *d = (float *)dst;
1854 d[0] = r;
1855 }
1856
1857 static inline void
pack_ubyte_rg_float16(const uint8_t src[4],void * dst)1858 pack_ubyte_rg_float16(const uint8_t src[4], void *dst)
1859 {
1860
1861
1862 uint16_t r =
1863 _mesa_unorm_to_half(src[0], 8);
1864
1865
1866 uint16_t g =
1867 _mesa_unorm_to_half(src[1], 8);
1868
1869 uint16_t *d = (uint16_t *)dst;
1870 d[0] = r;
1871 d[1] = g;
1872 }
1873
1874 static inline void
pack_ubyte_rg_float32(const uint8_t src[4],void * dst)1875 pack_ubyte_rg_float32(const uint8_t src[4], void *dst)
1876 {
1877
1878
1879 float r =
1880 _mesa_unorm_to_float(src[0], 8);
1881
1882
1883 float g =
1884 _mesa_unorm_to_float(src[1], 8);
1885
1886 float *d = (float *)dst;
1887 d[0] = r;
1888 d[1] = g;
1889 }
1890
1891 static inline void
pack_ubyte_rgb_float16(const uint8_t src[4],void * dst)1892 pack_ubyte_rgb_float16(const uint8_t src[4], void *dst)
1893 {
1894
1895
1896 uint16_t r =
1897 _mesa_unorm_to_half(src[0], 8);
1898
1899
1900 uint16_t g =
1901 _mesa_unorm_to_half(src[1], 8);
1902
1903
1904 uint16_t b =
1905 _mesa_unorm_to_half(src[2], 8);
1906
1907 uint16_t *d = (uint16_t *)dst;
1908 d[0] = r;
1909 d[1] = g;
1910 d[2] = b;
1911 }
1912
1913 static inline void
pack_ubyte_rgb_float32(const uint8_t src[4],void * dst)1914 pack_ubyte_rgb_float32(const uint8_t src[4], void *dst)
1915 {
1916
1917
1918 float r =
1919 _mesa_unorm_to_float(src[0], 8);
1920
1921
1922 float g =
1923 _mesa_unorm_to_float(src[1], 8);
1924
1925
1926 float b =
1927 _mesa_unorm_to_float(src[2], 8);
1928
1929 float *d = (float *)dst;
1930 d[0] = r;
1931 d[1] = g;
1932 d[2] = b;
1933 }
1934
1935 static inline void
pack_ubyte_rgba_float16(const uint8_t src[4],void * dst)1936 pack_ubyte_rgba_float16(const uint8_t src[4], void *dst)
1937 {
1938
1939
1940 uint16_t r =
1941 _mesa_unorm_to_half(src[0], 8);
1942
1943
1944 uint16_t g =
1945 _mesa_unorm_to_half(src[1], 8);
1946
1947
1948 uint16_t b =
1949 _mesa_unorm_to_half(src[2], 8);
1950
1951
1952 uint16_t a =
1953 _mesa_unorm_to_half(src[3], 8);
1954
1955 uint16_t *d = (uint16_t *)dst;
1956 d[0] = r;
1957 d[1] = g;
1958 d[2] = b;
1959 d[3] = a;
1960 }
1961
1962 static inline void
pack_ubyte_rgba_float32(const uint8_t src[4],void * dst)1963 pack_ubyte_rgba_float32(const uint8_t src[4], void *dst)
1964 {
1965
1966
1967 float r =
1968 _mesa_unorm_to_float(src[0], 8);
1969
1970
1971 float g =
1972 _mesa_unorm_to_float(src[1], 8);
1973
1974
1975 float b =
1976 _mesa_unorm_to_float(src[2], 8);
1977
1978
1979 float a =
1980 _mesa_unorm_to_float(src[3], 8);
1981
1982 float *d = (float *)dst;
1983 d[0] = r;
1984 d[1] = g;
1985 d[2] = b;
1986 d[3] = a;
1987 }
1988
1989 static inline void
pack_ubyte_rgbx_float16(const uint8_t src[4],void * dst)1990 pack_ubyte_rgbx_float16(const uint8_t src[4], void *dst)
1991 {
1992
1993
1994 uint16_t r =
1995 _mesa_unorm_to_half(src[0], 8);
1996
1997
1998 uint16_t g =
1999 _mesa_unorm_to_half(src[1], 8);
2000
2001
2002 uint16_t b =
2003 _mesa_unorm_to_half(src[2], 8);
2004
2005
2006 uint16_t *d = (uint16_t *)dst;
2007 d[0] = r;
2008 d[1] = g;
2009 d[2] = b;
2010 }
2011
2012 static inline void
pack_ubyte_rgbx_float32(const uint8_t src[4],void * dst)2013 pack_ubyte_rgbx_float32(const uint8_t src[4], void *dst)
2014 {
2015
2016
2017 float r =
2018 _mesa_unorm_to_float(src[0], 8);
2019
2020
2021 float g =
2022 _mesa_unorm_to_float(src[1], 8);
2023
2024
2025 float b =
2026 _mesa_unorm_to_float(src[2], 8);
2027
2028
2029 float *d = (float *)dst;
2030 d[0] = r;
2031 d[1] = g;
2032 d[2] = b;
2033 }
2034
2035 static inline void
pack_ubyte_a8b8g8r8_uint(const uint8_t src[4],void * dst)2036 pack_ubyte_a8b8g8r8_uint(const uint8_t src[4], void *dst)
2037 {
2038
2039
2040 uint8_t a =
2041 _mesa_unsigned_to_unsigned(src[3], 8);
2042
2043
2044 uint8_t b =
2045 _mesa_unsigned_to_unsigned(src[2], 8);
2046
2047
2048 uint8_t g =
2049 _mesa_unsigned_to_unsigned(src[1], 8);
2050
2051
2052 uint8_t r =
2053 _mesa_unsigned_to_unsigned(src[0], 8);
2054
2055 uint32_t d = 0;
2056 d |= PACK(a, 0, 8);
2057 d |= PACK(b, 8, 8);
2058 d |= PACK(g, 16, 8);
2059 d |= PACK(r, 24, 8);
2060 (*(uint32_t *)dst) = d;
2061 }
2062
2063 static inline void
pack_ubyte_a8r8g8b8_uint(const uint8_t src[4],void * dst)2064 pack_ubyte_a8r8g8b8_uint(const uint8_t src[4], void *dst)
2065 {
2066
2067
2068 uint8_t a =
2069 _mesa_unsigned_to_unsigned(src[3], 8);
2070
2071
2072 uint8_t r =
2073 _mesa_unsigned_to_unsigned(src[0], 8);
2074
2075
2076 uint8_t g =
2077 _mesa_unsigned_to_unsigned(src[1], 8);
2078
2079
2080 uint8_t b =
2081 _mesa_unsigned_to_unsigned(src[2], 8);
2082
2083 uint32_t d = 0;
2084 d |= PACK(a, 0, 8);
2085 d |= PACK(r, 8, 8);
2086 d |= PACK(g, 16, 8);
2087 d |= PACK(b, 24, 8);
2088 (*(uint32_t *)dst) = d;
2089 }
2090
2091 static inline void
pack_ubyte_r8g8b8a8_uint(const uint8_t src[4],void * dst)2092 pack_ubyte_r8g8b8a8_uint(const uint8_t src[4], void *dst)
2093 {
2094
2095
2096 uint8_t r =
2097 _mesa_unsigned_to_unsigned(src[0], 8);
2098
2099
2100 uint8_t g =
2101 _mesa_unsigned_to_unsigned(src[1], 8);
2102
2103
2104 uint8_t b =
2105 _mesa_unsigned_to_unsigned(src[2], 8);
2106
2107
2108 uint8_t a =
2109 _mesa_unsigned_to_unsigned(src[3], 8);
2110
2111 uint32_t d = 0;
2112 d |= PACK(r, 0, 8);
2113 d |= PACK(g, 8, 8);
2114 d |= PACK(b, 16, 8);
2115 d |= PACK(a, 24, 8);
2116 (*(uint32_t *)dst) = d;
2117 }
2118
2119 static inline void
pack_ubyte_b8g8r8a8_uint(const uint8_t src[4],void * dst)2120 pack_ubyte_b8g8r8a8_uint(const uint8_t src[4], void *dst)
2121 {
2122
2123
2124 uint8_t b =
2125 _mesa_unsigned_to_unsigned(src[2], 8);
2126
2127
2128 uint8_t g =
2129 _mesa_unsigned_to_unsigned(src[1], 8);
2130
2131
2132 uint8_t r =
2133 _mesa_unsigned_to_unsigned(src[0], 8);
2134
2135
2136 uint8_t a =
2137 _mesa_unsigned_to_unsigned(src[3], 8);
2138
2139 uint32_t d = 0;
2140 d |= PACK(b, 0, 8);
2141 d |= PACK(g, 8, 8);
2142 d |= PACK(r, 16, 8);
2143 d |= PACK(a, 24, 8);
2144 (*(uint32_t *)dst) = d;
2145 }
2146
2147 static inline void
pack_ubyte_b10g10r10a2_uint(const uint8_t src[4],void * dst)2148 pack_ubyte_b10g10r10a2_uint(const uint8_t src[4], void *dst)
2149 {
2150
2151
2152 uint16_t b =
2153 _mesa_unsigned_to_unsigned(src[2], 10);
2154
2155
2156 uint16_t g =
2157 _mesa_unsigned_to_unsigned(src[1], 10);
2158
2159
2160 uint16_t r =
2161 _mesa_unsigned_to_unsigned(src[0], 10);
2162
2163
2164 uint8_t a =
2165 _mesa_unsigned_to_unsigned(src[3], 2);
2166
2167 uint32_t d = 0;
2168 d |= PACK(b, 0, 10);
2169 d |= PACK(g, 10, 10);
2170 d |= PACK(r, 20, 10);
2171 d |= PACK(a, 30, 2);
2172 (*(uint32_t *)dst) = d;
2173 }
2174
2175 static inline void
pack_ubyte_r10g10b10a2_uint(const uint8_t src[4],void * dst)2176 pack_ubyte_r10g10b10a2_uint(const uint8_t src[4], void *dst)
2177 {
2178
2179
2180 uint16_t r =
2181 _mesa_unsigned_to_unsigned(src[0], 10);
2182
2183
2184 uint16_t g =
2185 _mesa_unsigned_to_unsigned(src[1], 10);
2186
2187
2188 uint16_t b =
2189 _mesa_unsigned_to_unsigned(src[2], 10);
2190
2191
2192 uint8_t a =
2193 _mesa_unsigned_to_unsigned(src[3], 2);
2194
2195 uint32_t d = 0;
2196 d |= PACK(r, 0, 10);
2197 d |= PACK(g, 10, 10);
2198 d |= PACK(b, 20, 10);
2199 d |= PACK(a, 30, 2);
2200 (*(uint32_t *)dst) = d;
2201 }
2202
2203 static inline void
pack_ubyte_a2b10g10r10_uint(const uint8_t src[4],void * dst)2204 pack_ubyte_a2b10g10r10_uint(const uint8_t src[4], void *dst)
2205 {
2206
2207
2208 uint8_t a =
2209 _mesa_unsigned_to_unsigned(src[3], 2);
2210
2211
2212 uint16_t b =
2213 _mesa_unsigned_to_unsigned(src[2], 10);
2214
2215
2216 uint16_t g =
2217 _mesa_unsigned_to_unsigned(src[1], 10);
2218
2219
2220 uint16_t r =
2221 _mesa_unsigned_to_unsigned(src[0], 10);
2222
2223 uint32_t d = 0;
2224 d |= PACK(a, 0, 2);
2225 d |= PACK(b, 2, 10);
2226 d |= PACK(g, 12, 10);
2227 d |= PACK(r, 22, 10);
2228 (*(uint32_t *)dst) = d;
2229 }
2230
2231 static inline void
pack_ubyte_a2r10g10b10_uint(const uint8_t src[4],void * dst)2232 pack_ubyte_a2r10g10b10_uint(const uint8_t src[4], void *dst)
2233 {
2234
2235
2236 uint8_t a =
2237 _mesa_unsigned_to_unsigned(src[3], 2);
2238
2239
2240 uint16_t r =
2241 _mesa_unsigned_to_unsigned(src[0], 10);
2242
2243
2244 uint16_t g =
2245 _mesa_unsigned_to_unsigned(src[1], 10);
2246
2247
2248 uint16_t b =
2249 _mesa_unsigned_to_unsigned(src[2], 10);
2250
2251 uint32_t d = 0;
2252 d |= PACK(a, 0, 2);
2253 d |= PACK(r, 2, 10);
2254 d |= PACK(g, 12, 10);
2255 d |= PACK(b, 22, 10);
2256 (*(uint32_t *)dst) = d;
2257 }
2258
2259 static inline void
pack_ubyte_b5g6r5_uint(const uint8_t src[4],void * dst)2260 pack_ubyte_b5g6r5_uint(const uint8_t src[4], void *dst)
2261 {
2262
2263
2264 uint8_t b =
2265 _mesa_unsigned_to_unsigned(src[2], 5);
2266
2267
2268 uint8_t g =
2269 _mesa_unsigned_to_unsigned(src[1], 6);
2270
2271
2272 uint8_t r =
2273 _mesa_unsigned_to_unsigned(src[0], 5);
2274
2275 uint16_t d = 0;
2276 d |= PACK(b, 0, 5);
2277 d |= PACK(g, 5, 6);
2278 d |= PACK(r, 11, 5);
2279 (*(uint16_t *)dst) = d;
2280 }
2281
2282 static inline void
pack_ubyte_r5g6b5_uint(const uint8_t src[4],void * dst)2283 pack_ubyte_r5g6b5_uint(const uint8_t src[4], void *dst)
2284 {
2285
2286
2287 uint8_t r =
2288 _mesa_unsigned_to_unsigned(src[0], 5);
2289
2290
2291 uint8_t g =
2292 _mesa_unsigned_to_unsigned(src[1], 6);
2293
2294
2295 uint8_t b =
2296 _mesa_unsigned_to_unsigned(src[2], 5);
2297
2298 uint16_t d = 0;
2299 d |= PACK(r, 0, 5);
2300 d |= PACK(g, 5, 6);
2301 d |= PACK(b, 11, 5);
2302 (*(uint16_t *)dst) = d;
2303 }
2304
2305 static inline void
pack_ubyte_b2g3r3_uint(const uint8_t src[4],void * dst)2306 pack_ubyte_b2g3r3_uint(const uint8_t src[4], void *dst)
2307 {
2308
2309
2310 uint8_t b =
2311 _mesa_unsigned_to_unsigned(src[2], 2);
2312
2313
2314 uint8_t g =
2315 _mesa_unsigned_to_unsigned(src[1], 3);
2316
2317
2318 uint8_t r =
2319 _mesa_unsigned_to_unsigned(src[0], 3);
2320
2321 uint8_t d = 0;
2322 d |= PACK(b, 0, 2);
2323 d |= PACK(g, 2, 3);
2324 d |= PACK(r, 5, 3);
2325 (*(uint8_t *)dst) = d;
2326 }
2327
2328 static inline void
pack_ubyte_r3g3b2_uint(const uint8_t src[4],void * dst)2329 pack_ubyte_r3g3b2_uint(const uint8_t src[4], void *dst)
2330 {
2331
2332
2333 uint8_t r =
2334 _mesa_unsigned_to_unsigned(src[0], 3);
2335
2336
2337 uint8_t g =
2338 _mesa_unsigned_to_unsigned(src[1], 3);
2339
2340
2341 uint8_t b =
2342 _mesa_unsigned_to_unsigned(src[2], 2);
2343
2344 uint8_t d = 0;
2345 d |= PACK(r, 0, 3);
2346 d |= PACK(g, 3, 3);
2347 d |= PACK(b, 6, 2);
2348 (*(uint8_t *)dst) = d;
2349 }
2350
2351 static inline void
pack_ubyte_a4b4g4r4_uint(const uint8_t src[4],void * dst)2352 pack_ubyte_a4b4g4r4_uint(const uint8_t src[4], void *dst)
2353 {
2354
2355
2356 uint8_t a =
2357 _mesa_unsigned_to_unsigned(src[3], 4);
2358
2359
2360 uint8_t b =
2361 _mesa_unsigned_to_unsigned(src[2], 4);
2362
2363
2364 uint8_t g =
2365 _mesa_unsigned_to_unsigned(src[1], 4);
2366
2367
2368 uint8_t r =
2369 _mesa_unsigned_to_unsigned(src[0], 4);
2370
2371 uint16_t d = 0;
2372 d |= PACK(a, 0, 4);
2373 d |= PACK(b, 4, 4);
2374 d |= PACK(g, 8, 4);
2375 d |= PACK(r, 12, 4);
2376 (*(uint16_t *)dst) = d;
2377 }
2378
2379 static inline void
pack_ubyte_r4g4b4a4_uint(const uint8_t src[4],void * dst)2380 pack_ubyte_r4g4b4a4_uint(const uint8_t src[4], void *dst)
2381 {
2382
2383
2384 uint8_t r =
2385 _mesa_unsigned_to_unsigned(src[0], 4);
2386
2387
2388 uint8_t g =
2389 _mesa_unsigned_to_unsigned(src[1], 4);
2390
2391
2392 uint8_t b =
2393 _mesa_unsigned_to_unsigned(src[2], 4);
2394
2395
2396 uint8_t a =
2397 _mesa_unsigned_to_unsigned(src[3], 4);
2398
2399 uint16_t d = 0;
2400 d |= PACK(r, 0, 4);
2401 d |= PACK(g, 4, 4);
2402 d |= PACK(b, 8, 4);
2403 d |= PACK(a, 12, 4);
2404 (*(uint16_t *)dst) = d;
2405 }
2406
2407 static inline void
pack_ubyte_b4g4r4a4_uint(const uint8_t src[4],void * dst)2408 pack_ubyte_b4g4r4a4_uint(const uint8_t src[4], void *dst)
2409 {
2410
2411
2412 uint8_t b =
2413 _mesa_unsigned_to_unsigned(src[2], 4);
2414
2415
2416 uint8_t g =
2417 _mesa_unsigned_to_unsigned(src[1], 4);
2418
2419
2420 uint8_t r =
2421 _mesa_unsigned_to_unsigned(src[0], 4);
2422
2423
2424 uint8_t a =
2425 _mesa_unsigned_to_unsigned(src[3], 4);
2426
2427 uint16_t d = 0;
2428 d |= PACK(b, 0, 4);
2429 d |= PACK(g, 4, 4);
2430 d |= PACK(r, 8, 4);
2431 d |= PACK(a, 12, 4);
2432 (*(uint16_t *)dst) = d;
2433 }
2434
2435 static inline void
pack_ubyte_a4r4g4b4_uint(const uint8_t src[4],void * dst)2436 pack_ubyte_a4r4g4b4_uint(const uint8_t src[4], void *dst)
2437 {
2438
2439
2440 uint8_t a =
2441 _mesa_unsigned_to_unsigned(src[3], 4);
2442
2443
2444 uint8_t r =
2445 _mesa_unsigned_to_unsigned(src[0], 4);
2446
2447
2448 uint8_t g =
2449 _mesa_unsigned_to_unsigned(src[1], 4);
2450
2451
2452 uint8_t b =
2453 _mesa_unsigned_to_unsigned(src[2], 4);
2454
2455 uint16_t d = 0;
2456 d |= PACK(a, 0, 4);
2457 d |= PACK(r, 4, 4);
2458 d |= PACK(g, 8, 4);
2459 d |= PACK(b, 12, 4);
2460 (*(uint16_t *)dst) = d;
2461 }
2462
2463 static inline void
pack_ubyte_a1b5g5r5_uint(const uint8_t src[4],void * dst)2464 pack_ubyte_a1b5g5r5_uint(const uint8_t src[4], void *dst)
2465 {
2466
2467
2468 uint8_t a =
2469 _mesa_unsigned_to_unsigned(src[3], 1);
2470
2471
2472 uint8_t b =
2473 _mesa_unsigned_to_unsigned(src[2], 5);
2474
2475
2476 uint8_t g =
2477 _mesa_unsigned_to_unsigned(src[1], 5);
2478
2479
2480 uint8_t r =
2481 _mesa_unsigned_to_unsigned(src[0], 5);
2482
2483 uint16_t d = 0;
2484 d |= PACK(a, 0, 1);
2485 d |= PACK(b, 1, 5);
2486 d |= PACK(g, 6, 5);
2487 d |= PACK(r, 11, 5);
2488 (*(uint16_t *)dst) = d;
2489 }
2490
2491 static inline void
pack_ubyte_b5g5r5a1_uint(const uint8_t src[4],void * dst)2492 pack_ubyte_b5g5r5a1_uint(const uint8_t src[4], void *dst)
2493 {
2494
2495
2496 uint8_t b =
2497 _mesa_unsigned_to_unsigned(src[2], 5);
2498
2499
2500 uint8_t g =
2501 _mesa_unsigned_to_unsigned(src[1], 5);
2502
2503
2504 uint8_t r =
2505 _mesa_unsigned_to_unsigned(src[0], 5);
2506
2507
2508 uint8_t a =
2509 _mesa_unsigned_to_unsigned(src[3], 1);
2510
2511 uint16_t d = 0;
2512 d |= PACK(b, 0, 5);
2513 d |= PACK(g, 5, 5);
2514 d |= PACK(r, 10, 5);
2515 d |= PACK(a, 15, 1);
2516 (*(uint16_t *)dst) = d;
2517 }
2518
2519 static inline void
pack_ubyte_a1r5g5b5_uint(const uint8_t src[4],void * dst)2520 pack_ubyte_a1r5g5b5_uint(const uint8_t src[4], void *dst)
2521 {
2522
2523
2524 uint8_t a =
2525 _mesa_unsigned_to_unsigned(src[3], 1);
2526
2527
2528 uint8_t r =
2529 _mesa_unsigned_to_unsigned(src[0], 5);
2530
2531
2532 uint8_t g =
2533 _mesa_unsigned_to_unsigned(src[1], 5);
2534
2535
2536 uint8_t b =
2537 _mesa_unsigned_to_unsigned(src[2], 5);
2538
2539 uint16_t d = 0;
2540 d |= PACK(a, 0, 1);
2541 d |= PACK(r, 1, 5);
2542 d |= PACK(g, 6, 5);
2543 d |= PACK(b, 11, 5);
2544 (*(uint16_t *)dst) = d;
2545 }
2546
2547 static inline void
pack_ubyte_r5g5b5a1_uint(const uint8_t src[4],void * dst)2548 pack_ubyte_r5g5b5a1_uint(const uint8_t src[4], void *dst)
2549 {
2550
2551
2552 uint8_t r =
2553 _mesa_unsigned_to_unsigned(src[0], 5);
2554
2555
2556 uint8_t g =
2557 _mesa_unsigned_to_unsigned(src[1], 5);
2558
2559
2560 uint8_t b =
2561 _mesa_unsigned_to_unsigned(src[2], 5);
2562
2563
2564 uint8_t a =
2565 _mesa_unsigned_to_unsigned(src[3], 1);
2566
2567 uint16_t d = 0;
2568 d |= PACK(r, 0, 5);
2569 d |= PACK(g, 5, 5);
2570 d |= PACK(b, 10, 5);
2571 d |= PACK(a, 15, 1);
2572 (*(uint16_t *)dst) = d;
2573 }
2574
2575 static inline void
pack_ubyte_a_uint8(const uint8_t src[4],void * dst)2576 pack_ubyte_a_uint8(const uint8_t src[4], void *dst)
2577 {
2578
2579
2580 uint8_t a =
2581 _mesa_unsigned_to_unsigned(src[3], 8);
2582
2583 uint8_t *d = (uint8_t *)dst;
2584 d[0] = a;
2585 }
2586
2587 static inline void
pack_ubyte_a_uint16(const uint8_t src[4],void * dst)2588 pack_ubyte_a_uint16(const uint8_t src[4], void *dst)
2589 {
2590
2591
2592 uint16_t a =
2593 _mesa_unsigned_to_unsigned(src[3], 16);
2594
2595 uint16_t *d = (uint16_t *)dst;
2596 d[0] = a;
2597 }
2598
2599 static inline void
pack_ubyte_a_uint32(const uint8_t src[4],void * dst)2600 pack_ubyte_a_uint32(const uint8_t src[4], void *dst)
2601 {
2602
2603
2604 uint32_t a =
2605 _mesa_unsigned_to_unsigned(src[3], 32);
2606
2607 uint32_t *d = (uint32_t *)dst;
2608 d[0] = a;
2609 }
2610
2611 static inline void
pack_ubyte_a_sint8(const uint8_t src[4],void * dst)2612 pack_ubyte_a_sint8(const uint8_t src[4], void *dst)
2613 {
2614
2615
2616 int8_t a =
2617 _mesa_unsigned_to_signed(src[3], 8);
2618
2619 int8_t *d = (int8_t *)dst;
2620 d[0] = a;
2621 }
2622
2623 static inline void
pack_ubyte_a_sint16(const uint8_t src[4],void * dst)2624 pack_ubyte_a_sint16(const uint8_t src[4], void *dst)
2625 {
2626
2627
2628 int16_t a =
2629 _mesa_unsigned_to_signed(src[3], 16);
2630
2631 int16_t *d = (int16_t *)dst;
2632 d[0] = a;
2633 }
2634
2635 static inline void
pack_ubyte_a_sint32(const uint8_t src[4],void * dst)2636 pack_ubyte_a_sint32(const uint8_t src[4], void *dst)
2637 {
2638
2639
2640 int32_t a =
2641 _mesa_unsigned_to_signed(src[3], 32);
2642
2643 int32_t *d = (int32_t *)dst;
2644 d[0] = a;
2645 }
2646
2647 static inline void
pack_ubyte_i_uint8(const uint8_t src[4],void * dst)2648 pack_ubyte_i_uint8(const uint8_t src[4], void *dst)
2649 {
2650
2651
2652 uint8_t i =
2653 _mesa_unsigned_to_unsigned(src[0], 8);
2654
2655 uint8_t *d = (uint8_t *)dst;
2656 d[0] = i;
2657 }
2658
2659 static inline void
pack_ubyte_i_uint16(const uint8_t src[4],void * dst)2660 pack_ubyte_i_uint16(const uint8_t src[4], void *dst)
2661 {
2662
2663
2664 uint16_t i =
2665 _mesa_unsigned_to_unsigned(src[0], 16);
2666
2667 uint16_t *d = (uint16_t *)dst;
2668 d[0] = i;
2669 }
2670
2671 static inline void
pack_ubyte_i_uint32(const uint8_t src[4],void * dst)2672 pack_ubyte_i_uint32(const uint8_t src[4], void *dst)
2673 {
2674
2675
2676 uint32_t i =
2677 _mesa_unsigned_to_unsigned(src[0], 32);
2678
2679 uint32_t *d = (uint32_t *)dst;
2680 d[0] = i;
2681 }
2682
2683 static inline void
pack_ubyte_i_sint8(const uint8_t src[4],void * dst)2684 pack_ubyte_i_sint8(const uint8_t src[4], void *dst)
2685 {
2686
2687
2688 int8_t i =
2689 _mesa_unsigned_to_signed(src[0], 8);
2690
2691 int8_t *d = (int8_t *)dst;
2692 d[0] = i;
2693 }
2694
2695 static inline void
pack_ubyte_i_sint16(const uint8_t src[4],void * dst)2696 pack_ubyte_i_sint16(const uint8_t src[4], void *dst)
2697 {
2698
2699
2700 int16_t i =
2701 _mesa_unsigned_to_signed(src[0], 16);
2702
2703 int16_t *d = (int16_t *)dst;
2704 d[0] = i;
2705 }
2706
2707 static inline void
pack_ubyte_i_sint32(const uint8_t src[4],void * dst)2708 pack_ubyte_i_sint32(const uint8_t src[4], void *dst)
2709 {
2710
2711
2712 int32_t i =
2713 _mesa_unsigned_to_signed(src[0], 32);
2714
2715 int32_t *d = (int32_t *)dst;
2716 d[0] = i;
2717 }
2718
2719 static inline void
pack_ubyte_l_uint8(const uint8_t src[4],void * dst)2720 pack_ubyte_l_uint8(const uint8_t src[4], void *dst)
2721 {
2722
2723
2724 uint8_t l =
2725 _mesa_unsigned_to_unsigned(src[0], 8);
2726
2727 uint8_t *d = (uint8_t *)dst;
2728 d[0] = l;
2729 }
2730
2731 static inline void
pack_ubyte_l_uint16(const uint8_t src[4],void * dst)2732 pack_ubyte_l_uint16(const uint8_t src[4], void *dst)
2733 {
2734
2735
2736 uint16_t l =
2737 _mesa_unsigned_to_unsigned(src[0], 16);
2738
2739 uint16_t *d = (uint16_t *)dst;
2740 d[0] = l;
2741 }
2742
2743 static inline void
pack_ubyte_l_uint32(const uint8_t src[4],void * dst)2744 pack_ubyte_l_uint32(const uint8_t src[4], void *dst)
2745 {
2746
2747
2748 uint32_t l =
2749 _mesa_unsigned_to_unsigned(src[0], 32);
2750
2751 uint32_t *d = (uint32_t *)dst;
2752 d[0] = l;
2753 }
2754
2755 static inline void
pack_ubyte_l_sint8(const uint8_t src[4],void * dst)2756 pack_ubyte_l_sint8(const uint8_t src[4], void *dst)
2757 {
2758
2759
2760 int8_t l =
2761 _mesa_unsigned_to_signed(src[0], 8);
2762
2763 int8_t *d = (int8_t *)dst;
2764 d[0] = l;
2765 }
2766
2767 static inline void
pack_ubyte_l_sint16(const uint8_t src[4],void * dst)2768 pack_ubyte_l_sint16(const uint8_t src[4], void *dst)
2769 {
2770
2771
2772 int16_t l =
2773 _mesa_unsigned_to_signed(src[0], 16);
2774
2775 int16_t *d = (int16_t *)dst;
2776 d[0] = l;
2777 }
2778
2779 static inline void
pack_ubyte_l_sint32(const uint8_t src[4],void * dst)2780 pack_ubyte_l_sint32(const uint8_t src[4], void *dst)
2781 {
2782
2783
2784 int32_t l =
2785 _mesa_unsigned_to_signed(src[0], 32);
2786
2787 int32_t *d = (int32_t *)dst;
2788 d[0] = l;
2789 }
2790
2791 static inline void
pack_ubyte_la_uint8(const uint8_t src[4],void * dst)2792 pack_ubyte_la_uint8(const uint8_t src[4], void *dst)
2793 {
2794
2795
2796 uint8_t l =
2797 _mesa_unsigned_to_unsigned(src[0], 8);
2798
2799
2800 uint8_t a =
2801 _mesa_unsigned_to_unsigned(src[3], 8);
2802
2803 uint8_t *d = (uint8_t *)dst;
2804 d[0] = l;
2805 d[1] = a;
2806 }
2807
2808 static inline void
pack_ubyte_la_uint16(const uint8_t src[4],void * dst)2809 pack_ubyte_la_uint16(const uint8_t src[4], void *dst)
2810 {
2811
2812
2813 uint16_t l =
2814 _mesa_unsigned_to_unsigned(src[0], 16);
2815
2816
2817 uint16_t a =
2818 _mesa_unsigned_to_unsigned(src[3], 16);
2819
2820 uint16_t *d = (uint16_t *)dst;
2821 d[0] = l;
2822 d[1] = a;
2823 }
2824
2825 static inline void
pack_ubyte_la_uint32(const uint8_t src[4],void * dst)2826 pack_ubyte_la_uint32(const uint8_t src[4], void *dst)
2827 {
2828
2829
2830 uint32_t l =
2831 _mesa_unsigned_to_unsigned(src[0], 32);
2832
2833
2834 uint32_t a =
2835 _mesa_unsigned_to_unsigned(src[3], 32);
2836
2837 uint32_t *d = (uint32_t *)dst;
2838 d[0] = l;
2839 d[1] = a;
2840 }
2841
2842 static inline void
pack_ubyte_la_sint8(const uint8_t src[4],void * dst)2843 pack_ubyte_la_sint8(const uint8_t src[4], void *dst)
2844 {
2845
2846
2847 int8_t l =
2848 _mesa_unsigned_to_signed(src[0], 8);
2849
2850
2851 int8_t a =
2852 _mesa_unsigned_to_signed(src[3], 8);
2853
2854 int8_t *d = (int8_t *)dst;
2855 d[0] = l;
2856 d[1] = a;
2857 }
2858
2859 static inline void
pack_ubyte_la_sint16(const uint8_t src[4],void * dst)2860 pack_ubyte_la_sint16(const uint8_t src[4], void *dst)
2861 {
2862
2863
2864 int16_t l =
2865 _mesa_unsigned_to_signed(src[0], 16);
2866
2867
2868 int16_t a =
2869 _mesa_unsigned_to_signed(src[3], 16);
2870
2871 int16_t *d = (int16_t *)dst;
2872 d[0] = l;
2873 d[1] = a;
2874 }
2875
2876 static inline void
pack_ubyte_la_sint32(const uint8_t src[4],void * dst)2877 pack_ubyte_la_sint32(const uint8_t src[4], void *dst)
2878 {
2879
2880
2881 int32_t l =
2882 _mesa_unsigned_to_signed(src[0], 32);
2883
2884
2885 int32_t a =
2886 _mesa_unsigned_to_signed(src[3], 32);
2887
2888 int32_t *d = (int32_t *)dst;
2889 d[0] = l;
2890 d[1] = a;
2891 }
2892
2893 static inline void
pack_ubyte_r_uint8(const uint8_t src[4],void * dst)2894 pack_ubyte_r_uint8(const uint8_t src[4], void *dst)
2895 {
2896
2897
2898 uint8_t r =
2899 _mesa_unsigned_to_unsigned(src[0], 8);
2900
2901 uint8_t *d = (uint8_t *)dst;
2902 d[0] = r;
2903 }
2904
2905 static inline void
pack_ubyte_r_uint16(const uint8_t src[4],void * dst)2906 pack_ubyte_r_uint16(const uint8_t src[4], void *dst)
2907 {
2908
2909
2910 uint16_t r =
2911 _mesa_unsigned_to_unsigned(src[0], 16);
2912
2913 uint16_t *d = (uint16_t *)dst;
2914 d[0] = r;
2915 }
2916
2917 static inline void
pack_ubyte_r_uint32(const uint8_t src[4],void * dst)2918 pack_ubyte_r_uint32(const uint8_t src[4], void *dst)
2919 {
2920
2921
2922 uint32_t r =
2923 _mesa_unsigned_to_unsigned(src[0], 32);
2924
2925 uint32_t *d = (uint32_t *)dst;
2926 d[0] = r;
2927 }
2928
2929 static inline void
pack_ubyte_r_sint8(const uint8_t src[4],void * dst)2930 pack_ubyte_r_sint8(const uint8_t src[4], void *dst)
2931 {
2932
2933
2934 int8_t r =
2935 _mesa_unsigned_to_signed(src[0], 8);
2936
2937 int8_t *d = (int8_t *)dst;
2938 d[0] = r;
2939 }
2940
2941 static inline void
pack_ubyte_r_sint16(const uint8_t src[4],void * dst)2942 pack_ubyte_r_sint16(const uint8_t src[4], void *dst)
2943 {
2944
2945
2946 int16_t r =
2947 _mesa_unsigned_to_signed(src[0], 16);
2948
2949 int16_t *d = (int16_t *)dst;
2950 d[0] = r;
2951 }
2952
2953 static inline void
pack_ubyte_r_sint32(const uint8_t src[4],void * dst)2954 pack_ubyte_r_sint32(const uint8_t src[4], void *dst)
2955 {
2956
2957
2958 int32_t r =
2959 _mesa_unsigned_to_signed(src[0], 32);
2960
2961 int32_t *d = (int32_t *)dst;
2962 d[0] = r;
2963 }
2964
2965 static inline void
pack_ubyte_rg_uint8(const uint8_t src[4],void * dst)2966 pack_ubyte_rg_uint8(const uint8_t src[4], void *dst)
2967 {
2968
2969
2970 uint8_t r =
2971 _mesa_unsigned_to_unsigned(src[0], 8);
2972
2973
2974 uint8_t g =
2975 _mesa_unsigned_to_unsigned(src[1], 8);
2976
2977 uint8_t *d = (uint8_t *)dst;
2978 d[0] = r;
2979 d[1] = g;
2980 }
2981
2982 static inline void
pack_ubyte_rg_uint16(const uint8_t src[4],void * dst)2983 pack_ubyte_rg_uint16(const uint8_t src[4], void *dst)
2984 {
2985
2986
2987 uint16_t r =
2988 _mesa_unsigned_to_unsigned(src[0], 16);
2989
2990
2991 uint16_t g =
2992 _mesa_unsigned_to_unsigned(src[1], 16);
2993
2994 uint16_t *d = (uint16_t *)dst;
2995 d[0] = r;
2996 d[1] = g;
2997 }
2998
2999 static inline void
pack_ubyte_rg_uint32(const uint8_t src[4],void * dst)3000 pack_ubyte_rg_uint32(const uint8_t src[4], void *dst)
3001 {
3002
3003
3004 uint32_t r =
3005 _mesa_unsigned_to_unsigned(src[0], 32);
3006
3007
3008 uint32_t g =
3009 _mesa_unsigned_to_unsigned(src[1], 32);
3010
3011 uint32_t *d = (uint32_t *)dst;
3012 d[0] = r;
3013 d[1] = g;
3014 }
3015
3016 static inline void
pack_ubyte_rg_sint8(const uint8_t src[4],void * dst)3017 pack_ubyte_rg_sint8(const uint8_t src[4], void *dst)
3018 {
3019
3020
3021 int8_t r =
3022 _mesa_unsigned_to_signed(src[0], 8);
3023
3024
3025 int8_t g =
3026 _mesa_unsigned_to_signed(src[1], 8);
3027
3028 int8_t *d = (int8_t *)dst;
3029 d[0] = r;
3030 d[1] = g;
3031 }
3032
3033 static inline void
pack_ubyte_rg_sint16(const uint8_t src[4],void * dst)3034 pack_ubyte_rg_sint16(const uint8_t src[4], void *dst)
3035 {
3036
3037
3038 int16_t r =
3039 _mesa_unsigned_to_signed(src[0], 16);
3040
3041
3042 int16_t g =
3043 _mesa_unsigned_to_signed(src[1], 16);
3044
3045 int16_t *d = (int16_t *)dst;
3046 d[0] = r;
3047 d[1] = g;
3048 }
3049
3050 static inline void
pack_ubyte_rg_sint32(const uint8_t src[4],void * dst)3051 pack_ubyte_rg_sint32(const uint8_t src[4], void *dst)
3052 {
3053
3054
3055 int32_t r =
3056 _mesa_unsigned_to_signed(src[0], 32);
3057
3058
3059 int32_t g =
3060 _mesa_unsigned_to_signed(src[1], 32);
3061
3062 int32_t *d = (int32_t *)dst;
3063 d[0] = r;
3064 d[1] = g;
3065 }
3066
3067 static inline void
pack_ubyte_rgb_uint8(const uint8_t src[4],void * dst)3068 pack_ubyte_rgb_uint8(const uint8_t src[4], void *dst)
3069 {
3070
3071
3072 uint8_t r =
3073 _mesa_unsigned_to_unsigned(src[0], 8);
3074
3075
3076 uint8_t g =
3077 _mesa_unsigned_to_unsigned(src[1], 8);
3078
3079
3080 uint8_t b =
3081 _mesa_unsigned_to_unsigned(src[2], 8);
3082
3083 uint8_t *d = (uint8_t *)dst;
3084 d[0] = r;
3085 d[1] = g;
3086 d[2] = b;
3087 }
3088
3089 static inline void
pack_ubyte_rgb_uint16(const uint8_t src[4],void * dst)3090 pack_ubyte_rgb_uint16(const uint8_t src[4], void *dst)
3091 {
3092
3093
3094 uint16_t r =
3095 _mesa_unsigned_to_unsigned(src[0], 16);
3096
3097
3098 uint16_t g =
3099 _mesa_unsigned_to_unsigned(src[1], 16);
3100
3101
3102 uint16_t b =
3103 _mesa_unsigned_to_unsigned(src[2], 16);
3104
3105 uint16_t *d = (uint16_t *)dst;
3106 d[0] = r;
3107 d[1] = g;
3108 d[2] = b;
3109 }
3110
3111 static inline void
pack_ubyte_rgb_uint32(const uint8_t src[4],void * dst)3112 pack_ubyte_rgb_uint32(const uint8_t src[4], void *dst)
3113 {
3114
3115
3116 uint32_t r =
3117 _mesa_unsigned_to_unsigned(src[0], 32);
3118
3119
3120 uint32_t g =
3121 _mesa_unsigned_to_unsigned(src[1], 32);
3122
3123
3124 uint32_t b =
3125 _mesa_unsigned_to_unsigned(src[2], 32);
3126
3127 uint32_t *d = (uint32_t *)dst;
3128 d[0] = r;
3129 d[1] = g;
3130 d[2] = b;
3131 }
3132
3133 static inline void
pack_ubyte_rgb_sint8(const uint8_t src[4],void * dst)3134 pack_ubyte_rgb_sint8(const uint8_t src[4], void *dst)
3135 {
3136
3137
3138 int8_t r =
3139 _mesa_unsigned_to_signed(src[0], 8);
3140
3141
3142 int8_t g =
3143 _mesa_unsigned_to_signed(src[1], 8);
3144
3145
3146 int8_t b =
3147 _mesa_unsigned_to_signed(src[2], 8);
3148
3149 int8_t *d = (int8_t *)dst;
3150 d[0] = r;
3151 d[1] = g;
3152 d[2] = b;
3153 }
3154
3155 static inline void
pack_ubyte_rgb_sint16(const uint8_t src[4],void * dst)3156 pack_ubyte_rgb_sint16(const uint8_t src[4], void *dst)
3157 {
3158
3159
3160 int16_t r =
3161 _mesa_unsigned_to_signed(src[0], 16);
3162
3163
3164 int16_t g =
3165 _mesa_unsigned_to_signed(src[1], 16);
3166
3167
3168 int16_t b =
3169 _mesa_unsigned_to_signed(src[2], 16);
3170
3171 int16_t *d = (int16_t *)dst;
3172 d[0] = r;
3173 d[1] = g;
3174 d[2] = b;
3175 }
3176
3177 static inline void
pack_ubyte_rgb_sint32(const uint8_t src[4],void * dst)3178 pack_ubyte_rgb_sint32(const uint8_t src[4], void *dst)
3179 {
3180
3181
3182 int32_t r =
3183 _mesa_unsigned_to_signed(src[0], 32);
3184
3185
3186 int32_t g =
3187 _mesa_unsigned_to_signed(src[1], 32);
3188
3189
3190 int32_t b =
3191 _mesa_unsigned_to_signed(src[2], 32);
3192
3193 int32_t *d = (int32_t *)dst;
3194 d[0] = r;
3195 d[1] = g;
3196 d[2] = b;
3197 }
3198
3199 static inline void
pack_ubyte_rgba_uint16(const uint8_t src[4],void * dst)3200 pack_ubyte_rgba_uint16(const uint8_t src[4], void *dst)
3201 {
3202
3203
3204 uint16_t r =
3205 _mesa_unsigned_to_unsigned(src[0], 16);
3206
3207
3208 uint16_t g =
3209 _mesa_unsigned_to_unsigned(src[1], 16);
3210
3211
3212 uint16_t b =
3213 _mesa_unsigned_to_unsigned(src[2], 16);
3214
3215
3216 uint16_t a =
3217 _mesa_unsigned_to_unsigned(src[3], 16);
3218
3219 uint16_t *d = (uint16_t *)dst;
3220 d[0] = r;
3221 d[1] = g;
3222 d[2] = b;
3223 d[3] = a;
3224 }
3225
3226 static inline void
pack_ubyte_rgba_uint32(const uint8_t src[4],void * dst)3227 pack_ubyte_rgba_uint32(const uint8_t src[4], void *dst)
3228 {
3229
3230
3231 uint32_t r =
3232 _mesa_unsigned_to_unsigned(src[0], 32);
3233
3234
3235 uint32_t g =
3236 _mesa_unsigned_to_unsigned(src[1], 32);
3237
3238
3239 uint32_t b =
3240 _mesa_unsigned_to_unsigned(src[2], 32);
3241
3242
3243 uint32_t a =
3244 _mesa_unsigned_to_unsigned(src[3], 32);
3245
3246 uint32_t *d = (uint32_t *)dst;
3247 d[0] = r;
3248 d[1] = g;
3249 d[2] = b;
3250 d[3] = a;
3251 }
3252
3253 static inline void
pack_ubyte_rgba_sint8(const uint8_t src[4],void * dst)3254 pack_ubyte_rgba_sint8(const uint8_t src[4], void *dst)
3255 {
3256
3257
3258 int8_t r =
3259 _mesa_unsigned_to_signed(src[0], 8);
3260
3261
3262 int8_t g =
3263 _mesa_unsigned_to_signed(src[1], 8);
3264
3265
3266 int8_t b =
3267 _mesa_unsigned_to_signed(src[2], 8);
3268
3269
3270 int8_t a =
3271 _mesa_unsigned_to_signed(src[3], 8);
3272
3273 int8_t *d = (int8_t *)dst;
3274 d[0] = r;
3275 d[1] = g;
3276 d[2] = b;
3277 d[3] = a;
3278 }
3279
3280 static inline void
pack_ubyte_rgba_sint16(const uint8_t src[4],void * dst)3281 pack_ubyte_rgba_sint16(const uint8_t src[4], void *dst)
3282 {
3283
3284
3285 int16_t r =
3286 _mesa_unsigned_to_signed(src[0], 16);
3287
3288
3289 int16_t g =
3290 _mesa_unsigned_to_signed(src[1], 16);
3291
3292
3293 int16_t b =
3294 _mesa_unsigned_to_signed(src[2], 16);
3295
3296
3297 int16_t a =
3298 _mesa_unsigned_to_signed(src[3], 16);
3299
3300 int16_t *d = (int16_t *)dst;
3301 d[0] = r;
3302 d[1] = g;
3303 d[2] = b;
3304 d[3] = a;
3305 }
3306
3307 static inline void
pack_ubyte_rgba_sint32(const uint8_t src[4],void * dst)3308 pack_ubyte_rgba_sint32(const uint8_t src[4], void *dst)
3309 {
3310
3311
3312 int32_t r =
3313 _mesa_unsigned_to_signed(src[0], 32);
3314
3315
3316 int32_t g =
3317 _mesa_unsigned_to_signed(src[1], 32);
3318
3319
3320 int32_t b =
3321 _mesa_unsigned_to_signed(src[2], 32);
3322
3323
3324 int32_t a =
3325 _mesa_unsigned_to_signed(src[3], 32);
3326
3327 int32_t *d = (int32_t *)dst;
3328 d[0] = r;
3329 d[1] = g;
3330 d[2] = b;
3331 d[3] = a;
3332 }
3333
3334 static inline void
pack_ubyte_rgbx_uint8(const uint8_t src[4],void * dst)3335 pack_ubyte_rgbx_uint8(const uint8_t src[4], void *dst)
3336 {
3337
3338
3339 uint8_t r =
3340 _mesa_unsigned_to_unsigned(src[0], 8);
3341
3342
3343 uint8_t g =
3344 _mesa_unsigned_to_unsigned(src[1], 8);
3345
3346
3347 uint8_t b =
3348 _mesa_unsigned_to_unsigned(src[2], 8);
3349
3350
3351 uint8_t *d = (uint8_t *)dst;
3352 d[0] = r;
3353 d[1] = g;
3354 d[2] = b;
3355 }
3356
3357 static inline void
pack_ubyte_rgbx_uint16(const uint8_t src[4],void * dst)3358 pack_ubyte_rgbx_uint16(const uint8_t src[4], void *dst)
3359 {
3360
3361
3362 uint16_t r =
3363 _mesa_unsigned_to_unsigned(src[0], 16);
3364
3365
3366 uint16_t g =
3367 _mesa_unsigned_to_unsigned(src[1], 16);
3368
3369
3370 uint16_t b =
3371 _mesa_unsigned_to_unsigned(src[2], 16);
3372
3373
3374 uint16_t *d = (uint16_t *)dst;
3375 d[0] = r;
3376 d[1] = g;
3377 d[2] = b;
3378 }
3379
3380 static inline void
pack_ubyte_rgbx_uint32(const uint8_t src[4],void * dst)3381 pack_ubyte_rgbx_uint32(const uint8_t src[4], void *dst)
3382 {
3383
3384
3385 uint32_t r =
3386 _mesa_unsigned_to_unsigned(src[0], 32);
3387
3388
3389 uint32_t g =
3390 _mesa_unsigned_to_unsigned(src[1], 32);
3391
3392
3393 uint32_t b =
3394 _mesa_unsigned_to_unsigned(src[2], 32);
3395
3396
3397 uint32_t *d = (uint32_t *)dst;
3398 d[0] = r;
3399 d[1] = g;
3400 d[2] = b;
3401 }
3402
3403 static inline void
pack_ubyte_rgbx_sint8(const uint8_t src[4],void * dst)3404 pack_ubyte_rgbx_sint8(const uint8_t src[4], void *dst)
3405 {
3406
3407
3408 int8_t r =
3409 _mesa_unsigned_to_signed(src[0], 8);
3410
3411
3412 int8_t g =
3413 _mesa_unsigned_to_signed(src[1], 8);
3414
3415
3416 int8_t b =
3417 _mesa_unsigned_to_signed(src[2], 8);
3418
3419
3420 int8_t *d = (int8_t *)dst;
3421 d[0] = r;
3422 d[1] = g;
3423 d[2] = b;
3424 }
3425
3426 static inline void
pack_ubyte_rgbx_sint16(const uint8_t src[4],void * dst)3427 pack_ubyte_rgbx_sint16(const uint8_t src[4], void *dst)
3428 {
3429
3430
3431 int16_t r =
3432 _mesa_unsigned_to_signed(src[0], 16);
3433
3434
3435 int16_t g =
3436 _mesa_unsigned_to_signed(src[1], 16);
3437
3438
3439 int16_t b =
3440 _mesa_unsigned_to_signed(src[2], 16);
3441
3442
3443 int16_t *d = (int16_t *)dst;
3444 d[0] = r;
3445 d[1] = g;
3446 d[2] = b;
3447 }
3448
3449 static inline void
pack_ubyte_rgbx_sint32(const uint8_t src[4],void * dst)3450 pack_ubyte_rgbx_sint32(const uint8_t src[4], void *dst)
3451 {
3452
3453
3454 int32_t r =
3455 _mesa_unsigned_to_signed(src[0], 32);
3456
3457
3458 int32_t g =
3459 _mesa_unsigned_to_signed(src[1], 32);
3460
3461
3462 int32_t b =
3463 _mesa_unsigned_to_signed(src[2], 32);
3464
3465
3466 int32_t *d = (int32_t *)dst;
3467 d[0] = r;
3468 d[1] = g;
3469 d[2] = b;
3470 }
3471
3472 static inline void
pack_ubyte_r9g9b9e5_float(const uint8_t src[4],void * dst)3473 pack_ubyte_r9g9b9e5_float(const uint8_t src[4], void *dst)
3474 {
3475 uint32_t *d = (uint32_t *) dst;
3476 float rgb[3];
3477 rgb[0] = _mesa_unorm_to_float(src[0], 8);
3478 rgb[1] = _mesa_unorm_to_float(src[1], 8);
3479 rgb[2] = _mesa_unorm_to_float(src[2], 8);
3480 *d = float3_to_rgb9e5(rgb);
3481 }
3482
3483 static inline void
pack_ubyte_r11g11b10_float(const uint8_t src[4],void * dst)3484 pack_ubyte_r11g11b10_float(const uint8_t src[4], void *dst)
3485 {
3486 uint32_t *d = (uint32_t *) dst;
3487 float rgb[3];
3488 rgb[0] = _mesa_unorm_to_float(src[0], 8);
3489 rgb[1] = _mesa_unorm_to_float(src[1], 8);
3490 rgb[2] = _mesa_unorm_to_float(src[2], 8);
3491 *d = float3_to_r11g11b10f(rgb);
3492 }
3493
3494 /* uint packing functions */
3495
3496
3497 static inline void
pack_uint_a8b8g8r8_uint(const uint32_t src[4],void * dst)3498 pack_uint_a8b8g8r8_uint(const uint32_t src[4], void *dst)
3499 {
3500
3501
3502 uint8_t a =
3503 _mesa_unsigned_to_unsigned(src[3], 8);
3504
3505
3506 uint8_t b =
3507 _mesa_unsigned_to_unsigned(src[2], 8);
3508
3509
3510 uint8_t g =
3511 _mesa_unsigned_to_unsigned(src[1], 8);
3512
3513
3514 uint8_t r =
3515 _mesa_unsigned_to_unsigned(src[0], 8);
3516
3517 uint32_t d = 0;
3518 d |= PACK(a, 0, 8);
3519 d |= PACK(b, 8, 8);
3520 d |= PACK(g, 16, 8);
3521 d |= PACK(r, 24, 8);
3522 (*(uint32_t *)dst) = d;
3523 }
3524
3525 static inline void
pack_uint_a8r8g8b8_uint(const uint32_t src[4],void * dst)3526 pack_uint_a8r8g8b8_uint(const uint32_t src[4], void *dst)
3527 {
3528
3529
3530 uint8_t a =
3531 _mesa_unsigned_to_unsigned(src[3], 8);
3532
3533
3534 uint8_t r =
3535 _mesa_unsigned_to_unsigned(src[0], 8);
3536
3537
3538 uint8_t g =
3539 _mesa_unsigned_to_unsigned(src[1], 8);
3540
3541
3542 uint8_t b =
3543 _mesa_unsigned_to_unsigned(src[2], 8);
3544
3545 uint32_t d = 0;
3546 d |= PACK(a, 0, 8);
3547 d |= PACK(r, 8, 8);
3548 d |= PACK(g, 16, 8);
3549 d |= PACK(b, 24, 8);
3550 (*(uint32_t *)dst) = d;
3551 }
3552
3553 static inline void
pack_uint_r8g8b8a8_uint(const uint32_t src[4],void * dst)3554 pack_uint_r8g8b8a8_uint(const uint32_t src[4], void *dst)
3555 {
3556
3557
3558 uint8_t r =
3559 _mesa_unsigned_to_unsigned(src[0], 8);
3560
3561
3562 uint8_t g =
3563 _mesa_unsigned_to_unsigned(src[1], 8);
3564
3565
3566 uint8_t b =
3567 _mesa_unsigned_to_unsigned(src[2], 8);
3568
3569
3570 uint8_t a =
3571 _mesa_unsigned_to_unsigned(src[3], 8);
3572
3573 uint32_t d = 0;
3574 d |= PACK(r, 0, 8);
3575 d |= PACK(g, 8, 8);
3576 d |= PACK(b, 16, 8);
3577 d |= PACK(a, 24, 8);
3578 (*(uint32_t *)dst) = d;
3579 }
3580
3581 static inline void
pack_uint_b8g8r8a8_uint(const uint32_t src[4],void * dst)3582 pack_uint_b8g8r8a8_uint(const uint32_t src[4], void *dst)
3583 {
3584
3585
3586 uint8_t b =
3587 _mesa_unsigned_to_unsigned(src[2], 8);
3588
3589
3590 uint8_t g =
3591 _mesa_unsigned_to_unsigned(src[1], 8);
3592
3593
3594 uint8_t r =
3595 _mesa_unsigned_to_unsigned(src[0], 8);
3596
3597
3598 uint8_t a =
3599 _mesa_unsigned_to_unsigned(src[3], 8);
3600
3601 uint32_t d = 0;
3602 d |= PACK(b, 0, 8);
3603 d |= PACK(g, 8, 8);
3604 d |= PACK(r, 16, 8);
3605 d |= PACK(a, 24, 8);
3606 (*(uint32_t *)dst) = d;
3607 }
3608
3609 static inline void
pack_uint_b10g10r10a2_uint(const uint32_t src[4],void * dst)3610 pack_uint_b10g10r10a2_uint(const uint32_t src[4], void *dst)
3611 {
3612
3613
3614 uint16_t b =
3615 _mesa_unsigned_to_unsigned(src[2], 10);
3616
3617
3618 uint16_t g =
3619 _mesa_unsigned_to_unsigned(src[1], 10);
3620
3621
3622 uint16_t r =
3623 _mesa_unsigned_to_unsigned(src[0], 10);
3624
3625
3626 uint8_t a =
3627 _mesa_unsigned_to_unsigned(src[3], 2);
3628
3629 uint32_t d = 0;
3630 d |= PACK(b, 0, 10);
3631 d |= PACK(g, 10, 10);
3632 d |= PACK(r, 20, 10);
3633 d |= PACK(a, 30, 2);
3634 (*(uint32_t *)dst) = d;
3635 }
3636
3637 static inline void
pack_uint_r10g10b10a2_uint(const uint32_t src[4],void * dst)3638 pack_uint_r10g10b10a2_uint(const uint32_t src[4], void *dst)
3639 {
3640
3641
3642 uint16_t r =
3643 _mesa_unsigned_to_unsigned(src[0], 10);
3644
3645
3646 uint16_t g =
3647 _mesa_unsigned_to_unsigned(src[1], 10);
3648
3649
3650 uint16_t b =
3651 _mesa_unsigned_to_unsigned(src[2], 10);
3652
3653
3654 uint8_t a =
3655 _mesa_unsigned_to_unsigned(src[3], 2);
3656
3657 uint32_t d = 0;
3658 d |= PACK(r, 0, 10);
3659 d |= PACK(g, 10, 10);
3660 d |= PACK(b, 20, 10);
3661 d |= PACK(a, 30, 2);
3662 (*(uint32_t *)dst) = d;
3663 }
3664
3665 static inline void
pack_uint_a2b10g10r10_uint(const uint32_t src[4],void * dst)3666 pack_uint_a2b10g10r10_uint(const uint32_t src[4], void *dst)
3667 {
3668
3669
3670 uint8_t a =
3671 _mesa_unsigned_to_unsigned(src[3], 2);
3672
3673
3674 uint16_t b =
3675 _mesa_unsigned_to_unsigned(src[2], 10);
3676
3677
3678 uint16_t g =
3679 _mesa_unsigned_to_unsigned(src[1], 10);
3680
3681
3682 uint16_t r =
3683 _mesa_unsigned_to_unsigned(src[0], 10);
3684
3685 uint32_t d = 0;
3686 d |= PACK(a, 0, 2);
3687 d |= PACK(b, 2, 10);
3688 d |= PACK(g, 12, 10);
3689 d |= PACK(r, 22, 10);
3690 (*(uint32_t *)dst) = d;
3691 }
3692
3693 static inline void
pack_uint_a2r10g10b10_uint(const uint32_t src[4],void * dst)3694 pack_uint_a2r10g10b10_uint(const uint32_t src[4], void *dst)
3695 {
3696
3697
3698 uint8_t a =
3699 _mesa_unsigned_to_unsigned(src[3], 2);
3700
3701
3702 uint16_t r =
3703 _mesa_unsigned_to_unsigned(src[0], 10);
3704
3705
3706 uint16_t g =
3707 _mesa_unsigned_to_unsigned(src[1], 10);
3708
3709
3710 uint16_t b =
3711 _mesa_unsigned_to_unsigned(src[2], 10);
3712
3713 uint32_t d = 0;
3714 d |= PACK(a, 0, 2);
3715 d |= PACK(r, 2, 10);
3716 d |= PACK(g, 12, 10);
3717 d |= PACK(b, 22, 10);
3718 (*(uint32_t *)dst) = d;
3719 }
3720
3721 static inline void
pack_uint_b5g6r5_uint(const uint32_t src[4],void * dst)3722 pack_uint_b5g6r5_uint(const uint32_t src[4], void *dst)
3723 {
3724
3725
3726 uint8_t b =
3727 _mesa_unsigned_to_unsigned(src[2], 5);
3728
3729
3730 uint8_t g =
3731 _mesa_unsigned_to_unsigned(src[1], 6);
3732
3733
3734 uint8_t r =
3735 _mesa_unsigned_to_unsigned(src[0], 5);
3736
3737 uint16_t d = 0;
3738 d |= PACK(b, 0, 5);
3739 d |= PACK(g, 5, 6);
3740 d |= PACK(r, 11, 5);
3741 (*(uint16_t *)dst) = d;
3742 }
3743
3744 static inline void
pack_uint_r5g6b5_uint(const uint32_t src[4],void * dst)3745 pack_uint_r5g6b5_uint(const uint32_t src[4], void *dst)
3746 {
3747
3748
3749 uint8_t r =
3750 _mesa_unsigned_to_unsigned(src[0], 5);
3751
3752
3753 uint8_t g =
3754 _mesa_unsigned_to_unsigned(src[1], 6);
3755
3756
3757 uint8_t b =
3758 _mesa_unsigned_to_unsigned(src[2], 5);
3759
3760 uint16_t d = 0;
3761 d |= PACK(r, 0, 5);
3762 d |= PACK(g, 5, 6);
3763 d |= PACK(b, 11, 5);
3764 (*(uint16_t *)dst) = d;
3765 }
3766
3767 static inline void
pack_uint_b2g3r3_uint(const uint32_t src[4],void * dst)3768 pack_uint_b2g3r3_uint(const uint32_t src[4], void *dst)
3769 {
3770
3771
3772 uint8_t b =
3773 _mesa_unsigned_to_unsigned(src[2], 2);
3774
3775
3776 uint8_t g =
3777 _mesa_unsigned_to_unsigned(src[1], 3);
3778
3779
3780 uint8_t r =
3781 _mesa_unsigned_to_unsigned(src[0], 3);
3782
3783 uint8_t d = 0;
3784 d |= PACK(b, 0, 2);
3785 d |= PACK(g, 2, 3);
3786 d |= PACK(r, 5, 3);
3787 (*(uint8_t *)dst) = d;
3788 }
3789
3790 static inline void
pack_uint_r3g3b2_uint(const uint32_t src[4],void * dst)3791 pack_uint_r3g3b2_uint(const uint32_t src[4], void *dst)
3792 {
3793
3794
3795 uint8_t r =
3796 _mesa_unsigned_to_unsigned(src[0], 3);
3797
3798
3799 uint8_t g =
3800 _mesa_unsigned_to_unsigned(src[1], 3);
3801
3802
3803 uint8_t b =
3804 _mesa_unsigned_to_unsigned(src[2], 2);
3805
3806 uint8_t d = 0;
3807 d |= PACK(r, 0, 3);
3808 d |= PACK(g, 3, 3);
3809 d |= PACK(b, 6, 2);
3810 (*(uint8_t *)dst) = d;
3811 }
3812
3813 static inline void
pack_uint_a4b4g4r4_uint(const uint32_t src[4],void * dst)3814 pack_uint_a4b4g4r4_uint(const uint32_t src[4], void *dst)
3815 {
3816
3817
3818 uint8_t a =
3819 _mesa_unsigned_to_unsigned(src[3], 4);
3820
3821
3822 uint8_t b =
3823 _mesa_unsigned_to_unsigned(src[2], 4);
3824
3825
3826 uint8_t g =
3827 _mesa_unsigned_to_unsigned(src[1], 4);
3828
3829
3830 uint8_t r =
3831 _mesa_unsigned_to_unsigned(src[0], 4);
3832
3833 uint16_t d = 0;
3834 d |= PACK(a, 0, 4);
3835 d |= PACK(b, 4, 4);
3836 d |= PACK(g, 8, 4);
3837 d |= PACK(r, 12, 4);
3838 (*(uint16_t *)dst) = d;
3839 }
3840
3841 static inline void
pack_uint_r4g4b4a4_uint(const uint32_t src[4],void * dst)3842 pack_uint_r4g4b4a4_uint(const uint32_t src[4], void *dst)
3843 {
3844
3845
3846 uint8_t r =
3847 _mesa_unsigned_to_unsigned(src[0], 4);
3848
3849
3850 uint8_t g =
3851 _mesa_unsigned_to_unsigned(src[1], 4);
3852
3853
3854 uint8_t b =
3855 _mesa_unsigned_to_unsigned(src[2], 4);
3856
3857
3858 uint8_t a =
3859 _mesa_unsigned_to_unsigned(src[3], 4);
3860
3861 uint16_t d = 0;
3862 d |= PACK(r, 0, 4);
3863 d |= PACK(g, 4, 4);
3864 d |= PACK(b, 8, 4);
3865 d |= PACK(a, 12, 4);
3866 (*(uint16_t *)dst) = d;
3867 }
3868
3869 static inline void
pack_uint_b4g4r4a4_uint(const uint32_t src[4],void * dst)3870 pack_uint_b4g4r4a4_uint(const uint32_t src[4], void *dst)
3871 {
3872
3873
3874 uint8_t b =
3875 _mesa_unsigned_to_unsigned(src[2], 4);
3876
3877
3878 uint8_t g =
3879 _mesa_unsigned_to_unsigned(src[1], 4);
3880
3881
3882 uint8_t r =
3883 _mesa_unsigned_to_unsigned(src[0], 4);
3884
3885
3886 uint8_t a =
3887 _mesa_unsigned_to_unsigned(src[3], 4);
3888
3889 uint16_t d = 0;
3890 d |= PACK(b, 0, 4);
3891 d |= PACK(g, 4, 4);
3892 d |= PACK(r, 8, 4);
3893 d |= PACK(a, 12, 4);
3894 (*(uint16_t *)dst) = d;
3895 }
3896
3897 static inline void
pack_uint_a4r4g4b4_uint(const uint32_t src[4],void * dst)3898 pack_uint_a4r4g4b4_uint(const uint32_t src[4], void *dst)
3899 {
3900
3901
3902 uint8_t a =
3903 _mesa_unsigned_to_unsigned(src[3], 4);
3904
3905
3906 uint8_t r =
3907 _mesa_unsigned_to_unsigned(src[0], 4);
3908
3909
3910 uint8_t g =
3911 _mesa_unsigned_to_unsigned(src[1], 4);
3912
3913
3914 uint8_t b =
3915 _mesa_unsigned_to_unsigned(src[2], 4);
3916
3917 uint16_t d = 0;
3918 d |= PACK(a, 0, 4);
3919 d |= PACK(r, 4, 4);
3920 d |= PACK(g, 8, 4);
3921 d |= PACK(b, 12, 4);
3922 (*(uint16_t *)dst) = d;
3923 }
3924
3925 static inline void
pack_uint_a1b5g5r5_uint(const uint32_t src[4],void * dst)3926 pack_uint_a1b5g5r5_uint(const uint32_t src[4], void *dst)
3927 {
3928
3929
3930 uint8_t a =
3931 _mesa_unsigned_to_unsigned(src[3], 1);
3932
3933
3934 uint8_t b =
3935 _mesa_unsigned_to_unsigned(src[2], 5);
3936
3937
3938 uint8_t g =
3939 _mesa_unsigned_to_unsigned(src[1], 5);
3940
3941
3942 uint8_t r =
3943 _mesa_unsigned_to_unsigned(src[0], 5);
3944
3945 uint16_t d = 0;
3946 d |= PACK(a, 0, 1);
3947 d |= PACK(b, 1, 5);
3948 d |= PACK(g, 6, 5);
3949 d |= PACK(r, 11, 5);
3950 (*(uint16_t *)dst) = d;
3951 }
3952
3953 static inline void
pack_uint_b5g5r5a1_uint(const uint32_t src[4],void * dst)3954 pack_uint_b5g5r5a1_uint(const uint32_t src[4], void *dst)
3955 {
3956
3957
3958 uint8_t b =
3959 _mesa_unsigned_to_unsigned(src[2], 5);
3960
3961
3962 uint8_t g =
3963 _mesa_unsigned_to_unsigned(src[1], 5);
3964
3965
3966 uint8_t r =
3967 _mesa_unsigned_to_unsigned(src[0], 5);
3968
3969
3970 uint8_t a =
3971 _mesa_unsigned_to_unsigned(src[3], 1);
3972
3973 uint16_t d = 0;
3974 d |= PACK(b, 0, 5);
3975 d |= PACK(g, 5, 5);
3976 d |= PACK(r, 10, 5);
3977 d |= PACK(a, 15, 1);
3978 (*(uint16_t *)dst) = d;
3979 }
3980
3981 static inline void
pack_uint_a1r5g5b5_uint(const uint32_t src[4],void * dst)3982 pack_uint_a1r5g5b5_uint(const uint32_t src[4], void *dst)
3983 {
3984
3985
3986 uint8_t a =
3987 _mesa_unsigned_to_unsigned(src[3], 1);
3988
3989
3990 uint8_t r =
3991 _mesa_unsigned_to_unsigned(src[0], 5);
3992
3993
3994 uint8_t g =
3995 _mesa_unsigned_to_unsigned(src[1], 5);
3996
3997
3998 uint8_t b =
3999 _mesa_unsigned_to_unsigned(src[2], 5);
4000
4001 uint16_t d = 0;
4002 d |= PACK(a, 0, 1);
4003 d |= PACK(r, 1, 5);
4004 d |= PACK(g, 6, 5);
4005 d |= PACK(b, 11, 5);
4006 (*(uint16_t *)dst) = d;
4007 }
4008
4009 static inline void
pack_uint_r5g5b5a1_uint(const uint32_t src[4],void * dst)4010 pack_uint_r5g5b5a1_uint(const uint32_t src[4], void *dst)
4011 {
4012
4013
4014 uint8_t r =
4015 _mesa_unsigned_to_unsigned(src[0], 5);
4016
4017
4018 uint8_t g =
4019 _mesa_unsigned_to_unsigned(src[1], 5);
4020
4021
4022 uint8_t b =
4023 _mesa_unsigned_to_unsigned(src[2], 5);
4024
4025
4026 uint8_t a =
4027 _mesa_unsigned_to_unsigned(src[3], 1);
4028
4029 uint16_t d = 0;
4030 d |= PACK(r, 0, 5);
4031 d |= PACK(g, 5, 5);
4032 d |= PACK(b, 10, 5);
4033 d |= PACK(a, 15, 1);
4034 (*(uint16_t *)dst) = d;
4035 }
4036
4037 static inline void
pack_uint_a_uint8(const uint32_t src[4],void * dst)4038 pack_uint_a_uint8(const uint32_t src[4], void *dst)
4039 {
4040
4041
4042 uint8_t a =
4043 _mesa_unsigned_to_unsigned(src[3], 8);
4044
4045 uint8_t *d = (uint8_t *)dst;
4046 d[0] = a;
4047 }
4048
4049 static inline void
pack_uint_a_uint16(const uint32_t src[4],void * dst)4050 pack_uint_a_uint16(const uint32_t src[4], void *dst)
4051 {
4052
4053
4054 uint16_t a =
4055 _mesa_unsigned_to_unsigned(src[3], 16);
4056
4057 uint16_t *d = (uint16_t *)dst;
4058 d[0] = a;
4059 }
4060
4061 static inline void
pack_uint_a_uint32(const uint32_t src[4],void * dst)4062 pack_uint_a_uint32(const uint32_t src[4], void *dst)
4063 {
4064
4065
4066 uint32_t a =
4067 _mesa_unsigned_to_unsigned(src[3], 32);
4068
4069 uint32_t *d = (uint32_t *)dst;
4070 d[0] = a;
4071 }
4072
4073 static inline void
pack_uint_a_sint8(const uint32_t src[4],void * dst)4074 pack_uint_a_sint8(const uint32_t src[4], void *dst)
4075 {
4076
4077
4078 int8_t a =
4079 _mesa_signed_to_signed(src[3], 8);
4080
4081 int8_t *d = (int8_t *)dst;
4082 d[0] = a;
4083 }
4084
4085 static inline void
pack_uint_a_sint16(const uint32_t src[4],void * dst)4086 pack_uint_a_sint16(const uint32_t src[4], void *dst)
4087 {
4088
4089
4090 int16_t a =
4091 _mesa_signed_to_signed(src[3], 16);
4092
4093 int16_t *d = (int16_t *)dst;
4094 d[0] = a;
4095 }
4096
4097 static inline void
pack_uint_a_sint32(const uint32_t src[4],void * dst)4098 pack_uint_a_sint32(const uint32_t src[4], void *dst)
4099 {
4100
4101
4102 int32_t a =
4103 _mesa_signed_to_signed(src[3], 32);
4104
4105 int32_t *d = (int32_t *)dst;
4106 d[0] = a;
4107 }
4108
4109 static inline void
pack_uint_i_uint8(const uint32_t src[4],void * dst)4110 pack_uint_i_uint8(const uint32_t src[4], void *dst)
4111 {
4112
4113
4114 uint8_t i =
4115 _mesa_unsigned_to_unsigned(src[0], 8);
4116
4117 uint8_t *d = (uint8_t *)dst;
4118 d[0] = i;
4119 }
4120
4121 static inline void
pack_uint_i_uint16(const uint32_t src[4],void * dst)4122 pack_uint_i_uint16(const uint32_t src[4], void *dst)
4123 {
4124
4125
4126 uint16_t i =
4127 _mesa_unsigned_to_unsigned(src[0], 16);
4128
4129 uint16_t *d = (uint16_t *)dst;
4130 d[0] = i;
4131 }
4132
4133 static inline void
pack_uint_i_uint32(const uint32_t src[4],void * dst)4134 pack_uint_i_uint32(const uint32_t src[4], void *dst)
4135 {
4136
4137
4138 uint32_t i =
4139 _mesa_unsigned_to_unsigned(src[0], 32);
4140
4141 uint32_t *d = (uint32_t *)dst;
4142 d[0] = i;
4143 }
4144
4145 static inline void
pack_uint_i_sint8(const uint32_t src[4],void * dst)4146 pack_uint_i_sint8(const uint32_t src[4], void *dst)
4147 {
4148
4149
4150 int8_t i =
4151 _mesa_signed_to_signed(src[0], 8);
4152
4153 int8_t *d = (int8_t *)dst;
4154 d[0] = i;
4155 }
4156
4157 static inline void
pack_uint_i_sint16(const uint32_t src[4],void * dst)4158 pack_uint_i_sint16(const uint32_t src[4], void *dst)
4159 {
4160
4161
4162 int16_t i =
4163 _mesa_signed_to_signed(src[0], 16);
4164
4165 int16_t *d = (int16_t *)dst;
4166 d[0] = i;
4167 }
4168
4169 static inline void
pack_uint_i_sint32(const uint32_t src[4],void * dst)4170 pack_uint_i_sint32(const uint32_t src[4], void *dst)
4171 {
4172
4173
4174 int32_t i =
4175 _mesa_signed_to_signed(src[0], 32);
4176
4177 int32_t *d = (int32_t *)dst;
4178 d[0] = i;
4179 }
4180
4181 static inline void
pack_uint_l_uint8(const uint32_t src[4],void * dst)4182 pack_uint_l_uint8(const uint32_t src[4], void *dst)
4183 {
4184
4185
4186 uint8_t l =
4187 _mesa_unsigned_to_unsigned(src[0], 8);
4188
4189 uint8_t *d = (uint8_t *)dst;
4190 d[0] = l;
4191 }
4192
4193 static inline void
pack_uint_l_uint16(const uint32_t src[4],void * dst)4194 pack_uint_l_uint16(const uint32_t src[4], void *dst)
4195 {
4196
4197
4198 uint16_t l =
4199 _mesa_unsigned_to_unsigned(src[0], 16);
4200
4201 uint16_t *d = (uint16_t *)dst;
4202 d[0] = l;
4203 }
4204
4205 static inline void
pack_uint_l_uint32(const uint32_t src[4],void * dst)4206 pack_uint_l_uint32(const uint32_t src[4], void *dst)
4207 {
4208
4209
4210 uint32_t l =
4211 _mesa_unsigned_to_unsigned(src[0], 32);
4212
4213 uint32_t *d = (uint32_t *)dst;
4214 d[0] = l;
4215 }
4216
4217 static inline void
pack_uint_l_sint8(const uint32_t src[4],void * dst)4218 pack_uint_l_sint8(const uint32_t src[4], void *dst)
4219 {
4220
4221
4222 int8_t l =
4223 _mesa_signed_to_signed(src[0], 8);
4224
4225 int8_t *d = (int8_t *)dst;
4226 d[0] = l;
4227 }
4228
4229 static inline void
pack_uint_l_sint16(const uint32_t src[4],void * dst)4230 pack_uint_l_sint16(const uint32_t src[4], void *dst)
4231 {
4232
4233
4234 int16_t l =
4235 _mesa_signed_to_signed(src[0], 16);
4236
4237 int16_t *d = (int16_t *)dst;
4238 d[0] = l;
4239 }
4240
4241 static inline void
pack_uint_l_sint32(const uint32_t src[4],void * dst)4242 pack_uint_l_sint32(const uint32_t src[4], void *dst)
4243 {
4244
4245
4246 int32_t l =
4247 _mesa_signed_to_signed(src[0], 32);
4248
4249 int32_t *d = (int32_t *)dst;
4250 d[0] = l;
4251 }
4252
4253 static inline void
pack_uint_la_uint8(const uint32_t src[4],void * dst)4254 pack_uint_la_uint8(const uint32_t src[4], void *dst)
4255 {
4256
4257
4258 uint8_t l =
4259 _mesa_unsigned_to_unsigned(src[0], 8);
4260
4261
4262 uint8_t a =
4263 _mesa_unsigned_to_unsigned(src[3], 8);
4264
4265 uint8_t *d = (uint8_t *)dst;
4266 d[0] = l;
4267 d[1] = a;
4268 }
4269
4270 static inline void
pack_uint_la_uint16(const uint32_t src[4],void * dst)4271 pack_uint_la_uint16(const uint32_t src[4], void *dst)
4272 {
4273
4274
4275 uint16_t l =
4276 _mesa_unsigned_to_unsigned(src[0], 16);
4277
4278
4279 uint16_t a =
4280 _mesa_unsigned_to_unsigned(src[3], 16);
4281
4282 uint16_t *d = (uint16_t *)dst;
4283 d[0] = l;
4284 d[1] = a;
4285 }
4286
4287 static inline void
pack_uint_la_uint32(const uint32_t src[4],void * dst)4288 pack_uint_la_uint32(const uint32_t src[4], void *dst)
4289 {
4290
4291
4292 uint32_t l =
4293 _mesa_unsigned_to_unsigned(src[0], 32);
4294
4295
4296 uint32_t a =
4297 _mesa_unsigned_to_unsigned(src[3], 32);
4298
4299 uint32_t *d = (uint32_t *)dst;
4300 d[0] = l;
4301 d[1] = a;
4302 }
4303
4304 static inline void
pack_uint_la_sint8(const uint32_t src[4],void * dst)4305 pack_uint_la_sint8(const uint32_t src[4], void *dst)
4306 {
4307
4308
4309 int8_t l =
4310 _mesa_signed_to_signed(src[0], 8);
4311
4312
4313 int8_t a =
4314 _mesa_signed_to_signed(src[3], 8);
4315
4316 int8_t *d = (int8_t *)dst;
4317 d[0] = l;
4318 d[1] = a;
4319 }
4320
4321 static inline void
pack_uint_la_sint16(const uint32_t src[4],void * dst)4322 pack_uint_la_sint16(const uint32_t src[4], void *dst)
4323 {
4324
4325
4326 int16_t l =
4327 _mesa_signed_to_signed(src[0], 16);
4328
4329
4330 int16_t a =
4331 _mesa_signed_to_signed(src[3], 16);
4332
4333 int16_t *d = (int16_t *)dst;
4334 d[0] = l;
4335 d[1] = a;
4336 }
4337
4338 static inline void
pack_uint_la_sint32(const uint32_t src[4],void * dst)4339 pack_uint_la_sint32(const uint32_t src[4], void *dst)
4340 {
4341
4342
4343 int32_t l =
4344 _mesa_signed_to_signed(src[0], 32);
4345
4346
4347 int32_t a =
4348 _mesa_signed_to_signed(src[3], 32);
4349
4350 int32_t *d = (int32_t *)dst;
4351 d[0] = l;
4352 d[1] = a;
4353 }
4354
4355 static inline void
pack_uint_r_uint8(const uint32_t src[4],void * dst)4356 pack_uint_r_uint8(const uint32_t src[4], void *dst)
4357 {
4358
4359
4360 uint8_t r =
4361 _mesa_unsigned_to_unsigned(src[0], 8);
4362
4363 uint8_t *d = (uint8_t *)dst;
4364 d[0] = r;
4365 }
4366
4367 static inline void
pack_uint_r_uint16(const uint32_t src[4],void * dst)4368 pack_uint_r_uint16(const uint32_t src[4], void *dst)
4369 {
4370
4371
4372 uint16_t r =
4373 _mesa_unsigned_to_unsigned(src[0], 16);
4374
4375 uint16_t *d = (uint16_t *)dst;
4376 d[0] = r;
4377 }
4378
4379 static inline void
pack_uint_r_uint32(const uint32_t src[4],void * dst)4380 pack_uint_r_uint32(const uint32_t src[4], void *dst)
4381 {
4382
4383
4384 uint32_t r =
4385 _mesa_unsigned_to_unsigned(src[0], 32);
4386
4387 uint32_t *d = (uint32_t *)dst;
4388 d[0] = r;
4389 }
4390
4391 static inline void
pack_uint_r_sint8(const uint32_t src[4],void * dst)4392 pack_uint_r_sint8(const uint32_t src[4], void *dst)
4393 {
4394
4395
4396 int8_t r =
4397 _mesa_signed_to_signed(src[0], 8);
4398
4399 int8_t *d = (int8_t *)dst;
4400 d[0] = r;
4401 }
4402
4403 static inline void
pack_uint_r_sint16(const uint32_t src[4],void * dst)4404 pack_uint_r_sint16(const uint32_t src[4], void *dst)
4405 {
4406
4407
4408 int16_t r =
4409 _mesa_signed_to_signed(src[0], 16);
4410
4411 int16_t *d = (int16_t *)dst;
4412 d[0] = r;
4413 }
4414
4415 static inline void
pack_uint_r_sint32(const uint32_t src[4],void * dst)4416 pack_uint_r_sint32(const uint32_t src[4], void *dst)
4417 {
4418
4419
4420 int32_t r =
4421 _mesa_signed_to_signed(src[0], 32);
4422
4423 int32_t *d = (int32_t *)dst;
4424 d[0] = r;
4425 }
4426
4427 static inline void
pack_uint_rg_uint8(const uint32_t src[4],void * dst)4428 pack_uint_rg_uint8(const uint32_t src[4], void *dst)
4429 {
4430
4431
4432 uint8_t r =
4433 _mesa_unsigned_to_unsigned(src[0], 8);
4434
4435
4436 uint8_t g =
4437 _mesa_unsigned_to_unsigned(src[1], 8);
4438
4439 uint8_t *d = (uint8_t *)dst;
4440 d[0] = r;
4441 d[1] = g;
4442 }
4443
4444 static inline void
pack_uint_rg_uint16(const uint32_t src[4],void * dst)4445 pack_uint_rg_uint16(const uint32_t src[4], void *dst)
4446 {
4447
4448
4449 uint16_t r =
4450 _mesa_unsigned_to_unsigned(src[0], 16);
4451
4452
4453 uint16_t g =
4454 _mesa_unsigned_to_unsigned(src[1], 16);
4455
4456 uint16_t *d = (uint16_t *)dst;
4457 d[0] = r;
4458 d[1] = g;
4459 }
4460
4461 static inline void
pack_uint_rg_uint32(const uint32_t src[4],void * dst)4462 pack_uint_rg_uint32(const uint32_t src[4], void *dst)
4463 {
4464
4465
4466 uint32_t r =
4467 _mesa_unsigned_to_unsigned(src[0], 32);
4468
4469
4470 uint32_t g =
4471 _mesa_unsigned_to_unsigned(src[1], 32);
4472
4473 uint32_t *d = (uint32_t *)dst;
4474 d[0] = r;
4475 d[1] = g;
4476 }
4477
4478 static inline void
pack_uint_rg_sint8(const uint32_t src[4],void * dst)4479 pack_uint_rg_sint8(const uint32_t src[4], void *dst)
4480 {
4481
4482
4483 int8_t r =
4484 _mesa_signed_to_signed(src[0], 8);
4485
4486
4487 int8_t g =
4488 _mesa_signed_to_signed(src[1], 8);
4489
4490 int8_t *d = (int8_t *)dst;
4491 d[0] = r;
4492 d[1] = g;
4493 }
4494
4495 static inline void
pack_uint_rg_sint16(const uint32_t src[4],void * dst)4496 pack_uint_rg_sint16(const uint32_t src[4], void *dst)
4497 {
4498
4499
4500 int16_t r =
4501 _mesa_signed_to_signed(src[0], 16);
4502
4503
4504 int16_t g =
4505 _mesa_signed_to_signed(src[1], 16);
4506
4507 int16_t *d = (int16_t *)dst;
4508 d[0] = r;
4509 d[1] = g;
4510 }
4511
4512 static inline void
pack_uint_rg_sint32(const uint32_t src[4],void * dst)4513 pack_uint_rg_sint32(const uint32_t src[4], void *dst)
4514 {
4515
4516
4517 int32_t r =
4518 _mesa_signed_to_signed(src[0], 32);
4519
4520
4521 int32_t g =
4522 _mesa_signed_to_signed(src[1], 32);
4523
4524 int32_t *d = (int32_t *)dst;
4525 d[0] = r;
4526 d[1] = g;
4527 }
4528
4529 static inline void
pack_uint_rgb_uint8(const uint32_t src[4],void * dst)4530 pack_uint_rgb_uint8(const uint32_t src[4], void *dst)
4531 {
4532
4533
4534 uint8_t r =
4535 _mesa_unsigned_to_unsigned(src[0], 8);
4536
4537
4538 uint8_t g =
4539 _mesa_unsigned_to_unsigned(src[1], 8);
4540
4541
4542 uint8_t b =
4543 _mesa_unsigned_to_unsigned(src[2], 8);
4544
4545 uint8_t *d = (uint8_t *)dst;
4546 d[0] = r;
4547 d[1] = g;
4548 d[2] = b;
4549 }
4550
4551 static inline void
pack_uint_rgb_uint16(const uint32_t src[4],void * dst)4552 pack_uint_rgb_uint16(const uint32_t src[4], void *dst)
4553 {
4554
4555
4556 uint16_t r =
4557 _mesa_unsigned_to_unsigned(src[0], 16);
4558
4559
4560 uint16_t g =
4561 _mesa_unsigned_to_unsigned(src[1], 16);
4562
4563
4564 uint16_t b =
4565 _mesa_unsigned_to_unsigned(src[2], 16);
4566
4567 uint16_t *d = (uint16_t *)dst;
4568 d[0] = r;
4569 d[1] = g;
4570 d[2] = b;
4571 }
4572
4573 static inline void
pack_uint_rgb_uint32(const uint32_t src[4],void * dst)4574 pack_uint_rgb_uint32(const uint32_t src[4], void *dst)
4575 {
4576
4577
4578 uint32_t r =
4579 _mesa_unsigned_to_unsigned(src[0], 32);
4580
4581
4582 uint32_t g =
4583 _mesa_unsigned_to_unsigned(src[1], 32);
4584
4585
4586 uint32_t b =
4587 _mesa_unsigned_to_unsigned(src[2], 32);
4588
4589 uint32_t *d = (uint32_t *)dst;
4590 d[0] = r;
4591 d[1] = g;
4592 d[2] = b;
4593 }
4594
4595 static inline void
pack_uint_rgb_sint8(const uint32_t src[4],void * dst)4596 pack_uint_rgb_sint8(const uint32_t src[4], void *dst)
4597 {
4598
4599
4600 int8_t r =
4601 _mesa_signed_to_signed(src[0], 8);
4602
4603
4604 int8_t g =
4605 _mesa_signed_to_signed(src[1], 8);
4606
4607
4608 int8_t b =
4609 _mesa_signed_to_signed(src[2], 8);
4610
4611 int8_t *d = (int8_t *)dst;
4612 d[0] = r;
4613 d[1] = g;
4614 d[2] = b;
4615 }
4616
4617 static inline void
pack_uint_rgb_sint16(const uint32_t src[4],void * dst)4618 pack_uint_rgb_sint16(const uint32_t src[4], void *dst)
4619 {
4620
4621
4622 int16_t r =
4623 _mesa_signed_to_signed(src[0], 16);
4624
4625
4626 int16_t g =
4627 _mesa_signed_to_signed(src[1], 16);
4628
4629
4630 int16_t b =
4631 _mesa_signed_to_signed(src[2], 16);
4632
4633 int16_t *d = (int16_t *)dst;
4634 d[0] = r;
4635 d[1] = g;
4636 d[2] = b;
4637 }
4638
4639 static inline void
pack_uint_rgb_sint32(const uint32_t src[4],void * dst)4640 pack_uint_rgb_sint32(const uint32_t src[4], void *dst)
4641 {
4642
4643
4644 int32_t r =
4645 _mesa_signed_to_signed(src[0], 32);
4646
4647
4648 int32_t g =
4649 _mesa_signed_to_signed(src[1], 32);
4650
4651
4652 int32_t b =
4653 _mesa_signed_to_signed(src[2], 32);
4654
4655 int32_t *d = (int32_t *)dst;
4656 d[0] = r;
4657 d[1] = g;
4658 d[2] = b;
4659 }
4660
4661 static inline void
pack_uint_rgba_uint16(const uint32_t src[4],void * dst)4662 pack_uint_rgba_uint16(const uint32_t src[4], void *dst)
4663 {
4664
4665
4666 uint16_t r =
4667 _mesa_unsigned_to_unsigned(src[0], 16);
4668
4669
4670 uint16_t g =
4671 _mesa_unsigned_to_unsigned(src[1], 16);
4672
4673
4674 uint16_t b =
4675 _mesa_unsigned_to_unsigned(src[2], 16);
4676
4677
4678 uint16_t a =
4679 _mesa_unsigned_to_unsigned(src[3], 16);
4680
4681 uint16_t *d = (uint16_t *)dst;
4682 d[0] = r;
4683 d[1] = g;
4684 d[2] = b;
4685 d[3] = a;
4686 }
4687
4688 static inline void
pack_uint_rgba_uint32(const uint32_t src[4],void * dst)4689 pack_uint_rgba_uint32(const uint32_t src[4], void *dst)
4690 {
4691
4692
4693 uint32_t r =
4694 _mesa_unsigned_to_unsigned(src[0], 32);
4695
4696
4697 uint32_t g =
4698 _mesa_unsigned_to_unsigned(src[1], 32);
4699
4700
4701 uint32_t b =
4702 _mesa_unsigned_to_unsigned(src[2], 32);
4703
4704
4705 uint32_t a =
4706 _mesa_unsigned_to_unsigned(src[3], 32);
4707
4708 uint32_t *d = (uint32_t *)dst;
4709 d[0] = r;
4710 d[1] = g;
4711 d[2] = b;
4712 d[3] = a;
4713 }
4714
4715 static inline void
pack_uint_rgba_sint8(const uint32_t src[4],void * dst)4716 pack_uint_rgba_sint8(const uint32_t src[4], void *dst)
4717 {
4718
4719
4720 int8_t r =
4721 _mesa_signed_to_signed(src[0], 8);
4722
4723
4724 int8_t g =
4725 _mesa_signed_to_signed(src[1], 8);
4726
4727
4728 int8_t b =
4729 _mesa_signed_to_signed(src[2], 8);
4730
4731
4732 int8_t a =
4733 _mesa_signed_to_signed(src[3], 8);
4734
4735 int8_t *d = (int8_t *)dst;
4736 d[0] = r;
4737 d[1] = g;
4738 d[2] = b;
4739 d[3] = a;
4740 }
4741
4742 static inline void
pack_uint_rgba_sint16(const uint32_t src[4],void * dst)4743 pack_uint_rgba_sint16(const uint32_t src[4], void *dst)
4744 {
4745
4746
4747 int16_t r =
4748 _mesa_signed_to_signed(src[0], 16);
4749
4750
4751 int16_t g =
4752 _mesa_signed_to_signed(src[1], 16);
4753
4754
4755 int16_t b =
4756 _mesa_signed_to_signed(src[2], 16);
4757
4758
4759 int16_t a =
4760 _mesa_signed_to_signed(src[3], 16);
4761
4762 int16_t *d = (int16_t *)dst;
4763 d[0] = r;
4764 d[1] = g;
4765 d[2] = b;
4766 d[3] = a;
4767 }
4768
4769 static inline void
pack_uint_rgba_sint32(const uint32_t src[4],void * dst)4770 pack_uint_rgba_sint32(const uint32_t src[4], void *dst)
4771 {
4772
4773
4774 int32_t r =
4775 _mesa_signed_to_signed(src[0], 32);
4776
4777
4778 int32_t g =
4779 _mesa_signed_to_signed(src[1], 32);
4780
4781
4782 int32_t b =
4783 _mesa_signed_to_signed(src[2], 32);
4784
4785
4786 int32_t a =
4787 _mesa_signed_to_signed(src[3], 32);
4788
4789 int32_t *d = (int32_t *)dst;
4790 d[0] = r;
4791 d[1] = g;
4792 d[2] = b;
4793 d[3] = a;
4794 }
4795
4796 static inline void
pack_uint_rgbx_uint8(const uint32_t src[4],void * dst)4797 pack_uint_rgbx_uint8(const uint32_t src[4], void *dst)
4798 {
4799
4800
4801 uint8_t r =
4802 _mesa_unsigned_to_unsigned(src[0], 8);
4803
4804
4805 uint8_t g =
4806 _mesa_unsigned_to_unsigned(src[1], 8);
4807
4808
4809 uint8_t b =
4810 _mesa_unsigned_to_unsigned(src[2], 8);
4811
4812
4813 uint8_t *d = (uint8_t *)dst;
4814 d[0] = r;
4815 d[1] = g;
4816 d[2] = b;
4817 }
4818
4819 static inline void
pack_uint_rgbx_uint16(const uint32_t src[4],void * dst)4820 pack_uint_rgbx_uint16(const uint32_t src[4], void *dst)
4821 {
4822
4823
4824 uint16_t r =
4825 _mesa_unsigned_to_unsigned(src[0], 16);
4826
4827
4828 uint16_t g =
4829 _mesa_unsigned_to_unsigned(src[1], 16);
4830
4831
4832 uint16_t b =
4833 _mesa_unsigned_to_unsigned(src[2], 16);
4834
4835
4836 uint16_t *d = (uint16_t *)dst;
4837 d[0] = r;
4838 d[1] = g;
4839 d[2] = b;
4840 }
4841
4842 static inline void
pack_uint_rgbx_uint32(const uint32_t src[4],void * dst)4843 pack_uint_rgbx_uint32(const uint32_t src[4], void *dst)
4844 {
4845
4846
4847 uint32_t r =
4848 _mesa_unsigned_to_unsigned(src[0], 32);
4849
4850
4851 uint32_t g =
4852 _mesa_unsigned_to_unsigned(src[1], 32);
4853
4854
4855 uint32_t b =
4856 _mesa_unsigned_to_unsigned(src[2], 32);
4857
4858
4859 uint32_t *d = (uint32_t *)dst;
4860 d[0] = r;
4861 d[1] = g;
4862 d[2] = b;
4863 }
4864
4865 static inline void
pack_uint_rgbx_sint8(const uint32_t src[4],void * dst)4866 pack_uint_rgbx_sint8(const uint32_t src[4], void *dst)
4867 {
4868
4869
4870 int8_t r =
4871 _mesa_signed_to_signed(src[0], 8);
4872
4873
4874 int8_t g =
4875 _mesa_signed_to_signed(src[1], 8);
4876
4877
4878 int8_t b =
4879 _mesa_signed_to_signed(src[2], 8);
4880
4881
4882 int8_t *d = (int8_t *)dst;
4883 d[0] = r;
4884 d[1] = g;
4885 d[2] = b;
4886 }
4887
4888 static inline void
pack_uint_rgbx_sint16(const uint32_t src[4],void * dst)4889 pack_uint_rgbx_sint16(const uint32_t src[4], void *dst)
4890 {
4891
4892
4893 int16_t r =
4894 _mesa_signed_to_signed(src[0], 16);
4895
4896
4897 int16_t g =
4898 _mesa_signed_to_signed(src[1], 16);
4899
4900
4901 int16_t b =
4902 _mesa_signed_to_signed(src[2], 16);
4903
4904
4905 int16_t *d = (int16_t *)dst;
4906 d[0] = r;
4907 d[1] = g;
4908 d[2] = b;
4909 }
4910
4911 static inline void
pack_uint_rgbx_sint32(const uint32_t src[4],void * dst)4912 pack_uint_rgbx_sint32(const uint32_t src[4], void *dst)
4913 {
4914
4915
4916 int32_t r =
4917 _mesa_signed_to_signed(src[0], 32);
4918
4919
4920 int32_t g =
4921 _mesa_signed_to_signed(src[1], 32);
4922
4923
4924 int32_t b =
4925 _mesa_signed_to_signed(src[2], 32);
4926
4927
4928 int32_t *d = (int32_t *)dst;
4929 d[0] = r;
4930 d[1] = g;
4931 d[2] = b;
4932 }
4933
4934 /* float packing functions */
4935
4936
4937 static inline void
pack_float_a8b8g8r8_unorm(const float src[4],void * dst)4938 pack_float_a8b8g8r8_unorm(const float src[4], void *dst)
4939 {
4940
4941
4942 uint8_t a =
4943 _mesa_float_to_unorm(src[3], 8);
4944
4945
4946 uint8_t b =
4947 _mesa_float_to_unorm(src[2], 8);
4948
4949
4950 uint8_t g =
4951 _mesa_float_to_unorm(src[1], 8);
4952
4953
4954 uint8_t r =
4955 _mesa_float_to_unorm(src[0], 8);
4956
4957 uint32_t d = 0;
4958 d |= PACK(a, 0, 8);
4959 d |= PACK(b, 8, 8);
4960 d |= PACK(g, 16, 8);
4961 d |= PACK(r, 24, 8);
4962 (*(uint32_t *)dst) = d;
4963 }
4964
4965 static inline void
pack_float_x8b8g8r8_unorm(const float src[4],void * dst)4966 pack_float_x8b8g8r8_unorm(const float src[4], void *dst)
4967 {
4968
4969
4970
4971 uint8_t b =
4972 _mesa_float_to_unorm(src[2], 8);
4973
4974
4975 uint8_t g =
4976 _mesa_float_to_unorm(src[1], 8);
4977
4978
4979 uint8_t r =
4980 _mesa_float_to_unorm(src[0], 8);
4981
4982 uint32_t d = 0;
4983 d |= PACK(b, 8, 8);
4984 d |= PACK(g, 16, 8);
4985 d |= PACK(r, 24, 8);
4986 (*(uint32_t *)dst) = d;
4987 }
4988
4989 static inline void
pack_float_r8g8b8a8_unorm(const float src[4],void * dst)4990 pack_float_r8g8b8a8_unorm(const float src[4], void *dst)
4991 {
4992
4993
4994 uint8_t r =
4995 _mesa_float_to_unorm(src[0], 8);
4996
4997
4998 uint8_t g =
4999 _mesa_float_to_unorm(src[1], 8);
5000
5001
5002 uint8_t b =
5003 _mesa_float_to_unorm(src[2], 8);
5004
5005
5006 uint8_t a =
5007 _mesa_float_to_unorm(src[3], 8);
5008
5009 uint32_t d = 0;
5010 d |= PACK(r, 0, 8);
5011 d |= PACK(g, 8, 8);
5012 d |= PACK(b, 16, 8);
5013 d |= PACK(a, 24, 8);
5014 (*(uint32_t *)dst) = d;
5015 }
5016
5017 static inline void
pack_float_r8g8b8x8_unorm(const float src[4],void * dst)5018 pack_float_r8g8b8x8_unorm(const float src[4], void *dst)
5019 {
5020
5021
5022 uint8_t r =
5023 _mesa_float_to_unorm(src[0], 8);
5024
5025
5026 uint8_t g =
5027 _mesa_float_to_unorm(src[1], 8);
5028
5029
5030 uint8_t b =
5031 _mesa_float_to_unorm(src[2], 8);
5032
5033
5034 uint32_t d = 0;
5035 d |= PACK(r, 0, 8);
5036 d |= PACK(g, 8, 8);
5037 d |= PACK(b, 16, 8);
5038 (*(uint32_t *)dst) = d;
5039 }
5040
5041 static inline void
pack_float_b8g8r8a8_unorm(const float src[4],void * dst)5042 pack_float_b8g8r8a8_unorm(const float src[4], void *dst)
5043 {
5044
5045
5046 uint8_t b =
5047 _mesa_float_to_unorm(src[2], 8);
5048
5049
5050 uint8_t g =
5051 _mesa_float_to_unorm(src[1], 8);
5052
5053
5054 uint8_t r =
5055 _mesa_float_to_unorm(src[0], 8);
5056
5057
5058 uint8_t a =
5059 _mesa_float_to_unorm(src[3], 8);
5060
5061 uint32_t d = 0;
5062 d |= PACK(b, 0, 8);
5063 d |= PACK(g, 8, 8);
5064 d |= PACK(r, 16, 8);
5065 d |= PACK(a, 24, 8);
5066 (*(uint32_t *)dst) = d;
5067 }
5068
5069 static inline void
pack_float_b8g8r8x8_unorm(const float src[4],void * dst)5070 pack_float_b8g8r8x8_unorm(const float src[4], void *dst)
5071 {
5072
5073
5074 uint8_t b =
5075 _mesa_float_to_unorm(src[2], 8);
5076
5077
5078 uint8_t g =
5079 _mesa_float_to_unorm(src[1], 8);
5080
5081
5082 uint8_t r =
5083 _mesa_float_to_unorm(src[0], 8);
5084
5085
5086 uint32_t d = 0;
5087 d |= PACK(b, 0, 8);
5088 d |= PACK(g, 8, 8);
5089 d |= PACK(r, 16, 8);
5090 (*(uint32_t *)dst) = d;
5091 }
5092
5093 static inline void
pack_float_a8r8g8b8_unorm(const float src[4],void * dst)5094 pack_float_a8r8g8b8_unorm(const float src[4], void *dst)
5095 {
5096
5097
5098 uint8_t a =
5099 _mesa_float_to_unorm(src[3], 8);
5100
5101
5102 uint8_t r =
5103 _mesa_float_to_unorm(src[0], 8);
5104
5105
5106 uint8_t g =
5107 _mesa_float_to_unorm(src[1], 8);
5108
5109
5110 uint8_t b =
5111 _mesa_float_to_unorm(src[2], 8);
5112
5113 uint32_t d = 0;
5114 d |= PACK(a, 0, 8);
5115 d |= PACK(r, 8, 8);
5116 d |= PACK(g, 16, 8);
5117 d |= PACK(b, 24, 8);
5118 (*(uint32_t *)dst) = d;
5119 }
5120
5121 static inline void
pack_float_x8r8g8b8_unorm(const float src[4],void * dst)5122 pack_float_x8r8g8b8_unorm(const float src[4], void *dst)
5123 {
5124
5125
5126
5127 uint8_t r =
5128 _mesa_float_to_unorm(src[0], 8);
5129
5130
5131 uint8_t g =
5132 _mesa_float_to_unorm(src[1], 8);
5133
5134
5135 uint8_t b =
5136 _mesa_float_to_unorm(src[2], 8);
5137
5138 uint32_t d = 0;
5139 d |= PACK(r, 8, 8);
5140 d |= PACK(g, 16, 8);
5141 d |= PACK(b, 24, 8);
5142 (*(uint32_t *)dst) = d;
5143 }
5144
5145 static inline void
pack_float_b5g6r5_unorm(const float src[4],void * dst)5146 pack_float_b5g6r5_unorm(const float src[4], void *dst)
5147 {
5148
5149
5150 uint8_t b =
5151 _mesa_float_to_unorm(src[2], 5);
5152
5153
5154 uint8_t g =
5155 _mesa_float_to_unorm(src[1], 6);
5156
5157
5158 uint8_t r =
5159 _mesa_float_to_unorm(src[0], 5);
5160
5161 uint16_t d = 0;
5162 d |= PACK(b, 0, 5);
5163 d |= PACK(g, 5, 6);
5164 d |= PACK(r, 11, 5);
5165 (*(uint16_t *)dst) = d;
5166 }
5167
5168 static inline void
pack_float_r5g6b5_unorm(const float src[4],void * dst)5169 pack_float_r5g6b5_unorm(const float src[4], void *dst)
5170 {
5171
5172
5173 uint8_t r =
5174 _mesa_float_to_unorm(src[0], 5);
5175
5176
5177 uint8_t g =
5178 _mesa_float_to_unorm(src[1], 6);
5179
5180
5181 uint8_t b =
5182 _mesa_float_to_unorm(src[2], 5);
5183
5184 uint16_t d = 0;
5185 d |= PACK(r, 0, 5);
5186 d |= PACK(g, 5, 6);
5187 d |= PACK(b, 11, 5);
5188 (*(uint16_t *)dst) = d;
5189 }
5190
5191 static inline void
pack_float_b4g4r4a4_unorm(const float src[4],void * dst)5192 pack_float_b4g4r4a4_unorm(const float src[4], void *dst)
5193 {
5194
5195
5196 uint8_t b =
5197 _mesa_float_to_unorm(src[2], 4);
5198
5199
5200 uint8_t g =
5201 _mesa_float_to_unorm(src[1], 4);
5202
5203
5204 uint8_t r =
5205 _mesa_float_to_unorm(src[0], 4);
5206
5207
5208 uint8_t a =
5209 _mesa_float_to_unorm(src[3], 4);
5210
5211 uint16_t d = 0;
5212 d |= PACK(b, 0, 4);
5213 d |= PACK(g, 4, 4);
5214 d |= PACK(r, 8, 4);
5215 d |= PACK(a, 12, 4);
5216 (*(uint16_t *)dst) = d;
5217 }
5218
5219 static inline void
pack_float_b4g4r4x4_unorm(const float src[4],void * dst)5220 pack_float_b4g4r4x4_unorm(const float src[4], void *dst)
5221 {
5222
5223
5224 uint8_t b =
5225 _mesa_float_to_unorm(src[2], 4);
5226
5227
5228 uint8_t g =
5229 _mesa_float_to_unorm(src[1], 4);
5230
5231
5232 uint8_t r =
5233 _mesa_float_to_unorm(src[0], 4);
5234
5235
5236 uint16_t d = 0;
5237 d |= PACK(b, 0, 4);
5238 d |= PACK(g, 4, 4);
5239 d |= PACK(r, 8, 4);
5240 (*(uint16_t *)dst) = d;
5241 }
5242
5243 static inline void
pack_float_a4r4g4b4_unorm(const float src[4],void * dst)5244 pack_float_a4r4g4b4_unorm(const float src[4], void *dst)
5245 {
5246
5247
5248 uint8_t a =
5249 _mesa_float_to_unorm(src[3], 4);
5250
5251
5252 uint8_t r =
5253 _mesa_float_to_unorm(src[0], 4);
5254
5255
5256 uint8_t g =
5257 _mesa_float_to_unorm(src[1], 4);
5258
5259
5260 uint8_t b =
5261 _mesa_float_to_unorm(src[2], 4);
5262
5263 uint16_t d = 0;
5264 d |= PACK(a, 0, 4);
5265 d |= PACK(r, 4, 4);
5266 d |= PACK(g, 8, 4);
5267 d |= PACK(b, 12, 4);
5268 (*(uint16_t *)dst) = d;
5269 }
5270
5271 static inline void
pack_float_a1b5g5r5_unorm(const float src[4],void * dst)5272 pack_float_a1b5g5r5_unorm(const float src[4], void *dst)
5273 {
5274
5275
5276 uint8_t a =
5277 _mesa_float_to_unorm(src[3], 1);
5278
5279
5280 uint8_t b =
5281 _mesa_float_to_unorm(src[2], 5);
5282
5283
5284 uint8_t g =
5285 _mesa_float_to_unorm(src[1], 5);
5286
5287
5288 uint8_t r =
5289 _mesa_float_to_unorm(src[0], 5);
5290
5291 uint16_t d = 0;
5292 d |= PACK(a, 0, 1);
5293 d |= PACK(b, 1, 5);
5294 d |= PACK(g, 6, 5);
5295 d |= PACK(r, 11, 5);
5296 (*(uint16_t *)dst) = d;
5297 }
5298
5299 static inline void
pack_float_x1b5g5r5_unorm(const float src[4],void * dst)5300 pack_float_x1b5g5r5_unorm(const float src[4], void *dst)
5301 {
5302
5303
5304
5305 uint8_t b =
5306 _mesa_float_to_unorm(src[2], 5);
5307
5308
5309 uint8_t g =
5310 _mesa_float_to_unorm(src[1], 5);
5311
5312
5313 uint8_t r =
5314 _mesa_float_to_unorm(src[0], 5);
5315
5316 uint16_t d = 0;
5317 d |= PACK(b, 1, 5);
5318 d |= PACK(g, 6, 5);
5319 d |= PACK(r, 11, 5);
5320 (*(uint16_t *)dst) = d;
5321 }
5322
5323 static inline void
pack_float_b5g5r5a1_unorm(const float src[4],void * dst)5324 pack_float_b5g5r5a1_unorm(const float src[4], void *dst)
5325 {
5326
5327
5328 uint8_t b =
5329 _mesa_float_to_unorm(src[2], 5);
5330
5331
5332 uint8_t g =
5333 _mesa_float_to_unorm(src[1], 5);
5334
5335
5336 uint8_t r =
5337 _mesa_float_to_unorm(src[0], 5);
5338
5339
5340 uint8_t a =
5341 _mesa_float_to_unorm(src[3], 1);
5342
5343 uint16_t d = 0;
5344 d |= PACK(b, 0, 5);
5345 d |= PACK(g, 5, 5);
5346 d |= PACK(r, 10, 5);
5347 d |= PACK(a, 15, 1);
5348 (*(uint16_t *)dst) = d;
5349 }
5350
5351 static inline void
pack_float_b5g5r5x1_unorm(const float src[4],void * dst)5352 pack_float_b5g5r5x1_unorm(const float src[4], void *dst)
5353 {
5354
5355
5356 uint8_t b =
5357 _mesa_float_to_unorm(src[2], 5);
5358
5359
5360 uint8_t g =
5361 _mesa_float_to_unorm(src[1], 5);
5362
5363
5364 uint8_t r =
5365 _mesa_float_to_unorm(src[0], 5);
5366
5367
5368 uint16_t d = 0;
5369 d |= PACK(b, 0, 5);
5370 d |= PACK(g, 5, 5);
5371 d |= PACK(r, 10, 5);
5372 (*(uint16_t *)dst) = d;
5373 }
5374
5375 static inline void
pack_float_a1r5g5b5_unorm(const float src[4],void * dst)5376 pack_float_a1r5g5b5_unorm(const float src[4], void *dst)
5377 {
5378
5379
5380 uint8_t a =
5381 _mesa_float_to_unorm(src[3], 1);
5382
5383
5384 uint8_t r =
5385 _mesa_float_to_unorm(src[0], 5);
5386
5387
5388 uint8_t g =
5389 _mesa_float_to_unorm(src[1], 5);
5390
5391
5392 uint8_t b =
5393 _mesa_float_to_unorm(src[2], 5);
5394
5395 uint16_t d = 0;
5396 d |= PACK(a, 0, 1);
5397 d |= PACK(r, 1, 5);
5398 d |= PACK(g, 6, 5);
5399 d |= PACK(b, 11, 5);
5400 (*(uint16_t *)dst) = d;
5401 }
5402
5403 static inline void
pack_float_l4a4_unorm(const float src[4],void * dst)5404 pack_float_l4a4_unorm(const float src[4], void *dst)
5405 {
5406
5407
5408 uint8_t l =
5409 _mesa_float_to_unorm(src[0], 4);
5410
5411
5412 uint8_t a =
5413 _mesa_float_to_unorm(src[3], 4);
5414
5415 uint8_t d = 0;
5416 d |= PACK(l, 0, 4);
5417 d |= PACK(a, 4, 4);
5418 (*(uint8_t *)dst) = d;
5419 }
5420
5421 static inline void
pack_float_b2g3r3_unorm(const float src[4],void * dst)5422 pack_float_b2g3r3_unorm(const float src[4], void *dst)
5423 {
5424
5425
5426 uint8_t b =
5427 _mesa_float_to_unorm(src[2], 2);
5428
5429
5430 uint8_t g =
5431 _mesa_float_to_unorm(src[1], 3);
5432
5433
5434 uint8_t r =
5435 _mesa_float_to_unorm(src[0], 3);
5436
5437 uint8_t d = 0;
5438 d |= PACK(b, 0, 2);
5439 d |= PACK(g, 2, 3);
5440 d |= PACK(r, 5, 3);
5441 (*(uint8_t *)dst) = d;
5442 }
5443
5444 static inline void
pack_float_b10g10r10a2_unorm(const float src[4],void * dst)5445 pack_float_b10g10r10a2_unorm(const float src[4], void *dst)
5446 {
5447
5448
5449 uint16_t b =
5450 _mesa_float_to_unorm(src[2], 10);
5451
5452
5453 uint16_t g =
5454 _mesa_float_to_unorm(src[1], 10);
5455
5456
5457 uint16_t r =
5458 _mesa_float_to_unorm(src[0], 10);
5459
5460
5461 uint8_t a =
5462 _mesa_float_to_unorm(src[3], 2);
5463
5464 uint32_t d = 0;
5465 d |= PACK(b, 0, 10);
5466 d |= PACK(g, 10, 10);
5467 d |= PACK(r, 20, 10);
5468 d |= PACK(a, 30, 2);
5469 (*(uint32_t *)dst) = d;
5470 }
5471
5472 static inline void
pack_float_b10g10r10x2_unorm(const float src[4],void * dst)5473 pack_float_b10g10r10x2_unorm(const float src[4], void *dst)
5474 {
5475
5476
5477 uint16_t b =
5478 _mesa_float_to_unorm(src[2], 10);
5479
5480
5481 uint16_t g =
5482 _mesa_float_to_unorm(src[1], 10);
5483
5484
5485 uint16_t r =
5486 _mesa_float_to_unorm(src[0], 10);
5487
5488
5489 uint32_t d = 0;
5490 d |= PACK(b, 0, 10);
5491 d |= PACK(g, 10, 10);
5492 d |= PACK(r, 20, 10);
5493 (*(uint32_t *)dst) = d;
5494 }
5495
5496 static inline void
pack_float_r10g10b10a2_unorm(const float src[4],void * dst)5497 pack_float_r10g10b10a2_unorm(const float src[4], void *dst)
5498 {
5499
5500
5501 uint16_t r =
5502 _mesa_float_to_unorm(src[0], 10);
5503
5504
5505 uint16_t g =
5506 _mesa_float_to_unorm(src[1], 10);
5507
5508
5509 uint16_t b =
5510 _mesa_float_to_unorm(src[2], 10);
5511
5512
5513 uint8_t a =
5514 _mesa_float_to_unorm(src[3], 2);
5515
5516 uint32_t d = 0;
5517 d |= PACK(r, 0, 10);
5518 d |= PACK(g, 10, 10);
5519 d |= PACK(b, 20, 10);
5520 d |= PACK(a, 30, 2);
5521 (*(uint32_t *)dst) = d;
5522 }
5523
5524 static inline void
pack_float_r10g10b10x2_unorm(const float src[4],void * dst)5525 pack_float_r10g10b10x2_unorm(const float src[4], void *dst)
5526 {
5527
5528
5529 uint16_t r =
5530 _mesa_float_to_unorm(src[0], 10);
5531
5532
5533 uint16_t g =
5534 _mesa_float_to_unorm(src[1], 10);
5535
5536
5537 uint16_t b =
5538 _mesa_float_to_unorm(src[2], 10);
5539
5540
5541 uint32_t d = 0;
5542 d |= PACK(r, 0, 10);
5543 d |= PACK(g, 10, 10);
5544 d |= PACK(b, 20, 10);
5545 (*(uint32_t *)dst) = d;
5546 }
5547
5548 static inline void
pack_float_r3g3b2_unorm(const float src[4],void * dst)5549 pack_float_r3g3b2_unorm(const float src[4], void *dst)
5550 {
5551
5552
5553 uint8_t r =
5554 _mesa_float_to_unorm(src[0], 3);
5555
5556
5557 uint8_t g =
5558 _mesa_float_to_unorm(src[1], 3);
5559
5560
5561 uint8_t b =
5562 _mesa_float_to_unorm(src[2], 2);
5563
5564 uint8_t d = 0;
5565 d |= PACK(r, 0, 3);
5566 d |= PACK(g, 3, 3);
5567 d |= PACK(b, 6, 2);
5568 (*(uint8_t *)dst) = d;
5569 }
5570
5571 static inline void
pack_float_a4b4g4r4_unorm(const float src[4],void * dst)5572 pack_float_a4b4g4r4_unorm(const float src[4], void *dst)
5573 {
5574
5575
5576 uint8_t a =
5577 _mesa_float_to_unorm(src[3], 4);
5578
5579
5580 uint8_t b =
5581 _mesa_float_to_unorm(src[2], 4);
5582
5583
5584 uint8_t g =
5585 _mesa_float_to_unorm(src[1], 4);
5586
5587
5588 uint8_t r =
5589 _mesa_float_to_unorm(src[0], 4);
5590
5591 uint16_t d = 0;
5592 d |= PACK(a, 0, 4);
5593 d |= PACK(b, 4, 4);
5594 d |= PACK(g, 8, 4);
5595 d |= PACK(r, 12, 4);
5596 (*(uint16_t *)dst) = d;
5597 }
5598
5599 static inline void
pack_float_r4g4b4a4_unorm(const float src[4],void * dst)5600 pack_float_r4g4b4a4_unorm(const float src[4], void *dst)
5601 {
5602
5603
5604 uint8_t r =
5605 _mesa_float_to_unorm(src[0], 4);
5606
5607
5608 uint8_t g =
5609 _mesa_float_to_unorm(src[1], 4);
5610
5611
5612 uint8_t b =
5613 _mesa_float_to_unorm(src[2], 4);
5614
5615
5616 uint8_t a =
5617 _mesa_float_to_unorm(src[3], 4);
5618
5619 uint16_t d = 0;
5620 d |= PACK(r, 0, 4);
5621 d |= PACK(g, 4, 4);
5622 d |= PACK(b, 8, 4);
5623 d |= PACK(a, 12, 4);
5624 (*(uint16_t *)dst) = d;
5625 }
5626
5627 static inline void
pack_float_r5g5b5a1_unorm(const float src[4],void * dst)5628 pack_float_r5g5b5a1_unorm(const float src[4], void *dst)
5629 {
5630
5631
5632 uint8_t r =
5633 _mesa_float_to_unorm(src[0], 5);
5634
5635
5636 uint8_t g =
5637 _mesa_float_to_unorm(src[1], 5);
5638
5639
5640 uint8_t b =
5641 _mesa_float_to_unorm(src[2], 5);
5642
5643
5644 uint8_t a =
5645 _mesa_float_to_unorm(src[3], 1);
5646
5647 uint16_t d = 0;
5648 d |= PACK(r, 0, 5);
5649 d |= PACK(g, 5, 5);
5650 d |= PACK(b, 10, 5);
5651 d |= PACK(a, 15, 1);
5652 (*(uint16_t *)dst) = d;
5653 }
5654
5655 static inline void
pack_float_a2b10g10r10_unorm(const float src[4],void * dst)5656 pack_float_a2b10g10r10_unorm(const float src[4], void *dst)
5657 {
5658
5659
5660 uint8_t a =
5661 _mesa_float_to_unorm(src[3], 2);
5662
5663
5664 uint16_t b =
5665 _mesa_float_to_unorm(src[2], 10);
5666
5667
5668 uint16_t g =
5669 _mesa_float_to_unorm(src[1], 10);
5670
5671
5672 uint16_t r =
5673 _mesa_float_to_unorm(src[0], 10);
5674
5675 uint32_t d = 0;
5676 d |= PACK(a, 0, 2);
5677 d |= PACK(b, 2, 10);
5678 d |= PACK(g, 12, 10);
5679 d |= PACK(r, 22, 10);
5680 (*(uint32_t *)dst) = d;
5681 }
5682
5683 static inline void
pack_float_a2r10g10b10_unorm(const float src[4],void * dst)5684 pack_float_a2r10g10b10_unorm(const float src[4], void *dst)
5685 {
5686
5687
5688 uint8_t a =
5689 _mesa_float_to_unorm(src[3], 2);
5690
5691
5692 uint16_t r =
5693 _mesa_float_to_unorm(src[0], 10);
5694
5695
5696 uint16_t g =
5697 _mesa_float_to_unorm(src[1], 10);
5698
5699
5700 uint16_t b =
5701 _mesa_float_to_unorm(src[2], 10);
5702
5703 uint32_t d = 0;
5704 d |= PACK(a, 0, 2);
5705 d |= PACK(r, 2, 10);
5706 d |= PACK(g, 12, 10);
5707 d |= PACK(b, 22, 10);
5708 (*(uint32_t *)dst) = d;
5709 }
5710
5711 static inline void
pack_float_a_unorm8(const float src[4],void * dst)5712 pack_float_a_unorm8(const float src[4], void *dst)
5713 {
5714
5715
5716 uint8_t a =
5717 _mesa_float_to_unorm(src[3], 8);
5718
5719 uint8_t *d = (uint8_t *)dst;
5720 d[0] = a;
5721 }
5722
5723 static inline void
pack_float_a_unorm16(const float src[4],void * dst)5724 pack_float_a_unorm16(const float src[4], void *dst)
5725 {
5726
5727
5728 uint16_t a =
5729 _mesa_float_to_unorm(src[3], 16);
5730
5731 uint16_t *d = (uint16_t *)dst;
5732 d[0] = a;
5733 }
5734
5735 static inline void
pack_float_l_unorm8(const float src[4],void * dst)5736 pack_float_l_unorm8(const float src[4], void *dst)
5737 {
5738
5739
5740 uint8_t l =
5741 _mesa_float_to_unorm(src[0], 8);
5742
5743 uint8_t *d = (uint8_t *)dst;
5744 d[0] = l;
5745 }
5746
5747 static inline void
pack_float_l_unorm16(const float src[4],void * dst)5748 pack_float_l_unorm16(const float src[4], void *dst)
5749 {
5750
5751
5752 uint16_t l =
5753 _mesa_float_to_unorm(src[0], 16);
5754
5755 uint16_t *d = (uint16_t *)dst;
5756 d[0] = l;
5757 }
5758
5759 static inline void
pack_float_la_unorm8(const float src[4],void * dst)5760 pack_float_la_unorm8(const float src[4], void *dst)
5761 {
5762
5763
5764 uint8_t l =
5765 _mesa_float_to_unorm(src[0], 8);
5766
5767
5768 uint8_t a =
5769 _mesa_float_to_unorm(src[3], 8);
5770
5771 uint8_t *d = (uint8_t *)dst;
5772 d[0] = l;
5773 d[1] = a;
5774 }
5775
5776 static inline void
pack_float_la_unorm16(const float src[4],void * dst)5777 pack_float_la_unorm16(const float src[4], void *dst)
5778 {
5779
5780
5781 uint16_t l =
5782 _mesa_float_to_unorm(src[0], 16);
5783
5784
5785 uint16_t a =
5786 _mesa_float_to_unorm(src[3], 16);
5787
5788 uint16_t *d = (uint16_t *)dst;
5789 d[0] = l;
5790 d[1] = a;
5791 }
5792
5793 static inline void
pack_float_i_unorm8(const float src[4],void * dst)5794 pack_float_i_unorm8(const float src[4], void *dst)
5795 {
5796
5797
5798 uint8_t i =
5799 _mesa_float_to_unorm(src[0], 8);
5800
5801 uint8_t *d = (uint8_t *)dst;
5802 d[0] = i;
5803 }
5804
5805 static inline void
pack_float_i_unorm16(const float src[4],void * dst)5806 pack_float_i_unorm16(const float src[4], void *dst)
5807 {
5808
5809
5810 uint16_t i =
5811 _mesa_float_to_unorm(src[0], 16);
5812
5813 uint16_t *d = (uint16_t *)dst;
5814 d[0] = i;
5815 }
5816
5817 static inline void
pack_float_r_unorm8(const float src[4],void * dst)5818 pack_float_r_unorm8(const float src[4], void *dst)
5819 {
5820
5821
5822 uint8_t r =
5823 _mesa_float_to_unorm(src[0], 8);
5824
5825 uint8_t *d = (uint8_t *)dst;
5826 d[0] = r;
5827 }
5828
5829 static inline void
pack_float_r_unorm16(const float src[4],void * dst)5830 pack_float_r_unorm16(const float src[4], void *dst)
5831 {
5832
5833
5834 uint16_t r =
5835 _mesa_float_to_unorm(src[0], 16);
5836
5837 uint16_t *d = (uint16_t *)dst;
5838 d[0] = r;
5839 }
5840
5841 static inline void
pack_float_rg_unorm8(const float src[4],void * dst)5842 pack_float_rg_unorm8(const float src[4], void *dst)
5843 {
5844
5845
5846 uint8_t r =
5847 _mesa_float_to_unorm(src[0], 8);
5848
5849
5850 uint8_t g =
5851 _mesa_float_to_unorm(src[1], 8);
5852
5853 uint8_t *d = (uint8_t *)dst;
5854 d[0] = r;
5855 d[1] = g;
5856 }
5857
5858 static inline void
pack_float_rg_unorm16(const float src[4],void * dst)5859 pack_float_rg_unorm16(const float src[4], void *dst)
5860 {
5861
5862
5863 uint16_t r =
5864 _mesa_float_to_unorm(src[0], 16);
5865
5866
5867 uint16_t g =
5868 _mesa_float_to_unorm(src[1], 16);
5869
5870 uint16_t *d = (uint16_t *)dst;
5871 d[0] = r;
5872 d[1] = g;
5873 }
5874
5875 static inline void
pack_float_bgr_unorm8(const float src[4],void * dst)5876 pack_float_bgr_unorm8(const float src[4], void *dst)
5877 {
5878
5879
5880 uint8_t b =
5881 _mesa_float_to_unorm(src[2], 8);
5882
5883
5884 uint8_t g =
5885 _mesa_float_to_unorm(src[1], 8);
5886
5887
5888 uint8_t r =
5889 _mesa_float_to_unorm(src[0], 8);
5890
5891 uint8_t *d = (uint8_t *)dst;
5892 d[0] = b;
5893 d[1] = g;
5894 d[2] = r;
5895 }
5896
5897 static inline void
pack_float_rgb_unorm8(const float src[4],void * dst)5898 pack_float_rgb_unorm8(const float src[4], void *dst)
5899 {
5900
5901
5902 uint8_t r =
5903 _mesa_float_to_unorm(src[0], 8);
5904
5905
5906 uint8_t g =
5907 _mesa_float_to_unorm(src[1], 8);
5908
5909
5910 uint8_t b =
5911 _mesa_float_to_unorm(src[2], 8);
5912
5913 uint8_t *d = (uint8_t *)dst;
5914 d[0] = r;
5915 d[1] = g;
5916 d[2] = b;
5917 }
5918
5919 static inline void
pack_float_rgba_unorm16(const float src[4],void * dst)5920 pack_float_rgba_unorm16(const float src[4], void *dst)
5921 {
5922
5923
5924 uint16_t r =
5925 _mesa_float_to_unorm(src[0], 16);
5926
5927
5928 uint16_t g =
5929 _mesa_float_to_unorm(src[1], 16);
5930
5931
5932 uint16_t b =
5933 _mesa_float_to_unorm(src[2], 16);
5934
5935
5936 uint16_t a =
5937 _mesa_float_to_unorm(src[3], 16);
5938
5939 uint16_t *d = (uint16_t *)dst;
5940 d[0] = r;
5941 d[1] = g;
5942 d[2] = b;
5943 d[3] = a;
5944 }
5945
5946 static inline void
pack_float_rgbx_unorm16(const float src[4],void * dst)5947 pack_float_rgbx_unorm16(const float src[4], void *dst)
5948 {
5949
5950
5951 uint16_t r =
5952 _mesa_float_to_unorm(src[0], 16);
5953
5954
5955 uint16_t g =
5956 _mesa_float_to_unorm(src[1], 16);
5957
5958
5959 uint16_t b =
5960 _mesa_float_to_unorm(src[2], 16);
5961
5962
5963 uint16_t *d = (uint16_t *)dst;
5964 d[0] = r;
5965 d[1] = g;
5966 d[2] = b;
5967 }
5968
5969 static inline void
pack_float_a8b8g8r8_snorm(const float src[4],void * dst)5970 pack_float_a8b8g8r8_snorm(const float src[4], void *dst)
5971 {
5972
5973
5974 int8_t a =
5975 _mesa_float_to_snorm(src[3], 8);
5976
5977
5978 int8_t b =
5979 _mesa_float_to_snorm(src[2], 8);
5980
5981
5982 int8_t g =
5983 _mesa_float_to_snorm(src[1], 8);
5984
5985
5986 int8_t r =
5987 _mesa_float_to_snorm(src[0], 8);
5988
5989 uint32_t d = 0;
5990 d |= PACK(a, 0, 8);
5991 d |= PACK(b, 8, 8);
5992 d |= PACK(g, 16, 8);
5993 d |= PACK(r, 24, 8);
5994 (*(uint32_t *)dst) = d;
5995 }
5996
5997 static inline void
pack_float_x8b8g8r8_snorm(const float src[4],void * dst)5998 pack_float_x8b8g8r8_snorm(const float src[4], void *dst)
5999 {
6000
6001
6002
6003 int8_t b =
6004 _mesa_float_to_snorm(src[2], 8);
6005
6006
6007 int8_t g =
6008 _mesa_float_to_snorm(src[1], 8);
6009
6010
6011 int8_t r =
6012 _mesa_float_to_snorm(src[0], 8);
6013
6014 uint32_t d = 0;
6015 d |= PACK(b, 8, 8);
6016 d |= PACK(g, 16, 8);
6017 d |= PACK(r, 24, 8);
6018 (*(uint32_t *)dst) = d;
6019 }
6020
6021 static inline void
pack_float_r8g8b8a8_snorm(const float src[4],void * dst)6022 pack_float_r8g8b8a8_snorm(const float src[4], void *dst)
6023 {
6024
6025
6026 int8_t r =
6027 _mesa_float_to_snorm(src[0], 8);
6028
6029
6030 int8_t g =
6031 _mesa_float_to_snorm(src[1], 8);
6032
6033
6034 int8_t b =
6035 _mesa_float_to_snorm(src[2], 8);
6036
6037
6038 int8_t a =
6039 _mesa_float_to_snorm(src[3], 8);
6040
6041 uint32_t d = 0;
6042 d |= PACK(r, 0, 8);
6043 d |= PACK(g, 8, 8);
6044 d |= PACK(b, 16, 8);
6045 d |= PACK(a, 24, 8);
6046 (*(uint32_t *)dst) = d;
6047 }
6048
6049 static inline void
pack_float_r8g8b8x8_snorm(const float src[4],void * dst)6050 pack_float_r8g8b8x8_snorm(const float src[4], void *dst)
6051 {
6052
6053
6054 int8_t r =
6055 _mesa_float_to_snorm(src[0], 8);
6056
6057
6058 int8_t g =
6059 _mesa_float_to_snorm(src[1], 8);
6060
6061
6062 int8_t b =
6063 _mesa_float_to_snorm(src[2], 8);
6064
6065
6066 uint32_t d = 0;
6067 d |= PACK(r, 0, 8);
6068 d |= PACK(g, 8, 8);
6069 d |= PACK(b, 16, 8);
6070 (*(uint32_t *)dst) = d;
6071 }
6072
6073 static inline void
pack_float_a_snorm8(const float src[4],void * dst)6074 pack_float_a_snorm8(const float src[4], void *dst)
6075 {
6076
6077
6078 int8_t a =
6079 _mesa_float_to_snorm(src[3], 8);
6080
6081 int8_t *d = (int8_t *)dst;
6082 d[0] = a;
6083 }
6084
6085 static inline void
pack_float_a_snorm16(const float src[4],void * dst)6086 pack_float_a_snorm16(const float src[4], void *dst)
6087 {
6088
6089
6090 int16_t a =
6091 _mesa_float_to_snorm(src[3], 16);
6092
6093 int16_t *d = (int16_t *)dst;
6094 d[0] = a;
6095 }
6096
6097 static inline void
pack_float_l_snorm8(const float src[4],void * dst)6098 pack_float_l_snorm8(const float src[4], void *dst)
6099 {
6100
6101
6102 int8_t l =
6103 _mesa_float_to_snorm(src[0], 8);
6104
6105 int8_t *d = (int8_t *)dst;
6106 d[0] = l;
6107 }
6108
6109 static inline void
pack_float_l_snorm16(const float src[4],void * dst)6110 pack_float_l_snorm16(const float src[4], void *dst)
6111 {
6112
6113
6114 int16_t l =
6115 _mesa_float_to_snorm(src[0], 16);
6116
6117 int16_t *d = (int16_t *)dst;
6118 d[0] = l;
6119 }
6120
6121 static inline void
pack_float_i_snorm8(const float src[4],void * dst)6122 pack_float_i_snorm8(const float src[4], void *dst)
6123 {
6124
6125
6126 int8_t i =
6127 _mesa_float_to_snorm(src[0], 8);
6128
6129 int8_t *d = (int8_t *)dst;
6130 d[0] = i;
6131 }
6132
6133 static inline void
pack_float_i_snorm16(const float src[4],void * dst)6134 pack_float_i_snorm16(const float src[4], void *dst)
6135 {
6136
6137
6138 int16_t i =
6139 _mesa_float_to_snorm(src[0], 16);
6140
6141 int16_t *d = (int16_t *)dst;
6142 d[0] = i;
6143 }
6144
6145 static inline void
pack_float_r_snorm8(const float src[4],void * dst)6146 pack_float_r_snorm8(const float src[4], void *dst)
6147 {
6148
6149
6150 int8_t r =
6151 _mesa_float_to_snorm(src[0], 8);
6152
6153 int8_t *d = (int8_t *)dst;
6154 d[0] = r;
6155 }
6156
6157 static inline void
pack_float_r_snorm16(const float src[4],void * dst)6158 pack_float_r_snorm16(const float src[4], void *dst)
6159 {
6160
6161
6162 int16_t r =
6163 _mesa_float_to_snorm(src[0], 16);
6164
6165 int16_t *d = (int16_t *)dst;
6166 d[0] = r;
6167 }
6168
6169 static inline void
pack_float_la_snorm8(const float src[4],void * dst)6170 pack_float_la_snorm8(const float src[4], void *dst)
6171 {
6172
6173
6174 int8_t l =
6175 _mesa_float_to_snorm(src[0], 8);
6176
6177
6178 int8_t a =
6179 _mesa_float_to_snorm(src[3], 8);
6180
6181 int8_t *d = (int8_t *)dst;
6182 d[0] = l;
6183 d[1] = a;
6184 }
6185
6186 static inline void
pack_float_la_snorm16(const float src[4],void * dst)6187 pack_float_la_snorm16(const float src[4], void *dst)
6188 {
6189
6190
6191 int16_t l =
6192 _mesa_float_to_snorm(src[0], 16);
6193
6194
6195 int16_t a =
6196 _mesa_float_to_snorm(src[3], 16);
6197
6198 int16_t *d = (int16_t *)dst;
6199 d[0] = l;
6200 d[1] = a;
6201 }
6202
6203 static inline void
pack_float_rg_snorm8(const float src[4],void * dst)6204 pack_float_rg_snorm8(const float src[4], void *dst)
6205 {
6206
6207
6208 int8_t r =
6209 _mesa_float_to_snorm(src[0], 8);
6210
6211
6212 int8_t g =
6213 _mesa_float_to_snorm(src[1], 8);
6214
6215 int8_t *d = (int8_t *)dst;
6216 d[0] = r;
6217 d[1] = g;
6218 }
6219
6220 static inline void
pack_float_rg_snorm16(const float src[4],void * dst)6221 pack_float_rg_snorm16(const float src[4], void *dst)
6222 {
6223
6224
6225 int16_t r =
6226 _mesa_float_to_snorm(src[0], 16);
6227
6228
6229 int16_t g =
6230 _mesa_float_to_snorm(src[1], 16);
6231
6232 int16_t *d = (int16_t *)dst;
6233 d[0] = r;
6234 d[1] = g;
6235 }
6236
6237 static inline void
pack_float_rgb_snorm16(const float src[4],void * dst)6238 pack_float_rgb_snorm16(const float src[4], void *dst)
6239 {
6240
6241
6242 int16_t r =
6243 _mesa_float_to_snorm(src[0], 16);
6244
6245
6246 int16_t g =
6247 _mesa_float_to_snorm(src[1], 16);
6248
6249
6250 int16_t b =
6251 _mesa_float_to_snorm(src[2], 16);
6252
6253 int16_t *d = (int16_t *)dst;
6254 d[0] = r;
6255 d[1] = g;
6256 d[2] = b;
6257 }
6258
6259 static inline void
pack_float_rgba_snorm16(const float src[4],void * dst)6260 pack_float_rgba_snorm16(const float src[4], void *dst)
6261 {
6262
6263
6264 int16_t r =
6265 _mesa_float_to_snorm(src[0], 16);
6266
6267
6268 int16_t g =
6269 _mesa_float_to_snorm(src[1], 16);
6270
6271
6272 int16_t b =
6273 _mesa_float_to_snorm(src[2], 16);
6274
6275
6276 int16_t a =
6277 _mesa_float_to_snorm(src[3], 16);
6278
6279 int16_t *d = (int16_t *)dst;
6280 d[0] = r;
6281 d[1] = g;
6282 d[2] = b;
6283 d[3] = a;
6284 }
6285
6286 static inline void
pack_float_rgbx_snorm16(const float src[4],void * dst)6287 pack_float_rgbx_snorm16(const float src[4], void *dst)
6288 {
6289
6290
6291 int16_t r =
6292 _mesa_float_to_snorm(src[0], 16);
6293
6294
6295 int16_t g =
6296 _mesa_float_to_snorm(src[1], 16);
6297
6298
6299 int16_t b =
6300 _mesa_float_to_snorm(src[2], 16);
6301
6302
6303 int16_t *d = (int16_t *)dst;
6304 d[0] = r;
6305 d[1] = g;
6306 d[2] = b;
6307 }
6308
6309 static inline void
pack_float_a8b8g8r8_srgb(const float src[4],void * dst)6310 pack_float_a8b8g8r8_srgb(const float src[4], void *dst)
6311 {
6312
6313
6314 uint8_t a =
6315 _mesa_float_to_unorm(src[3], 8);
6316
6317
6318 uint8_t b =
6319
6320 util_format_linear_float_to_srgb_8unorm(src[2]);
6321
6322
6323 uint8_t g =
6324
6325 util_format_linear_float_to_srgb_8unorm(src[1]);
6326
6327
6328 uint8_t r =
6329
6330 util_format_linear_float_to_srgb_8unorm(src[0]);
6331
6332 uint32_t d = 0;
6333 d |= PACK(a, 0, 8);
6334 d |= PACK(b, 8, 8);
6335 d |= PACK(g, 16, 8);
6336 d |= PACK(r, 24, 8);
6337 (*(uint32_t *)dst) = d;
6338 }
6339
6340 static inline void
pack_float_b8g8r8a8_srgb(const float src[4],void * dst)6341 pack_float_b8g8r8a8_srgb(const float src[4], void *dst)
6342 {
6343
6344
6345 uint8_t b =
6346
6347 util_format_linear_float_to_srgb_8unorm(src[2]);
6348
6349
6350 uint8_t g =
6351
6352 util_format_linear_float_to_srgb_8unorm(src[1]);
6353
6354
6355 uint8_t r =
6356
6357 util_format_linear_float_to_srgb_8unorm(src[0]);
6358
6359
6360 uint8_t a =
6361 _mesa_float_to_unorm(src[3], 8);
6362
6363 uint32_t d = 0;
6364 d |= PACK(b, 0, 8);
6365 d |= PACK(g, 8, 8);
6366 d |= PACK(r, 16, 8);
6367 d |= PACK(a, 24, 8);
6368 (*(uint32_t *)dst) = d;
6369 }
6370
6371 static inline void
pack_float_a8r8g8b8_srgb(const float src[4],void * dst)6372 pack_float_a8r8g8b8_srgb(const float src[4], void *dst)
6373 {
6374
6375
6376 uint8_t a =
6377 _mesa_float_to_unorm(src[3], 8);
6378
6379
6380 uint8_t r =
6381
6382 util_format_linear_float_to_srgb_8unorm(src[0]);
6383
6384
6385 uint8_t g =
6386
6387 util_format_linear_float_to_srgb_8unorm(src[1]);
6388
6389
6390 uint8_t b =
6391
6392 util_format_linear_float_to_srgb_8unorm(src[2]);
6393
6394 uint32_t d = 0;
6395 d |= PACK(a, 0, 8);
6396 d |= PACK(r, 8, 8);
6397 d |= PACK(g, 16, 8);
6398 d |= PACK(b, 24, 8);
6399 (*(uint32_t *)dst) = d;
6400 }
6401
6402 static inline void
pack_float_b8g8r8x8_srgb(const float src[4],void * dst)6403 pack_float_b8g8r8x8_srgb(const float src[4], void *dst)
6404 {
6405
6406
6407 uint8_t b =
6408
6409 util_format_linear_float_to_srgb_8unorm(src[2]);
6410
6411
6412 uint8_t g =
6413
6414 util_format_linear_float_to_srgb_8unorm(src[1]);
6415
6416
6417 uint8_t r =
6418
6419 util_format_linear_float_to_srgb_8unorm(src[0]);
6420
6421
6422 uint32_t d = 0;
6423 d |= PACK(b, 0, 8);
6424 d |= PACK(g, 8, 8);
6425 d |= PACK(r, 16, 8);
6426 (*(uint32_t *)dst) = d;
6427 }
6428
6429 static inline void
pack_float_x8r8g8b8_srgb(const float src[4],void * dst)6430 pack_float_x8r8g8b8_srgb(const float src[4], void *dst)
6431 {
6432
6433
6434
6435 uint8_t r =
6436
6437 util_format_linear_float_to_srgb_8unorm(src[0]);
6438
6439
6440 uint8_t g =
6441
6442 util_format_linear_float_to_srgb_8unorm(src[1]);
6443
6444
6445 uint8_t b =
6446
6447 util_format_linear_float_to_srgb_8unorm(src[2]);
6448
6449 uint32_t d = 0;
6450 d |= PACK(r, 8, 8);
6451 d |= PACK(g, 16, 8);
6452 d |= PACK(b, 24, 8);
6453 (*(uint32_t *)dst) = d;
6454 }
6455
6456 static inline void
pack_float_r8g8b8a8_srgb(const float src[4],void * dst)6457 pack_float_r8g8b8a8_srgb(const float src[4], void *dst)
6458 {
6459
6460
6461 uint8_t r =
6462
6463 util_format_linear_float_to_srgb_8unorm(src[0]);
6464
6465
6466 uint8_t g =
6467
6468 util_format_linear_float_to_srgb_8unorm(src[1]);
6469
6470
6471 uint8_t b =
6472
6473 util_format_linear_float_to_srgb_8unorm(src[2]);
6474
6475
6476 uint8_t a =
6477 _mesa_float_to_unorm(src[3], 8);
6478
6479 uint32_t d = 0;
6480 d |= PACK(r, 0, 8);
6481 d |= PACK(g, 8, 8);
6482 d |= PACK(b, 16, 8);
6483 d |= PACK(a, 24, 8);
6484 (*(uint32_t *)dst) = d;
6485 }
6486
6487 static inline void
pack_float_r8g8b8x8_srgb(const float src[4],void * dst)6488 pack_float_r8g8b8x8_srgb(const float src[4], void *dst)
6489 {
6490
6491
6492 uint8_t r =
6493
6494 util_format_linear_float_to_srgb_8unorm(src[0]);
6495
6496
6497 uint8_t g =
6498
6499 util_format_linear_float_to_srgb_8unorm(src[1]);
6500
6501
6502 uint8_t b =
6503
6504 util_format_linear_float_to_srgb_8unorm(src[2]);
6505
6506
6507 uint32_t d = 0;
6508 d |= PACK(r, 0, 8);
6509 d |= PACK(g, 8, 8);
6510 d |= PACK(b, 16, 8);
6511 (*(uint32_t *)dst) = d;
6512 }
6513
6514 static inline void
pack_float_x8b8g8r8_srgb(const float src[4],void * dst)6515 pack_float_x8b8g8r8_srgb(const float src[4], void *dst)
6516 {
6517
6518
6519
6520 uint8_t b =
6521
6522 util_format_linear_float_to_srgb_8unorm(src[2]);
6523
6524
6525 uint8_t g =
6526
6527 util_format_linear_float_to_srgb_8unorm(src[1]);
6528
6529
6530 uint8_t r =
6531
6532 util_format_linear_float_to_srgb_8unorm(src[0]);
6533
6534 uint32_t d = 0;
6535 d |= PACK(b, 8, 8);
6536 d |= PACK(g, 16, 8);
6537 d |= PACK(r, 24, 8);
6538 (*(uint32_t *)dst) = d;
6539 }
6540
6541 static inline void
pack_float_r_srgb8(const float src[4],void * dst)6542 pack_float_r_srgb8(const float src[4], void *dst)
6543 {
6544
6545
6546 uint8_t r =
6547
6548 util_format_linear_float_to_srgb_8unorm(src[0]);
6549
6550 uint8_t *d = (uint8_t *)dst;
6551 d[0] = r;
6552 }
6553
6554 static inline void
pack_float_l_srgb8(const float src[4],void * dst)6555 pack_float_l_srgb8(const float src[4], void *dst)
6556 {
6557
6558
6559 uint8_t l =
6560 _mesa_float_to_unorm(src[0], 8);
6561
6562 uint8_t *d = (uint8_t *)dst;
6563 d[0] = l;
6564 }
6565
6566 static inline void
pack_float_la_srgb8(const float src[4],void * dst)6567 pack_float_la_srgb8(const float src[4], void *dst)
6568 {
6569
6570
6571 uint8_t l =
6572 _mesa_float_to_unorm(src[0], 8);
6573
6574
6575 uint8_t a =
6576 _mesa_float_to_unorm(src[3], 8);
6577
6578 uint8_t *d = (uint8_t *)dst;
6579 d[0] = l;
6580 d[1] = a;
6581 }
6582
6583 static inline void
pack_float_bgr_srgb8(const float src[4],void * dst)6584 pack_float_bgr_srgb8(const float src[4], void *dst)
6585 {
6586
6587
6588 uint8_t b =
6589
6590 util_format_linear_float_to_srgb_8unorm(src[2]);
6591
6592
6593 uint8_t g =
6594
6595 util_format_linear_float_to_srgb_8unorm(src[1]);
6596
6597
6598 uint8_t r =
6599
6600 util_format_linear_float_to_srgb_8unorm(src[0]);
6601
6602 uint8_t *d = (uint8_t *)dst;
6603 d[0] = b;
6604 d[1] = g;
6605 d[2] = r;
6606 }
6607
6608 static inline void
pack_float_a_float16(const float src[4],void * dst)6609 pack_float_a_float16(const float src[4], void *dst)
6610 {
6611
6612
6613 uint16_t a =
6614 _mesa_float_to_half(src[3]);
6615
6616 uint16_t *d = (uint16_t *)dst;
6617 d[0] = a;
6618 }
6619
6620 static inline void
pack_float_a_float32(const float src[4],void * dst)6621 pack_float_a_float32(const float src[4], void *dst)
6622 {
6623
6624
6625 float a =
6626 src[3];
6627
6628 float *d = (float *)dst;
6629 d[0] = a;
6630 }
6631
6632 static inline void
pack_float_l_float16(const float src[4],void * dst)6633 pack_float_l_float16(const float src[4], void *dst)
6634 {
6635
6636
6637 uint16_t l =
6638 _mesa_float_to_half(src[0]);
6639
6640 uint16_t *d = (uint16_t *)dst;
6641 d[0] = l;
6642 }
6643
6644 static inline void
pack_float_l_float32(const float src[4],void * dst)6645 pack_float_l_float32(const float src[4], void *dst)
6646 {
6647
6648
6649 float l =
6650 src[0];
6651
6652 float *d = (float *)dst;
6653 d[0] = l;
6654 }
6655
6656 static inline void
pack_float_la_float16(const float src[4],void * dst)6657 pack_float_la_float16(const float src[4], void *dst)
6658 {
6659
6660
6661 uint16_t l =
6662 _mesa_float_to_half(src[0]);
6663
6664
6665 uint16_t a =
6666 _mesa_float_to_half(src[3]);
6667
6668 uint16_t *d = (uint16_t *)dst;
6669 d[0] = l;
6670 d[1] = a;
6671 }
6672
6673 static inline void
pack_float_la_float32(const float src[4],void * dst)6674 pack_float_la_float32(const float src[4], void *dst)
6675 {
6676
6677
6678 float l =
6679 src[0];
6680
6681
6682 float a =
6683 src[3];
6684
6685 float *d = (float *)dst;
6686 d[0] = l;
6687 d[1] = a;
6688 }
6689
6690 static inline void
pack_float_i_float16(const float src[4],void * dst)6691 pack_float_i_float16(const float src[4], void *dst)
6692 {
6693
6694
6695 uint16_t i =
6696 _mesa_float_to_half(src[0]);
6697
6698 uint16_t *d = (uint16_t *)dst;
6699 d[0] = i;
6700 }
6701
6702 static inline void
pack_float_i_float32(const float src[4],void * dst)6703 pack_float_i_float32(const float src[4], void *dst)
6704 {
6705
6706
6707 float i =
6708 src[0];
6709
6710 float *d = (float *)dst;
6711 d[0] = i;
6712 }
6713
6714 static inline void
pack_float_r_float16(const float src[4],void * dst)6715 pack_float_r_float16(const float src[4], void *dst)
6716 {
6717
6718
6719 uint16_t r =
6720 _mesa_float_to_half(src[0]);
6721
6722 uint16_t *d = (uint16_t *)dst;
6723 d[0] = r;
6724 }
6725
6726 static inline void
pack_float_r_float32(const float src[4],void * dst)6727 pack_float_r_float32(const float src[4], void *dst)
6728 {
6729
6730
6731 float r =
6732 src[0];
6733
6734 float *d = (float *)dst;
6735 d[0] = r;
6736 }
6737
6738 static inline void
pack_float_rg_float16(const float src[4],void * dst)6739 pack_float_rg_float16(const float src[4], void *dst)
6740 {
6741
6742
6743 uint16_t r =
6744 _mesa_float_to_half(src[0]);
6745
6746
6747 uint16_t g =
6748 _mesa_float_to_half(src[1]);
6749
6750 uint16_t *d = (uint16_t *)dst;
6751 d[0] = r;
6752 d[1] = g;
6753 }
6754
6755 static inline void
pack_float_rg_float32(const float src[4],void * dst)6756 pack_float_rg_float32(const float src[4], void *dst)
6757 {
6758
6759
6760 float r =
6761 src[0];
6762
6763
6764 float g =
6765 src[1];
6766
6767 float *d = (float *)dst;
6768 d[0] = r;
6769 d[1] = g;
6770 }
6771
6772 static inline void
pack_float_rgb_float16(const float src[4],void * dst)6773 pack_float_rgb_float16(const float src[4], void *dst)
6774 {
6775
6776
6777 uint16_t r =
6778 _mesa_float_to_half(src[0]);
6779
6780
6781 uint16_t g =
6782 _mesa_float_to_half(src[1]);
6783
6784
6785 uint16_t b =
6786 _mesa_float_to_half(src[2]);
6787
6788 uint16_t *d = (uint16_t *)dst;
6789 d[0] = r;
6790 d[1] = g;
6791 d[2] = b;
6792 }
6793
6794 static inline void
pack_float_rgb_float32(const float src[4],void * dst)6795 pack_float_rgb_float32(const float src[4], void *dst)
6796 {
6797
6798
6799 float r =
6800 src[0];
6801
6802
6803 float g =
6804 src[1];
6805
6806
6807 float b =
6808 src[2];
6809
6810 float *d = (float *)dst;
6811 d[0] = r;
6812 d[1] = g;
6813 d[2] = b;
6814 }
6815
6816 static inline void
pack_float_rgba_float16(const float src[4],void * dst)6817 pack_float_rgba_float16(const float src[4], void *dst)
6818 {
6819
6820
6821 uint16_t r =
6822 _mesa_float_to_half(src[0]);
6823
6824
6825 uint16_t g =
6826 _mesa_float_to_half(src[1]);
6827
6828
6829 uint16_t b =
6830 _mesa_float_to_half(src[2]);
6831
6832
6833 uint16_t a =
6834 _mesa_float_to_half(src[3]);
6835
6836 uint16_t *d = (uint16_t *)dst;
6837 d[0] = r;
6838 d[1] = g;
6839 d[2] = b;
6840 d[3] = a;
6841 }
6842
6843 static inline void
pack_float_rgba_float32(const float src[4],void * dst)6844 pack_float_rgba_float32(const float src[4], void *dst)
6845 {
6846
6847
6848 float r =
6849 src[0];
6850
6851
6852 float g =
6853 src[1];
6854
6855
6856 float b =
6857 src[2];
6858
6859
6860 float a =
6861 src[3];
6862
6863 float *d = (float *)dst;
6864 d[0] = r;
6865 d[1] = g;
6866 d[2] = b;
6867 d[3] = a;
6868 }
6869
6870 static inline void
pack_float_rgbx_float16(const float src[4],void * dst)6871 pack_float_rgbx_float16(const float src[4], void *dst)
6872 {
6873
6874
6875 uint16_t r =
6876 _mesa_float_to_half(src[0]);
6877
6878
6879 uint16_t g =
6880 _mesa_float_to_half(src[1]);
6881
6882
6883 uint16_t b =
6884 _mesa_float_to_half(src[2]);
6885
6886
6887 uint16_t *d = (uint16_t *)dst;
6888 d[0] = r;
6889 d[1] = g;
6890 d[2] = b;
6891 }
6892
6893 static inline void
pack_float_rgbx_float32(const float src[4],void * dst)6894 pack_float_rgbx_float32(const float src[4], void *dst)
6895 {
6896
6897
6898 float r =
6899 src[0];
6900
6901
6902 float g =
6903 src[1];
6904
6905
6906 float b =
6907 src[2];
6908
6909
6910 float *d = (float *)dst;
6911 d[0] = r;
6912 d[1] = g;
6913 d[2] = b;
6914 }
6915
6916 static inline void
pack_float_r9g9b9e5_float(const float src[4],void * dst)6917 pack_float_r9g9b9e5_float(const float src[4], void *dst)
6918 {
6919 uint32_t *d = (uint32_t *) dst;
6920 *d = float3_to_rgb9e5(src);
6921 }
6922
6923 static inline void
pack_float_r11g11b10_float(const float src[4],void * dst)6924 pack_float_r11g11b10_float(const float src[4], void *dst)
6925 {
6926 uint32_t *d = (uint32_t *) dst;
6927 *d = float3_to_r11g11b10f(src);
6928 }
6929
6930 /**
6931 * Return a function that can pack a uint8_t rgba[4] color.
6932 */
6933 mesa_pack_ubyte_rgba_func
_mesa_get_pack_ubyte_rgba_function(mesa_format format)6934 _mesa_get_pack_ubyte_rgba_function(mesa_format format)
6935 {
6936 switch (format) {
6937
6938 case MESA_FORMAT_A8B8G8R8_UNORM:
6939 return pack_ubyte_a8b8g8r8_unorm;
6940
6941 case MESA_FORMAT_X8B8G8R8_UNORM:
6942 return pack_ubyte_x8b8g8r8_unorm;
6943
6944 case MESA_FORMAT_R8G8B8A8_UNORM:
6945 return pack_ubyte_r8g8b8a8_unorm;
6946
6947 case MESA_FORMAT_R8G8B8X8_UNORM:
6948 return pack_ubyte_r8g8b8x8_unorm;
6949
6950 case MESA_FORMAT_B8G8R8A8_UNORM:
6951 return pack_ubyte_b8g8r8a8_unorm;
6952
6953 case MESA_FORMAT_B8G8R8X8_UNORM:
6954 return pack_ubyte_b8g8r8x8_unorm;
6955
6956 case MESA_FORMAT_A8R8G8B8_UNORM:
6957 return pack_ubyte_a8r8g8b8_unorm;
6958
6959 case MESA_FORMAT_X8R8G8B8_UNORM:
6960 return pack_ubyte_x8r8g8b8_unorm;
6961
6962 case MESA_FORMAT_B5G6R5_UNORM:
6963 return pack_ubyte_b5g6r5_unorm;
6964
6965 case MESA_FORMAT_R5G6B5_UNORM:
6966 return pack_ubyte_r5g6b5_unorm;
6967
6968 case MESA_FORMAT_B4G4R4A4_UNORM:
6969 return pack_ubyte_b4g4r4a4_unorm;
6970
6971 case MESA_FORMAT_B4G4R4X4_UNORM:
6972 return pack_ubyte_b4g4r4x4_unorm;
6973
6974 case MESA_FORMAT_A4R4G4B4_UNORM:
6975 return pack_ubyte_a4r4g4b4_unorm;
6976
6977 case MESA_FORMAT_A1B5G5R5_UNORM:
6978 return pack_ubyte_a1b5g5r5_unorm;
6979
6980 case MESA_FORMAT_X1B5G5R5_UNORM:
6981 return pack_ubyte_x1b5g5r5_unorm;
6982
6983 case MESA_FORMAT_B5G5R5A1_UNORM:
6984 return pack_ubyte_b5g5r5a1_unorm;
6985
6986 case MESA_FORMAT_B5G5R5X1_UNORM:
6987 return pack_ubyte_b5g5r5x1_unorm;
6988
6989 case MESA_FORMAT_A1R5G5B5_UNORM:
6990 return pack_ubyte_a1r5g5b5_unorm;
6991
6992 case MESA_FORMAT_L4A4_UNORM:
6993 return pack_ubyte_l4a4_unorm;
6994
6995 case MESA_FORMAT_B2G3R3_UNORM:
6996 return pack_ubyte_b2g3r3_unorm;
6997
6998 case MESA_FORMAT_B10G10R10A2_UNORM:
6999 return pack_ubyte_b10g10r10a2_unorm;
7000
7001 case MESA_FORMAT_B10G10R10X2_UNORM:
7002 return pack_ubyte_b10g10r10x2_unorm;
7003
7004 case MESA_FORMAT_R10G10B10A2_UNORM:
7005 return pack_ubyte_r10g10b10a2_unorm;
7006
7007 case MESA_FORMAT_R10G10B10X2_UNORM:
7008 return pack_ubyte_r10g10b10x2_unorm;
7009
7010 case MESA_FORMAT_R3G3B2_UNORM:
7011 return pack_ubyte_r3g3b2_unorm;
7012
7013 case MESA_FORMAT_A4B4G4R4_UNORM:
7014 return pack_ubyte_a4b4g4r4_unorm;
7015
7016 case MESA_FORMAT_R4G4B4A4_UNORM:
7017 return pack_ubyte_r4g4b4a4_unorm;
7018
7019 case MESA_FORMAT_R5G5B5A1_UNORM:
7020 return pack_ubyte_r5g5b5a1_unorm;
7021
7022 case MESA_FORMAT_A2B10G10R10_UNORM:
7023 return pack_ubyte_a2b10g10r10_unorm;
7024
7025 case MESA_FORMAT_A2R10G10B10_UNORM:
7026 return pack_ubyte_a2r10g10b10_unorm;
7027
7028 case MESA_FORMAT_A_UNORM8:
7029 return pack_ubyte_a_unorm8;
7030
7031 case MESA_FORMAT_A_UNORM16:
7032 return pack_ubyte_a_unorm16;
7033
7034 case MESA_FORMAT_L_UNORM8:
7035 return pack_ubyte_l_unorm8;
7036
7037 case MESA_FORMAT_L_UNORM16:
7038 return pack_ubyte_l_unorm16;
7039
7040 case MESA_FORMAT_LA_UNORM8:
7041 return pack_ubyte_la_unorm8;
7042
7043 case MESA_FORMAT_LA_UNORM16:
7044 return pack_ubyte_la_unorm16;
7045
7046 case MESA_FORMAT_I_UNORM8:
7047 return pack_ubyte_i_unorm8;
7048
7049 case MESA_FORMAT_I_UNORM16:
7050 return pack_ubyte_i_unorm16;
7051
7052 case MESA_FORMAT_R_UNORM8:
7053 return pack_ubyte_r_unorm8;
7054
7055 case MESA_FORMAT_R_UNORM16:
7056 return pack_ubyte_r_unorm16;
7057
7058 case MESA_FORMAT_RG_UNORM8:
7059 return pack_ubyte_rg_unorm8;
7060
7061 case MESA_FORMAT_RG_UNORM16:
7062 return pack_ubyte_rg_unorm16;
7063
7064 case MESA_FORMAT_BGR_UNORM8:
7065 return pack_ubyte_bgr_unorm8;
7066
7067 case MESA_FORMAT_RGB_UNORM8:
7068 return pack_ubyte_rgb_unorm8;
7069
7070 case MESA_FORMAT_RGBA_UNORM16:
7071 return pack_ubyte_rgba_unorm16;
7072
7073 case MESA_FORMAT_RGBX_UNORM16:
7074 return pack_ubyte_rgbx_unorm16;
7075
7076 case MESA_FORMAT_A8B8G8R8_SNORM:
7077 return pack_ubyte_a8b8g8r8_snorm;
7078
7079 case MESA_FORMAT_X8B8G8R8_SNORM:
7080 return pack_ubyte_x8b8g8r8_snorm;
7081
7082 case MESA_FORMAT_R8G8B8A8_SNORM:
7083 return pack_ubyte_r8g8b8a8_snorm;
7084
7085 case MESA_FORMAT_R8G8B8X8_SNORM:
7086 return pack_ubyte_r8g8b8x8_snorm;
7087
7088 case MESA_FORMAT_A_SNORM8:
7089 return pack_ubyte_a_snorm8;
7090
7091 case MESA_FORMAT_A_SNORM16:
7092 return pack_ubyte_a_snorm16;
7093
7094 case MESA_FORMAT_L_SNORM8:
7095 return pack_ubyte_l_snorm8;
7096
7097 case MESA_FORMAT_L_SNORM16:
7098 return pack_ubyte_l_snorm16;
7099
7100 case MESA_FORMAT_I_SNORM8:
7101 return pack_ubyte_i_snorm8;
7102
7103 case MESA_FORMAT_I_SNORM16:
7104 return pack_ubyte_i_snorm16;
7105
7106 case MESA_FORMAT_R_SNORM8:
7107 return pack_ubyte_r_snorm8;
7108
7109 case MESA_FORMAT_R_SNORM16:
7110 return pack_ubyte_r_snorm16;
7111
7112 case MESA_FORMAT_LA_SNORM8:
7113 return pack_ubyte_la_snorm8;
7114
7115 case MESA_FORMAT_LA_SNORM16:
7116 return pack_ubyte_la_snorm16;
7117
7118 case MESA_FORMAT_RG_SNORM8:
7119 return pack_ubyte_rg_snorm8;
7120
7121 case MESA_FORMAT_RG_SNORM16:
7122 return pack_ubyte_rg_snorm16;
7123
7124 case MESA_FORMAT_RGB_SNORM16:
7125 return pack_ubyte_rgb_snorm16;
7126
7127 case MESA_FORMAT_RGBA_SNORM16:
7128 return pack_ubyte_rgba_snorm16;
7129
7130 case MESA_FORMAT_RGBX_SNORM16:
7131 return pack_ubyte_rgbx_snorm16;
7132
7133 case MESA_FORMAT_A8B8G8R8_SRGB:
7134 return pack_ubyte_a8b8g8r8_srgb;
7135
7136 case MESA_FORMAT_B8G8R8A8_SRGB:
7137 return pack_ubyte_b8g8r8a8_srgb;
7138
7139 case MESA_FORMAT_A8R8G8B8_SRGB:
7140 return pack_ubyte_a8r8g8b8_srgb;
7141
7142 case MESA_FORMAT_B8G8R8X8_SRGB:
7143 return pack_ubyte_b8g8r8x8_srgb;
7144
7145 case MESA_FORMAT_X8R8G8B8_SRGB:
7146 return pack_ubyte_x8r8g8b8_srgb;
7147
7148 case MESA_FORMAT_R8G8B8A8_SRGB:
7149 return pack_ubyte_r8g8b8a8_srgb;
7150
7151 case MESA_FORMAT_R8G8B8X8_SRGB:
7152 return pack_ubyte_r8g8b8x8_srgb;
7153
7154 case MESA_FORMAT_X8B8G8R8_SRGB:
7155 return pack_ubyte_x8b8g8r8_srgb;
7156
7157 case MESA_FORMAT_R_SRGB8:
7158 return pack_ubyte_r_srgb8;
7159
7160 case MESA_FORMAT_L_SRGB8:
7161 return pack_ubyte_l_srgb8;
7162
7163 case MESA_FORMAT_LA_SRGB8:
7164 return pack_ubyte_la_srgb8;
7165
7166 case MESA_FORMAT_BGR_SRGB8:
7167 return pack_ubyte_bgr_srgb8;
7168
7169 case MESA_FORMAT_R9G9B9E5_FLOAT:
7170 return pack_ubyte_r9g9b9e5_float;
7171
7172 case MESA_FORMAT_R11G11B10_FLOAT:
7173 return pack_ubyte_r11g11b10_float;
7174
7175 case MESA_FORMAT_A_FLOAT16:
7176 return pack_ubyte_a_float16;
7177
7178 case MESA_FORMAT_A_FLOAT32:
7179 return pack_ubyte_a_float32;
7180
7181 case MESA_FORMAT_L_FLOAT16:
7182 return pack_ubyte_l_float16;
7183
7184 case MESA_FORMAT_L_FLOAT32:
7185 return pack_ubyte_l_float32;
7186
7187 case MESA_FORMAT_LA_FLOAT16:
7188 return pack_ubyte_la_float16;
7189
7190 case MESA_FORMAT_LA_FLOAT32:
7191 return pack_ubyte_la_float32;
7192
7193 case MESA_FORMAT_I_FLOAT16:
7194 return pack_ubyte_i_float16;
7195
7196 case MESA_FORMAT_I_FLOAT32:
7197 return pack_ubyte_i_float32;
7198
7199 case MESA_FORMAT_R_FLOAT16:
7200 return pack_ubyte_r_float16;
7201
7202 case MESA_FORMAT_R_FLOAT32:
7203 return pack_ubyte_r_float32;
7204
7205 case MESA_FORMAT_RG_FLOAT16:
7206 return pack_ubyte_rg_float16;
7207
7208 case MESA_FORMAT_RG_FLOAT32:
7209 return pack_ubyte_rg_float32;
7210
7211 case MESA_FORMAT_RGB_FLOAT16:
7212 return pack_ubyte_rgb_float16;
7213
7214 case MESA_FORMAT_RGB_FLOAT32:
7215 return pack_ubyte_rgb_float32;
7216
7217 case MESA_FORMAT_RGBA_FLOAT16:
7218 return pack_ubyte_rgba_float16;
7219
7220 case MESA_FORMAT_RGBA_FLOAT32:
7221 return pack_ubyte_rgba_float32;
7222
7223 case MESA_FORMAT_RGBX_FLOAT16:
7224 return pack_ubyte_rgbx_float16;
7225
7226 case MESA_FORMAT_RGBX_FLOAT32:
7227 return pack_ubyte_rgbx_float32;
7228
7229 case MESA_FORMAT_A8B8G8R8_UINT:
7230 return pack_ubyte_a8b8g8r8_uint;
7231
7232 case MESA_FORMAT_A8R8G8B8_UINT:
7233 return pack_ubyte_a8r8g8b8_uint;
7234
7235 case MESA_FORMAT_R8G8B8A8_UINT:
7236 return pack_ubyte_r8g8b8a8_uint;
7237
7238 case MESA_FORMAT_B8G8R8A8_UINT:
7239 return pack_ubyte_b8g8r8a8_uint;
7240
7241 case MESA_FORMAT_B10G10R10A2_UINT:
7242 return pack_ubyte_b10g10r10a2_uint;
7243
7244 case MESA_FORMAT_R10G10B10A2_UINT:
7245 return pack_ubyte_r10g10b10a2_uint;
7246
7247 case MESA_FORMAT_A2B10G10R10_UINT:
7248 return pack_ubyte_a2b10g10r10_uint;
7249
7250 case MESA_FORMAT_A2R10G10B10_UINT:
7251 return pack_ubyte_a2r10g10b10_uint;
7252
7253 case MESA_FORMAT_B5G6R5_UINT:
7254 return pack_ubyte_b5g6r5_uint;
7255
7256 case MESA_FORMAT_R5G6B5_UINT:
7257 return pack_ubyte_r5g6b5_uint;
7258
7259 case MESA_FORMAT_B2G3R3_UINT:
7260 return pack_ubyte_b2g3r3_uint;
7261
7262 case MESA_FORMAT_R3G3B2_UINT:
7263 return pack_ubyte_r3g3b2_uint;
7264
7265 case MESA_FORMAT_A4B4G4R4_UINT:
7266 return pack_ubyte_a4b4g4r4_uint;
7267
7268 case MESA_FORMAT_R4G4B4A4_UINT:
7269 return pack_ubyte_r4g4b4a4_uint;
7270
7271 case MESA_FORMAT_B4G4R4A4_UINT:
7272 return pack_ubyte_b4g4r4a4_uint;
7273
7274 case MESA_FORMAT_A4R4G4B4_UINT:
7275 return pack_ubyte_a4r4g4b4_uint;
7276
7277 case MESA_FORMAT_A1B5G5R5_UINT:
7278 return pack_ubyte_a1b5g5r5_uint;
7279
7280 case MESA_FORMAT_B5G5R5A1_UINT:
7281 return pack_ubyte_b5g5r5a1_uint;
7282
7283 case MESA_FORMAT_A1R5G5B5_UINT:
7284 return pack_ubyte_a1r5g5b5_uint;
7285
7286 case MESA_FORMAT_R5G5B5A1_UINT:
7287 return pack_ubyte_r5g5b5a1_uint;
7288
7289 case MESA_FORMAT_A_UINT8:
7290 return pack_ubyte_a_uint8;
7291
7292 case MESA_FORMAT_A_UINT16:
7293 return pack_ubyte_a_uint16;
7294
7295 case MESA_FORMAT_A_UINT32:
7296 return pack_ubyte_a_uint32;
7297
7298 case MESA_FORMAT_A_SINT8:
7299 return pack_ubyte_a_sint8;
7300
7301 case MESA_FORMAT_A_SINT16:
7302 return pack_ubyte_a_sint16;
7303
7304 case MESA_FORMAT_A_SINT32:
7305 return pack_ubyte_a_sint32;
7306
7307 case MESA_FORMAT_I_UINT8:
7308 return pack_ubyte_i_uint8;
7309
7310 case MESA_FORMAT_I_UINT16:
7311 return pack_ubyte_i_uint16;
7312
7313 case MESA_FORMAT_I_UINT32:
7314 return pack_ubyte_i_uint32;
7315
7316 case MESA_FORMAT_I_SINT8:
7317 return pack_ubyte_i_sint8;
7318
7319 case MESA_FORMAT_I_SINT16:
7320 return pack_ubyte_i_sint16;
7321
7322 case MESA_FORMAT_I_SINT32:
7323 return pack_ubyte_i_sint32;
7324
7325 case MESA_FORMAT_L_UINT8:
7326 return pack_ubyte_l_uint8;
7327
7328 case MESA_FORMAT_L_UINT16:
7329 return pack_ubyte_l_uint16;
7330
7331 case MESA_FORMAT_L_UINT32:
7332 return pack_ubyte_l_uint32;
7333
7334 case MESA_FORMAT_L_SINT8:
7335 return pack_ubyte_l_sint8;
7336
7337 case MESA_FORMAT_L_SINT16:
7338 return pack_ubyte_l_sint16;
7339
7340 case MESA_FORMAT_L_SINT32:
7341 return pack_ubyte_l_sint32;
7342
7343 case MESA_FORMAT_LA_UINT8:
7344 return pack_ubyte_la_uint8;
7345
7346 case MESA_FORMAT_LA_UINT16:
7347 return pack_ubyte_la_uint16;
7348
7349 case MESA_FORMAT_LA_UINT32:
7350 return pack_ubyte_la_uint32;
7351
7352 case MESA_FORMAT_LA_SINT8:
7353 return pack_ubyte_la_sint8;
7354
7355 case MESA_FORMAT_LA_SINT16:
7356 return pack_ubyte_la_sint16;
7357
7358 case MESA_FORMAT_LA_SINT32:
7359 return pack_ubyte_la_sint32;
7360
7361 case MESA_FORMAT_R_UINT8:
7362 return pack_ubyte_r_uint8;
7363
7364 case MESA_FORMAT_R_UINT16:
7365 return pack_ubyte_r_uint16;
7366
7367 case MESA_FORMAT_R_UINT32:
7368 return pack_ubyte_r_uint32;
7369
7370 case MESA_FORMAT_R_SINT8:
7371 return pack_ubyte_r_sint8;
7372
7373 case MESA_FORMAT_R_SINT16:
7374 return pack_ubyte_r_sint16;
7375
7376 case MESA_FORMAT_R_SINT32:
7377 return pack_ubyte_r_sint32;
7378
7379 case MESA_FORMAT_RG_UINT8:
7380 return pack_ubyte_rg_uint8;
7381
7382 case MESA_FORMAT_RG_UINT16:
7383 return pack_ubyte_rg_uint16;
7384
7385 case MESA_FORMAT_RG_UINT32:
7386 return pack_ubyte_rg_uint32;
7387
7388 case MESA_FORMAT_RG_SINT8:
7389 return pack_ubyte_rg_sint8;
7390
7391 case MESA_FORMAT_RG_SINT16:
7392 return pack_ubyte_rg_sint16;
7393
7394 case MESA_FORMAT_RG_SINT32:
7395 return pack_ubyte_rg_sint32;
7396
7397 case MESA_FORMAT_RGB_UINT8:
7398 return pack_ubyte_rgb_uint8;
7399
7400 case MESA_FORMAT_RGB_UINT16:
7401 return pack_ubyte_rgb_uint16;
7402
7403 case MESA_FORMAT_RGB_UINT32:
7404 return pack_ubyte_rgb_uint32;
7405
7406 case MESA_FORMAT_RGB_SINT8:
7407 return pack_ubyte_rgb_sint8;
7408
7409 case MESA_FORMAT_RGB_SINT16:
7410 return pack_ubyte_rgb_sint16;
7411
7412 case MESA_FORMAT_RGB_SINT32:
7413 return pack_ubyte_rgb_sint32;
7414
7415 case MESA_FORMAT_RGBA_UINT16:
7416 return pack_ubyte_rgba_uint16;
7417
7418 case MESA_FORMAT_RGBA_UINT32:
7419 return pack_ubyte_rgba_uint32;
7420
7421 case MESA_FORMAT_RGBA_SINT8:
7422 return pack_ubyte_rgba_sint8;
7423
7424 case MESA_FORMAT_RGBA_SINT16:
7425 return pack_ubyte_rgba_sint16;
7426
7427 case MESA_FORMAT_RGBA_SINT32:
7428 return pack_ubyte_rgba_sint32;
7429
7430 case MESA_FORMAT_RGBX_UINT8:
7431 return pack_ubyte_rgbx_uint8;
7432
7433 case MESA_FORMAT_RGBX_UINT16:
7434 return pack_ubyte_rgbx_uint16;
7435
7436 case MESA_FORMAT_RGBX_UINT32:
7437 return pack_ubyte_rgbx_uint32;
7438
7439 case MESA_FORMAT_RGBX_SINT8:
7440 return pack_ubyte_rgbx_sint8;
7441
7442 case MESA_FORMAT_RGBX_SINT16:
7443 return pack_ubyte_rgbx_sint16;
7444
7445 case MESA_FORMAT_RGBX_SINT32:
7446 return pack_ubyte_rgbx_sint32;
7447 default:
7448 return NULL;
7449 }
7450 }
7451
7452 /**
7453 * Return a function that can pack a float rgba[4] color.
7454 */
7455 mesa_pack_float_rgba_func
_mesa_get_pack_float_rgba_function(mesa_format format)7456 _mesa_get_pack_float_rgba_function(mesa_format format)
7457 {
7458 switch (format) {
7459
7460 case MESA_FORMAT_A8B8G8R8_UNORM:
7461 return pack_float_a8b8g8r8_unorm;
7462
7463 case MESA_FORMAT_X8B8G8R8_UNORM:
7464 return pack_float_x8b8g8r8_unorm;
7465
7466 case MESA_FORMAT_R8G8B8A8_UNORM:
7467 return pack_float_r8g8b8a8_unorm;
7468
7469 case MESA_FORMAT_R8G8B8X8_UNORM:
7470 return pack_float_r8g8b8x8_unorm;
7471
7472 case MESA_FORMAT_B8G8R8A8_UNORM:
7473 return pack_float_b8g8r8a8_unorm;
7474
7475 case MESA_FORMAT_B8G8R8X8_UNORM:
7476 return pack_float_b8g8r8x8_unorm;
7477
7478 case MESA_FORMAT_A8R8G8B8_UNORM:
7479 return pack_float_a8r8g8b8_unorm;
7480
7481 case MESA_FORMAT_X8R8G8B8_UNORM:
7482 return pack_float_x8r8g8b8_unorm;
7483
7484 case MESA_FORMAT_B5G6R5_UNORM:
7485 return pack_float_b5g6r5_unorm;
7486
7487 case MESA_FORMAT_R5G6B5_UNORM:
7488 return pack_float_r5g6b5_unorm;
7489
7490 case MESA_FORMAT_B4G4R4A4_UNORM:
7491 return pack_float_b4g4r4a4_unorm;
7492
7493 case MESA_FORMAT_B4G4R4X4_UNORM:
7494 return pack_float_b4g4r4x4_unorm;
7495
7496 case MESA_FORMAT_A4R4G4B4_UNORM:
7497 return pack_float_a4r4g4b4_unorm;
7498
7499 case MESA_FORMAT_A1B5G5R5_UNORM:
7500 return pack_float_a1b5g5r5_unorm;
7501
7502 case MESA_FORMAT_X1B5G5R5_UNORM:
7503 return pack_float_x1b5g5r5_unorm;
7504
7505 case MESA_FORMAT_B5G5R5A1_UNORM:
7506 return pack_float_b5g5r5a1_unorm;
7507
7508 case MESA_FORMAT_B5G5R5X1_UNORM:
7509 return pack_float_b5g5r5x1_unorm;
7510
7511 case MESA_FORMAT_A1R5G5B5_UNORM:
7512 return pack_float_a1r5g5b5_unorm;
7513
7514 case MESA_FORMAT_L4A4_UNORM:
7515 return pack_float_l4a4_unorm;
7516
7517 case MESA_FORMAT_B2G3R3_UNORM:
7518 return pack_float_b2g3r3_unorm;
7519
7520 case MESA_FORMAT_B10G10R10A2_UNORM:
7521 return pack_float_b10g10r10a2_unorm;
7522
7523 case MESA_FORMAT_B10G10R10X2_UNORM:
7524 return pack_float_b10g10r10x2_unorm;
7525
7526 case MESA_FORMAT_R10G10B10A2_UNORM:
7527 return pack_float_r10g10b10a2_unorm;
7528
7529 case MESA_FORMAT_R10G10B10X2_UNORM:
7530 return pack_float_r10g10b10x2_unorm;
7531
7532 case MESA_FORMAT_R3G3B2_UNORM:
7533 return pack_float_r3g3b2_unorm;
7534
7535 case MESA_FORMAT_A4B4G4R4_UNORM:
7536 return pack_float_a4b4g4r4_unorm;
7537
7538 case MESA_FORMAT_R4G4B4A4_UNORM:
7539 return pack_float_r4g4b4a4_unorm;
7540
7541 case MESA_FORMAT_R5G5B5A1_UNORM:
7542 return pack_float_r5g5b5a1_unorm;
7543
7544 case MESA_FORMAT_A2B10G10R10_UNORM:
7545 return pack_float_a2b10g10r10_unorm;
7546
7547 case MESA_FORMAT_A2R10G10B10_UNORM:
7548 return pack_float_a2r10g10b10_unorm;
7549
7550 case MESA_FORMAT_A_UNORM8:
7551 return pack_float_a_unorm8;
7552
7553 case MESA_FORMAT_A_UNORM16:
7554 return pack_float_a_unorm16;
7555
7556 case MESA_FORMAT_L_UNORM8:
7557 return pack_float_l_unorm8;
7558
7559 case MESA_FORMAT_L_UNORM16:
7560 return pack_float_l_unorm16;
7561
7562 case MESA_FORMAT_LA_UNORM8:
7563 return pack_float_la_unorm8;
7564
7565 case MESA_FORMAT_LA_UNORM16:
7566 return pack_float_la_unorm16;
7567
7568 case MESA_FORMAT_I_UNORM8:
7569 return pack_float_i_unorm8;
7570
7571 case MESA_FORMAT_I_UNORM16:
7572 return pack_float_i_unorm16;
7573
7574 case MESA_FORMAT_R_UNORM8:
7575 return pack_float_r_unorm8;
7576
7577 case MESA_FORMAT_R_UNORM16:
7578 return pack_float_r_unorm16;
7579
7580 case MESA_FORMAT_RG_UNORM8:
7581 return pack_float_rg_unorm8;
7582
7583 case MESA_FORMAT_RG_UNORM16:
7584 return pack_float_rg_unorm16;
7585
7586 case MESA_FORMAT_BGR_UNORM8:
7587 return pack_float_bgr_unorm8;
7588
7589 case MESA_FORMAT_RGB_UNORM8:
7590 return pack_float_rgb_unorm8;
7591
7592 case MESA_FORMAT_RGBA_UNORM16:
7593 return pack_float_rgba_unorm16;
7594
7595 case MESA_FORMAT_RGBX_UNORM16:
7596 return pack_float_rgbx_unorm16;
7597
7598 case MESA_FORMAT_A8B8G8R8_SNORM:
7599 return pack_float_a8b8g8r8_snorm;
7600
7601 case MESA_FORMAT_X8B8G8R8_SNORM:
7602 return pack_float_x8b8g8r8_snorm;
7603
7604 case MESA_FORMAT_R8G8B8A8_SNORM:
7605 return pack_float_r8g8b8a8_snorm;
7606
7607 case MESA_FORMAT_R8G8B8X8_SNORM:
7608 return pack_float_r8g8b8x8_snorm;
7609
7610 case MESA_FORMAT_A_SNORM8:
7611 return pack_float_a_snorm8;
7612
7613 case MESA_FORMAT_A_SNORM16:
7614 return pack_float_a_snorm16;
7615
7616 case MESA_FORMAT_L_SNORM8:
7617 return pack_float_l_snorm8;
7618
7619 case MESA_FORMAT_L_SNORM16:
7620 return pack_float_l_snorm16;
7621
7622 case MESA_FORMAT_I_SNORM8:
7623 return pack_float_i_snorm8;
7624
7625 case MESA_FORMAT_I_SNORM16:
7626 return pack_float_i_snorm16;
7627
7628 case MESA_FORMAT_R_SNORM8:
7629 return pack_float_r_snorm8;
7630
7631 case MESA_FORMAT_R_SNORM16:
7632 return pack_float_r_snorm16;
7633
7634 case MESA_FORMAT_LA_SNORM8:
7635 return pack_float_la_snorm8;
7636
7637 case MESA_FORMAT_LA_SNORM16:
7638 return pack_float_la_snorm16;
7639
7640 case MESA_FORMAT_RG_SNORM8:
7641 return pack_float_rg_snorm8;
7642
7643 case MESA_FORMAT_RG_SNORM16:
7644 return pack_float_rg_snorm16;
7645
7646 case MESA_FORMAT_RGB_SNORM16:
7647 return pack_float_rgb_snorm16;
7648
7649 case MESA_FORMAT_RGBA_SNORM16:
7650 return pack_float_rgba_snorm16;
7651
7652 case MESA_FORMAT_RGBX_SNORM16:
7653 return pack_float_rgbx_snorm16;
7654
7655 case MESA_FORMAT_A8B8G8R8_SRGB:
7656 return pack_float_a8b8g8r8_srgb;
7657
7658 case MESA_FORMAT_B8G8R8A8_SRGB:
7659 return pack_float_b8g8r8a8_srgb;
7660
7661 case MESA_FORMAT_A8R8G8B8_SRGB:
7662 return pack_float_a8r8g8b8_srgb;
7663
7664 case MESA_FORMAT_B8G8R8X8_SRGB:
7665 return pack_float_b8g8r8x8_srgb;
7666
7667 case MESA_FORMAT_X8R8G8B8_SRGB:
7668 return pack_float_x8r8g8b8_srgb;
7669
7670 case MESA_FORMAT_R8G8B8A8_SRGB:
7671 return pack_float_r8g8b8a8_srgb;
7672
7673 case MESA_FORMAT_R8G8B8X8_SRGB:
7674 return pack_float_r8g8b8x8_srgb;
7675
7676 case MESA_FORMAT_X8B8G8R8_SRGB:
7677 return pack_float_x8b8g8r8_srgb;
7678
7679 case MESA_FORMAT_R_SRGB8:
7680 return pack_float_r_srgb8;
7681
7682 case MESA_FORMAT_L_SRGB8:
7683 return pack_float_l_srgb8;
7684
7685 case MESA_FORMAT_LA_SRGB8:
7686 return pack_float_la_srgb8;
7687
7688 case MESA_FORMAT_BGR_SRGB8:
7689 return pack_float_bgr_srgb8;
7690
7691 case MESA_FORMAT_R9G9B9E5_FLOAT:
7692 return pack_float_r9g9b9e5_float;
7693
7694 case MESA_FORMAT_R11G11B10_FLOAT:
7695 return pack_float_r11g11b10_float;
7696
7697 case MESA_FORMAT_A_FLOAT16:
7698 return pack_float_a_float16;
7699
7700 case MESA_FORMAT_A_FLOAT32:
7701 return pack_float_a_float32;
7702
7703 case MESA_FORMAT_L_FLOAT16:
7704 return pack_float_l_float16;
7705
7706 case MESA_FORMAT_L_FLOAT32:
7707 return pack_float_l_float32;
7708
7709 case MESA_FORMAT_LA_FLOAT16:
7710 return pack_float_la_float16;
7711
7712 case MESA_FORMAT_LA_FLOAT32:
7713 return pack_float_la_float32;
7714
7715 case MESA_FORMAT_I_FLOAT16:
7716 return pack_float_i_float16;
7717
7718 case MESA_FORMAT_I_FLOAT32:
7719 return pack_float_i_float32;
7720
7721 case MESA_FORMAT_R_FLOAT16:
7722 return pack_float_r_float16;
7723
7724 case MESA_FORMAT_R_FLOAT32:
7725 return pack_float_r_float32;
7726
7727 case MESA_FORMAT_RG_FLOAT16:
7728 return pack_float_rg_float16;
7729
7730 case MESA_FORMAT_RG_FLOAT32:
7731 return pack_float_rg_float32;
7732
7733 case MESA_FORMAT_RGB_FLOAT16:
7734 return pack_float_rgb_float16;
7735
7736 case MESA_FORMAT_RGB_FLOAT32:
7737 return pack_float_rgb_float32;
7738
7739 case MESA_FORMAT_RGBA_FLOAT16:
7740 return pack_float_rgba_float16;
7741
7742 case MESA_FORMAT_RGBA_FLOAT32:
7743 return pack_float_rgba_float32;
7744
7745 case MESA_FORMAT_RGBX_FLOAT16:
7746 return pack_float_rgbx_float16;
7747
7748 case MESA_FORMAT_RGBX_FLOAT32:
7749 return pack_float_rgbx_float32;
7750 default:
7751 return NULL;
7752 }
7753 }
7754
7755 /**
7756 * Pack a row of uint8_t rgba[4] values to the destination.
7757 */
7758 void
_mesa_pack_ubyte_rgba_row(mesa_format format,uint32_t n,const uint8_t src[][4],void * dst)7759 _mesa_pack_ubyte_rgba_row(mesa_format format, uint32_t n,
7760 const uint8_t src[][4], void *dst)
7761 {
7762 uint32_t i;
7763 uint8_t *d = dst;
7764
7765 switch (format) {
7766
7767 case MESA_FORMAT_A8B8G8R8_UNORM:
7768 for (i = 0; i < n; ++i) {
7769 pack_ubyte_a8b8g8r8_unorm(src[i], d);
7770 d += 4;
7771 }
7772 break;
7773
7774 case MESA_FORMAT_X8B8G8R8_UNORM:
7775 for (i = 0; i < n; ++i) {
7776 pack_ubyte_x8b8g8r8_unorm(src[i], d);
7777 d += 4;
7778 }
7779 break;
7780
7781 case MESA_FORMAT_R8G8B8A8_UNORM:
7782 for (i = 0; i < n; ++i) {
7783 pack_ubyte_r8g8b8a8_unorm(src[i], d);
7784 d += 4;
7785 }
7786 break;
7787
7788 case MESA_FORMAT_R8G8B8X8_UNORM:
7789 for (i = 0; i < n; ++i) {
7790 pack_ubyte_r8g8b8x8_unorm(src[i], d);
7791 d += 4;
7792 }
7793 break;
7794
7795 case MESA_FORMAT_B8G8R8A8_UNORM:
7796 for (i = 0; i < n; ++i) {
7797 pack_ubyte_b8g8r8a8_unorm(src[i], d);
7798 d += 4;
7799 }
7800 break;
7801
7802 case MESA_FORMAT_B8G8R8X8_UNORM:
7803 for (i = 0; i < n; ++i) {
7804 pack_ubyte_b8g8r8x8_unorm(src[i], d);
7805 d += 4;
7806 }
7807 break;
7808
7809 case MESA_FORMAT_A8R8G8B8_UNORM:
7810 for (i = 0; i < n; ++i) {
7811 pack_ubyte_a8r8g8b8_unorm(src[i], d);
7812 d += 4;
7813 }
7814 break;
7815
7816 case MESA_FORMAT_X8R8G8B8_UNORM:
7817 for (i = 0; i < n; ++i) {
7818 pack_ubyte_x8r8g8b8_unorm(src[i], d);
7819 d += 4;
7820 }
7821 break;
7822
7823 case MESA_FORMAT_B5G6R5_UNORM:
7824 for (i = 0; i < n; ++i) {
7825 pack_ubyte_b5g6r5_unorm(src[i], d);
7826 d += 2;
7827 }
7828 break;
7829
7830 case MESA_FORMAT_R5G6B5_UNORM:
7831 for (i = 0; i < n; ++i) {
7832 pack_ubyte_r5g6b5_unorm(src[i], d);
7833 d += 2;
7834 }
7835 break;
7836
7837 case MESA_FORMAT_B4G4R4A4_UNORM:
7838 for (i = 0; i < n; ++i) {
7839 pack_ubyte_b4g4r4a4_unorm(src[i], d);
7840 d += 2;
7841 }
7842 break;
7843
7844 case MESA_FORMAT_B4G4R4X4_UNORM:
7845 for (i = 0; i < n; ++i) {
7846 pack_ubyte_b4g4r4x4_unorm(src[i], d);
7847 d += 2;
7848 }
7849 break;
7850
7851 case MESA_FORMAT_A4R4G4B4_UNORM:
7852 for (i = 0; i < n; ++i) {
7853 pack_ubyte_a4r4g4b4_unorm(src[i], d);
7854 d += 2;
7855 }
7856 break;
7857
7858 case MESA_FORMAT_A1B5G5R5_UNORM:
7859 for (i = 0; i < n; ++i) {
7860 pack_ubyte_a1b5g5r5_unorm(src[i], d);
7861 d += 2;
7862 }
7863 break;
7864
7865 case MESA_FORMAT_X1B5G5R5_UNORM:
7866 for (i = 0; i < n; ++i) {
7867 pack_ubyte_x1b5g5r5_unorm(src[i], d);
7868 d += 2;
7869 }
7870 break;
7871
7872 case MESA_FORMAT_B5G5R5A1_UNORM:
7873 for (i = 0; i < n; ++i) {
7874 pack_ubyte_b5g5r5a1_unorm(src[i], d);
7875 d += 2;
7876 }
7877 break;
7878
7879 case MESA_FORMAT_B5G5R5X1_UNORM:
7880 for (i = 0; i < n; ++i) {
7881 pack_ubyte_b5g5r5x1_unorm(src[i], d);
7882 d += 2;
7883 }
7884 break;
7885
7886 case MESA_FORMAT_A1R5G5B5_UNORM:
7887 for (i = 0; i < n; ++i) {
7888 pack_ubyte_a1r5g5b5_unorm(src[i], d);
7889 d += 2;
7890 }
7891 break;
7892
7893 case MESA_FORMAT_L4A4_UNORM:
7894 for (i = 0; i < n; ++i) {
7895 pack_ubyte_l4a4_unorm(src[i], d);
7896 d += 1;
7897 }
7898 break;
7899
7900 case MESA_FORMAT_B2G3R3_UNORM:
7901 for (i = 0; i < n; ++i) {
7902 pack_ubyte_b2g3r3_unorm(src[i], d);
7903 d += 1;
7904 }
7905 break;
7906
7907 case MESA_FORMAT_B10G10R10A2_UNORM:
7908 for (i = 0; i < n; ++i) {
7909 pack_ubyte_b10g10r10a2_unorm(src[i], d);
7910 d += 4;
7911 }
7912 break;
7913
7914 case MESA_FORMAT_B10G10R10X2_UNORM:
7915 for (i = 0; i < n; ++i) {
7916 pack_ubyte_b10g10r10x2_unorm(src[i], d);
7917 d += 4;
7918 }
7919 break;
7920
7921 case MESA_FORMAT_R10G10B10A2_UNORM:
7922 for (i = 0; i < n; ++i) {
7923 pack_ubyte_r10g10b10a2_unorm(src[i], d);
7924 d += 4;
7925 }
7926 break;
7927
7928 case MESA_FORMAT_R10G10B10X2_UNORM:
7929 for (i = 0; i < n; ++i) {
7930 pack_ubyte_r10g10b10x2_unorm(src[i], d);
7931 d += 4;
7932 }
7933 break;
7934
7935 case MESA_FORMAT_R3G3B2_UNORM:
7936 for (i = 0; i < n; ++i) {
7937 pack_ubyte_r3g3b2_unorm(src[i], d);
7938 d += 1;
7939 }
7940 break;
7941
7942 case MESA_FORMAT_A4B4G4R4_UNORM:
7943 for (i = 0; i < n; ++i) {
7944 pack_ubyte_a4b4g4r4_unorm(src[i], d);
7945 d += 2;
7946 }
7947 break;
7948
7949 case MESA_FORMAT_R4G4B4A4_UNORM:
7950 for (i = 0; i < n; ++i) {
7951 pack_ubyte_r4g4b4a4_unorm(src[i], d);
7952 d += 2;
7953 }
7954 break;
7955
7956 case MESA_FORMAT_R5G5B5A1_UNORM:
7957 for (i = 0; i < n; ++i) {
7958 pack_ubyte_r5g5b5a1_unorm(src[i], d);
7959 d += 2;
7960 }
7961 break;
7962
7963 case MESA_FORMAT_A2B10G10R10_UNORM:
7964 for (i = 0; i < n; ++i) {
7965 pack_ubyte_a2b10g10r10_unorm(src[i], d);
7966 d += 4;
7967 }
7968 break;
7969
7970 case MESA_FORMAT_A2R10G10B10_UNORM:
7971 for (i = 0; i < n; ++i) {
7972 pack_ubyte_a2r10g10b10_unorm(src[i], d);
7973 d += 4;
7974 }
7975 break;
7976
7977 case MESA_FORMAT_A_UNORM8:
7978 for (i = 0; i < n; ++i) {
7979 pack_ubyte_a_unorm8(src[i], d);
7980 d += 1;
7981 }
7982 break;
7983
7984 case MESA_FORMAT_A_UNORM16:
7985 for (i = 0; i < n; ++i) {
7986 pack_ubyte_a_unorm16(src[i], d);
7987 d += 2;
7988 }
7989 break;
7990
7991 case MESA_FORMAT_L_UNORM8:
7992 for (i = 0; i < n; ++i) {
7993 pack_ubyte_l_unorm8(src[i], d);
7994 d += 1;
7995 }
7996 break;
7997
7998 case MESA_FORMAT_L_UNORM16:
7999 for (i = 0; i < n; ++i) {
8000 pack_ubyte_l_unorm16(src[i], d);
8001 d += 2;
8002 }
8003 break;
8004
8005 case MESA_FORMAT_LA_UNORM8:
8006 for (i = 0; i < n; ++i) {
8007 pack_ubyte_la_unorm8(src[i], d);
8008 d += 2;
8009 }
8010 break;
8011
8012 case MESA_FORMAT_LA_UNORM16:
8013 for (i = 0; i < n; ++i) {
8014 pack_ubyte_la_unorm16(src[i], d);
8015 d += 4;
8016 }
8017 break;
8018
8019 case MESA_FORMAT_I_UNORM8:
8020 for (i = 0; i < n; ++i) {
8021 pack_ubyte_i_unorm8(src[i], d);
8022 d += 1;
8023 }
8024 break;
8025
8026 case MESA_FORMAT_I_UNORM16:
8027 for (i = 0; i < n; ++i) {
8028 pack_ubyte_i_unorm16(src[i], d);
8029 d += 2;
8030 }
8031 break;
8032
8033 case MESA_FORMAT_R_UNORM8:
8034 for (i = 0; i < n; ++i) {
8035 pack_ubyte_r_unorm8(src[i], d);
8036 d += 1;
8037 }
8038 break;
8039
8040 case MESA_FORMAT_R_UNORM16:
8041 for (i = 0; i < n; ++i) {
8042 pack_ubyte_r_unorm16(src[i], d);
8043 d += 2;
8044 }
8045 break;
8046
8047 case MESA_FORMAT_RG_UNORM8:
8048 for (i = 0; i < n; ++i) {
8049 pack_ubyte_rg_unorm8(src[i], d);
8050 d += 2;
8051 }
8052 break;
8053
8054 case MESA_FORMAT_RG_UNORM16:
8055 for (i = 0; i < n; ++i) {
8056 pack_ubyte_rg_unorm16(src[i], d);
8057 d += 4;
8058 }
8059 break;
8060
8061 case MESA_FORMAT_BGR_UNORM8:
8062 for (i = 0; i < n; ++i) {
8063 pack_ubyte_bgr_unorm8(src[i], d);
8064 d += 3;
8065 }
8066 break;
8067
8068 case MESA_FORMAT_RGB_UNORM8:
8069 for (i = 0; i < n; ++i) {
8070 pack_ubyte_rgb_unorm8(src[i], d);
8071 d += 3;
8072 }
8073 break;
8074
8075 case MESA_FORMAT_RGBA_UNORM16:
8076 for (i = 0; i < n; ++i) {
8077 pack_ubyte_rgba_unorm16(src[i], d);
8078 d += 8;
8079 }
8080 break;
8081
8082 case MESA_FORMAT_RGBX_UNORM16:
8083 for (i = 0; i < n; ++i) {
8084 pack_ubyte_rgbx_unorm16(src[i], d);
8085 d += 8;
8086 }
8087 break;
8088
8089 case MESA_FORMAT_A8B8G8R8_SNORM:
8090 for (i = 0; i < n; ++i) {
8091 pack_ubyte_a8b8g8r8_snorm(src[i], d);
8092 d += 4;
8093 }
8094 break;
8095
8096 case MESA_FORMAT_X8B8G8R8_SNORM:
8097 for (i = 0; i < n; ++i) {
8098 pack_ubyte_x8b8g8r8_snorm(src[i], d);
8099 d += 4;
8100 }
8101 break;
8102
8103 case MESA_FORMAT_R8G8B8A8_SNORM:
8104 for (i = 0; i < n; ++i) {
8105 pack_ubyte_r8g8b8a8_snorm(src[i], d);
8106 d += 4;
8107 }
8108 break;
8109
8110 case MESA_FORMAT_R8G8B8X8_SNORM:
8111 for (i = 0; i < n; ++i) {
8112 pack_ubyte_r8g8b8x8_snorm(src[i], d);
8113 d += 4;
8114 }
8115 break;
8116
8117 case MESA_FORMAT_A_SNORM8:
8118 for (i = 0; i < n; ++i) {
8119 pack_ubyte_a_snorm8(src[i], d);
8120 d += 1;
8121 }
8122 break;
8123
8124 case MESA_FORMAT_A_SNORM16:
8125 for (i = 0; i < n; ++i) {
8126 pack_ubyte_a_snorm16(src[i], d);
8127 d += 2;
8128 }
8129 break;
8130
8131 case MESA_FORMAT_L_SNORM8:
8132 for (i = 0; i < n; ++i) {
8133 pack_ubyte_l_snorm8(src[i], d);
8134 d += 1;
8135 }
8136 break;
8137
8138 case MESA_FORMAT_L_SNORM16:
8139 for (i = 0; i < n; ++i) {
8140 pack_ubyte_l_snorm16(src[i], d);
8141 d += 2;
8142 }
8143 break;
8144
8145 case MESA_FORMAT_I_SNORM8:
8146 for (i = 0; i < n; ++i) {
8147 pack_ubyte_i_snorm8(src[i], d);
8148 d += 1;
8149 }
8150 break;
8151
8152 case MESA_FORMAT_I_SNORM16:
8153 for (i = 0; i < n; ++i) {
8154 pack_ubyte_i_snorm16(src[i], d);
8155 d += 2;
8156 }
8157 break;
8158
8159 case MESA_FORMAT_R_SNORM8:
8160 for (i = 0; i < n; ++i) {
8161 pack_ubyte_r_snorm8(src[i], d);
8162 d += 1;
8163 }
8164 break;
8165
8166 case MESA_FORMAT_R_SNORM16:
8167 for (i = 0; i < n; ++i) {
8168 pack_ubyte_r_snorm16(src[i], d);
8169 d += 2;
8170 }
8171 break;
8172
8173 case MESA_FORMAT_LA_SNORM8:
8174 for (i = 0; i < n; ++i) {
8175 pack_ubyte_la_snorm8(src[i], d);
8176 d += 2;
8177 }
8178 break;
8179
8180 case MESA_FORMAT_LA_SNORM16:
8181 for (i = 0; i < n; ++i) {
8182 pack_ubyte_la_snorm16(src[i], d);
8183 d += 4;
8184 }
8185 break;
8186
8187 case MESA_FORMAT_RG_SNORM8:
8188 for (i = 0; i < n; ++i) {
8189 pack_ubyte_rg_snorm8(src[i], d);
8190 d += 2;
8191 }
8192 break;
8193
8194 case MESA_FORMAT_RG_SNORM16:
8195 for (i = 0; i < n; ++i) {
8196 pack_ubyte_rg_snorm16(src[i], d);
8197 d += 4;
8198 }
8199 break;
8200
8201 case MESA_FORMAT_RGB_SNORM16:
8202 for (i = 0; i < n; ++i) {
8203 pack_ubyte_rgb_snorm16(src[i], d);
8204 d += 6;
8205 }
8206 break;
8207
8208 case MESA_FORMAT_RGBA_SNORM16:
8209 for (i = 0; i < n; ++i) {
8210 pack_ubyte_rgba_snorm16(src[i], d);
8211 d += 8;
8212 }
8213 break;
8214
8215 case MESA_FORMAT_RGBX_SNORM16:
8216 for (i = 0; i < n; ++i) {
8217 pack_ubyte_rgbx_snorm16(src[i], d);
8218 d += 8;
8219 }
8220 break;
8221
8222 case MESA_FORMAT_A8B8G8R8_SRGB:
8223 for (i = 0; i < n; ++i) {
8224 pack_ubyte_a8b8g8r8_srgb(src[i], d);
8225 d += 4;
8226 }
8227 break;
8228
8229 case MESA_FORMAT_B8G8R8A8_SRGB:
8230 for (i = 0; i < n; ++i) {
8231 pack_ubyte_b8g8r8a8_srgb(src[i], d);
8232 d += 4;
8233 }
8234 break;
8235
8236 case MESA_FORMAT_A8R8G8B8_SRGB:
8237 for (i = 0; i < n; ++i) {
8238 pack_ubyte_a8r8g8b8_srgb(src[i], d);
8239 d += 4;
8240 }
8241 break;
8242
8243 case MESA_FORMAT_B8G8R8X8_SRGB:
8244 for (i = 0; i < n; ++i) {
8245 pack_ubyte_b8g8r8x8_srgb(src[i], d);
8246 d += 4;
8247 }
8248 break;
8249
8250 case MESA_FORMAT_X8R8G8B8_SRGB:
8251 for (i = 0; i < n; ++i) {
8252 pack_ubyte_x8r8g8b8_srgb(src[i], d);
8253 d += 4;
8254 }
8255 break;
8256
8257 case MESA_FORMAT_R8G8B8A8_SRGB:
8258 for (i = 0; i < n; ++i) {
8259 pack_ubyte_r8g8b8a8_srgb(src[i], d);
8260 d += 4;
8261 }
8262 break;
8263
8264 case MESA_FORMAT_R8G8B8X8_SRGB:
8265 for (i = 0; i < n; ++i) {
8266 pack_ubyte_r8g8b8x8_srgb(src[i], d);
8267 d += 4;
8268 }
8269 break;
8270
8271 case MESA_FORMAT_X8B8G8R8_SRGB:
8272 for (i = 0; i < n; ++i) {
8273 pack_ubyte_x8b8g8r8_srgb(src[i], d);
8274 d += 4;
8275 }
8276 break;
8277
8278 case MESA_FORMAT_R_SRGB8:
8279 for (i = 0; i < n; ++i) {
8280 pack_ubyte_r_srgb8(src[i], d);
8281 d += 1;
8282 }
8283 break;
8284
8285 case MESA_FORMAT_L_SRGB8:
8286 for (i = 0; i < n; ++i) {
8287 pack_ubyte_l_srgb8(src[i], d);
8288 d += 1;
8289 }
8290 break;
8291
8292 case MESA_FORMAT_LA_SRGB8:
8293 for (i = 0; i < n; ++i) {
8294 pack_ubyte_la_srgb8(src[i], d);
8295 d += 2;
8296 }
8297 break;
8298
8299 case MESA_FORMAT_BGR_SRGB8:
8300 for (i = 0; i < n; ++i) {
8301 pack_ubyte_bgr_srgb8(src[i], d);
8302 d += 3;
8303 }
8304 break;
8305
8306 case MESA_FORMAT_R9G9B9E5_FLOAT:
8307 for (i = 0; i < n; ++i) {
8308 pack_ubyte_r9g9b9e5_float(src[i], d);
8309 d += 4;
8310 }
8311 break;
8312
8313 case MESA_FORMAT_R11G11B10_FLOAT:
8314 for (i = 0; i < n; ++i) {
8315 pack_ubyte_r11g11b10_float(src[i], d);
8316 d += 4;
8317 }
8318 break;
8319
8320 case MESA_FORMAT_A_FLOAT16:
8321 for (i = 0; i < n; ++i) {
8322 pack_ubyte_a_float16(src[i], d);
8323 d += 2;
8324 }
8325 break;
8326
8327 case MESA_FORMAT_A_FLOAT32:
8328 for (i = 0; i < n; ++i) {
8329 pack_ubyte_a_float32(src[i], d);
8330 d += 4;
8331 }
8332 break;
8333
8334 case MESA_FORMAT_L_FLOAT16:
8335 for (i = 0; i < n; ++i) {
8336 pack_ubyte_l_float16(src[i], d);
8337 d += 2;
8338 }
8339 break;
8340
8341 case MESA_FORMAT_L_FLOAT32:
8342 for (i = 0; i < n; ++i) {
8343 pack_ubyte_l_float32(src[i], d);
8344 d += 4;
8345 }
8346 break;
8347
8348 case MESA_FORMAT_LA_FLOAT16:
8349 for (i = 0; i < n; ++i) {
8350 pack_ubyte_la_float16(src[i], d);
8351 d += 4;
8352 }
8353 break;
8354
8355 case MESA_FORMAT_LA_FLOAT32:
8356 for (i = 0; i < n; ++i) {
8357 pack_ubyte_la_float32(src[i], d);
8358 d += 8;
8359 }
8360 break;
8361
8362 case MESA_FORMAT_I_FLOAT16:
8363 for (i = 0; i < n; ++i) {
8364 pack_ubyte_i_float16(src[i], d);
8365 d += 2;
8366 }
8367 break;
8368
8369 case MESA_FORMAT_I_FLOAT32:
8370 for (i = 0; i < n; ++i) {
8371 pack_ubyte_i_float32(src[i], d);
8372 d += 4;
8373 }
8374 break;
8375
8376 case MESA_FORMAT_R_FLOAT16:
8377 for (i = 0; i < n; ++i) {
8378 pack_ubyte_r_float16(src[i], d);
8379 d += 2;
8380 }
8381 break;
8382
8383 case MESA_FORMAT_R_FLOAT32:
8384 for (i = 0; i < n; ++i) {
8385 pack_ubyte_r_float32(src[i], d);
8386 d += 4;
8387 }
8388 break;
8389
8390 case MESA_FORMAT_RG_FLOAT16:
8391 for (i = 0; i < n; ++i) {
8392 pack_ubyte_rg_float16(src[i], d);
8393 d += 4;
8394 }
8395 break;
8396
8397 case MESA_FORMAT_RG_FLOAT32:
8398 for (i = 0; i < n; ++i) {
8399 pack_ubyte_rg_float32(src[i], d);
8400 d += 8;
8401 }
8402 break;
8403
8404 case MESA_FORMAT_RGB_FLOAT16:
8405 for (i = 0; i < n; ++i) {
8406 pack_ubyte_rgb_float16(src[i], d);
8407 d += 6;
8408 }
8409 break;
8410
8411 case MESA_FORMAT_RGB_FLOAT32:
8412 for (i = 0; i < n; ++i) {
8413 pack_ubyte_rgb_float32(src[i], d);
8414 d += 12;
8415 }
8416 break;
8417
8418 case MESA_FORMAT_RGBA_FLOAT16:
8419 for (i = 0; i < n; ++i) {
8420 pack_ubyte_rgba_float16(src[i], d);
8421 d += 8;
8422 }
8423 break;
8424
8425 case MESA_FORMAT_RGBA_FLOAT32:
8426 for (i = 0; i < n; ++i) {
8427 pack_ubyte_rgba_float32(src[i], d);
8428 d += 16;
8429 }
8430 break;
8431
8432 case MESA_FORMAT_RGBX_FLOAT16:
8433 for (i = 0; i < n; ++i) {
8434 pack_ubyte_rgbx_float16(src[i], d);
8435 d += 8;
8436 }
8437 break;
8438
8439 case MESA_FORMAT_RGBX_FLOAT32:
8440 for (i = 0; i < n; ++i) {
8441 pack_ubyte_rgbx_float32(src[i], d);
8442 d += 16;
8443 }
8444 break;
8445
8446 case MESA_FORMAT_A8B8G8R8_UINT:
8447 for (i = 0; i < n; ++i) {
8448 pack_ubyte_a8b8g8r8_uint(src[i], d);
8449 d += 4;
8450 }
8451 break;
8452
8453 case MESA_FORMAT_A8R8G8B8_UINT:
8454 for (i = 0; i < n; ++i) {
8455 pack_ubyte_a8r8g8b8_uint(src[i], d);
8456 d += 4;
8457 }
8458 break;
8459
8460 case MESA_FORMAT_R8G8B8A8_UINT:
8461 for (i = 0; i < n; ++i) {
8462 pack_ubyte_r8g8b8a8_uint(src[i], d);
8463 d += 4;
8464 }
8465 break;
8466
8467 case MESA_FORMAT_B8G8R8A8_UINT:
8468 for (i = 0; i < n; ++i) {
8469 pack_ubyte_b8g8r8a8_uint(src[i], d);
8470 d += 4;
8471 }
8472 break;
8473
8474 case MESA_FORMAT_B10G10R10A2_UINT:
8475 for (i = 0; i < n; ++i) {
8476 pack_ubyte_b10g10r10a2_uint(src[i], d);
8477 d += 4;
8478 }
8479 break;
8480
8481 case MESA_FORMAT_R10G10B10A2_UINT:
8482 for (i = 0; i < n; ++i) {
8483 pack_ubyte_r10g10b10a2_uint(src[i], d);
8484 d += 4;
8485 }
8486 break;
8487
8488 case MESA_FORMAT_A2B10G10R10_UINT:
8489 for (i = 0; i < n; ++i) {
8490 pack_ubyte_a2b10g10r10_uint(src[i], d);
8491 d += 4;
8492 }
8493 break;
8494
8495 case MESA_FORMAT_A2R10G10B10_UINT:
8496 for (i = 0; i < n; ++i) {
8497 pack_ubyte_a2r10g10b10_uint(src[i], d);
8498 d += 4;
8499 }
8500 break;
8501
8502 case MESA_FORMAT_B5G6R5_UINT:
8503 for (i = 0; i < n; ++i) {
8504 pack_ubyte_b5g6r5_uint(src[i], d);
8505 d += 2;
8506 }
8507 break;
8508
8509 case MESA_FORMAT_R5G6B5_UINT:
8510 for (i = 0; i < n; ++i) {
8511 pack_ubyte_r5g6b5_uint(src[i], d);
8512 d += 2;
8513 }
8514 break;
8515
8516 case MESA_FORMAT_B2G3R3_UINT:
8517 for (i = 0; i < n; ++i) {
8518 pack_ubyte_b2g3r3_uint(src[i], d);
8519 d += 1;
8520 }
8521 break;
8522
8523 case MESA_FORMAT_R3G3B2_UINT:
8524 for (i = 0; i < n; ++i) {
8525 pack_ubyte_r3g3b2_uint(src[i], d);
8526 d += 1;
8527 }
8528 break;
8529
8530 case MESA_FORMAT_A4B4G4R4_UINT:
8531 for (i = 0; i < n; ++i) {
8532 pack_ubyte_a4b4g4r4_uint(src[i], d);
8533 d += 2;
8534 }
8535 break;
8536
8537 case MESA_FORMAT_R4G4B4A4_UINT:
8538 for (i = 0; i < n; ++i) {
8539 pack_ubyte_r4g4b4a4_uint(src[i], d);
8540 d += 2;
8541 }
8542 break;
8543
8544 case MESA_FORMAT_B4G4R4A4_UINT:
8545 for (i = 0; i < n; ++i) {
8546 pack_ubyte_b4g4r4a4_uint(src[i], d);
8547 d += 2;
8548 }
8549 break;
8550
8551 case MESA_FORMAT_A4R4G4B4_UINT:
8552 for (i = 0; i < n; ++i) {
8553 pack_ubyte_a4r4g4b4_uint(src[i], d);
8554 d += 2;
8555 }
8556 break;
8557
8558 case MESA_FORMAT_A1B5G5R5_UINT:
8559 for (i = 0; i < n; ++i) {
8560 pack_ubyte_a1b5g5r5_uint(src[i], d);
8561 d += 2;
8562 }
8563 break;
8564
8565 case MESA_FORMAT_B5G5R5A1_UINT:
8566 for (i = 0; i < n; ++i) {
8567 pack_ubyte_b5g5r5a1_uint(src[i], d);
8568 d += 2;
8569 }
8570 break;
8571
8572 case MESA_FORMAT_A1R5G5B5_UINT:
8573 for (i = 0; i < n; ++i) {
8574 pack_ubyte_a1r5g5b5_uint(src[i], d);
8575 d += 2;
8576 }
8577 break;
8578
8579 case MESA_FORMAT_R5G5B5A1_UINT:
8580 for (i = 0; i < n; ++i) {
8581 pack_ubyte_r5g5b5a1_uint(src[i], d);
8582 d += 2;
8583 }
8584 break;
8585
8586 case MESA_FORMAT_A_UINT8:
8587 for (i = 0; i < n; ++i) {
8588 pack_ubyte_a_uint8(src[i], d);
8589 d += 1;
8590 }
8591 break;
8592
8593 case MESA_FORMAT_A_UINT16:
8594 for (i = 0; i < n; ++i) {
8595 pack_ubyte_a_uint16(src[i], d);
8596 d += 2;
8597 }
8598 break;
8599
8600 case MESA_FORMAT_A_UINT32:
8601 for (i = 0; i < n; ++i) {
8602 pack_ubyte_a_uint32(src[i], d);
8603 d += 4;
8604 }
8605 break;
8606
8607 case MESA_FORMAT_A_SINT8:
8608 for (i = 0; i < n; ++i) {
8609 pack_ubyte_a_sint8(src[i], d);
8610 d += 1;
8611 }
8612 break;
8613
8614 case MESA_FORMAT_A_SINT16:
8615 for (i = 0; i < n; ++i) {
8616 pack_ubyte_a_sint16(src[i], d);
8617 d += 2;
8618 }
8619 break;
8620
8621 case MESA_FORMAT_A_SINT32:
8622 for (i = 0; i < n; ++i) {
8623 pack_ubyte_a_sint32(src[i], d);
8624 d += 4;
8625 }
8626 break;
8627
8628 case MESA_FORMAT_I_UINT8:
8629 for (i = 0; i < n; ++i) {
8630 pack_ubyte_i_uint8(src[i], d);
8631 d += 1;
8632 }
8633 break;
8634
8635 case MESA_FORMAT_I_UINT16:
8636 for (i = 0; i < n; ++i) {
8637 pack_ubyte_i_uint16(src[i], d);
8638 d += 2;
8639 }
8640 break;
8641
8642 case MESA_FORMAT_I_UINT32:
8643 for (i = 0; i < n; ++i) {
8644 pack_ubyte_i_uint32(src[i], d);
8645 d += 4;
8646 }
8647 break;
8648
8649 case MESA_FORMAT_I_SINT8:
8650 for (i = 0; i < n; ++i) {
8651 pack_ubyte_i_sint8(src[i], d);
8652 d += 1;
8653 }
8654 break;
8655
8656 case MESA_FORMAT_I_SINT16:
8657 for (i = 0; i < n; ++i) {
8658 pack_ubyte_i_sint16(src[i], d);
8659 d += 2;
8660 }
8661 break;
8662
8663 case MESA_FORMAT_I_SINT32:
8664 for (i = 0; i < n; ++i) {
8665 pack_ubyte_i_sint32(src[i], d);
8666 d += 4;
8667 }
8668 break;
8669
8670 case MESA_FORMAT_L_UINT8:
8671 for (i = 0; i < n; ++i) {
8672 pack_ubyte_l_uint8(src[i], d);
8673 d += 1;
8674 }
8675 break;
8676
8677 case MESA_FORMAT_L_UINT16:
8678 for (i = 0; i < n; ++i) {
8679 pack_ubyte_l_uint16(src[i], d);
8680 d += 2;
8681 }
8682 break;
8683
8684 case MESA_FORMAT_L_UINT32:
8685 for (i = 0; i < n; ++i) {
8686 pack_ubyte_l_uint32(src[i], d);
8687 d += 4;
8688 }
8689 break;
8690
8691 case MESA_FORMAT_L_SINT8:
8692 for (i = 0; i < n; ++i) {
8693 pack_ubyte_l_sint8(src[i], d);
8694 d += 1;
8695 }
8696 break;
8697
8698 case MESA_FORMAT_L_SINT16:
8699 for (i = 0; i < n; ++i) {
8700 pack_ubyte_l_sint16(src[i], d);
8701 d += 2;
8702 }
8703 break;
8704
8705 case MESA_FORMAT_L_SINT32:
8706 for (i = 0; i < n; ++i) {
8707 pack_ubyte_l_sint32(src[i], d);
8708 d += 4;
8709 }
8710 break;
8711
8712 case MESA_FORMAT_LA_UINT8:
8713 for (i = 0; i < n; ++i) {
8714 pack_ubyte_la_uint8(src[i], d);
8715 d += 2;
8716 }
8717 break;
8718
8719 case MESA_FORMAT_LA_UINT16:
8720 for (i = 0; i < n; ++i) {
8721 pack_ubyte_la_uint16(src[i], d);
8722 d += 4;
8723 }
8724 break;
8725
8726 case MESA_FORMAT_LA_UINT32:
8727 for (i = 0; i < n; ++i) {
8728 pack_ubyte_la_uint32(src[i], d);
8729 d += 8;
8730 }
8731 break;
8732
8733 case MESA_FORMAT_LA_SINT8:
8734 for (i = 0; i < n; ++i) {
8735 pack_ubyte_la_sint8(src[i], d);
8736 d += 2;
8737 }
8738 break;
8739
8740 case MESA_FORMAT_LA_SINT16:
8741 for (i = 0; i < n; ++i) {
8742 pack_ubyte_la_sint16(src[i], d);
8743 d += 4;
8744 }
8745 break;
8746
8747 case MESA_FORMAT_LA_SINT32:
8748 for (i = 0; i < n; ++i) {
8749 pack_ubyte_la_sint32(src[i], d);
8750 d += 8;
8751 }
8752 break;
8753
8754 case MESA_FORMAT_R_UINT8:
8755 for (i = 0; i < n; ++i) {
8756 pack_ubyte_r_uint8(src[i], d);
8757 d += 1;
8758 }
8759 break;
8760
8761 case MESA_FORMAT_R_UINT16:
8762 for (i = 0; i < n; ++i) {
8763 pack_ubyte_r_uint16(src[i], d);
8764 d += 2;
8765 }
8766 break;
8767
8768 case MESA_FORMAT_R_UINT32:
8769 for (i = 0; i < n; ++i) {
8770 pack_ubyte_r_uint32(src[i], d);
8771 d += 4;
8772 }
8773 break;
8774
8775 case MESA_FORMAT_R_SINT8:
8776 for (i = 0; i < n; ++i) {
8777 pack_ubyte_r_sint8(src[i], d);
8778 d += 1;
8779 }
8780 break;
8781
8782 case MESA_FORMAT_R_SINT16:
8783 for (i = 0; i < n; ++i) {
8784 pack_ubyte_r_sint16(src[i], d);
8785 d += 2;
8786 }
8787 break;
8788
8789 case MESA_FORMAT_R_SINT32:
8790 for (i = 0; i < n; ++i) {
8791 pack_ubyte_r_sint32(src[i], d);
8792 d += 4;
8793 }
8794 break;
8795
8796 case MESA_FORMAT_RG_UINT8:
8797 for (i = 0; i < n; ++i) {
8798 pack_ubyte_rg_uint8(src[i], d);
8799 d += 2;
8800 }
8801 break;
8802
8803 case MESA_FORMAT_RG_UINT16:
8804 for (i = 0; i < n; ++i) {
8805 pack_ubyte_rg_uint16(src[i], d);
8806 d += 4;
8807 }
8808 break;
8809
8810 case MESA_FORMAT_RG_UINT32:
8811 for (i = 0; i < n; ++i) {
8812 pack_ubyte_rg_uint32(src[i], d);
8813 d += 8;
8814 }
8815 break;
8816
8817 case MESA_FORMAT_RG_SINT8:
8818 for (i = 0; i < n; ++i) {
8819 pack_ubyte_rg_sint8(src[i], d);
8820 d += 2;
8821 }
8822 break;
8823
8824 case MESA_FORMAT_RG_SINT16:
8825 for (i = 0; i < n; ++i) {
8826 pack_ubyte_rg_sint16(src[i], d);
8827 d += 4;
8828 }
8829 break;
8830
8831 case MESA_FORMAT_RG_SINT32:
8832 for (i = 0; i < n; ++i) {
8833 pack_ubyte_rg_sint32(src[i], d);
8834 d += 8;
8835 }
8836 break;
8837
8838 case MESA_FORMAT_RGB_UINT8:
8839 for (i = 0; i < n; ++i) {
8840 pack_ubyte_rgb_uint8(src[i], d);
8841 d += 3;
8842 }
8843 break;
8844
8845 case MESA_FORMAT_RGB_UINT16:
8846 for (i = 0; i < n; ++i) {
8847 pack_ubyte_rgb_uint16(src[i], d);
8848 d += 6;
8849 }
8850 break;
8851
8852 case MESA_FORMAT_RGB_UINT32:
8853 for (i = 0; i < n; ++i) {
8854 pack_ubyte_rgb_uint32(src[i], d);
8855 d += 12;
8856 }
8857 break;
8858
8859 case MESA_FORMAT_RGB_SINT8:
8860 for (i = 0; i < n; ++i) {
8861 pack_ubyte_rgb_sint8(src[i], d);
8862 d += 3;
8863 }
8864 break;
8865
8866 case MESA_FORMAT_RGB_SINT16:
8867 for (i = 0; i < n; ++i) {
8868 pack_ubyte_rgb_sint16(src[i], d);
8869 d += 6;
8870 }
8871 break;
8872
8873 case MESA_FORMAT_RGB_SINT32:
8874 for (i = 0; i < n; ++i) {
8875 pack_ubyte_rgb_sint32(src[i], d);
8876 d += 12;
8877 }
8878 break;
8879
8880 case MESA_FORMAT_RGBA_UINT16:
8881 for (i = 0; i < n; ++i) {
8882 pack_ubyte_rgba_uint16(src[i], d);
8883 d += 8;
8884 }
8885 break;
8886
8887 case MESA_FORMAT_RGBA_UINT32:
8888 for (i = 0; i < n; ++i) {
8889 pack_ubyte_rgba_uint32(src[i], d);
8890 d += 16;
8891 }
8892 break;
8893
8894 case MESA_FORMAT_RGBA_SINT8:
8895 for (i = 0; i < n; ++i) {
8896 pack_ubyte_rgba_sint8(src[i], d);
8897 d += 4;
8898 }
8899 break;
8900
8901 case MESA_FORMAT_RGBA_SINT16:
8902 for (i = 0; i < n; ++i) {
8903 pack_ubyte_rgba_sint16(src[i], d);
8904 d += 8;
8905 }
8906 break;
8907
8908 case MESA_FORMAT_RGBA_SINT32:
8909 for (i = 0; i < n; ++i) {
8910 pack_ubyte_rgba_sint32(src[i], d);
8911 d += 16;
8912 }
8913 break;
8914
8915 case MESA_FORMAT_RGBX_UINT8:
8916 for (i = 0; i < n; ++i) {
8917 pack_ubyte_rgbx_uint8(src[i], d);
8918 d += 4;
8919 }
8920 break;
8921
8922 case MESA_FORMAT_RGBX_UINT16:
8923 for (i = 0; i < n; ++i) {
8924 pack_ubyte_rgbx_uint16(src[i], d);
8925 d += 8;
8926 }
8927 break;
8928
8929 case MESA_FORMAT_RGBX_UINT32:
8930 for (i = 0; i < n; ++i) {
8931 pack_ubyte_rgbx_uint32(src[i], d);
8932 d += 16;
8933 }
8934 break;
8935
8936 case MESA_FORMAT_RGBX_SINT8:
8937 for (i = 0; i < n; ++i) {
8938 pack_ubyte_rgbx_sint8(src[i], d);
8939 d += 4;
8940 }
8941 break;
8942
8943 case MESA_FORMAT_RGBX_SINT16:
8944 for (i = 0; i < n; ++i) {
8945 pack_ubyte_rgbx_sint16(src[i], d);
8946 d += 8;
8947 }
8948 break;
8949
8950 case MESA_FORMAT_RGBX_SINT32:
8951 for (i = 0; i < n; ++i) {
8952 pack_ubyte_rgbx_sint32(src[i], d);
8953 d += 16;
8954 }
8955 break;
8956 default:
8957 assert(!"Invalid format");
8958 }
8959 }
8960
8961 /**
8962 * Pack a row of uint32_t rgba[4] values to the destination.
8963 */
8964 void
_mesa_pack_uint_rgba_row(mesa_format format,uint32_t n,const uint32_t src[][4],void * dst)8965 _mesa_pack_uint_rgba_row(mesa_format format, uint32_t n,
8966 const uint32_t src[][4], void *dst)
8967 {
8968 uint32_t i;
8969 uint8_t *d = dst;
8970
8971 switch (format) {
8972
8973 case MESA_FORMAT_A8B8G8R8_UINT:
8974 for (i = 0; i < n; ++i) {
8975 pack_uint_a8b8g8r8_uint(src[i], d);
8976 d += 4;
8977 }
8978 break;
8979
8980 case MESA_FORMAT_A8R8G8B8_UINT:
8981 for (i = 0; i < n; ++i) {
8982 pack_uint_a8r8g8b8_uint(src[i], d);
8983 d += 4;
8984 }
8985 break;
8986
8987 case MESA_FORMAT_R8G8B8A8_UINT:
8988 for (i = 0; i < n; ++i) {
8989 pack_uint_r8g8b8a8_uint(src[i], d);
8990 d += 4;
8991 }
8992 break;
8993
8994 case MESA_FORMAT_B8G8R8A8_UINT:
8995 for (i = 0; i < n; ++i) {
8996 pack_uint_b8g8r8a8_uint(src[i], d);
8997 d += 4;
8998 }
8999 break;
9000
9001 case MESA_FORMAT_B10G10R10A2_UINT:
9002 for (i = 0; i < n; ++i) {
9003 pack_uint_b10g10r10a2_uint(src[i], d);
9004 d += 4;
9005 }
9006 break;
9007
9008 case MESA_FORMAT_R10G10B10A2_UINT:
9009 for (i = 0; i < n; ++i) {
9010 pack_uint_r10g10b10a2_uint(src[i], d);
9011 d += 4;
9012 }
9013 break;
9014
9015 case MESA_FORMAT_A2B10G10R10_UINT:
9016 for (i = 0; i < n; ++i) {
9017 pack_uint_a2b10g10r10_uint(src[i], d);
9018 d += 4;
9019 }
9020 break;
9021
9022 case MESA_FORMAT_A2R10G10B10_UINT:
9023 for (i = 0; i < n; ++i) {
9024 pack_uint_a2r10g10b10_uint(src[i], d);
9025 d += 4;
9026 }
9027 break;
9028
9029 case MESA_FORMAT_B5G6R5_UINT:
9030 for (i = 0; i < n; ++i) {
9031 pack_uint_b5g6r5_uint(src[i], d);
9032 d += 2;
9033 }
9034 break;
9035
9036 case MESA_FORMAT_R5G6B5_UINT:
9037 for (i = 0; i < n; ++i) {
9038 pack_uint_r5g6b5_uint(src[i], d);
9039 d += 2;
9040 }
9041 break;
9042
9043 case MESA_FORMAT_B2G3R3_UINT:
9044 for (i = 0; i < n; ++i) {
9045 pack_uint_b2g3r3_uint(src[i], d);
9046 d += 1;
9047 }
9048 break;
9049
9050 case MESA_FORMAT_R3G3B2_UINT:
9051 for (i = 0; i < n; ++i) {
9052 pack_uint_r3g3b2_uint(src[i], d);
9053 d += 1;
9054 }
9055 break;
9056
9057 case MESA_FORMAT_A4B4G4R4_UINT:
9058 for (i = 0; i < n; ++i) {
9059 pack_uint_a4b4g4r4_uint(src[i], d);
9060 d += 2;
9061 }
9062 break;
9063
9064 case MESA_FORMAT_R4G4B4A4_UINT:
9065 for (i = 0; i < n; ++i) {
9066 pack_uint_r4g4b4a4_uint(src[i], d);
9067 d += 2;
9068 }
9069 break;
9070
9071 case MESA_FORMAT_B4G4R4A4_UINT:
9072 for (i = 0; i < n; ++i) {
9073 pack_uint_b4g4r4a4_uint(src[i], d);
9074 d += 2;
9075 }
9076 break;
9077
9078 case MESA_FORMAT_A4R4G4B4_UINT:
9079 for (i = 0; i < n; ++i) {
9080 pack_uint_a4r4g4b4_uint(src[i], d);
9081 d += 2;
9082 }
9083 break;
9084
9085 case MESA_FORMAT_A1B5G5R5_UINT:
9086 for (i = 0; i < n; ++i) {
9087 pack_uint_a1b5g5r5_uint(src[i], d);
9088 d += 2;
9089 }
9090 break;
9091
9092 case MESA_FORMAT_B5G5R5A1_UINT:
9093 for (i = 0; i < n; ++i) {
9094 pack_uint_b5g5r5a1_uint(src[i], d);
9095 d += 2;
9096 }
9097 break;
9098
9099 case MESA_FORMAT_A1R5G5B5_UINT:
9100 for (i = 0; i < n; ++i) {
9101 pack_uint_a1r5g5b5_uint(src[i], d);
9102 d += 2;
9103 }
9104 break;
9105
9106 case MESA_FORMAT_R5G5B5A1_UINT:
9107 for (i = 0; i < n; ++i) {
9108 pack_uint_r5g5b5a1_uint(src[i], d);
9109 d += 2;
9110 }
9111 break;
9112
9113 case MESA_FORMAT_A_UINT8:
9114 for (i = 0; i < n; ++i) {
9115 pack_uint_a_uint8(src[i], d);
9116 d += 1;
9117 }
9118 break;
9119
9120 case MESA_FORMAT_A_UINT16:
9121 for (i = 0; i < n; ++i) {
9122 pack_uint_a_uint16(src[i], d);
9123 d += 2;
9124 }
9125 break;
9126
9127 case MESA_FORMAT_A_UINT32:
9128 for (i = 0; i < n; ++i) {
9129 pack_uint_a_uint32(src[i], d);
9130 d += 4;
9131 }
9132 break;
9133
9134 case MESA_FORMAT_A_SINT8:
9135 for (i = 0; i < n; ++i) {
9136 pack_uint_a_sint8(src[i], d);
9137 d += 1;
9138 }
9139 break;
9140
9141 case MESA_FORMAT_A_SINT16:
9142 for (i = 0; i < n; ++i) {
9143 pack_uint_a_sint16(src[i], d);
9144 d += 2;
9145 }
9146 break;
9147
9148 case MESA_FORMAT_A_SINT32:
9149 for (i = 0; i < n; ++i) {
9150 pack_uint_a_sint32(src[i], d);
9151 d += 4;
9152 }
9153 break;
9154
9155 case MESA_FORMAT_I_UINT8:
9156 for (i = 0; i < n; ++i) {
9157 pack_uint_i_uint8(src[i], d);
9158 d += 1;
9159 }
9160 break;
9161
9162 case MESA_FORMAT_I_UINT16:
9163 for (i = 0; i < n; ++i) {
9164 pack_uint_i_uint16(src[i], d);
9165 d += 2;
9166 }
9167 break;
9168
9169 case MESA_FORMAT_I_UINT32:
9170 for (i = 0; i < n; ++i) {
9171 pack_uint_i_uint32(src[i], d);
9172 d += 4;
9173 }
9174 break;
9175
9176 case MESA_FORMAT_I_SINT8:
9177 for (i = 0; i < n; ++i) {
9178 pack_uint_i_sint8(src[i], d);
9179 d += 1;
9180 }
9181 break;
9182
9183 case MESA_FORMAT_I_SINT16:
9184 for (i = 0; i < n; ++i) {
9185 pack_uint_i_sint16(src[i], d);
9186 d += 2;
9187 }
9188 break;
9189
9190 case MESA_FORMAT_I_SINT32:
9191 for (i = 0; i < n; ++i) {
9192 pack_uint_i_sint32(src[i], d);
9193 d += 4;
9194 }
9195 break;
9196
9197 case MESA_FORMAT_L_UINT8:
9198 for (i = 0; i < n; ++i) {
9199 pack_uint_l_uint8(src[i], d);
9200 d += 1;
9201 }
9202 break;
9203
9204 case MESA_FORMAT_L_UINT16:
9205 for (i = 0; i < n; ++i) {
9206 pack_uint_l_uint16(src[i], d);
9207 d += 2;
9208 }
9209 break;
9210
9211 case MESA_FORMAT_L_UINT32:
9212 for (i = 0; i < n; ++i) {
9213 pack_uint_l_uint32(src[i], d);
9214 d += 4;
9215 }
9216 break;
9217
9218 case MESA_FORMAT_L_SINT8:
9219 for (i = 0; i < n; ++i) {
9220 pack_uint_l_sint8(src[i], d);
9221 d += 1;
9222 }
9223 break;
9224
9225 case MESA_FORMAT_L_SINT16:
9226 for (i = 0; i < n; ++i) {
9227 pack_uint_l_sint16(src[i], d);
9228 d += 2;
9229 }
9230 break;
9231
9232 case MESA_FORMAT_L_SINT32:
9233 for (i = 0; i < n; ++i) {
9234 pack_uint_l_sint32(src[i], d);
9235 d += 4;
9236 }
9237 break;
9238
9239 case MESA_FORMAT_LA_UINT8:
9240 for (i = 0; i < n; ++i) {
9241 pack_uint_la_uint8(src[i], d);
9242 d += 2;
9243 }
9244 break;
9245
9246 case MESA_FORMAT_LA_UINT16:
9247 for (i = 0; i < n; ++i) {
9248 pack_uint_la_uint16(src[i], d);
9249 d += 4;
9250 }
9251 break;
9252
9253 case MESA_FORMAT_LA_UINT32:
9254 for (i = 0; i < n; ++i) {
9255 pack_uint_la_uint32(src[i], d);
9256 d += 8;
9257 }
9258 break;
9259
9260 case MESA_FORMAT_LA_SINT8:
9261 for (i = 0; i < n; ++i) {
9262 pack_uint_la_sint8(src[i], d);
9263 d += 2;
9264 }
9265 break;
9266
9267 case MESA_FORMAT_LA_SINT16:
9268 for (i = 0; i < n; ++i) {
9269 pack_uint_la_sint16(src[i], d);
9270 d += 4;
9271 }
9272 break;
9273
9274 case MESA_FORMAT_LA_SINT32:
9275 for (i = 0; i < n; ++i) {
9276 pack_uint_la_sint32(src[i], d);
9277 d += 8;
9278 }
9279 break;
9280
9281 case MESA_FORMAT_R_UINT8:
9282 for (i = 0; i < n; ++i) {
9283 pack_uint_r_uint8(src[i], d);
9284 d += 1;
9285 }
9286 break;
9287
9288 case MESA_FORMAT_R_UINT16:
9289 for (i = 0; i < n; ++i) {
9290 pack_uint_r_uint16(src[i], d);
9291 d += 2;
9292 }
9293 break;
9294
9295 case MESA_FORMAT_R_UINT32:
9296 for (i = 0; i < n; ++i) {
9297 pack_uint_r_uint32(src[i], d);
9298 d += 4;
9299 }
9300 break;
9301
9302 case MESA_FORMAT_R_SINT8:
9303 for (i = 0; i < n; ++i) {
9304 pack_uint_r_sint8(src[i], d);
9305 d += 1;
9306 }
9307 break;
9308
9309 case MESA_FORMAT_R_SINT16:
9310 for (i = 0; i < n; ++i) {
9311 pack_uint_r_sint16(src[i], d);
9312 d += 2;
9313 }
9314 break;
9315
9316 case MESA_FORMAT_R_SINT32:
9317 for (i = 0; i < n; ++i) {
9318 pack_uint_r_sint32(src[i], d);
9319 d += 4;
9320 }
9321 break;
9322
9323 case MESA_FORMAT_RG_UINT8:
9324 for (i = 0; i < n; ++i) {
9325 pack_uint_rg_uint8(src[i], d);
9326 d += 2;
9327 }
9328 break;
9329
9330 case MESA_FORMAT_RG_UINT16:
9331 for (i = 0; i < n; ++i) {
9332 pack_uint_rg_uint16(src[i], d);
9333 d += 4;
9334 }
9335 break;
9336
9337 case MESA_FORMAT_RG_UINT32:
9338 for (i = 0; i < n; ++i) {
9339 pack_uint_rg_uint32(src[i], d);
9340 d += 8;
9341 }
9342 break;
9343
9344 case MESA_FORMAT_RG_SINT8:
9345 for (i = 0; i < n; ++i) {
9346 pack_uint_rg_sint8(src[i], d);
9347 d += 2;
9348 }
9349 break;
9350
9351 case MESA_FORMAT_RG_SINT16:
9352 for (i = 0; i < n; ++i) {
9353 pack_uint_rg_sint16(src[i], d);
9354 d += 4;
9355 }
9356 break;
9357
9358 case MESA_FORMAT_RG_SINT32:
9359 for (i = 0; i < n; ++i) {
9360 pack_uint_rg_sint32(src[i], d);
9361 d += 8;
9362 }
9363 break;
9364
9365 case MESA_FORMAT_RGB_UINT8:
9366 for (i = 0; i < n; ++i) {
9367 pack_uint_rgb_uint8(src[i], d);
9368 d += 3;
9369 }
9370 break;
9371
9372 case MESA_FORMAT_RGB_UINT16:
9373 for (i = 0; i < n; ++i) {
9374 pack_uint_rgb_uint16(src[i], d);
9375 d += 6;
9376 }
9377 break;
9378
9379 case MESA_FORMAT_RGB_UINT32:
9380 for (i = 0; i < n; ++i) {
9381 pack_uint_rgb_uint32(src[i], d);
9382 d += 12;
9383 }
9384 break;
9385
9386 case MESA_FORMAT_RGB_SINT8:
9387 for (i = 0; i < n; ++i) {
9388 pack_uint_rgb_sint8(src[i], d);
9389 d += 3;
9390 }
9391 break;
9392
9393 case MESA_FORMAT_RGB_SINT16:
9394 for (i = 0; i < n; ++i) {
9395 pack_uint_rgb_sint16(src[i], d);
9396 d += 6;
9397 }
9398 break;
9399
9400 case MESA_FORMAT_RGB_SINT32:
9401 for (i = 0; i < n; ++i) {
9402 pack_uint_rgb_sint32(src[i], d);
9403 d += 12;
9404 }
9405 break;
9406
9407 case MESA_FORMAT_RGBA_UINT16:
9408 for (i = 0; i < n; ++i) {
9409 pack_uint_rgba_uint16(src[i], d);
9410 d += 8;
9411 }
9412 break;
9413
9414 case MESA_FORMAT_RGBA_UINT32:
9415 for (i = 0; i < n; ++i) {
9416 pack_uint_rgba_uint32(src[i], d);
9417 d += 16;
9418 }
9419 break;
9420
9421 case MESA_FORMAT_RGBA_SINT8:
9422 for (i = 0; i < n; ++i) {
9423 pack_uint_rgba_sint8(src[i], d);
9424 d += 4;
9425 }
9426 break;
9427
9428 case MESA_FORMAT_RGBA_SINT16:
9429 for (i = 0; i < n; ++i) {
9430 pack_uint_rgba_sint16(src[i], d);
9431 d += 8;
9432 }
9433 break;
9434
9435 case MESA_FORMAT_RGBA_SINT32:
9436 for (i = 0; i < n; ++i) {
9437 pack_uint_rgba_sint32(src[i], d);
9438 d += 16;
9439 }
9440 break;
9441
9442 case MESA_FORMAT_RGBX_UINT8:
9443 for (i = 0; i < n; ++i) {
9444 pack_uint_rgbx_uint8(src[i], d);
9445 d += 4;
9446 }
9447 break;
9448
9449 case MESA_FORMAT_RGBX_UINT16:
9450 for (i = 0; i < n; ++i) {
9451 pack_uint_rgbx_uint16(src[i], d);
9452 d += 8;
9453 }
9454 break;
9455
9456 case MESA_FORMAT_RGBX_UINT32:
9457 for (i = 0; i < n; ++i) {
9458 pack_uint_rgbx_uint32(src[i], d);
9459 d += 16;
9460 }
9461 break;
9462
9463 case MESA_FORMAT_RGBX_SINT8:
9464 for (i = 0; i < n; ++i) {
9465 pack_uint_rgbx_sint8(src[i], d);
9466 d += 4;
9467 }
9468 break;
9469
9470 case MESA_FORMAT_RGBX_SINT16:
9471 for (i = 0; i < n; ++i) {
9472 pack_uint_rgbx_sint16(src[i], d);
9473 d += 8;
9474 }
9475 break;
9476
9477 case MESA_FORMAT_RGBX_SINT32:
9478 for (i = 0; i < n; ++i) {
9479 pack_uint_rgbx_sint32(src[i], d);
9480 d += 16;
9481 }
9482 break;
9483 default:
9484 assert(!"Invalid format");
9485 }
9486 }
9487
9488 /**
9489 * Pack a row of float rgba[4] values to the destination.
9490 */
9491 void
_mesa_pack_float_rgba_row(mesa_format format,uint32_t n,const float src[][4],void * dst)9492 _mesa_pack_float_rgba_row(mesa_format format, uint32_t n,
9493 const float src[][4], void *dst)
9494 {
9495 uint32_t i;
9496 uint8_t *d = dst;
9497
9498 switch (format) {
9499
9500 case MESA_FORMAT_A8B8G8R8_UNORM:
9501 for (i = 0; i < n; ++i) {
9502 pack_float_a8b8g8r8_unorm(src[i], d);
9503 d += 4;
9504 }
9505 break;
9506
9507 case MESA_FORMAT_X8B8G8R8_UNORM:
9508 for (i = 0; i < n; ++i) {
9509 pack_float_x8b8g8r8_unorm(src[i], d);
9510 d += 4;
9511 }
9512 break;
9513
9514 case MESA_FORMAT_R8G8B8A8_UNORM:
9515 for (i = 0; i < n; ++i) {
9516 pack_float_r8g8b8a8_unorm(src[i], d);
9517 d += 4;
9518 }
9519 break;
9520
9521 case MESA_FORMAT_R8G8B8X8_UNORM:
9522 for (i = 0; i < n; ++i) {
9523 pack_float_r8g8b8x8_unorm(src[i], d);
9524 d += 4;
9525 }
9526 break;
9527
9528 case MESA_FORMAT_B8G8R8A8_UNORM:
9529 for (i = 0; i < n; ++i) {
9530 pack_float_b8g8r8a8_unorm(src[i], d);
9531 d += 4;
9532 }
9533 break;
9534
9535 case MESA_FORMAT_B8G8R8X8_UNORM:
9536 for (i = 0; i < n; ++i) {
9537 pack_float_b8g8r8x8_unorm(src[i], d);
9538 d += 4;
9539 }
9540 break;
9541
9542 case MESA_FORMAT_A8R8G8B8_UNORM:
9543 for (i = 0; i < n; ++i) {
9544 pack_float_a8r8g8b8_unorm(src[i], d);
9545 d += 4;
9546 }
9547 break;
9548
9549 case MESA_FORMAT_X8R8G8B8_UNORM:
9550 for (i = 0; i < n; ++i) {
9551 pack_float_x8r8g8b8_unorm(src[i], d);
9552 d += 4;
9553 }
9554 break;
9555
9556 case MESA_FORMAT_B5G6R5_UNORM:
9557 for (i = 0; i < n; ++i) {
9558 pack_float_b5g6r5_unorm(src[i], d);
9559 d += 2;
9560 }
9561 break;
9562
9563 case MESA_FORMAT_R5G6B5_UNORM:
9564 for (i = 0; i < n; ++i) {
9565 pack_float_r5g6b5_unorm(src[i], d);
9566 d += 2;
9567 }
9568 break;
9569
9570 case MESA_FORMAT_B4G4R4A4_UNORM:
9571 for (i = 0; i < n; ++i) {
9572 pack_float_b4g4r4a4_unorm(src[i], d);
9573 d += 2;
9574 }
9575 break;
9576
9577 case MESA_FORMAT_B4G4R4X4_UNORM:
9578 for (i = 0; i < n; ++i) {
9579 pack_float_b4g4r4x4_unorm(src[i], d);
9580 d += 2;
9581 }
9582 break;
9583
9584 case MESA_FORMAT_A4R4G4B4_UNORM:
9585 for (i = 0; i < n; ++i) {
9586 pack_float_a4r4g4b4_unorm(src[i], d);
9587 d += 2;
9588 }
9589 break;
9590
9591 case MESA_FORMAT_A1B5G5R5_UNORM:
9592 for (i = 0; i < n; ++i) {
9593 pack_float_a1b5g5r5_unorm(src[i], d);
9594 d += 2;
9595 }
9596 break;
9597
9598 case MESA_FORMAT_X1B5G5R5_UNORM:
9599 for (i = 0; i < n; ++i) {
9600 pack_float_x1b5g5r5_unorm(src[i], d);
9601 d += 2;
9602 }
9603 break;
9604
9605 case MESA_FORMAT_B5G5R5A1_UNORM:
9606 for (i = 0; i < n; ++i) {
9607 pack_float_b5g5r5a1_unorm(src[i], d);
9608 d += 2;
9609 }
9610 break;
9611
9612 case MESA_FORMAT_B5G5R5X1_UNORM:
9613 for (i = 0; i < n; ++i) {
9614 pack_float_b5g5r5x1_unorm(src[i], d);
9615 d += 2;
9616 }
9617 break;
9618
9619 case MESA_FORMAT_A1R5G5B5_UNORM:
9620 for (i = 0; i < n; ++i) {
9621 pack_float_a1r5g5b5_unorm(src[i], d);
9622 d += 2;
9623 }
9624 break;
9625
9626 case MESA_FORMAT_L4A4_UNORM:
9627 for (i = 0; i < n; ++i) {
9628 pack_float_l4a4_unorm(src[i], d);
9629 d += 1;
9630 }
9631 break;
9632
9633 case MESA_FORMAT_B2G3R3_UNORM:
9634 for (i = 0; i < n; ++i) {
9635 pack_float_b2g3r3_unorm(src[i], d);
9636 d += 1;
9637 }
9638 break;
9639
9640 case MESA_FORMAT_B10G10R10A2_UNORM:
9641 for (i = 0; i < n; ++i) {
9642 pack_float_b10g10r10a2_unorm(src[i], d);
9643 d += 4;
9644 }
9645 break;
9646
9647 case MESA_FORMAT_B10G10R10X2_UNORM:
9648 for (i = 0; i < n; ++i) {
9649 pack_float_b10g10r10x2_unorm(src[i], d);
9650 d += 4;
9651 }
9652 break;
9653
9654 case MESA_FORMAT_R10G10B10A2_UNORM:
9655 for (i = 0; i < n; ++i) {
9656 pack_float_r10g10b10a2_unorm(src[i], d);
9657 d += 4;
9658 }
9659 break;
9660
9661 case MESA_FORMAT_R10G10B10X2_UNORM:
9662 for (i = 0; i < n; ++i) {
9663 pack_float_r10g10b10x2_unorm(src[i], d);
9664 d += 4;
9665 }
9666 break;
9667
9668 case MESA_FORMAT_R3G3B2_UNORM:
9669 for (i = 0; i < n; ++i) {
9670 pack_float_r3g3b2_unorm(src[i], d);
9671 d += 1;
9672 }
9673 break;
9674
9675 case MESA_FORMAT_A4B4G4R4_UNORM:
9676 for (i = 0; i < n; ++i) {
9677 pack_float_a4b4g4r4_unorm(src[i], d);
9678 d += 2;
9679 }
9680 break;
9681
9682 case MESA_FORMAT_R4G4B4A4_UNORM:
9683 for (i = 0; i < n; ++i) {
9684 pack_float_r4g4b4a4_unorm(src[i], d);
9685 d += 2;
9686 }
9687 break;
9688
9689 case MESA_FORMAT_R5G5B5A1_UNORM:
9690 for (i = 0; i < n; ++i) {
9691 pack_float_r5g5b5a1_unorm(src[i], d);
9692 d += 2;
9693 }
9694 break;
9695
9696 case MESA_FORMAT_A2B10G10R10_UNORM:
9697 for (i = 0; i < n; ++i) {
9698 pack_float_a2b10g10r10_unorm(src[i], d);
9699 d += 4;
9700 }
9701 break;
9702
9703 case MESA_FORMAT_A2R10G10B10_UNORM:
9704 for (i = 0; i < n; ++i) {
9705 pack_float_a2r10g10b10_unorm(src[i], d);
9706 d += 4;
9707 }
9708 break;
9709
9710 case MESA_FORMAT_A_UNORM8:
9711 for (i = 0; i < n; ++i) {
9712 pack_float_a_unorm8(src[i], d);
9713 d += 1;
9714 }
9715 break;
9716
9717 case MESA_FORMAT_A_UNORM16:
9718 for (i = 0; i < n; ++i) {
9719 pack_float_a_unorm16(src[i], d);
9720 d += 2;
9721 }
9722 break;
9723
9724 case MESA_FORMAT_L_UNORM8:
9725 for (i = 0; i < n; ++i) {
9726 pack_float_l_unorm8(src[i], d);
9727 d += 1;
9728 }
9729 break;
9730
9731 case MESA_FORMAT_L_UNORM16:
9732 for (i = 0; i < n; ++i) {
9733 pack_float_l_unorm16(src[i], d);
9734 d += 2;
9735 }
9736 break;
9737
9738 case MESA_FORMAT_LA_UNORM8:
9739 for (i = 0; i < n; ++i) {
9740 pack_float_la_unorm8(src[i], d);
9741 d += 2;
9742 }
9743 break;
9744
9745 case MESA_FORMAT_LA_UNORM16:
9746 for (i = 0; i < n; ++i) {
9747 pack_float_la_unorm16(src[i], d);
9748 d += 4;
9749 }
9750 break;
9751
9752 case MESA_FORMAT_I_UNORM8:
9753 for (i = 0; i < n; ++i) {
9754 pack_float_i_unorm8(src[i], d);
9755 d += 1;
9756 }
9757 break;
9758
9759 case MESA_FORMAT_I_UNORM16:
9760 for (i = 0; i < n; ++i) {
9761 pack_float_i_unorm16(src[i], d);
9762 d += 2;
9763 }
9764 break;
9765
9766 case MESA_FORMAT_R_UNORM8:
9767 for (i = 0; i < n; ++i) {
9768 pack_float_r_unorm8(src[i], d);
9769 d += 1;
9770 }
9771 break;
9772
9773 case MESA_FORMAT_R_UNORM16:
9774 for (i = 0; i < n; ++i) {
9775 pack_float_r_unorm16(src[i], d);
9776 d += 2;
9777 }
9778 break;
9779
9780 case MESA_FORMAT_RG_UNORM8:
9781 for (i = 0; i < n; ++i) {
9782 pack_float_rg_unorm8(src[i], d);
9783 d += 2;
9784 }
9785 break;
9786
9787 case MESA_FORMAT_RG_UNORM16:
9788 for (i = 0; i < n; ++i) {
9789 pack_float_rg_unorm16(src[i], d);
9790 d += 4;
9791 }
9792 break;
9793
9794 case MESA_FORMAT_BGR_UNORM8:
9795 for (i = 0; i < n; ++i) {
9796 pack_float_bgr_unorm8(src[i], d);
9797 d += 3;
9798 }
9799 break;
9800
9801 case MESA_FORMAT_RGB_UNORM8:
9802 for (i = 0; i < n; ++i) {
9803 pack_float_rgb_unorm8(src[i], d);
9804 d += 3;
9805 }
9806 break;
9807
9808 case MESA_FORMAT_RGBA_UNORM16:
9809 for (i = 0; i < n; ++i) {
9810 pack_float_rgba_unorm16(src[i], d);
9811 d += 8;
9812 }
9813 break;
9814
9815 case MESA_FORMAT_RGBX_UNORM16:
9816 for (i = 0; i < n; ++i) {
9817 pack_float_rgbx_unorm16(src[i], d);
9818 d += 8;
9819 }
9820 break;
9821
9822 case MESA_FORMAT_A8B8G8R8_SNORM:
9823 for (i = 0; i < n; ++i) {
9824 pack_float_a8b8g8r8_snorm(src[i], d);
9825 d += 4;
9826 }
9827 break;
9828
9829 case MESA_FORMAT_X8B8G8R8_SNORM:
9830 for (i = 0; i < n; ++i) {
9831 pack_float_x8b8g8r8_snorm(src[i], d);
9832 d += 4;
9833 }
9834 break;
9835
9836 case MESA_FORMAT_R8G8B8A8_SNORM:
9837 for (i = 0; i < n; ++i) {
9838 pack_float_r8g8b8a8_snorm(src[i], d);
9839 d += 4;
9840 }
9841 break;
9842
9843 case MESA_FORMAT_R8G8B8X8_SNORM:
9844 for (i = 0; i < n; ++i) {
9845 pack_float_r8g8b8x8_snorm(src[i], d);
9846 d += 4;
9847 }
9848 break;
9849
9850 case MESA_FORMAT_A_SNORM8:
9851 for (i = 0; i < n; ++i) {
9852 pack_float_a_snorm8(src[i], d);
9853 d += 1;
9854 }
9855 break;
9856
9857 case MESA_FORMAT_A_SNORM16:
9858 for (i = 0; i < n; ++i) {
9859 pack_float_a_snorm16(src[i], d);
9860 d += 2;
9861 }
9862 break;
9863
9864 case MESA_FORMAT_L_SNORM8:
9865 for (i = 0; i < n; ++i) {
9866 pack_float_l_snorm8(src[i], d);
9867 d += 1;
9868 }
9869 break;
9870
9871 case MESA_FORMAT_L_SNORM16:
9872 for (i = 0; i < n; ++i) {
9873 pack_float_l_snorm16(src[i], d);
9874 d += 2;
9875 }
9876 break;
9877
9878 case MESA_FORMAT_I_SNORM8:
9879 for (i = 0; i < n; ++i) {
9880 pack_float_i_snorm8(src[i], d);
9881 d += 1;
9882 }
9883 break;
9884
9885 case MESA_FORMAT_I_SNORM16:
9886 for (i = 0; i < n; ++i) {
9887 pack_float_i_snorm16(src[i], d);
9888 d += 2;
9889 }
9890 break;
9891
9892 case MESA_FORMAT_R_SNORM8:
9893 for (i = 0; i < n; ++i) {
9894 pack_float_r_snorm8(src[i], d);
9895 d += 1;
9896 }
9897 break;
9898
9899 case MESA_FORMAT_R_SNORM16:
9900 for (i = 0; i < n; ++i) {
9901 pack_float_r_snorm16(src[i], d);
9902 d += 2;
9903 }
9904 break;
9905
9906 case MESA_FORMAT_LA_SNORM8:
9907 for (i = 0; i < n; ++i) {
9908 pack_float_la_snorm8(src[i], d);
9909 d += 2;
9910 }
9911 break;
9912
9913 case MESA_FORMAT_LA_SNORM16:
9914 for (i = 0; i < n; ++i) {
9915 pack_float_la_snorm16(src[i], d);
9916 d += 4;
9917 }
9918 break;
9919
9920 case MESA_FORMAT_RG_SNORM8:
9921 for (i = 0; i < n; ++i) {
9922 pack_float_rg_snorm8(src[i], d);
9923 d += 2;
9924 }
9925 break;
9926
9927 case MESA_FORMAT_RG_SNORM16:
9928 for (i = 0; i < n; ++i) {
9929 pack_float_rg_snorm16(src[i], d);
9930 d += 4;
9931 }
9932 break;
9933
9934 case MESA_FORMAT_RGB_SNORM16:
9935 for (i = 0; i < n; ++i) {
9936 pack_float_rgb_snorm16(src[i], d);
9937 d += 6;
9938 }
9939 break;
9940
9941 case MESA_FORMAT_RGBA_SNORM16:
9942 for (i = 0; i < n; ++i) {
9943 pack_float_rgba_snorm16(src[i], d);
9944 d += 8;
9945 }
9946 break;
9947
9948 case MESA_FORMAT_RGBX_SNORM16:
9949 for (i = 0; i < n; ++i) {
9950 pack_float_rgbx_snorm16(src[i], d);
9951 d += 8;
9952 }
9953 break;
9954
9955 case MESA_FORMAT_A8B8G8R8_SRGB:
9956 for (i = 0; i < n; ++i) {
9957 pack_float_a8b8g8r8_srgb(src[i], d);
9958 d += 4;
9959 }
9960 break;
9961
9962 case MESA_FORMAT_B8G8R8A8_SRGB:
9963 for (i = 0; i < n; ++i) {
9964 pack_float_b8g8r8a8_srgb(src[i], d);
9965 d += 4;
9966 }
9967 break;
9968
9969 case MESA_FORMAT_A8R8G8B8_SRGB:
9970 for (i = 0; i < n; ++i) {
9971 pack_float_a8r8g8b8_srgb(src[i], d);
9972 d += 4;
9973 }
9974 break;
9975
9976 case MESA_FORMAT_B8G8R8X8_SRGB:
9977 for (i = 0; i < n; ++i) {
9978 pack_float_b8g8r8x8_srgb(src[i], d);
9979 d += 4;
9980 }
9981 break;
9982
9983 case MESA_FORMAT_X8R8G8B8_SRGB:
9984 for (i = 0; i < n; ++i) {
9985 pack_float_x8r8g8b8_srgb(src[i], d);
9986 d += 4;
9987 }
9988 break;
9989
9990 case MESA_FORMAT_R8G8B8A8_SRGB:
9991 for (i = 0; i < n; ++i) {
9992 pack_float_r8g8b8a8_srgb(src[i], d);
9993 d += 4;
9994 }
9995 break;
9996
9997 case MESA_FORMAT_R8G8B8X8_SRGB:
9998 for (i = 0; i < n; ++i) {
9999 pack_float_r8g8b8x8_srgb(src[i], d);
10000 d += 4;
10001 }
10002 break;
10003
10004 case MESA_FORMAT_X8B8G8R8_SRGB:
10005 for (i = 0; i < n; ++i) {
10006 pack_float_x8b8g8r8_srgb(src[i], d);
10007 d += 4;
10008 }
10009 break;
10010
10011 case MESA_FORMAT_R_SRGB8:
10012 for (i = 0; i < n; ++i) {
10013 pack_float_r_srgb8(src[i], d);
10014 d += 1;
10015 }
10016 break;
10017
10018 case MESA_FORMAT_L_SRGB8:
10019 for (i = 0; i < n; ++i) {
10020 pack_float_l_srgb8(src[i], d);
10021 d += 1;
10022 }
10023 break;
10024
10025 case MESA_FORMAT_LA_SRGB8:
10026 for (i = 0; i < n; ++i) {
10027 pack_float_la_srgb8(src[i], d);
10028 d += 2;
10029 }
10030 break;
10031
10032 case MESA_FORMAT_BGR_SRGB8:
10033 for (i = 0; i < n; ++i) {
10034 pack_float_bgr_srgb8(src[i], d);
10035 d += 3;
10036 }
10037 break;
10038
10039 case MESA_FORMAT_R9G9B9E5_FLOAT:
10040 for (i = 0; i < n; ++i) {
10041 pack_float_r9g9b9e5_float(src[i], d);
10042 d += 4;
10043 }
10044 break;
10045
10046 case MESA_FORMAT_R11G11B10_FLOAT:
10047 for (i = 0; i < n; ++i) {
10048 pack_float_r11g11b10_float(src[i], d);
10049 d += 4;
10050 }
10051 break;
10052
10053 case MESA_FORMAT_A_FLOAT16:
10054 for (i = 0; i < n; ++i) {
10055 pack_float_a_float16(src[i], d);
10056 d += 2;
10057 }
10058 break;
10059
10060 case MESA_FORMAT_A_FLOAT32:
10061 for (i = 0; i < n; ++i) {
10062 pack_float_a_float32(src[i], d);
10063 d += 4;
10064 }
10065 break;
10066
10067 case MESA_FORMAT_L_FLOAT16:
10068 for (i = 0; i < n; ++i) {
10069 pack_float_l_float16(src[i], d);
10070 d += 2;
10071 }
10072 break;
10073
10074 case MESA_FORMAT_L_FLOAT32:
10075 for (i = 0; i < n; ++i) {
10076 pack_float_l_float32(src[i], d);
10077 d += 4;
10078 }
10079 break;
10080
10081 case MESA_FORMAT_LA_FLOAT16:
10082 for (i = 0; i < n; ++i) {
10083 pack_float_la_float16(src[i], d);
10084 d += 4;
10085 }
10086 break;
10087
10088 case MESA_FORMAT_LA_FLOAT32:
10089 for (i = 0; i < n; ++i) {
10090 pack_float_la_float32(src[i], d);
10091 d += 8;
10092 }
10093 break;
10094
10095 case MESA_FORMAT_I_FLOAT16:
10096 for (i = 0; i < n; ++i) {
10097 pack_float_i_float16(src[i], d);
10098 d += 2;
10099 }
10100 break;
10101
10102 case MESA_FORMAT_I_FLOAT32:
10103 for (i = 0; i < n; ++i) {
10104 pack_float_i_float32(src[i], d);
10105 d += 4;
10106 }
10107 break;
10108
10109 case MESA_FORMAT_R_FLOAT16:
10110 for (i = 0; i < n; ++i) {
10111 pack_float_r_float16(src[i], d);
10112 d += 2;
10113 }
10114 break;
10115
10116 case MESA_FORMAT_R_FLOAT32:
10117 for (i = 0; i < n; ++i) {
10118 pack_float_r_float32(src[i], d);
10119 d += 4;
10120 }
10121 break;
10122
10123 case MESA_FORMAT_RG_FLOAT16:
10124 for (i = 0; i < n; ++i) {
10125 pack_float_rg_float16(src[i], d);
10126 d += 4;
10127 }
10128 break;
10129
10130 case MESA_FORMAT_RG_FLOAT32:
10131 for (i = 0; i < n; ++i) {
10132 pack_float_rg_float32(src[i], d);
10133 d += 8;
10134 }
10135 break;
10136
10137 case MESA_FORMAT_RGB_FLOAT16:
10138 for (i = 0; i < n; ++i) {
10139 pack_float_rgb_float16(src[i], d);
10140 d += 6;
10141 }
10142 break;
10143
10144 case MESA_FORMAT_RGB_FLOAT32:
10145 for (i = 0; i < n; ++i) {
10146 pack_float_rgb_float32(src[i], d);
10147 d += 12;
10148 }
10149 break;
10150
10151 case MESA_FORMAT_RGBA_FLOAT16:
10152 for (i = 0; i < n; ++i) {
10153 pack_float_rgba_float16(src[i], d);
10154 d += 8;
10155 }
10156 break;
10157
10158 case MESA_FORMAT_RGBA_FLOAT32:
10159 for (i = 0; i < n; ++i) {
10160 pack_float_rgba_float32(src[i], d);
10161 d += 16;
10162 }
10163 break;
10164
10165 case MESA_FORMAT_RGBX_FLOAT16:
10166 for (i = 0; i < n; ++i) {
10167 pack_float_rgbx_float16(src[i], d);
10168 d += 8;
10169 }
10170 break;
10171
10172 case MESA_FORMAT_RGBX_FLOAT32:
10173 for (i = 0; i < n; ++i) {
10174 pack_float_rgbx_float32(src[i], d);
10175 d += 16;
10176 }
10177 break;
10178 default:
10179 assert(!"Invalid format");
10180 }
10181 }
10182
10183 /**
10184 * Pack a 2D image of ubyte RGBA pixels in the given format.
10185 * \param srcRowStride source image row stride in bytes
10186 * \param dstRowStride destination image row stride in bytes
10187 */
10188 void
_mesa_pack_ubyte_rgba_rect(mesa_format format,uint32_t width,uint32_t height,const uint8_t * src,int32_t srcRowStride,void * dst,int32_t dstRowStride)10189 _mesa_pack_ubyte_rgba_rect(mesa_format format, uint32_t width, uint32_t height,
10190 const uint8_t *src, int32_t srcRowStride,
10191 void *dst, int32_t dstRowStride)
10192 {
10193 uint8_t *dstUB = dst;
10194 uint32_t i;
10195
10196 if (srcRowStride == width * 4 * sizeof(uint8_t) &&
10197 dstRowStride == _mesa_format_row_stride(format, width)) {
10198 /* do whole image at once */
10199 _mesa_pack_ubyte_rgba_row(format, width * height,
10200 (const uint8_t (*)[4]) src, dst);
10201 }
10202 else {
10203 /* row by row */
10204 for (i = 0; i < height; i++) {
10205 _mesa_pack_ubyte_rgba_row(format, width,
10206 (const uint8_t (*)[4]) src, dstUB);
10207 src += srcRowStride;
10208 dstUB += dstRowStride;
10209 }
10210 }
10211 }
10212
10213
10214 /** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
10215 struct z32f_x24s8
10216 {
10217 float z;
10218 uint32_t x24s8;
10219 };
10220
10221
10222 /**
10223 ** Pack float Z pixels
10224 **/
10225
10226 static void
pack_float_S8_UINT_Z24_UNORM(const float * src,void * dst)10227 pack_float_S8_UINT_Z24_UNORM(const float *src, void *dst)
10228 {
10229 /* don't disturb the stencil values */
10230 uint32_t *d = ((uint32_t *) dst);
10231 const double scale = (double) 0xffffff;
10232 uint32_t s = *d & 0xff;
10233 uint32_t z = (uint32_t) (*src * scale);
10234 assert(z <= 0xffffff);
10235 *d = (z << 8) | s;
10236 }
10237
10238 static void
pack_float_Z24_UNORM_S8_UINT(const float * src,void * dst)10239 pack_float_Z24_UNORM_S8_UINT(const float *src, void *dst)
10240 {
10241 /* don't disturb the stencil values */
10242 uint32_t *d = ((uint32_t *) dst);
10243 const double scale = (double) 0xffffff;
10244 uint32_t s = *d & 0xff000000;
10245 uint32_t z = (uint32_t) (*src * scale);
10246 assert(z <= 0xffffff);
10247 *d = s | z;
10248 }
10249
10250 static void
pack_float_Z_UNORM16(const float * src,void * dst)10251 pack_float_Z_UNORM16(const float *src, void *dst)
10252 {
10253 uint16_t *d = ((uint16_t *) dst);
10254 const float scale = (float) 0xffff;
10255 *d = (uint16_t) (*src * scale);
10256 }
10257
10258 static void
pack_float_Z_UNORM32(const float * src,void * dst)10259 pack_float_Z_UNORM32(const float *src, void *dst)
10260 {
10261 uint32_t *d = ((uint32_t *) dst);
10262 const double scale = (double) 0xffffffff;
10263 *d = (uint32_t) (*src * scale);
10264 }
10265
10266 /**
10267 ** Pack float to Z_FLOAT32 or Z_FLOAT32_X24S8.
10268 **/
10269
10270 static void
pack_float_Z_FLOAT32(const float * src,void * dst)10271 pack_float_Z_FLOAT32(const float *src, void *dst)
10272 {
10273 float *d = (float *) dst;
10274 *d = *src;
10275 }
10276
10277 mesa_pack_float_z_func
_mesa_get_pack_float_z_func(mesa_format format)10278 _mesa_get_pack_float_z_func(mesa_format format)
10279 {
10280 switch (format) {
10281 case MESA_FORMAT_S8_UINT_Z24_UNORM:
10282 case MESA_FORMAT_X8_UINT_Z24_UNORM:
10283 return pack_float_S8_UINT_Z24_UNORM;
10284 case MESA_FORMAT_Z24_UNORM_S8_UINT:
10285 case MESA_FORMAT_Z24_UNORM_X8_UINT:
10286 return pack_float_Z24_UNORM_S8_UINT;
10287 case MESA_FORMAT_Z_UNORM16:
10288 return pack_float_Z_UNORM16;
10289 case MESA_FORMAT_Z_UNORM32:
10290 return pack_float_Z_UNORM32;
10291 case MESA_FORMAT_Z_FLOAT32:
10292 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
10293 return pack_float_Z_FLOAT32;
10294 default:
10295 unreachable("unexpected format in _mesa_get_pack_float_z_func()");
10296 }
10297 }
10298
10299
10300
10301 /**
10302 ** Pack uint Z pixels. The incoming src value is always in
10303 ** the range [0, 2^32-1].
10304 **/
10305
10306 static void
pack_uint_S8_UINT_Z24_UNORM(const uint32_t * src,void * dst)10307 pack_uint_S8_UINT_Z24_UNORM(const uint32_t *src, void *dst)
10308 {
10309 /* don't disturb the stencil values */
10310 uint32_t *d = ((uint32_t *) dst);
10311 uint32_t s = *d & 0xff;
10312 uint32_t z = *src & 0xffffff00;
10313 *d = z | s;
10314 }
10315
10316 static void
pack_uint_Z24_UNORM_S8_UINT(const uint32_t * src,void * dst)10317 pack_uint_Z24_UNORM_S8_UINT(const uint32_t *src, void *dst)
10318 {
10319 /* don't disturb the stencil values */
10320 uint32_t *d = ((uint32_t *) dst);
10321 uint32_t s = *d & 0xff000000;
10322 uint32_t z = *src >> 8;
10323 *d = s | z;
10324 }
10325
10326 static void
pack_uint_Z_UNORM16(const uint32_t * src,void * dst)10327 pack_uint_Z_UNORM16(const uint32_t *src, void *dst)
10328 {
10329 uint16_t *d = ((uint16_t *) dst);
10330 *d = *src >> 16;
10331 }
10332
10333 static void
pack_uint_Z_UNORM32(const uint32_t * src,void * dst)10334 pack_uint_Z_UNORM32(const uint32_t *src, void *dst)
10335 {
10336 uint32_t *d = ((uint32_t *) dst);
10337 *d = *src;
10338 }
10339
10340 /**
10341 ** Pack uint to Z_FLOAT32 or Z_FLOAT32_X24S8.
10342 **/
10343
10344 static void
pack_uint_Z_FLOAT32(const uint32_t * src,void * dst)10345 pack_uint_Z_FLOAT32(const uint32_t *src, void *dst)
10346 {
10347 float *d = ((float *) dst);
10348 const double scale = 1.0 / (double) 0xffffffff;
10349 *d = (float) (*src * scale);
10350 assert(*d >= 0.0f);
10351 assert(*d <= 1.0f);
10352 }
10353
10354 mesa_pack_uint_z_func
_mesa_get_pack_uint_z_func(mesa_format format)10355 _mesa_get_pack_uint_z_func(mesa_format format)
10356 {
10357 switch (format) {
10358 case MESA_FORMAT_S8_UINT_Z24_UNORM:
10359 case MESA_FORMAT_X8_UINT_Z24_UNORM:
10360 return pack_uint_S8_UINT_Z24_UNORM;
10361 case MESA_FORMAT_Z24_UNORM_S8_UINT:
10362 case MESA_FORMAT_Z24_UNORM_X8_UINT:
10363 return pack_uint_Z24_UNORM_S8_UINT;
10364 case MESA_FORMAT_Z_UNORM16:
10365 return pack_uint_Z_UNORM16;
10366 case MESA_FORMAT_Z_UNORM32:
10367 return pack_uint_Z_UNORM32;
10368 case MESA_FORMAT_Z_FLOAT32:
10369 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
10370 return pack_uint_Z_FLOAT32;
10371 default:
10372 unreachable("unexpected format in _mesa_get_pack_uint_z_func()");
10373 }
10374 }
10375
10376
10377 /**
10378 ** Pack ubyte stencil pixels
10379 **/
10380
10381 static void
pack_ubyte_stencil_Z24_S8(const uint8_t * src,void * dst)10382 pack_ubyte_stencil_Z24_S8(const uint8_t *src, void *dst)
10383 {
10384 /* don't disturb the Z values */
10385 uint32_t *d = ((uint32_t *) dst);
10386 uint32_t s = *src;
10387 uint32_t z = *d & 0xffffff00;
10388 *d = z | s;
10389 }
10390
10391 static void
pack_ubyte_stencil_S8_Z24(const uint8_t * src,void * dst)10392 pack_ubyte_stencil_S8_Z24(const uint8_t *src, void *dst)
10393 {
10394 /* don't disturb the Z values */
10395 uint32_t *d = ((uint32_t *) dst);
10396 uint32_t s = *src << 24;
10397 uint32_t z = *d & 0xffffff;
10398 *d = s | z;
10399 }
10400
10401 static void
pack_ubyte_stencil_S8(const uint8_t * src,void * dst)10402 pack_ubyte_stencil_S8(const uint8_t *src, void *dst)
10403 {
10404 uint8_t *d = (uint8_t *) dst;
10405 *d = *src;
10406 }
10407
10408 static void
pack_ubyte_stencil_Z32_FLOAT_X24S8(const uint8_t * src,void * dst)10409 pack_ubyte_stencil_Z32_FLOAT_X24S8(const uint8_t *src, void *dst)
10410 {
10411 float *d = ((float *) dst);
10412 d[1] = *src;
10413 }
10414
10415
10416 mesa_pack_ubyte_stencil_func
_mesa_get_pack_ubyte_stencil_func(mesa_format format)10417 _mesa_get_pack_ubyte_stencil_func(mesa_format format)
10418 {
10419 switch (format) {
10420 case MESA_FORMAT_S8_UINT_Z24_UNORM:
10421 return pack_ubyte_stencil_Z24_S8;
10422 case MESA_FORMAT_Z24_UNORM_S8_UINT:
10423 return pack_ubyte_stencil_S8_Z24;
10424 case MESA_FORMAT_S_UINT8:
10425 return pack_ubyte_stencil_S8;
10426 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
10427 return pack_ubyte_stencil_Z32_FLOAT_X24S8;
10428 default:
10429 unreachable("unexpected format in _mesa_pack_ubyte_stencil_func()");
10430 }
10431 }
10432
10433
10434
10435 void
_mesa_pack_float_z_row(mesa_format format,uint32_t n,const float * src,void * dst)10436 _mesa_pack_float_z_row(mesa_format format, uint32_t n,
10437 const float *src, void *dst)
10438 {
10439 switch (format) {
10440 case MESA_FORMAT_S8_UINT_Z24_UNORM:
10441 case MESA_FORMAT_X8_UINT_Z24_UNORM:
10442 {
10443 /* don't disturb the stencil values */
10444 uint32_t *d = ((uint32_t *) dst);
10445 const double scale = (double) 0xffffff;
10446 uint32_t i;
10447 for (i = 0; i < n; i++) {
10448 uint32_t s = d[i] & 0xff;
10449 uint32_t z = (uint32_t) (src[i] * scale);
10450 assert(z <= 0xffffff);
10451 d[i] = (z << 8) | s;
10452 }
10453 }
10454 break;
10455 case MESA_FORMAT_Z24_UNORM_S8_UINT:
10456 case MESA_FORMAT_Z24_UNORM_X8_UINT:
10457 {
10458 /* don't disturb the stencil values */
10459 uint32_t *d = ((uint32_t *) dst);
10460 const double scale = (double) 0xffffff;
10461 uint32_t i;
10462 for (i = 0; i < n; i++) {
10463 uint32_t s = d[i] & 0xff000000;
10464 uint32_t z = (uint32_t) (src[i] * scale);
10465 assert(z <= 0xffffff);
10466 d[i] = s | z;
10467 }
10468 }
10469 break;
10470 case MESA_FORMAT_Z_UNORM16:
10471 {
10472 uint16_t *d = ((uint16_t *) dst);
10473 const float scale = (float) 0xffff;
10474 uint32_t i;
10475 for (i = 0; i < n; i++) {
10476 d[i] = (uint16_t) (src[i] * scale);
10477 }
10478 }
10479 break;
10480 case MESA_FORMAT_Z_UNORM32:
10481 {
10482 uint32_t *d = ((uint32_t *) dst);
10483 const double scale = (double) 0xffffffff;
10484 uint32_t i;
10485 for (i = 0; i < n; i++) {
10486 d[i] = (uint32_t) (src[i] * scale);
10487 }
10488 }
10489 break;
10490 case MESA_FORMAT_Z_FLOAT32:
10491 memcpy(dst, src, n * sizeof(float));
10492 break;
10493 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
10494 {
10495 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
10496 uint32_t i;
10497 for (i = 0; i < n; i++) {
10498 d[i].z = src[i];
10499 }
10500 }
10501 break;
10502 default:
10503 unreachable("unexpected format in _mesa_pack_float_z_row()");
10504 }
10505 }
10506
10507
10508 /**
10509 * The incoming Z values are always in the range [0, 0xffffffff].
10510 */
10511 void
_mesa_pack_uint_z_row(mesa_format format,uint32_t n,const uint32_t * src,void * dst)10512 _mesa_pack_uint_z_row(mesa_format format, uint32_t n,
10513 const uint32_t *src, void *dst)
10514 {
10515 switch (format) {
10516 case MESA_FORMAT_S8_UINT_Z24_UNORM:
10517 case MESA_FORMAT_X8_UINT_Z24_UNORM:
10518 {
10519 /* don't disturb the stencil values */
10520 uint32_t *d = ((uint32_t *) dst);
10521 uint32_t i;
10522 for (i = 0; i < n; i++) {
10523 uint32_t s = d[i] & 0xff;
10524 uint32_t z = src[i] & 0xffffff00;
10525 d[i] = z | s;
10526 }
10527 }
10528 break;
10529 case MESA_FORMAT_Z24_UNORM_S8_UINT:
10530 case MESA_FORMAT_Z24_UNORM_X8_UINT:
10531 {
10532 /* don't disturb the stencil values */
10533 uint32_t *d = ((uint32_t *) dst);
10534 uint32_t i;
10535 for (i = 0; i < n; i++) {
10536 uint32_t s = d[i] & 0xff000000;
10537 uint32_t z = src[i] >> 8;
10538 d[i] = s | z;
10539 }
10540 }
10541 break;
10542 case MESA_FORMAT_Z_UNORM16:
10543 {
10544 uint16_t *d = ((uint16_t *) dst);
10545 uint32_t i;
10546 for (i = 0; i < n; i++) {
10547 d[i] = src[i] >> 16;
10548 }
10549 }
10550 break;
10551 case MESA_FORMAT_Z_UNORM32:
10552 memcpy(dst, src, n * sizeof(float));
10553 break;
10554 case MESA_FORMAT_Z_FLOAT32:
10555 {
10556 uint32_t *d = ((uint32_t *) dst);
10557 const double scale = 1.0 / (double) 0xffffffff;
10558 uint32_t i;
10559 for (i = 0; i < n; i++) {
10560 d[i] = (uint32_t) (src[i] * scale);
10561 assert(d[i] >= 0.0f);
10562 assert(d[i] <= 1.0f);
10563 }
10564 }
10565 break;
10566 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
10567 {
10568 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
10569 const double scale = 1.0 / (double) 0xffffffff;
10570 uint32_t i;
10571 for (i = 0; i < n; i++) {
10572 d[i].z = (float) (src[i] * scale);
10573 assert(d[i].z >= 0.0f);
10574 assert(d[i].z <= 1.0f);
10575 }
10576 }
10577 break;
10578 default:
10579 unreachable("unexpected format in _mesa_pack_uint_z_row()");
10580 }
10581 }
10582
10583
10584 void
_mesa_pack_ubyte_stencil_row(mesa_format format,uint32_t n,const uint8_t * src,void * dst)10585 _mesa_pack_ubyte_stencil_row(mesa_format format, uint32_t n,
10586 const uint8_t *src, void *dst)
10587 {
10588 switch (format) {
10589 case MESA_FORMAT_S8_UINT_Z24_UNORM:
10590 {
10591 /* don't disturb the Z values */
10592 uint32_t *d = ((uint32_t *) dst);
10593 uint32_t i;
10594 for (i = 0; i < n; i++) {
10595 uint32_t s = src[i];
10596 uint32_t z = d[i] & 0xffffff00;
10597 d[i] = z | s;
10598 }
10599 }
10600 break;
10601 case MESA_FORMAT_Z24_UNORM_S8_UINT:
10602 {
10603 /* don't disturb the Z values */
10604 uint32_t *d = ((uint32_t *) dst);
10605 uint32_t i;
10606 for (i = 0; i < n; i++) {
10607 uint32_t s = src[i] << 24;
10608 uint32_t z = d[i] & 0xffffff;
10609 d[i] = s | z;
10610 }
10611 }
10612 break;
10613 case MESA_FORMAT_S_UINT8:
10614 memcpy(dst, src, n * sizeof(uint8_t));
10615 break;
10616 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
10617 {
10618 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
10619 uint32_t i;
10620 for (i = 0; i < n; i++) {
10621 d[i].x24s8 = src[i];
10622 }
10623 }
10624 break;
10625 default:
10626 unreachable("unexpected format in _mesa_pack_ubyte_stencil_row()");
10627 }
10628 }
10629
10630
10631 /**
10632 * Incoming Z/stencil values are always in uint_24_8 format.
10633 */
10634 void
_mesa_pack_uint_24_8_depth_stencil_row(mesa_format format,uint32_t n,const uint32_t * src,void * dst)10635 _mesa_pack_uint_24_8_depth_stencil_row(mesa_format format, uint32_t n,
10636 const uint32_t *src, void *dst)
10637 {
10638 switch (format) {
10639 case MESA_FORMAT_S8_UINT_Z24_UNORM:
10640 memcpy(dst, src, n * sizeof(uint32_t));
10641 break;
10642 case MESA_FORMAT_Z24_UNORM_S8_UINT:
10643 {
10644 uint32_t *d = ((uint32_t *) dst);
10645 uint32_t i;
10646 for (i = 0; i < n; i++) {
10647 uint32_t s = src[i] << 24;
10648 uint32_t z = src[i] >> 8;
10649 d[i] = s | z;
10650 }
10651 }
10652 break;
10653 case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
10654 {
10655 const double scale = 1.0 / (double) 0xffffff;
10656 struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
10657 uint32_t i;
10658 for (i = 0; i < n; i++) {
10659 float z = (float) ((src[i] >> 8) * scale);
10660 d[i].z = z;
10661 d[i].x24s8 = src[i];
10662 }
10663 }
10664 break;
10665 default:
10666 unreachable("bad format in _mesa_pack_ubyte_s_row");
10667 }
10668 }
10669
10670
10671