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