From 62ebd342e67fc0c12b181f91a488fa7a834fff6c Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Sun, 2 Aug 2020 11:35:48 -0700 Subject: [PATCH] freedreno/registers: split header build into subdirs Instead of building the adreno/foo.xml headers from the toplevel, split out a subdir(). This fits better with how meson likes things to be structured. But it does require fixing a bit about how gen_header.py resolves imports, ie. it cannot assume the src file is at the root of the $RNN_PATH. This is needed for the next patch, to add support for installing the register database for use with installed tools. Signed-off-by: Rob Clark Part-of: --- src/freedreno/computerator/a6xx.c | 6 +-- src/freedreno/computerator/main.h | 4 +- src/freedreno/meson.build | 2 +- src/freedreno/registers/adreno/meson.build | 56 ++++++++++++++++++++++ src/freedreno/registers/gen_header.py | 22 ++++----- src/freedreno/registers/meson.build | 34 ++++--------- src/freedreno/vulkan/tu_cmd_buffer.c | 4 +- src/freedreno/vulkan/tu_cs.h | 2 +- src/freedreno/vulkan/tu_formats.c | 4 +- src/freedreno/vulkan/tu_query.c | 6 +-- 10 files changed, 87 insertions(+), 53 deletions(-) create mode 100644 src/freedreno/registers/adreno/meson.build diff --git a/src/freedreno/computerator/a6xx.c b/src/freedreno/computerator/a6xx.c index 21d7d1c4894..4d8dce2b6aa 100644 --- a/src/freedreno/computerator/a6xx.c +++ b/src/freedreno/computerator/a6xx.c @@ -25,9 +25,9 @@ #include "util/u_math.h" -#include "registers/adreno_pm4.xml.h" -#include "registers/adreno_common.xml.h" -#include "registers/a6xx.xml.h" +#include "adreno_pm4.xml.h" +#include "adreno_common.xml.h" +#include "a6xx.xml.h" #include "main.h" #include "ir3_asm.h" diff --git a/src/freedreno/computerator/main.h b/src/freedreno/computerator/main.h index d72e143a3ae..8d310f76969 100644 --- a/src/freedreno/computerator/main.h +++ b/src/freedreno/computerator/main.h @@ -31,8 +31,8 @@ #include "drm/freedreno_drmif.h" #include "drm/freedreno_ringbuffer.h" -#include "registers/adreno_pm4.xml.h" -#include "registers/adreno_common.xml.h" +#include "adreno_pm4.xml.h" +#include "adreno_common.xml.h" #define MAX_BUFS 4 diff --git a/src/freedreno/meson.build b/src/freedreno/meson.build index 4350aa8d526..e039ab9c9a6 100644 --- a/src/freedreno/meson.build +++ b/src/freedreno/meson.build @@ -18,7 +18,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -inc_freedreno = include_directories(['.', './registers', './common']) +inc_freedreno = include_directories(['.', './registers', './registers/adreno', './common']) inc_freedreno_rnn = include_directories('rnn') rnn_src_path = meson.source_root() + '/src/freedreno/registers' diff --git a/src/freedreno/registers/adreno/meson.build b/src/freedreno/registers/adreno/meson.build new file mode 100644 index 00000000000..eb9c0730df4 --- /dev/null +++ b/src/freedreno/registers/adreno/meson.build @@ -0,0 +1,56 @@ +# Copyright © 2019 Google, Inc + +# 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 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. + +xml_files = [ + 'a2xx.xml', + 'a3xx.xml', + 'a4xx.xml', + 'a5xx.xml', + 'a6xx.xml', + 'adreno_common.xml', + 'adreno_pm4.xml', +] + +foreach f : xml_files + _name = f + '.h' + freedreno_xml_header_files += custom_target( + _name, + input: [gen_header_py, f], + output: _name, + command: [prog_python, '@INPUT0@', rnn_src_path, '@INPUT1@'], + capture: true, + ) +endforeach + +freedreno_xml_header_files += custom_target( + 'a6xx-pack.xml.h', + input: [gen_header_py, 'a6xx.xml'], + output: 'a6xx-pack.xml.h', + command: [prog_python, '@INPUT0@', rnn_src_path, '@INPUT1@', '--pack-structs'], + capture: true, +) + +freedreno_xml_header_files += custom_target( + 'adreno-pm4-pack.xml.h', + input: [gen_header_py, 'adreno_pm4.xml'], + output: 'adreno-pm4-pack.xml.h', + command: [prog_python, '@INPUT0@', rnn_src_path, '@INPUT1@', '--pack-structs'], + capture: true, +) diff --git a/src/freedreno/registers/gen_header.py b/src/freedreno/registers/gen_header.py index c0fc47fd8b4..db491cfbbb0 100644 --- a/src/freedreno/registers/gen_header.py +++ b/src/freedreno/registers/gen_header.py @@ -335,14 +335,7 @@ class Parser(object): raise self.error(e); def do_parse(self, filename): - try: - file = open(filename, "rb") - except FileNotFoundError as e: - # Look for the file in the parent directory if not - # found in same directory: - path = os.path.dirname(filename) - base = os.path.basename(filename) - file = open(path + "/../" + base, "rb") + file = open(filename, "rb") parser = xml.parsers.expat.ParserCreate() self.stack.append((parser, filename)) parser.StartElementHandler = self.start_element @@ -351,8 +344,8 @@ class Parser(object): self.stack.pop() file.close() - def parse(self, filename): - self.path = os.path.dirname(filename) + def parse(self, rnn_path, filename): + self.path = rnn_path self.stack = [] self.do_parse(filename) @@ -373,7 +366,7 @@ class Parser(object): def start_element(self, name, attrs): if name == "import": - filename = os.path.basename(attrs["file"]) + filename = attrs["file"] self.do_parse(os.path.join(self.path, filename)) elif name == "domain": self.current_domain = attrs["name"] @@ -449,8 +442,9 @@ class Parser(object): def main(): p = Parser() - xml_file = sys.argv[1] - if len(sys.argv) > 2 and sys.argv[2] == '--pack-structs': + rnn_path = sys.argv[1] + xml_file = sys.argv[2] + if len(sys.argv) > 3 and sys.argv[3] == '--pack-structs': do_structs = True guard = str.replace(os.path.basename(xml_file), '.', '_').upper() + '_STRUCTS' else: @@ -460,7 +454,7 @@ def main(): print("#ifndef %s\n#define %s\n" % (guard, guard)) try: - p.parse(xml_file) + p.parse(rnn_path, xml_file) except Error as e: print(e) exit(1) diff --git a/src/freedreno/registers/meson.build b/src/freedreno/registers/meson.build index d38e1661262..a0f2b351f88 100644 --- a/src/freedreno/registers/meson.build +++ b/src/freedreno/registers/meson.build @@ -19,38 +19,22 @@ # SOFTWARE. xml_files = [ - 'a2xx.xml', - 'a3xx.xml', - 'a4xx.xml', - 'a5xx.xml', - 'a6xx.xml', - 'adreno_common.xml', - 'adreno_pm4.xml', + 'adreno.xml', ] +gen_header_py = files('gen_header.py') + freedreno_xml_header_files = [] + foreach f : xml_files _name = f + '.h' freedreno_xml_header_files += custom_target( _name, - input : ['gen_header.py', 'adreno/' + f], - output : _name, - command : [prog_python, '@INPUT@'], - capture : true, + input: [gen_header_py, f], + output: _name, + command: [prog_python, '@INPUT0@', rnn_src_path, '@INPUT1@'], + capture: true, ) endforeach -freedreno_xml_header_files += custom_target( - 'a6xx-pack.xml.h', - input : ['gen_header.py', 'adreno/a6xx.xml'], - output : 'a6xx-pack.xml.h', - command : [prog_python, '@INPUT@', '--pack-structs'], - capture : true, - ) -freedreno_xml_header_files += custom_target( - 'adreno-pm4-pack.xml.h', - input : ['gen_header.py', 'adreno/adreno_pm4.xml'], - output : 'adreno-pm4-pack.xml.h', - command : [prog_python, '@INPUT@', '--pack-structs'], - capture : true, - ) +subdir('adreno') diff --git a/src/freedreno/vulkan/tu_cmd_buffer.c b/src/freedreno/vulkan/tu_cmd_buffer.c index ae89c9ab86d..deebd7132d5 100644 --- a/src/freedreno/vulkan/tu_cmd_buffer.c +++ b/src/freedreno/vulkan/tu_cmd_buffer.c @@ -27,8 +27,8 @@ #include "tu_private.h" -#include "registers/adreno_pm4.xml.h" -#include "registers/adreno_common.xml.h" +#include "adreno_pm4.xml.h" +#include "adreno_common.xml.h" #include "vk_format.h" diff --git a/src/freedreno/vulkan/tu_cs.h b/src/freedreno/vulkan/tu_cs.h index 85c53ea4f6e..77be4319a11 100644 --- a/src/freedreno/vulkan/tu_cs.h +++ b/src/freedreno/vulkan/tu_cs.h @@ -25,7 +25,7 @@ #include "tu_private.h" -#include "registers/adreno_pm4.xml.h" +#include "adreno_pm4.xml.h" void tu_cs_init(struct tu_cs *cs, diff --git a/src/freedreno/vulkan/tu_formats.c b/src/freedreno/vulkan/tu_formats.c index 819a6902982..6394ba138b8 100644 --- a/src/freedreno/vulkan/tu_formats.c +++ b/src/freedreno/vulkan/tu_formats.c @@ -25,8 +25,8 @@ #include "tu_private.h" -#include "registers/adreno_common.xml.h" -#include "registers/a6xx.xml.h" +#include "adreno_common.xml.h" +#include "a6xx.xml.h" #include "vk_format.h" #include "vk_util.h" diff --git a/src/freedreno/vulkan/tu_query.c b/src/freedreno/vulkan/tu_query.c index 4e7427161a2..9b013060cb3 100644 --- a/src/freedreno/vulkan/tu_query.c +++ b/src/freedreno/vulkan/tu_query.c @@ -31,9 +31,9 @@ #include #include -#include "registers/adreno_pm4.xml.h" -#include "registers/adreno_common.xml.h" -#include "registers/a6xx.xml.h" +#include "adreno_pm4.xml.h" +#include "adreno_common.xml.h" +#include "a6xx.xml.h" #include "nir/nir_builder.h" #include "util/os_time.h" -- 2.30.2