[Mesa-dev] [PATCH v5] intel: aubinator: generate a standalone binary
Jason Ekstrand
jason at jlekstrand.net
Fri Oct 7 19:39:51 UTC 2016
On Fri, Oct 7, 2016 at 2:27 AM, Lionel Landwerlin <llandwerlin at gmail.com>
wrote:
> Embed the xml files into the binary, so aubinator can be used from any
> location.
>
> v2: Split generation packing into another patch (Jason)
> Check for xxd (Jason)
>
> v3: Fix out of tree builds (Jason)
> Generate custom variable name rather than names generated by xxd
> (Lionel)
>
> v4: Move generated _xml.h files to genxml/ (Sirisha)
>
> v5: Remove newline from makefile (Jason)
>
> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
> Cc: Sirisha Gandikota <Sirisha.Gandikota at intel.com>
> ---
> configure.ac | 1 +
> src/intel/Makefile.genxml.am | 9 ++++-
> src/intel/Makefile.sources | 7 +++-
> src/intel/genxml/.gitignore | 1 +
> src/intel/tools/aubinator.c | 37 +++++++++--------
> src/intel/tools/decoder.c | 94 +++++++++++++++++++++++++++++-
> --------------
> src/intel/tools/decoder.h | 4 +-
> 7 files changed, 100 insertions(+), 53 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 0c437a5..77eefd1 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -110,6 +110,7 @@ LT_PREREQ([2.2])
> LT_INIT([disable-static])
>
> AC_CHECK_PROG(RM, rm, [rm -f])
> +AC_CHECK_PROG(XXD, xxd, [xxd])
>
> AX_PROG_BISON([],
> AS_IF([test ! -f "$srcdir/src/compiler/glsl/
> glcpp/glcpp-parse.c"],
> diff --git a/src/intel/Makefile.genxml.am b/src/intel/Makefile.genxml.am
> index f80e2fd..e2a23c9 100644
> --- a/src/intel/Makefile.genxml.am
> +++ b/src/intel/Makefile.genxml.am
> @@ -21,7 +21,7 @@
>
> BUILT_SOURCES += $(GENXML_GENERATED_FILES)
>
> -SUFFIXES = _pack.h .xml
> +SUFFIXES = _pack.h _xml.h .xml
>
> $(GENXML_GENERATED_FILES): genxml/gen_pack_header.py
>
> @@ -29,6 +29,13 @@ $(GENXML_GENERATED_FILES): genxml/gen_pack_header.py
> $(MKDIR_GEN)
> $(PYTHON_GEN) $(srcdir)/genxml/gen_pack_header.py $< > $@
>
> +%_xml.h: %.xml Makefile
> + $(MKDIR_GEN)
> + $(AM_V_GEN) echo -n "static const uint8_t " > $@; \
> + sed -e 's,_xml.h,,' <<< "`basename $@`_xml[] = {" >> $@; \
> + cat $< | $(XXD) -i >> $@; \
> + echo "};" >> $@
>
It'd still be nice to have a comment here about why all this is needed
(out-of-tree builds). With that,
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Sorry for all the review churn. :/
> +
> EXTRA_DIST += \
> genxml/gen4.xml \
> genxml/gen45.xml \
> diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources
> index 22ca63b..5b759bf 100644
> --- a/src/intel/Makefile.sources
> +++ b/src/intel/Makefile.sources
> @@ -21,7 +21,12 @@ GENXML_GENERATED_FILES = \
> genxml/gen7_pack.h \
> genxml/gen75_pack.h \
> genxml/gen8_pack.h \
> - genxml/gen9_pack.h
> + genxml/gen9_pack.h \
> + genxml/gen6_xml.h \
> + genxml/gen7_xml.h \
> + genxml/gen75_xml.h \
> + genxml/gen8_xml.h \
> + genxml/gen9_xml.h
>
> ISL_FILES = \
> isl/isl.c \
> diff --git a/src/intel/genxml/.gitignore b/src/intel/genxml/.gitignore
> index dd11495..c5672b5 100644
> --- a/src/intel/genxml/.gitignore
> +++ b/src/intel/genxml/.gitignore
> @@ -1 +1,2 @@
> gen*_pack.h
> +gen*_xml.h
> diff --git a/src/intel/tools/aubinator.c b/src/intel/tools/aubinator.c
> index 44a6bb2..8be7580 100644
> --- a/src/intel/tools/aubinator.c
> +++ b/src/intel/tools/aubinator.c
> @@ -1048,21 +1048,19 @@ int main(int argc, char *argv[])
> int c, i;
> bool help = false, pager = true;
> const char *input_file = NULL;
> - char gen_file[256], gen_val[24];
> + char gen_val[24];
> const struct {
> const char *name;
> int pci_id;
> - int major;
> - int minor;
> } gens[] = {
> - { "ivb", 0x0166, 7, 0 }, /* Intel(R) Ivybridge Mobile GT2 */
> - { "hsw", 0x0416, 7, 5 }, /* Intel(R) Haswell Mobile GT2 */
> - { "byt", 0x0155, 7, 5 }, /* Intel(R) Bay Trail */
> - { "bdw", 0x1616, 8, 0 }, /* Intel(R) HD Graphics 5500 (Broadwell
> GT2) */
> - { "chv", 0x22B3, 8, 0 }, /* Intel(R) HD Graphics (Cherryview) */
> - { "skl", 0x1912, 9, 0 }, /* Intel(R) HD Graphics 530 (Skylake GT2)
> */
> - { "kbl", 0x591D, 9, 0 }, /* Intel(R) Kabylake GT2 */
> - { "bxt", 0x0A84, 9, 0 } /* Intel(R) HD Graphics (Broxton) */
> + { "ivb", 0x0166 }, /* Intel(R) Ivybridge Mobile GT2 */
> + { "hsw", 0x0416 }, /* Intel(R) Haswell Mobile GT2 */
> + { "byt", 0x0155 }, /* Intel(R) Bay Trail */
> + { "bdw", 0x1616 }, /* Intel(R) HD Graphics 5500 (Broadwell GT2) */
> + { "chv", 0x22B3 }, /* Intel(R) HD Graphics (Cherryview) */
> + { "skl", 0x1912 }, /* Intel(R) HD Graphics 530 (Skylake GT2) */
> + { "kbl", 0x591D }, /* Intel(R) Kabylake GT2 */
> + { "bxt", 0x0A84 } /* Intel(R) HD Graphics (Broxton) */
> }, *gen = NULL;
> const struct option aubinator_opts[] = {
> { "help", no_argument, (int *) &help,
> true },
> @@ -1073,6 +1071,7 @@ int main(int argc, char *argv[])
> { "color", required_argument, NULL,
> 'c' },
> { NULL, 0, NULL, 0
> }
> };
> + struct gen_device_info devinfo;
>
> i = 0;
> while ((c = getopt_long(argc, argv, "", aubinator_opts, &i)) != -1) {
> @@ -1118,6 +1117,13 @@ int main(int argc, char *argv[])
> exit(EXIT_FAILURE);
> }
>
> + if (!gen_get_device_info(gen->pci_id, &devinfo)) {
> + fprintf(stderr, "can't find device information: pci_id=0x%x
> name=%s\n",
> + gen->pci_id, gen->name);
> + exit(EXIT_FAILURE);
> + }
> +
> +
> /* Do this before we redirect stdout to pager. */
> if (option_color == COLOR_AUTO)
> option_color = isatty(1) ? COLOR_ALWAYS : COLOR_NEVER;
> @@ -1125,14 +1131,7 @@ int main(int argc, char *argv[])
> if (isatty(1) && pager)
> setup_pager();
>
> - if (gen->minor > 0) {
> - snprintf(gen_file, sizeof(gen_file), "../genxml/gen%d%d.xml",
> - gen->major, gen->minor);
> - } else {
> - snprintf(gen_file, sizeof(gen_file), "../genxml/gen%d.xml",
> gen->major);
> - }
> -
> - spec = gen_spec_load(gen_file);
> + spec = gen_spec_load(&devinfo);
> disasm = gen_disasm_create(gen->pci_id);
>
> if (input_file == NULL) {
> diff --git a/src/intel/tools/decoder.c b/src/intel/tools/decoder.c
> index 4cbaab2..778cd5b 100644
> --- a/src/intel/tools/decoder.c
> +++ b/src/intel/tools/decoder.c
> @@ -33,6 +33,12 @@
>
> #include "decoder.h"
>
> +#include "genxml/gen6_xml.h"
> +#include "genxml/gen7_xml.h"
> +#include "genxml/gen75_xml.h"
> +#include "genxml/gen8_xml.h"
> +#include "genxml/gen9_xml.h"
> +
> #define XML_BUFFER_SIZE 4096
>
> #define MAKE_GEN(major, minor) ( ((major) << 8) | (minor) )
> @@ -395,57 +401,83 @@ character_data(void *data, const XML_Char *s, int
> len)
> {
> }
>
> +static int
> +devinfo_to_gen(const struct gen_device_info *devinfo)
> +{
> + int value = 10 * devinfo->gen;
> +
> + if (devinfo->is_baytrail || devinfo->is_haswell)
> + value += 5;
> +
> + return value;
> +}
> +
> +static const struct {
> + int gen;
> + const uint8_t *data;
> + size_t data_length;
> +} gen_data[] = {
> + { .gen = 60, .data = gen6_xml, .data_length = sizeof(gen6_xml) },
> + { .gen = 70, .data = gen7_xml, .data_length = sizeof(gen7_xml) },
> + { .gen = 75, .data = gen75_xml, .data_length = sizeof(gen75_xml) },
> + { .gen = 80, .data = gen8_xml, .data_length = sizeof(gen8_xml) },
> + { .gen = 90, .data = gen9_xml, .data_length = sizeof(gen9_xml) }
> +};
> +
> +static const uint8_t *
> +devinfo_to_xml_data(const struct gen_device_info *devinfo,
> + uint32_t *data_length)
> +{
> + int i, gen = devinfo_to_gen(devinfo);
> +
> + for (i = 0; i < ARRAY_SIZE(gen_data); i++) {
> + if (gen_data[i].gen == gen) {
> + *data_length = gen_data[i].data_length;
> + return gen_data[i].data;
> + }
> + }
> +
> + unreachable("Unknown generation");
> + return NULL;
> +}
> +
> struct gen_spec *
> -gen_spec_load(const char *filename)
> +gen_spec_load(const struct gen_device_info *devinfo)
> {
> struct parser_context ctx;
> void *buf;
> - int len;
> - FILE *input;
> -
> - input = fopen(filename, "r");
> - printf("xml filename = %s\n", filename);
> - if (input == NULL) {
> - fprintf(stderr, "failed to open xml description\n");
> - exit(EXIT_FAILURE);
> - }
> + const void *data;
> + uint32_t data_length = 0;
>
> memset(&ctx, 0, sizeof ctx);
> ctx.parser = XML_ParserCreate(NULL);
> XML_SetUserData(ctx.parser, &ctx);
> if (ctx.parser == NULL) {
> fprintf(stderr, "failed to create parser\n");
> - fclose(input);
> return NULL;
> }
>
> XML_SetElementHandler(ctx.parser, start_element, end_element);
> XML_SetCharacterDataHandler(ctx.parser, character_data);
> - ctx.loc.filename = filename;
>
> ctx.spec = xzalloc(sizeof(*ctx.spec));
>
> - do {
> - buf = XML_GetBuffer(ctx.parser, XML_BUFFER_SIZE);
> - len = fread(buf, 1, XML_BUFFER_SIZE, input);
> - if (len < 0) {
> - fprintf(stderr, "fread: %m\n");
> - fclose(input);
> - return NULL;
> - }
> - if (XML_ParseBuffer(ctx.parser, len, len == 0) == 0) {
> - fprintf(stderr,
> - "Error parsing XML at line %ld col %ld: %s\n",
> - XML_GetCurrentLineNumber(ctx.parser),
> - XML_GetCurrentColumnNumber(ctx.parser),
> - XML_ErrorString(XML_GetErrorCode(ctx.parser)));
> - fclose(input);
> - return NULL;
> - }
> - } while (len > 0);
> + data = devinfo_to_xml_data(devinfo, &data_length);
> + buf = XML_GetBuffer(ctx.parser, data_length);
> +
> + memcpy(buf, data, data_length);
> +
> + if (XML_ParseBuffer(ctx.parser, data_length, true) == 0) {
> + fprintf(stderr,
> + "Error parsing XML at line %ld col %ld: %s\n",
> + XML_GetCurrentLineNumber(ctx.parser),
> + XML_GetCurrentColumnNumber(ctx.parser),
> + XML_ErrorString(XML_GetErrorCode(ctx.parser)));
> + XML_ParserFree(ctx.parser);
> + return NULL;
> + }
>
> XML_ParserFree(ctx.parser);
> - fclose(input);
>
> return ctx.spec;
> }
> diff --git a/src/intel/tools/decoder.h b/src/intel/tools/decoder.h
> index f688ba5..5bea9b9 100644
> --- a/src/intel/tools/decoder.h
> +++ b/src/intel/tools/decoder.h
> @@ -26,6 +26,8 @@
> #include <stdint.h>
> #include <stdbool.h>
>
> +#include "common/gen_device_info.h"
> +
> struct gen_spec;
> struct gen_group;
> struct gen_field;
> @@ -36,7 +38,7 @@ static inline uint32_t gen_make_gen(uint32_t major,
> uint32_t minor)
> }
>
> struct gen_group *gen_spec_find_struct(struct gen_spec *spec, const char
> *name);
> -struct gen_spec *gen_spec_load(const char *filename);
> +struct gen_spec *gen_spec_load(const struct gen_device_info *devinfo);
> uint32_t gen_spec_get_gen(struct gen_spec *spec);
> struct gen_group *gen_spec_find_instruction(struct gen_spec *spec, const
> uint32_t *p);
> struct gen_group *gen_spec_find_register(struct gen_spec *spec, uint32_t
> offset);
> --
> 2.9.3
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20161007/6d69c2da/attachment-0001.html>
More information about the mesa-dev
mailing list