summaryrefslogtreecommitdiff
path: root/lib/mesa/src/intel/isl/gen_format_layout.py
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2017-12-31 06:33:44 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2017-12-31 06:33:44 +0000
commitb90fb74e3c85f2799d21d1e07bf91c5fb8359eb8 (patch)
tree385895e8835e6989d7730ee516b433eb41826885 /lib/mesa/src/intel/isl/gen_format_layout.py
parentd9c6ca3ea74f178cbd2d5f0fb0bc14843854fd0f (diff)
Import Mesa 17.2.8
Diffstat (limited to 'lib/mesa/src/intel/isl/gen_format_layout.py')
-rw-r--r--lib/mesa/src/intel/isl/gen_format_layout.py161
1 files changed, 102 insertions, 59 deletions
diff --git a/lib/mesa/src/intel/isl/gen_format_layout.py b/lib/mesa/src/intel/isl/gen_format_layout.py
index f52e45499..0ca42dbab 100644
--- a/lib/mesa/src/intel/isl/gen_format_layout.py
+++ b/lib/mesa/src/intel/isl/gen_format_layout.py
@@ -32,64 +32,76 @@ from mako import template
# Load the template, ensure that __future__.division is imported, and set the
# bytes encoding to be utf-8. This last bit is important to getting simple
# consistent behavior for python 3 when we get there.
-TEMPLATE = template.Template(
- text=textwrap.dedent("""\
- /* This file is autogenerated by gen_format_layout.py. DO NOT EDIT! */
-
- /*
- * Copyright 2015 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
- #include "isl/isl.h"
-
- const struct isl_format_layout
- isl_format_layouts[] = {
- % for format in formats:
- [ISL_FORMAT_${format.name}] = {
- .format = ISL_FORMAT_${format.name},
- .name = "ISL_FORMAT_${format.name}",
- .bpb = ${format.bpb},
- .bw = ${format.bw},
- .bh = ${format.bh},
- .bd = ${format.bd},
- .channels = {
- % for mask in ['r', 'g', 'b', 'a', 'l', 'i', 'p']:
- <% channel = getattr(format, mask, None) %>\\
- % if channel.type is not None:
- .${mask} = { ISL_${channel.type}, ${channel.size} },
- % else:
- .${mask} = {},
- % endif
- % endfor
- },
- .colorspace = ISL_COLORSPACE_${format.colorspace},
- .txc = ISL_TXC_${format.txc},
- },
-
- % endfor
- };
- """),
- future_imports=['division'],
- output_encoding='utf-8')
+TEMPLATE = template.Template(future_imports=['division'],
+ output_encoding='utf-8',
+ text="""\
+/* This file is autogenerated by gen_format_layout.py. DO NOT EDIT! */
+
+/*
+ * Copyright 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "isl/isl.h"
+
+const struct isl_format_layout
+isl_format_layouts[] = {
+% for format in formats:
+ [ISL_FORMAT_${format.name}] = {
+ .format = ISL_FORMAT_${format.name},
+ .name = "ISL_FORMAT_${format.name}",
+ .bpb = ${format.bpb},
+ .bw = ${format.bw},
+ .bh = ${format.bh},
+ .bd = ${format.bd},
+ .channels = {
+ % for mask in ['r', 'g', 'b', 'a', 'l', 'i', 'p']:
+ <% channel = getattr(format, mask, None) %>\\
+ % if channel.type is not None:
+ .${mask} = { ISL_${channel.type}, ${channel.size} },
+ % else:
+ .${mask} = {},
+ % endif
+ % endfor
+ },
+ .colorspace = ISL_COLORSPACE_${format.colorspace},
+ .txc = ISL_TXC_${format.txc},
+ },
+
+% endfor
+};
+
+enum isl_format
+isl_format_srgb_to_linear(enum isl_format format)
+{
+ switch (format) {
+% for srgb, rgb in srgb_to_linear_map:
+ case ISL_FORMAT_${srgb}:
+ return ISL_FORMAT_${rgb};
+%endfor
+ default:
+ return format;
+ }
+}
+""")
class Channel(object):
@@ -168,6 +180,34 @@ def reader(csvfile):
if line and not line[0].startswith('#'):
yield line
+def get_srgb_to_linear_map(formats):
+ """Compute a map from sRGB to linear formats.
+
+ This function uses some probably somewhat fragile string munging to do
+ the conversion. However, we do assert that, if it's SRGB, the munging
+ succeeded so that gives some safety.
+ """
+ names = {f.name for f in formats}
+ for fmt in formats:
+ if fmt.colorspace != 'SRGB':
+ continue
+
+ replacements = [
+ ('_SRGB', ''),
+ ('SRGB', 'RGB'),
+ ('U8SRGB', 'FLT16'),
+ ]
+
+ found = False;
+ for rep in replacements:
+ rgb_name = fmt.name.replace(rep[0], rep[1])
+ if rgb_name in names:
+ found = True
+ yield fmt.name, rgb_name
+ break;
+
+ # We should have found a format name
+ assert found
def main():
"""Main function."""
@@ -184,11 +224,14 @@ def main():
# problem: Unicode can be rendered even if the shell calling this script
# doesn't.
with open(args.out, 'wb') as f:
+ formats = [Format(l) for l in reader(args.csv)]
try:
# This basically does lazy evaluation and initialization, which
# saves on memory and startup overhead.
f.write(TEMPLATE.render(
- formats=(Format(l) for l in reader(args.csv))))
+ formats = formats,
+ srgb_to_linear_map = list(get_srgb_to_linear_map(formats)),
+ ))
except Exception:
# In the even there's an error this imports some helpers from mako
# to print a useful stack trace and prints it, then exits with