u_format_pack.py revision a441feb757b1be4845ba378f0207dcdc5cc1a407
1#!/usr/bin/env python
2
3'''
4/**************************************************************************
5 *
6 * Copyright 2009-2010 VMware, Inc.
7 * All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the
11 * "Software"), to deal in the Software without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sub license, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
16 *
17 * The above copyright notice and this permission notice (including the
18 * next paragraph) shall be included in all copies or substantial portions
19 * of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
25 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 *
29 **************************************************************************/
30
31/**
32 * @file
33 * Pixel format packing and unpacking functions.
34 *
35 * @author Jose Fonseca <jfonseca@vmware.com>
36 */
37'''
38
39
40from u_format_parse import *
41
42
43def generate_format_type(format):
44    '''Generate a structure that describes the format.'''
45
46    assert format.layout == PLAIN
47
48    print 'union util_format_%s {' % format.short_name()
49
50    if format.block_size() in (8, 16, 32, 64):
51        print '   uint%u_t value;' % (format.block_size(),)
52
53    use_bitfields = False
54    for channel in format.channels:
55        if channel.size % 8 or not is_pot(channel.size):
56            use_bitfields = True
57
58    print '   struct {'
59    for channel in format.channels:
60        if use_bitfields:
61            if channel.type == VOID:
62                if channel.size:
63                    print '      unsigned %s:%u;' % (channel.name, channel.size)
64            elif channel.type == UNSIGNED:
65                print '      unsigned %s:%u;' % (channel.name, channel.size)
66            elif channel.type in (SIGNED, FIXED):
67                print '      int %s:%u;' % (channel.name, channel.size)
68            elif channel.type == FLOAT:
69                if channel.size == 64:
70                    print '      double %s;' % (channel.name)
71                elif channel.size == 32:
72                    print '      float %s;' % (channel.name)
73                else:
74                    print '      unsigned %s:%u;' % (channel.name, channel.size)
75            else:
76                assert 0
77        else:
78            assert channel.size % 8 == 0 and is_pot(channel.size)
79            if channel.type == VOID:
80                if channel.size:
81                    print '      uint%u_t %s;' % (channel.size, channel.name)
82            elif channel.type == UNSIGNED:
83                print '      uint%u_t %s;' % (channel.size, channel.name)
84            elif channel.type in (SIGNED, FIXED):
85                print '      int%u_t %s;' % (channel.size, channel.name)
86            elif channel.type == FLOAT:
87                if channel.size == 64:
88                    print '      double %s;' % (channel.name)
89                elif channel.size == 32:
90                    print '      float %s;' % (channel.name)
91                elif channel.size == 16:
92                    print '      uint16_t %s;' % (channel.name)
93                else:
94                    assert 0
95            else:
96                assert 0
97    print '   } chan;'
98    print '};'
99    print
100
101
102def bswap_format(format):
103    '''Generate a structure that describes the format.'''
104
105    if format.is_bitmask() and not format.is_array() and format.block_size() > 8:
106        print '#ifdef PIPE_ARCH_BIG_ENDIAN'
107        print '   pixel.value = util_bswap%u(pixel.value);' % format.block_size()
108        print '#endif'
109
110
111def is_format_supported(format):
112    '''Determines whether we actually have the plumbing necessary to generate the
113    to read/write to/from this format.'''
114
115    # FIXME: Ideally we would support any format combination here.
116
117    if format.layout != PLAIN:
118        return False
119
120    for i in range(4):
121        channel = format.channels[i]
122        if channel.type not in (VOID, UNSIGNED, SIGNED, FLOAT, FIXED):
123            return False
124        if channel.type == FLOAT and channel.size not in (16, 32, 64):
125            return False
126
127    return True
128
129def is_format_pure_unsigned(format):
130    for i in range(4):
131        channel = format.channels[i]
132        if channel.type not in (VOID, UNSIGNED):
133            return False
134        if channel.type == UNSIGNED and channel.pure == False:
135            return False
136
137    return True
138
139
140def is_format_pure_signed(format):
141    for i in range(4):
142        channel = format.channels[i]
143        if channel.type not in (VOID, SIGNED):
144            return False
145        if channel.type == SIGNED and channel.pure == False:
146            return False
147
148    return True
149
150def native_type(format):
151    '''Get the native appropriate for a format.'''
152
153    if format.layout == PLAIN:
154        if not format.is_array():
155            # For arithmetic pixel formats return the integer type that matches the whole pixel
156            return 'uint%u_t' % format.block_size()
157        else:
158            # For array pixel formats return the integer type that matches the color channel
159            channel = format.channels[0]
160            if channel.type in (UNSIGNED, VOID):
161                return 'uint%u_t' % channel.size
162            elif channel.type in (SIGNED, FIXED):
163                return 'int%u_t' % channel.size
164            elif channel.type == FLOAT:
165                if channel.size == 16:
166                    return 'uint16_t'
167                elif channel.size == 32:
168                    return 'float'
169                elif channel.size == 64:
170                    return 'double'
171                else:
172                    assert False
173            else:
174                assert False
175    else:
176        assert False
177
178
179def intermediate_native_type(bits, sign):
180    '''Find a native type adequate to hold intermediate results of the request bit size.'''
181
182    bytes = 4 # don't use anything smaller than 32bits
183    while bytes * 8 < bits:
184        bytes *= 2
185    bits = bytes*8
186
187    if sign:
188        return 'int%u_t' % bits
189    else:
190        return 'uint%u_t' % bits
191
192
193def get_one_shift(type):
194    '''Get the number of the bit that matches unity for this type.'''
195    if type.type == 'FLOAT':
196        assert False
197    if not type.norm:
198        return 0
199    if type.type == UNSIGNED:
200        return type.size
201    if type.type == SIGNED:
202        return type.size - 1
203    if type.type == FIXED:
204        return type.size / 2
205    assert False
206
207
208def value_to_native(type, value):
209    '''Get the value of unity for this type.'''
210    if type.type == FLOAT:
211        return value
212    if type.type == FIXED:
213        return int(value * (1 << (type.size/2)))
214    if not type.norm:
215        return int(value)
216    if type.type == UNSIGNED:
217        return int(value * ((1 << type.size) - 1))
218    if type.type == SIGNED:
219        return int(value * ((1 << (type.size - 1)) - 1))
220    assert False
221
222
223def native_to_constant(type, value):
224    '''Get the value of unity for this type.'''
225    if type.type == FLOAT:
226        if type.size <= 32:
227            return "%ff" % value
228        else:
229            return "%ff" % value
230    else:
231        return str(int(value))
232
233
234def get_one(type):
235    '''Get the value of unity for this type.'''
236    return value_to_native(type, 1)
237
238
239def clamp_expr(src_channel, dst_channel, dst_native_type, value):
240    '''Generate the expression to clamp the value in the source type to the
241    destination type range.'''
242
243    if src_channel == dst_channel:
244        return value
245
246    src_min = src_channel.min()
247    src_max = src_channel.max()
248    dst_min = dst_channel.min()
249    dst_max = dst_channel.max()
250
251    # Translate the destination range to the src native value
252    dst_min_native = value_to_native(src_channel, dst_min)
253    dst_max_native = value_to_native(src_channel, dst_max)
254
255    if src_min < dst_min and src_max > dst_max:
256        return 'CLAMP(%s, %s, %s)' % (value, dst_min_native, dst_max_native)
257
258    if src_max > dst_max:
259        return 'MIN2(%s, %s)' % (value, dst_max_native)
260
261    if src_min < dst_min:
262        return 'MAX2(%s, %s)' % (value, dst_min_native)
263
264    return value
265
266
267def conversion_expr(src_channel,
268                    dst_channel, dst_native_type,
269                    value,
270                    clamp=True,
271                    src_colorspace = RGB,
272                    dst_colorspace = RGB):
273    '''Generate the expression to convert a value between two types.'''
274
275    if src_colorspace != dst_colorspace:
276        if src_colorspace == SRGB:
277            assert src_channel.type == UNSIGNED
278            assert src_channel.norm
279            assert src_channel.size == 8
280            assert dst_colorspace == RGB
281            if dst_channel.type == FLOAT:
282                return 'util_format_srgb_8unorm_to_linear_float(%s)' % value
283            else:
284                assert dst_channel.type == UNSIGNED
285                assert dst_channel.norm
286                assert dst_channel.size == 8
287                return 'util_format_srgb_to_linear_8unorm(%s)' % value
288        elif dst_colorspace == SRGB:
289            assert dst_channel.type == UNSIGNED
290            assert dst_channel.norm
291            assert dst_channel.size == 8
292            assert src_colorspace == RGB
293            if src_channel.type == FLOAT:
294                return 'util_format_linear_float_to_srgb_8unorm(%s)' % value
295            else:
296                assert src_channel.type == UNSIGNED
297                assert src_channel.norm
298                assert src_channel.size == 8
299                return 'util_format_linear_to_srgb_8unorm(%s)' % value
300        elif src_colorspace == ZS:
301            pass
302        elif dst_colorspace == ZS:
303            pass
304        else:
305            assert 0
306
307    if src_channel == dst_channel:
308        return value
309
310    src_type = src_channel.type
311    src_size = src_channel.size
312    src_norm = src_channel.norm
313    src_pure = src_channel.pure
314
315    # Promote half to float
316    if src_type == FLOAT and src_size == 16:
317        value = 'util_half_to_float(%s)' % value
318        src_size = 32
319
320    # Special case for float <-> ubytes for more accurate results
321    # Done before clamping since these functions already take care of that
322    if src_type == UNSIGNED and src_norm and src_size == 8 and dst_channel.type == FLOAT and dst_channel.size == 32:
323        return 'ubyte_to_float(%s)' % value
324    if src_type == FLOAT and src_size == 32 and dst_channel.type == UNSIGNED and dst_channel.norm and dst_channel.size == 8:
325        return 'float_to_ubyte(%s)' % value
326
327    if clamp:
328        if dst_channel.type != FLOAT or src_type != FLOAT:
329            value = clamp_expr(src_channel, dst_channel, dst_native_type, value)
330
331    if src_type in (SIGNED, UNSIGNED) and dst_channel.type in (SIGNED, UNSIGNED):
332        if not src_norm and not dst_channel.norm:
333            # neither is normalized -- just cast
334            return '(%s)%s' % (dst_native_type, value)
335
336        src_one = get_one(src_channel)
337        dst_one = get_one(dst_channel)
338
339        if src_one > dst_one and src_norm and dst_channel.norm:
340            # We can just bitshift
341            src_shift = get_one_shift(src_channel)
342            dst_shift = get_one_shift(dst_channel)
343            value = '(%s >> %s)' % (value, src_shift - dst_shift)
344        else:
345            # We need to rescale using an intermediate type big enough to hold the multiplication of both
346            tmp_native_type = intermediate_native_type(src_size + dst_channel.size, src_channel.sign and dst_channel.sign)
347            value = '((%s)%s)' % (tmp_native_type, value)
348            value = '(%s * 0x%x / 0x%x)' % (value, dst_one, src_one)
349        value = '(%s)%s' % (dst_native_type, value)
350        return value
351
352    # Promote to either float or double
353    if src_type != FLOAT:
354        if src_norm or src_type == FIXED:
355            one = get_one(src_channel)
356            if src_size <= 23:
357                value = '(%s * (1.0f/0x%x))' % (value, one)
358                if dst_channel.size <= 32:
359                    value = '(float)%s' % value
360                src_size = 32
361            else:
362                # bigger than single precision mantissa, use double
363                value = '(%s * (1.0/0x%x))' % (value, one)
364                src_size = 64
365            src_norm = False
366        else:
367            if src_size <= 23 or dst_channel.size <= 32:
368                value = '(float)%s' % value
369                src_size = 32
370            else:
371                # bigger than single precision mantissa, use double
372                value = '(double)%s' % value
373                src_size = 64
374        src_type = FLOAT
375
376    # Convert double or float to non-float
377    if dst_channel.type != FLOAT:
378        if dst_channel.norm or dst_channel.type == FIXED:
379            dst_one = get_one(dst_channel)
380            if dst_channel.size <= 23:
381                value = '(%s * 0x%x)' % (value, dst_one)
382            else:
383                # bigger than single precision mantissa, use double
384                value = '(%s * (double)0x%x)' % (value, dst_one)
385        value = '(%s)%s' % (dst_native_type, value)
386    else:
387        # Cast double to float when converting to either half or float
388        if dst_channel.size <= 32 and src_size > 32:
389            value = '(float)%s' % value
390            src_size = 32
391
392        if dst_channel.size == 16:
393            value = 'util_float_to_half(%s)' % value
394        elif dst_channel.size == 64 and src_size < 64:
395            value = '(double)%s' % value
396
397    return value
398
399
400def generate_unpack_kernel(format, dst_channel, dst_native_type):
401
402    if not is_format_supported(format):
403        return
404
405    assert format.layout == PLAIN
406
407    src_native_type = native_type(format)
408
409    if format.is_bitmask():
410        depth = format.block_size()
411        print '         uint%u_t value = *(const uint%u_t *)src;' % (depth, depth)
412
413        # Declare the intermediate variables
414        for i in range(format.nr_channels()):
415            src_channel = format.channels[i]
416            if src_channel.type == UNSIGNED:
417                print '         uint%u_t %s;' % (depth, src_channel.name)
418            elif src_channel.type == SIGNED:
419                print '         int%u_t %s;' % (depth, src_channel.name)
420
421        if depth > 8:
422            print '#ifdef PIPE_ARCH_BIG_ENDIAN'
423            print '         value = util_bswap%u(value);' % depth
424            print '#endif'
425
426        # Compute the intermediate unshifted values
427        shift = 0
428        for i in range(format.nr_channels()):
429            src_channel = format.channels[i]
430            value = 'value'
431            if src_channel.type == UNSIGNED:
432                if shift:
433                    value = '%s >> %u' % (value, shift)
434                if shift + src_channel.size < depth:
435                    value = '(%s) & 0x%x' % (value, (1 << src_channel.size) - 1)
436            elif src_channel.type == SIGNED:
437                if shift + src_channel.size < depth:
438                    # Align the sign bit
439                    lshift = depth - (shift + src_channel.size)
440                    value = '%s << %u' % (value, lshift)
441                # Cast to signed
442                value = '(int%u_t)(%s) ' % (depth, value)
443                if src_channel.size < depth:
444                    # Align the LSB bit
445                    rshift = depth - src_channel.size
446                    value = '(%s) >> %u' % (value, rshift)
447            else:
448                value = None
449
450            if value is not None:
451                print '         %s = %s;' % (src_channel.name, value)
452
453            shift += src_channel.size
454
455        # Convert, swizzle, and store final values
456        for i in range(4):
457            swizzle = format.swizzles[i]
458            if swizzle < 4:
459                src_channel = format.channels[swizzle]
460                src_colorspace = format.colorspace
461                if src_colorspace == SRGB and i == 3:
462                    # Alpha channel is linear
463                    src_colorspace = RGB
464                value = src_channel.name
465                value = conversion_expr(src_channel,
466                                        dst_channel, dst_native_type,
467                                        value,
468                                        src_colorspace = src_colorspace)
469            elif swizzle == SWIZZLE_0:
470                value = '0'
471            elif swizzle == SWIZZLE_1:
472                value = get_one(dst_channel)
473            elif swizzle == SWIZZLE_NONE:
474                value = '0'
475            else:
476                assert False
477            print '         dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i])
478
479    else:
480        print '         union util_format_%s pixel;' % format.short_name()
481        print '         memcpy(&pixel, src, sizeof pixel);'
482        bswap_format(format)
483
484        for i in range(4):
485            swizzle = format.swizzles[i]
486            if swizzle < 4:
487                src_channel = format.channels[swizzle]
488                src_colorspace = format.colorspace
489                if src_colorspace == SRGB and i == 3:
490                    # Alpha channel is linear
491                    src_colorspace = RGB
492                value = 'pixel.chan.%s' % src_channel.name
493                value = conversion_expr(src_channel,
494                                        dst_channel, dst_native_type,
495                                        value,
496                                        src_colorspace = src_colorspace)
497            elif swizzle == SWIZZLE_0:
498                value = '0'
499            elif swizzle == SWIZZLE_1:
500                value = get_one(dst_channel)
501            elif swizzle == SWIZZLE_NONE:
502                value = '0'
503            else:
504                assert False
505            print '         dst[%u] = %s; /* %s */' % (i, value, 'rgba'[i])
506
507
508def generate_pack_kernel(format, src_channel, src_native_type):
509
510    if not is_format_supported(format):
511        return
512
513    dst_native_type = native_type(format)
514
515    assert format.layout == PLAIN
516
517    inv_swizzle = format.inv_swizzles()
518
519    if format.is_bitmask():
520        depth = format.block_size()
521        print '         uint%u_t value = 0;' % depth
522
523        shift = 0
524        for i in range(4):
525            dst_channel = format.channels[i]
526            if inv_swizzle[i] is not None:
527                value ='src[%u]' % inv_swizzle[i]
528                dst_colorspace = format.colorspace
529                if dst_colorspace == SRGB and inv_swizzle[i] == 3:
530                    # Alpha channel is linear
531                    dst_colorspace = RGB
532                value = conversion_expr(src_channel,
533                                        dst_channel, dst_native_type,
534                                        value,
535                                        dst_colorspace = dst_colorspace)
536                if dst_channel.type in (UNSIGNED, SIGNED):
537                    if shift + dst_channel.size < depth:
538                        value = '(%s) & 0x%x' % (value, (1 << dst_channel.size) - 1)
539                    if shift:
540                        value = '(%s) << %u' % (value, shift)
541                    if dst_channel.type == SIGNED:
542                        # Cast to unsigned
543                        value = '(uint%u_t)(%s) ' % (depth, value)
544                else:
545                    value = None
546                if value is not None:
547                    print '         value |= %s;' % (value)
548
549            shift += dst_channel.size
550
551        if depth > 8:
552            print '#ifdef PIPE_ARCH_BIG_ENDIAN'
553            print '         value = util_bswap%u(value);' % depth
554            print '#endif'
555
556        print '         *(uint%u_t *)dst = value;' % depth
557
558    else:
559        print '         union util_format_%s pixel;' % format.short_name()
560
561        for i in range(4):
562            dst_channel = format.channels[i]
563            width = dst_channel.size
564            if inv_swizzle[i] is None:
565                continue
566            dst_colorspace = format.colorspace
567            if dst_colorspace == SRGB and inv_swizzle[i] == 3:
568                # Alpha channel is linear
569                dst_colorspace = RGB
570            value ='src[%u]' % inv_swizzle[i]
571            value = conversion_expr(src_channel,
572                                    dst_channel, dst_native_type,
573                                    value,
574                                    dst_colorspace = dst_colorspace)
575            print '         pixel.chan.%s = %s;' % (dst_channel.name, value)
576
577        bswap_format(format)
578        print '         memcpy(dst, &pixel, sizeof pixel);'
579
580
581def generate_format_unpack(format, dst_channel, dst_native_type, dst_suffix):
582    '''Generate the function to unpack pixels from a particular format'''
583
584    name = format.short_name()
585
586    print 'static INLINE void'
587    print 'util_format_%s_unpack_%s(%s *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height)' % (name, dst_suffix, dst_native_type)
588    print '{'
589
590    if is_format_supported(format):
591        print '   unsigned x, y;'
592        print '   for(y = 0; y < height; y += %u) {' % (format.block_height,)
593        print '      %s *dst = dst_row;' % (dst_native_type)
594        print '      const uint8_t *src = src_row;'
595        print '      for(x = 0; x < width; x += %u) {' % (format.block_width,)
596
597        generate_unpack_kernel(format, dst_channel, dst_native_type)
598
599        print '         src += %u;' % (format.block_size() / 8,)
600        print '         dst += 4;'
601        print '      }'
602        print '      src_row += src_stride;'
603        print '      dst_row += dst_stride/sizeof(*dst_row);'
604        print '   }'
605
606    print '}'
607    print
608
609
610def generate_format_pack(format, src_channel, src_native_type, src_suffix):
611    '''Generate the function to pack pixels to a particular format'''
612
613    name = format.short_name()
614
615    print 'static INLINE void'
616    print 'util_format_%s_pack_%s(uint8_t *dst_row, unsigned dst_stride, const %s *src_row, unsigned src_stride, unsigned width, unsigned height)' % (name, src_suffix, src_native_type)
617    print '{'
618
619    if is_format_supported(format):
620        print '   unsigned x, y;'
621        print '   for(y = 0; y < height; y += %u) {' % (format.block_height,)
622        print '      const %s *src = src_row;' % (src_native_type)
623        print '      uint8_t *dst = dst_row;'
624        print '      for(x = 0; x < width; x += %u) {' % (format.block_width,)
625
626        generate_pack_kernel(format, src_channel, src_native_type)
627
628        print '         src += 4;'
629        print '         dst += %u;' % (format.block_size() / 8,)
630        print '      }'
631        print '      dst_row += dst_stride;'
632        print '      src_row += src_stride/sizeof(*src_row);'
633        print '   }'
634
635    print '}'
636    print
637
638
639def generate_format_fetch(format, dst_channel, dst_native_type, dst_suffix):
640    '''Generate the function to unpack pixels from a particular format'''
641
642    name = format.short_name()
643
644    print 'static INLINE void'
645    print 'util_format_%s_fetch_%s(%s *dst, const uint8_t *src, unsigned i, unsigned j)' % (name, dst_suffix, dst_native_type)
646    print '{'
647
648    if is_format_supported(format):
649        generate_unpack_kernel(format, dst_channel, dst_native_type)
650
651    print '}'
652    print
653
654
655def is_format_hand_written(format):
656    return format.layout in ('s3tc', 'rgtc', 'subsampled', 'other') or format.colorspace == ZS
657
658
659def generate(formats):
660    print
661    print '#include "pipe/p_compiler.h"'
662    print '#include "u_math.h"'
663    print '#include "u_half.h"'
664    print '#include "u_format.h"'
665    print '#include "u_format_other.h"'
666    print '#include "u_format_srgb.h"'
667    print '#include "u_format_yuv.h"'
668    print '#include "u_format_zs.h"'
669    print
670
671    for format in formats:
672        if not is_format_hand_written(format):
673
674            if is_format_supported(format):
675                generate_format_type(format)
676
677            if is_format_pure_unsigned(format):
678                native_type = 'unsigned'
679                suffix = 'unsigned'
680                channel = Channel(UNSIGNED, False, True, 32)
681
682                generate_format_unpack(format, channel, native_type, suffix)
683                generate_format_pack(format, channel, native_type, suffix)
684
685                channel = Channel(SIGNED, False, True, 32)
686                native_type = 'int'
687                suffix = 'signed'
688                generate_format_unpack(format, channel, native_type, suffix)
689                generate_format_pack(format, channel, native_type, suffix)
690            elif is_format_pure_signed(format):
691                native_type = 'int'
692                suffix = 'signed'
693                channel = Channel(SIGNED, False, True, 32)
694
695                generate_format_unpack(format, channel, native_type, suffix)
696                generate_format_pack(format, channel, native_type, suffix)
697
698                native_type = 'unsigned'
699                suffix = 'unsigned'
700                channel = Channel(UNSIGNED, False, True, 32)
701                generate_format_unpack(format, channel, native_type, suffix)
702                generate_format_pack(format, channel, native_type, suffix)
703            else:
704                channel = Channel(FLOAT, False, False, 32)
705                native_type = 'float'
706                suffix = 'rgba_float'
707
708                generate_format_unpack(format, channel, native_type, suffix)
709                generate_format_pack(format, channel, native_type, suffix)
710                generate_format_fetch(format, channel, native_type, suffix)
711
712                channel = Channel(UNSIGNED, True, False, 8)
713                native_type = 'uint8_t'
714                suffix = 'rgba_8unorm'
715
716                generate_format_unpack(format, channel, native_type, suffix)
717                generate_format_pack(format, channel, native_type, suffix)
718
719