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