yum-mirror/glslang
git clone https://git.yummers.dev/yum-mirror/glslang
a7603c13
main
1#!/usr/bin/env python3 2 3# Copyright (c) 2020 Google Inc. 4# 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 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 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. 16 17import glob 18import sys 19import os 20 21def generate_main (glsl_files ,output_header_file ): 22# Write commit ID to output header file 23with open (output_header_file ,"w" )as header_file : 24# Copyright Notice 25header_string = '/***************************************************************************\n' 26header_string += ' *\n' 27header_string += ' * Copyright (c) 2015-2021 The Khronos Group Inc.\n' 28header_string += ' * Copyright (c) 2015-2021 Valve Corporation\n' 29header_string += ' * Copyright (c) 2015-2021 LunarG, Inc.\n' 30header_string += ' * Copyright (c) 2015-2021 Google Inc.\n' 31header_string += ' * Copyright (c) 2021 Advanced Micro Devices, Inc.All rights reserved.\n' 32header_string += ' *\n' 33header_string += ' ****************************************************************************/\n' 34header_string += '#pragma once\n\n' 35header_string += '#ifndef _INTRINSIC_EXTENSION_HEADER_H_\n' 36header_string += '#define _INTRINSIC_EXTENSION_HEADER_H_\n\n' 37header_file .write (header_string ) 38 39symbol_name_list = [] 40 41for i in glsl_files : 42glsl_contents = open (i ,"r" ).read () 43 44filename = os .path .basename (i ) 45symbol_name = filename .split ("." )[0 ] 46symbol_name_list .append (symbol_name ) 47header_name = symbol_name + ".h" 48header_str = 'std::string %s_GLSL = R"(\n%s\n)";\n' % (symbol_name ,glsl_contents ) 49header_str += '\n' 50header_file .write (header_str ) 51 52contents = '' 53contents += '\n' 54contents += 'std::string getIntrinsic(const char* const* shaders, int n) {\n' 55contents += '\tstd::string shaderString = "";\n' ; 56 57contents += '\tfor (int i = 0; i < n; i++) {\n' 58 59for symbol_name in symbol_name_list : 60contents += '\t\tif (strstr(shaders[i], "%s") != nullptr) {\n' % (symbol_name ) 61contents += '\t\t shaderString.append(%s_GLSL);\n' % (symbol_name ) 62contents += '\t\t}\n' 63 64contents += '\t}\n' 65contents += '\treturn shaderString;\n' ; 66contents += '}\n' 67 68contents += '\n#endif\n' 69header_file .write (contents ) 70 71def main (): 72if len (sys .argv )< 2 : 73raise Exception ("Invalid number of arguments" ) 74 75i = 0 76while i < len (sys .argv ): 77opt = sys .argv [i ] 78i = i + 1 79 80if opt == "-i" or opt == "-o" : 81if i == len (sys .argv ): 82raise Exception ("Expected path after {}" .format (opt )) 83val = sys .argv [i ] 84i = i + 1 85if (opt == "-i" ): 86input_dir = val 87elif (opt == "-o" ): 88output_file = val 89else : 90raise Exception ("Unknown flag {}" .format (opt )) 91 92glsl_files = glob .glob (input_dir + '/*.glsl' ) 93 94# Generate main header 95generate_main (glsl_files ,output_file ) 96 97if __name__ == '__main__' : 98main ()