intel/clc: allow producing SPIRV files
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Thu, 6 May 2021 19:22:44 +0000 (22:22 +0300)
committerMarge Bot <emma+marge@anholt.net>
Mon, 21 Mar 2022 11:26:44 +0000 (11:26 +0000)
Useful to debug the parser.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13171>

src/intel/compiler/intel_clc.c

index e2fb221..23a97de 100644 (file)
@@ -261,6 +261,7 @@ print_usage(char *exec_name, FILE *f)
 "  -p, --platform <name>   Specify the target platform name.\n"
 "      --prefix <prefix>   Prefix for variable names in generated C code.\n"
 "  -g, --out <filename>    Specify the output filename.\n"
+"  -s, --spv <filename>    Specify the output filename for spirv.\n"
    , exec_name);
 }
 
@@ -277,10 +278,11 @@ int main(int argc, char **argv)
       {"prefix",     required_argument,   0, OPT_PREFIX},
       {"in",         required_argument,   0, 'i'},
       {"out",        required_argument,   0, 'o'},
+      {"spv",        required_argument,   0, 's'},
       {0, 0, 0, 0}
    };
 
-   char *entry_point = NULL, *platform = NULL, *outfile = NULL, *prefix = NULL;
+   char *entry_point = NULL, *platform = NULL, *outfile = NULL, *spv_outfile = NULL, *prefix = NULL;
    struct util_dynarray clang_args;
    struct util_dynarray input_files;
    struct util_dynarray spirv_objs;
@@ -294,7 +296,7 @@ int main(int argc, char **argv)
    util_dynarray_init(&spirv_ptr_objs, mem_ctx);
 
    int ch;
-   while ((ch = getopt_long(argc, argv, "he:p:o:", long_options, NULL)) != -1)
+   while ((ch = getopt_long(argc, argv, "he:p:s:o:", long_options, NULL)) != -1)
    {
       switch (ch)
       {
@@ -310,6 +312,9 @@ int main(int argc, char **argv)
       case 'o':
          outfile = optarg;
          break;
+      case 's':
+         spv_outfile = optarg;
+         break;
       case OPT_PREFIX:
          prefix = optarg;
          break;
@@ -412,6 +417,12 @@ int main(int argc, char **argv)
       return 1;
    }
 
+   if (spv_outfile) {
+      FILE *fp = fopen(spv_outfile, "w");
+      fwrite(final_spirv.data, final_spirv.size, 1, fp);
+      fclose(fp);
+   }
+
    struct clc_parsed_spirv parsed_spirv_data;
    if (!clc_parse_spirv(&final_spirv, &logger, &parsed_spirv_data)) {
       ralloc_free(mem_ctx);