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