isl: automake: don't include isl_format_layout.c in two lists.
[mesa.git] / src / intel / isl / isl_format_layout_gen.bash
1 #!/usr/bin/env bash
2 #
3 # Copyright 2015 Intel Corporation
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
14 # Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 # IN THE SOFTWARE.
23
24 set -eu
25 set -o pipefail
26
27 cat <<'EOF'
28 /*
29 * Copyright 2015 Intel Corporation
30 *
31 * Permission is hereby granted, free of charge, to any person obtaining a
32 * copy of this software and associated documentation files (the "Software"),
33 * to deal in the Software without restriction, including without limitation
34 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
35 * and/or sell copies of the Software, and to permit persons to whom the
36 * Software is furnished to do so, subject to the following conditions:
37 *
38 * The above copyright notice and this permission notice (including the next
39 * paragraph) shall be included in all copies or substantial portions of the
40 * Software.
41 *
42 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
45 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
47 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
48 * IN THE SOFTWARE.
49 */
50
51 #include "isl.h"
52
53 const struct isl_format_layout
54 isl_format_layouts[] = {
55 EOF
56
57 sed -r '
58 # Delete comment lines and empty lines
59 /^[[:space:]]*#/d
60 /^[[:space:]]*$/d
61
62 # Delete spaces
63 s/[[:space:]]//g
64
65 # Translate formats
66 s/^([A-Za-z0-9_]+),*/ISL_FORMAT_\1,/
67
68 # Translate data type of channels
69 s/\<x([0-9]+),/ISL_VOID@\1,/g
70 s/\<r([0-9]+),/ISL_RAW@\1,/g
71 s/\<un([0-9]+),/ISL_UNORM@\1,/g
72 s/\<sn([0-9]+),/ISL_SNORM@\1,/g
73 s/\<uf([0-9]+),/ISL_UFLOAT@\1,/g
74 s/\<sf([0-9]+),/ISL_SFLOAT@\1,/g
75 s/\<ux([0-9]+),/ISL_UFIXED@\1,/g
76 s/\<sx([0-9]+),/ISL_SFIXED@\1,/g
77 s/\<ui([0-9]+),/ISL_UINT@\1,/g
78 s/\<si([0-9]+),/ISL_SINT@\1,/g
79 s/\<us([0-9]+),/ISL_USCALED@\1,/g
80 s/\<ss([0-9]+),/ISL_SSCALED@\1,/g
81
82 # Translate colorspaces
83 # Interpret alpha-only formats as having no colorspace.
84 s/\<(linear|srgb|yuv)\>/ISL_COLORSPACE_\1/
85 s/\<alpha\>//
86
87 # Translate texture compression
88 s/\<(dxt|fxt|rgtc|bptc|etc|astc)([0-9]*)\>/ISL_TXC_\1\2/
89 ' |
90 tr 'a-z' 'A-Z' | # Convert to uppersace
91 while IFS=, read -r format bpb bw bh bd \
92 red green blue alpha \
93 luminance intensity palette \
94 colorspace txc
95 do
96 : ${colorspace:=ISL_COLORSPACE_NONE}
97 : ${txc:=ISL_TXC_NONE}
98
99 cat <<EOF
100 [$format] = {
101 .format = $format,
102 .name = "$format",
103 .bs = $((bpb/8)),
104 .bw = $bw, .bh = $bh, .bd = $bd,
105 .channels = {
106 .r = { $red },
107 .g = { $green },
108 .b = { $blue },
109 .a = { $alpha },
110 .l = { $luminance },
111 .i = { $intensity },
112 .p = { $palette },
113 },
114 .colorspace = $colorspace,
115 .txc = $txc,
116 },
117
118 EOF
119 done |
120 sed -r '
121 # Collapse empty channels
122 s/\{ \}/{}/
123
124 # Split non-empty channels into two members: base type and bit size
125 s/@/, /
126 '
127
128 # Terminate the table
129 printf '};\n'