Merge remote-tracking branch 'mesa-public/master' into vulkan
[mesa.git] / src / vulkan / 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)([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,
102 .bs = $((bpb/8)), .bpb = $bpb,
103 .bw = $bw, .bh = $bh, .bd = $bd,
104 .channels = {
105 .r = { $red },
106 .g = { $green },
107 .b = { $blue },
108 .a = { $alpha },
109 .l = { $luminance },
110 .i = { $intensity },
111 .p = { $palette },
112 },
113 .colorspace = $colorspace,
114 .txc = $txc,
115 },
116
117 EOF
118 done |
119 sed -r '
120 # Collapse empty channels
121 s/\{ \}/{}/
122
123 # Split non-empty channels into two members: base type and bit size
124 s/@/, /
125 '
126
127 # Terminate the table
128 printf '};\n'