Commit 188d0fe6 by Jamie Madill Committed by Commit Bot

Make Metal shader-gen cross platform.

This switches the generator script use the hermetic Clang instead of the system gcc/clang. It also uses common Python routines to manage the temporary file so that it works consistently on Win. Bug: angleproject:5186 Change-Id: I52906d1a708db8b925061a9d5578b3d54a6dc862 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2483464Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarLe Hoang Quyen <le.hoang.q@gmail.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 5b7c5b34
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
"src/libANGLE/renderer/metal/shaders/gen_mipmap.metal": "src/libANGLE/renderer/metal/shaders/gen_mipmap.metal":
"54dca94c48bead446624079070b9b309", "54dca94c48bead446624079070b9b309",
"src/libANGLE/renderer/metal/shaders/gen_mtl_internal_shaders.py": "src/libANGLE/renderer/metal/shaders/gen_mtl_internal_shaders.py":
"9f538745533b6bb14fbbc9e4252f31e0", "b48af61c8b02dda646b4c8febce50227",
"src/libANGLE/renderer/metal/shaders/mtl_default_shaders_src_autogen.inc": "src/libANGLE/renderer/metal/shaders/mtl_default_shaders_src_autogen.inc":
"2a0b015ebec36ee1304ae64a7187abb8", "72e525145bc8f11993791c0f44e79b33",
"src/libANGLE/renderer/metal/shaders/visibility.metal": "src/libANGLE/renderer/metal/shaders/visibility.metal":
"b82aa740cf4b0aed606aacef1024beea" "b82aa740cf4b0aed606aacef1024beea"
} }
\ No newline at end of file
...@@ -7,9 +7,11 @@ ...@@ -7,9 +7,11 @@
# Code generation for Metal backend's default shaders. # Code generation for Metal backend's default shaders.
# NOTE: don't run this script directly. Run scripts/run_code_generation.py. # NOTE: don't run this script directly. Run scripts/run_code_generation.py.
import json
import os import os
import subprocess
import sys import sys
import json
from datetime import datetime from datetime import datetime
sys.path.append('../..') sys.path.append('../..')
...@@ -51,6 +53,21 @@ def gen_shader_enums_code(angle_formats): ...@@ -51,6 +53,21 @@ def gen_shader_enums_code(angle_formats):
return code return code
def find_clang():
if os.name == 'nt':
binary = 'clang-cl.exe'
else:
binary = 'clang++'
clang = os.path.join('..', '..', '..', '..', '..', 'third_party', 'llvm-build',
'Release+Asserts', 'bin', binary)
if not os.path.isfile(clang):
raise Exception('Cannot find clang')
return clang
def main(): def main():
angle_format_script_files = [ angle_format_script_files = [
'../../angle_format_map.json', '../../angle_format.py', '../../gen_angle_format_table.py' '../../angle_format_map.json', '../../angle_format.py', '../../gen_angle_format_table.py'
...@@ -89,25 +106,25 @@ def main(): ...@@ -89,25 +106,25 @@ def main():
out_file.close() out_file.close()
# -------- Combine and create shader source string ----------- # -------- Combine and create shader source string -----------
# Generate a combination source # Generate combined source
os.system('mkdir -p temp && rm -f temp/master_source.metal && touch temp/master_source.metal') clang = find_clang()
for src_file in src_files:
os.system('echo "#include \\"../{0}\\"" >> temp/master_source.metal'.format(src_file))
# Use clang/gcc to preprocess the combination source. "@@" token is used to prevent clang from # Use clang to preprocess the combination source. "@@" token is used to prevent clang from
# expanding the preprocessor directive # expanding the preprocessor directive
if os.system('which gcc') == 0: temp_fname = 'temp_master_source.metal'
print('combining source files using gcc -E') with open(temp_fname, 'wb') as temp_file:
os.system('gcc -xc++ -E temp/master_source.metal > temp/master_source.metal.pp') for src_file in src_files:
else: temp_file.write('#include "%s"\n' % src_file)
print('combining source files using clang -E')
os.system('clang -xc++ -E temp/master_source.metal > temp/master_source.metal.pp') args = [clang]
if not os.name == 'nt':
args += ['-xc++']
args += ['-E', temp_fname]
combined_source = subprocess.check_output(args)
# Remove '@@' tokens # Remove '@@' tokens
final_combined_src_string = '' final_combined_src_string = combined_source.replace('@@', '')
with open('temp/master_source.metal.pp', 'rt') as in_file:
final_combined_src_string = in_file.read().replace('@@', '')
in_file.close()
# Generate final file: # Generate final file:
with open('mtl_default_shaders_src_autogen.inc', 'wt') as out_file: with open('mtl_default_shaders_src_autogen.inc', 'wt') as out_file:
...@@ -120,9 +137,7 @@ def main(): ...@@ -120,9 +137,7 @@ def main():
out_file.write(')";\n') out_file.write(')";\n')
out_file.close() out_file.close()
# Clean up os.remove(temp_fname)
os.system('rm -rf temp')
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment