3 # Copyright (c) 2020 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
\r
21 def generate_main(glsl_files, output_header_file):
\r
22 # Write commit ID to output header file
\r
23 with open(output_header_file, "w") as header_file:
\r
25 header_string = '/***************************************************************************\n'
\r
26 header_string += ' *\n'
\r
27 header_string += ' * Copyright (c) 2015-2021 The Khronos Group Inc.\n'
\r
28 header_string += ' * Copyright (c) 2015-2021 Valve Corporation\n'
\r
29 header_string += ' * Copyright (c) 2015-2021 LunarG, Inc.\n'
\r
30 header_string += ' * Copyright (c) 2015-2021 Google Inc.\n'
\r
31 header_string += ' * Copyright (c) 2021 Advanced Micro Devices, Inc.All rights reserved.\n'
\r
32 header_string += ' *\n'
\r
33 header_string += ' ****************************************************************************/\n'
\r
34 header_string += '#pragma once\n\n'
\r
35 header_string += '#ifndef _INTRINSIC_EXTENSION_HEADER_H_\n'
\r
36 header_string += '#define _INTRINSIC_EXTENSION_HEADER_H_\n\n'
\r
37 header_file.write(header_string)
\r
39 symbol_name_list = []
\r
41 for i in glsl_files:
\r
42 glsl_contents = open(i,"r").read()
\r
44 filename = os.path.basename(i)
\r
45 symbol_name = filename.split(".")[0]
\r
46 symbol_name_list.append(symbol_name)
\r
47 header_name = symbol_name + ".h"
\r
48 header_str = 'std::string %s_GLSL = R"(\n%s\n)";\n' % (symbol_name, glsl_contents)
\r
50 header_file.write(header_str)
\r
54 contents += 'std::string getIntrinsic(const char* const* shaders, int n) {\n'
55 contents += '\tstd::string shaderString = "";\n';
57 contents += '\tfor (int i = 0; i < n; i++) {\n'
59 for symbol_name in symbol_name_list:
\r
60 contents += '\t\tif (strstr(shaders[i], "%s") != NULL) {\n' % (symbol_name)
61 contents += '\t\t shaderString.append(%s_GLSL);\n' % (symbol_name)
62 contents += '\t\t}\n'
\r
65 contents += '\treturn shaderString;\n';
68 contents += '\n#endif\n'
\r
69 header_file.write(contents)
\r
73 raise Exception("Invalid number of arguments")
\r
76 while i < len(sys.argv):
80 if opt == "-i" or opt == "-o":
81 if i == len(sys.argv):
82 raise Exception("Expected path after {}".format(opt))
90 raise Exception("Unknown flag {}".format(opt))
\r
92 glsl_files = glob.glob(input_dir + '/*.glsl')
\r
94 # Generate main header
\r
95 generate_main(glsl_files, output_file)
\r
97 if __name__ == '__main__':
\r