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.
21 def generate_main(glsl_files
, output_header_file
):
22 # Write commit ID to output header file
23 with
open(output_header_file
, "w") as header_file
:
25 header_string
= '/***************************************************************************\n'
26 header_string
+= ' *\n'
27 header_string
+= ' * Copyright (c) 2015-2021 The Khronos Group Inc.\n'
28 header_string
+= ' * Copyright (c) 2015-2021 Valve Corporation\n'
29 header_string
+= ' * Copyright (c) 2015-2021 LunarG, Inc.\n'
30 header_string
+= ' * Copyright (c) 2015-2021 Google Inc.\n'
31 header_string
+= ' * Copyright (c) 2021 Advanced Micro Devices, Inc.All rights reserved.\n'
32 header_string
+= ' *\n'
33 header_string
+= ' ****************************************************************************/\n'
34 header_string
+= '#pragma once\n\n'
35 header_string
+= '#ifndef _INTRINSIC_EXTENSION_HEADER_H_\n'
36 header_string
+= '#define _INTRINSIC_EXTENSION_HEADER_H_\n\n'
37 header_file
.write(header_string
)
42 glsl_contents
= open(i
,"r").read()
44 filename
= os
.path
.basename(i
)
45 symbol_name
= filename
.split(".")[0]
46 symbol_name_list
.append(symbol_name
)
47 header_name
= symbol_name
+ ".h"
48 header_str
= 'std::string %s_GLSL = R"(\n%s\n)";\n' % (symbol_name
, glsl_contents
)
50 header_file
.write(header_str
)
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
:
60 contents
+= '\t\tif (strstr(shaders[i], "%s") != nullptr) {\n' % (symbol_name
)
61 contents
+= '\t\t shaderString.append(%s_GLSL);\n' % (symbol_name
)
65 contents
+= '\treturn shaderString;\n';
68 contents
+= '\n#endif\n'
69 header_file
.write(contents
)
73 raise Exception("Invalid number of arguments")
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
))
92 glsl_files
= glob
.glob(input_dir
+ '/*.glsl')
94 # Generate main header
95 generate_main(glsl_files
, output_file
)
97 if __name__
== '__main__':