• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 Valve Corporation
3  * Copyright 2023 Alyssa Rosenzweig
4  * SPDX-License-Identifier: MIT
5  */
6 
7 #include "compiler/spirv/nir_spirv.h"
8 
9 static const struct spirv_to_nir_options spirv_options = {
10    .environment = NIR_SPIRV_OPENCL,
11    .shared_addr_format = nir_address_format_62bit_generic,
12    .global_addr_format = nir_address_format_62bit_generic,
13    .temp_addr_format = nir_address_format_62bit_generic,
14    .constant_addr_format = nir_address_format_64bit_global,
15    .create_library = true,
16 };
17 
18 int
main(int argc,char ** argv)19 main(int argc, char **argv)
20 {
21    if (argc != 3) {
22       fprintf(stderr, "Usage: %s [input spir-v] [output header]\n", argv[0]);
23       return 1;
24    }
25 
26    const char *infile = argv[1];
27    const char *outfile = argv[2];
28 
29    FILE *fin = fopen(infile, "rb");
30    if (!fin) {
31       fprintf(stderr, "Failed to open %s\n", infile);
32       return 1;
33    }
34 
35    fseek(fin, 0L, SEEK_END);
36    size_t len = ftell(fin);
37    rewind(fin);
38 
39    uint32_t *map = malloc(ALIGN_POT(len, 4));
40    if (!map) {
41       fprintf(stderr, "Failed to allocate");
42       fclose(fin);
43       return 1;
44    }
45 
46    fread(map, 1, len, fin);
47    fclose(fin);
48 
49    FILE *fout = fopen(outfile, "w");
50    if (!fout) {
51       fprintf(stderr, "Failed to open %s\n", outfile);
52       free(map);
53       return 1;
54    }
55 
56    glsl_type_singleton_init_or_ref();
57 
58    fprintf(fout, "/*\n");
59    fprintf(fout, " * Copyright Mesa3D Contributors\n");
60    fprintf(fout, " * SPDX-License-Identifier: MIT\n");
61    fprintf(fout, " *\n");
62    fprintf(fout, " * Autogenerated file, do not edit\n");
63    fprintf(fout, " */\n");
64    fprintf(fout, "#pragma once\n");
65    fprintf(fout, "#include <stdint.h>\n");
66 
67    spirv_library_to_nir_builder(fout, map, len / 4, &spirv_options);
68 
69    glsl_type_singleton_decref();
70    fclose(fout);
71    free(map);
72    return 0;
73 }
74