<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 20, 2017 at 4:53 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Chad Versace <<a href="mailto:chadversary@chromium.org">chadversary@chromium.org</a>><br>
<br>
The new function takes a mesa_format and, if the format is an alpha<br>
format with a non-alpha variant, returns the non-alpha format.<br>
Otherwise, it returns the original format.<br>
<br>
Example:<br>
input -> output<br>
<br>
// Fallback exists<br>
MESA_FORMAT_R8G8B8X8_UNORM -> MESA_FORMAT_R8G8B8A8_UNORM<br>
MESA_FORMAT_RGBX_UNORM16 -> MESA_FORMAT_RGBA_UNORM16<br>
<br>
// No fallback<br>
MESA_FORMAT_R8G8B8A8_UNORM -> MESA_FORMAT_R8G8B8A8_UNORM<br>
MESA_FORMAT_Z_FLOAT32 -> MESA_FORMAT_Z_FLOAT32<br>
<br>
i965 will use this for EGLImages and DRIimages.<br>
<br>
v2 (Jason Ekstrand):<br>
- Use mako<br>
- Rework to be easier to read<br>
- Write directly to the output file<br>
---<br>
src/mesa/<a href="http://Android.gen.mk" rel="noreferrer" target="_blank">Android.gen.mk</a> | 12 +++++<br>
src/mesa/Makefile.am | 7 +++<br>
src/mesa/Makefile.sources | 2 +<br>
src/mesa/main/.gitignore | 1 +<br>
src/mesa/main/format_fallback.<wbr>h | 31 ++++++++++++<br>
src/mesa/main/format_fallback.<wbr>py | 104 ++++++++++++++++++++++++++++++<wbr>+++++++++<br>
src/mesa/main/formats.h | 3 ++<br>
7 files changed, 160 insertions(+)<br>
create mode 100644 src/mesa/main/format_fallback.<wbr>h<br>
create mode 100644 src/mesa/main/format_fallback.<wbr>py<br>
<br>
diff --git a/src/mesa/<a href="http://Android.gen.mk" rel="noreferrer" target="_blank">Android.gen.mk</a> b/src/mesa/<a href="http://Android.gen.mk" rel="noreferrer" target="_blank">Android.gen.mk</a><br>
index 366a6b1..8d24260 100644<br>
--- a/src/mesa/<a href="http://Android.gen.mk" rel="noreferrer" target="_blank">Android.gen.mk</a><br>
+++ b/src/mesa/<a href="http://Android.gen.mk" rel="noreferrer" target="_blank">Android.gen.mk</a><br>
@@ -34,6 +34,7 @@ sources := \<br>
main/enums.c \<br>
main/api_exec.c \<br>
main/dispatch.h \<br>
+ main/format_fallback.c \<br>
main/format_pack.c \<br>
main/format_unpack.c \<br>
main/format_info.h \<br>
@@ -123,6 +124,17 @@ $(intermediates)/main/get_<wbr>hash.h: $(glapi)/gl_and_es_API.xml \<br>
$(LOCAL_PATH)/main/get_hash_<wbr>params.py $(GET_HASH_GEN)<br>
$(call es-gen)<br>
<br>
+FORMAT_FALLBACK := $(LOCAL_PATH)/main/format_<wbr>fallback.py<br>
+format_fallback_deps := \<br>
+ $(LOCAL_PATH)/main/formats.csv \<br>
+ $(LOCAL_PATH)/main/format_<wbr>parser.py \<br>
+ $(FORMAT_FALLBACK)<br>
+<br>
+$(intermediates)/main/format_<wbr>fallback.c: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(FORMAT_FALLBACK)<br>
+$(intermediates)/main/format_<wbr>fallback.c: PRIVATE_XML :=<br>
+$(intermediates)/main/format_<wbr>fallback.c: $(format_fallback_deps)<br>
+ $(call es-gen, $<)<br>
+<br>
FORMAT_INFO := $(LOCAL_PATH)/main/format_<wbr>info.py<br>
format_info_deps := \<br>
$(LOCAL_PATH)/main/formats.csv \<br>
diff --git a/src/mesa/Makefile.am b/src/mesa/Makefile.am<br>
index 53f311d..97a9bbd 100644<br>
--- a/src/mesa/Makefile.am<br>
+++ b/src/mesa/Makefile.am<br>
@@ -37,6 +37,7 @@ include Makefile.sources<br>
<br>
EXTRA_DIST = \<br>
drivers/SConscript \<br>
+ main/format_fallback.py \<br>
main/format_info.py \<br>
main/format_pack.py \<br>
main/format_parser.py \<br>
@@ -54,6 +55,7 @@ EXTRA_DIST = \<br>
<br>
BUILT_SOURCES = \<br>
main/get_hash.h \<br>
+ main/format_fallback.c \<br>
main/format_info.h \<br>
main/format_pack.c \<br>
main/format_unpack.c \<br>
@@ -70,6 +72,11 @@ main/get_hash.h: ../mapi/glapi/gen/gl_and_es_<wbr>API.xml main/get_hash_params.py \<br>
$(PYTHON_GEN) $(srcdir)/main/get_hash_<wbr>generator.py \<br>
-f $(srcdir)/../mapi/glapi/gen/<wbr>gl_and_es_API.xml > $@<br>
<br>
+main/format_fallback.c: main/format_fallback.py \<br>
+ main/format_parser.py \<br>
+ main/formats.csv<br>
+ $(PYTHON_GEN) $(srcdir)/main/format_<wbr>fallback.py $(srcdir)/main/formats.csv $@<br>
+<br>
main/format_info.h: main/formats.csv \<br>
main/format_parser.py main/format_info.py<br>
$(PYTHON_GEN) $(srcdir)/main/format_info.py $(srcdir)/main/formats.csv > $@<br>
diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources<br>
index b80882f..3756e33 100644<br>
--- a/src/mesa/Makefile.sources<br>
+++ b/src/mesa/Makefile.sources<br>
@@ -94,6 +94,8 @@ MAIN_FILES = \<br>
main/ffvertex_prog.h \<br>
main/fog.c \<br>
main/fog.h \<br>
+ main/format_fallback.h \<br>
+ main/format_fallback.c \<br>
main/format_info.h \<br>
main/format_pack.h \<br>
main/format_pack.c \<br>
diff --git a/src/mesa/main/.gitignore b/src/mesa/main/.gitignore<br>
index 836d8f1..8cc33cf 100644<br>
--- a/src/mesa/main/.gitignore<br>
+++ b/src/mesa/main/.gitignore<br>
@@ -4,6 +4,7 @@ enums.c<br>
remap_helper.h<br>
get_hash.h<br>
get_hash.h.tmp<br>
+format_fallback.c<br>
format_info.h<br>
format_info.c<br>
format_pack.c<br>
diff --git a/src/mesa/main/format_<wbr>fallback.h b/src/mesa/main/format_<wbr>fallback.h<br>
new file mode 100644<br>
index 0000000..5ca8269<br>
--- /dev/null<br>
+++ b/src/mesa/main/format_<wbr>fallback.h<br>
@@ -0,0 +1,31 @@<br>
+/*<br>
+ * Copyright 2017 Google<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice shall be included<br>
+ * in all copies or substantial portions of the Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS<br>
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR<br>
+ * OTHER DEALINGS IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#ifndef FORMAT_FALLBACK_H<br>
+#define FORMAT_FALLBACK_H<br>
+<br>
+#include "formats.h"<br>
+<br>
+mesa_format<br>
+_mesa_format_fallback_rgbx_<wbr>to_rgba(mesa_format format);<br></blockquote><div><br></div><div>Whoever merges this, should make sure this extra header gets dropped.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+#endif /* FORMAT_FALLBACK_H */<br>
diff --git a/src/mesa/main/format_<wbr>fallback.py b/src/mesa/main/format_<wbr>fallback.py<br>
new file mode 100644<br>
index 0000000..b12f2ab<br>
--- /dev/null<br>
+++ b/src/mesa/main/format_<wbr>fallback.py<br>
@@ -0,0 +1,104 @@<br>
+COPYRIGHT = """\<br>
+/*<br>
+ * Copyright 2017 Google<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the<br>
+ * "Software"), to deal in the Software without restriction, including<br>
+ * without limitation the rights to use, copy, modify, merge, publish,<br>
+ * distribute, sub license, and/or sell copies of the Software, and to<br>
+ * permit persons to whom the Software is furnished to do so, subject to<br>
+ * the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the<br>
+ * next paragraph) shall be included in all copies or substantial portions<br>
+ * of the Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS<br>
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF<br>
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.<br>
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR<br>
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,<br>
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE<br>
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.<br>
+ */<br>
+"""<br>
+<br>
+# stdlib<br>
+import argparse<br>
+from sys import stdout<br>
+from mako.template import Template<br>
+<br>
+# local<br>
+import format_parser<br>
+<br>
+def parse_args():<br>
+ p = argparse.ArgumentParser()<br>
+ p.add_argument("csv")<br>
+ p.add_argument("out")<br>
+ return p.parse_args()<br>
+<br>
+def get_rgbx_to_rgba_map(formats):<br>
+ names = {<a href="http://fmt.name" rel="noreferrer" target="_blank">fmt.name</a> for fmt in formats}<br>
+<br>
+ for fmt in formats:<br>
+ if not fmt.has_channel('r') or not fmt.has_channel('x'):<br>
+ continue<br>
+<br>
+ # The condition above will still let MESA_FORMAT_R9G9B9E5_FLOAT<br>
+ # through. We need to ensure it actually has an X in the name.<br>
+ if not 'X' in <a href="http://fmt.name" rel="noreferrer" target="_blank">fmt.name</a>:<br>
+ continue<br>
+<br>
+ rgbx_name = <a href="http://fmt.name" rel="noreferrer" target="_blank">fmt.name</a><br>
+ rgba_name = rgbx_name.replace("X", "A")<br>
+ if rgba_name not in names:<br>
+ continue;<br>
+<br>
+ yield rgbx_name, rgba_name<br>
+<br>
+TEMPLATE = Template(COPYRIGHT + """<br>
+#include "formats.h"<br>
+<br>
+/**<br>
+ * If the format has an alpha channel, and there exists a non-alpha<br>
+ * variant of the format with an identical bit layout, then return<br>
+ * the non-alpha format. Otherwise return the original format.<br>
+ *<br>
+ * Examples:<br>
+ * Fallback exists:<br>
+ * MESA_FORMAT_R8G8B8X8_UNORM -> MESA_FORMAT_R8G8B8A8_UNORM<br>
+ * MESA_FORMAT_RGBX_UNORM16 -> MESA_FORMAT_RGBA_UNORM16<br>
+ *<br>
+ * No fallback:<br>
+ * MESA_FORMAT_R8G8B8A8_UNORM -> MESA_FORMAT_R8G8B8A8_UNORM<br>
+ * MESA_FORMAT_Z_FLOAT32 -> MESA_FORMAT_Z_FLOAT32<br>
+ */<br>
+mesa_format<br>
+_mesa_get_rgbx_format_rgba(<wbr>mesa_format format)<br>
+{<br>
+ switch (format) {<br>
+%for rgbx, rgba in rgbx_to_rgba_map:<br>
+ case ${rgbx}:<br>
+ return ${rgba};<br>
+%endfor<br>
+ default:<br>
+ return format;<br>
+ }<br>
+}<br>
+""");<br>
+<br>
+def main():<br>
+ pargs = parse_args()<br>
+<br>
+ formats = list(format_parser.parse(<wbr>pargs.csv))<br>
+<br>
+ template_env = {<br>
+ 'rgbx_to_rgba_map': list(get_rgbx_to_rgba_map(<wbr>formats)),<br>
+ }<br>
+<br>
+ with open(pargs.out, 'w') as f:<br>
+ f.write(TEMPLATE.render(**<wbr>template_env))<br>
+<br>
+if __name__ == "__main__":<br>
+ main()<br>
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h<br>
index b88466f..12790df 100644<br>
--- a/src/mesa/main/formats.h<br>
+++ b/src/mesa/main/formats.h<br>
@@ -749,6 +749,9 @@ extern mesa_format<br>
_mesa_get_srgb_format_linear(<wbr>mesa_format format);<br>
<br>
extern mesa_format<br>
+_mesa_get_rgbx_format_rgba(<wbr>mesa_format format);<br>
+<br>
+extern mesa_format<br>
_mesa_get_uncompressed_format(<wbr>mesa_format format);<br>
<br>
extern GLuint<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.5.0.400.gff86faf<br>
<br>
</font></span></blockquote></div><br></div></div>