[Mesa-dev] [PATCH v2 8/14] anv: generate anv_entrypoints.{h, c} in one command

Dylan Baker dylan at pnwbakers.com
Thu Feb 23 18:46:21 UTC 2017


This changes the python generator to write the files itself, rather than
piping them out. This has a couple of advantages: first, it encapsulates
the encoding. Second, it ensures that the header file and code file are
generated at the same time with the same data.

v2: - Update Android.mk

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 src/intel/vulkan/Android.mk             |  7 +-----
 src/intel/vulkan/Makefile.am            |  8 ++----
 src/intel/vulkan/anv_entrypoints_gen.py | 33 +++++++++++++-------------
 3 files changed, 22 insertions(+), 26 deletions(-)

diff --git a/src/intel/vulkan/Android.mk b/src/intel/vulkan/Android.mk
index 9dabf1c..df10141 100644
--- a/src/intel/vulkan/Android.mk
+++ b/src/intel/vulkan/Android.mk
@@ -60,8 +60,8 @@ $(intermediates)/dummy.c:
 	@echo "Gen Dummy: $(PRIVATE_MODULE) <= $(notdir $(@))"
 	$(hide) touch $@
 
-$(intermediates)/anv_entrypoints.h:
-	$(VK_ENTRYPOINTS_SCRIPT) header --xml $(MESA_TOP)/src/vulkan/registry/vk.xml > $@
+$(intermediates)/anv_entrypoints.h $(intermediates)/anv_entrypoints.c:
+	$(VK_ENTRYPOINTS_SCRIPT) --xml $(MESA_TOP)/src/vulkan/registry/vk.xml
 
 LOCAL_EXPORT_C_INCLUDE_DIRS := \
         $(intermediates)
@@ -176,9 +176,6 @@ LOCAL_WHOLE_STATIC_LIBRARIES := libmesa_anv_entrypoints libmesa_genxml
 
 LOCAL_GENERATED_SOURCES += $(intermediates)/anv_entrypoints.c
 
-$(intermediates)/anv_entrypoints.c:
-	$(VK_ENTRYPOINTS_SCRIPT) code --xml $(MESA_TOP)/src/vulkan/registry/vk.xml > $@
-
 LOCAL_SHARED_LIBRARIES := libdrm_intel
 
 include $(MESA_COMMON_MK)
diff --git a/src/intel/vulkan/Makefile.am b/src/intel/vulkan/Makefile.am
index 565559c..38a50c9 100644
--- a/src/intel/vulkan/Makefile.am
+++ b/src/intel/vulkan/Makefile.am
@@ -145,11 +145,9 @@ libvulkan_intel_la_SOURCES = $(VULKAN_GEM_FILES)
 
 vulkan_api_xml = $(top_srcdir)/src/vulkan/registry/vk.xml
 
-anv_entrypoints.h : anv_entrypoints_gen.py $(vulkan_api_xml)
-	$(AM_V_GEN)$(PYTHON2) $(srcdir)/anv_entrypoints_gen.py header --xml $(vulkan_api_xml) > $@
-
-anv_entrypoints.c : anv_entrypoints_gen.py $(vulkan_api_xml)
-	$(AM_V_GEN)$(PYTHON2) $(srcdir)/anv_entrypoints_gen.py code --xml $(vulkan_api_xml) > $@
+anv_entrypoints.h anv_entrypoints.c: anv_entrypoints_gen.py $(vulkan_api_xml)
+	$(AM_V_GEN)$(PYTHON2) $(srcdir)/anv_entrypoints_gen.py \
+		--xml $(vulkan_api_xml) --outdir $(builddir)
 
 BUILT_SOURCES = $(VULKAN_GENERATED_FILES)
 CLEANFILES = $(BUILT_SOURCES) dev_icd.json intel_icd. at host_cpu@.json
diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py
index 45a463c..5066195 100644
--- a/src/intel/vulkan/anv_entrypoints_gen.py
+++ b/src/intel/vulkan/anv_entrypoints_gen.py
@@ -23,6 +23,7 @@
 #
 
 import argparse
+import os
 import textwrap
 import xml.etree.ElementTree as et
 
@@ -83,7 +84,7 @@ TEMPLATE_H = Template(textwrap.dedent("""\
     #endif // ${guard}
       % endif
     % endfor
-    """))
+    """), output_encoding='utf-8')
 
 TEMPLATE_C = Template(textwrap.dedent(u"""\
     /*
@@ -337,22 +338,22 @@ def gen_code(entrypoints):
             collisions[level] += 1
         mapping[h & HASH_MASK] = num
 
-    print TEMPLATE_C.render(entrypoints=entrypoints,
-                            offsets=offsets,
-                            collisions=collisions,
-                            mapping=mapping,
-                            hash_mask=HASH_MASK,
-                            prime_step=PRIME_STEP,
-                            prime_factor=PRIME_FACTOR,
-                            none=NONE,
-                            hash_size=HASH_SIZE)
+    return TEMPLATE_C.render(entrypoints=entrypoints,
+                             offsets=offsets,
+                             collisions=collisions,
+                             mapping=mapping,
+                             hash_mask=HASH_MASK,
+                             prime_step=PRIME_STEP,
+                             prime_factor=PRIME_FACTOR,
+                             none=NONE,
+                             hash_size=HASH_SIZE)
 
 
 def main():
     parser = argparse.ArgumentParser()
-    parser.add_argument('target', choices=['header', 'code'],
-                        help='Which file to generate.')
     parser.add_argument('--xml', help='Vulkan API XML file.')
+    parser.add_argument('--outdir',
+                        help='Directory to put the generated files in')
     args = parser.parse_args()
 
     doc = et.parse(args.xml)
@@ -370,10 +371,10 @@ def main():
 
     # For outputting entrypoints.h we generate a anv_EntryPoint() prototype
     # per entry point.
-    if args.target == 'header':
-        print TEMPLATE_H.render(entrypoints=entrypoints)
-    else:
-        gen_code(entrypoints)
+    with open(os.path.join(args.outdir, 'anv_entrypoints.h'), 'wb') as f:
+        f.write(TEMPLATE_H.render(entrypoints=entrypoints))
+    with open(os.path.join(args.outdir, 'anv_entrypoints.c'), 'wb') as f:
+        f.write(gen_code(entrypoints))
 
 
 if __name__ == '__main__':
-- 
git-series 0.9.0


More information about the mesa-dev mailing list