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 @@
"src/libANGLE/renderer/metal/shaders/gen_mipmap.metal":
"54dca94c48bead446624079070b9b309",
"src/libANGLE/renderer/metal/shaders/gen_mtl_internal_shaders.py":
"9f538745533b6bb14fbbc9e4252f31e0",
"b48af61c8b02dda646b4c8febce50227",
"src/libANGLE/renderer/metal/shaders/mtl_default_shaders_src_autogen.inc":
"2a0b015ebec36ee1304ae64a7187abb8",
"72e525145bc8f11993791c0f44e79b33",
"src/libANGLE/renderer/metal/shaders/visibility.metal":
"b82aa740cf4b0aed606aacef1024beea"
}
\ No newline at end of file
......@@ -7,9 +7,11 @@
# Code generation for Metal backend's default shaders.
# NOTE: don't run this script directly. Run scripts/run_code_generation.py.
import json
import os
import subprocess
import sys
import json
from datetime import datetime
sys.path.append('../..')
......@@ -51,6 +53,21 @@ def gen_shader_enums_code(angle_formats):
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():
angle_format_script_files = [
'../../angle_format_map.json', '../../angle_format.py', '../../gen_angle_format_table.py'
......@@ -89,25 +106,25 @@ def main():
out_file.close()
# -------- Combine and create shader source string -----------
# Generate a combination source
os.system('mkdir -p temp && rm -f temp/master_source.metal && touch temp/master_source.metal')
for src_file in src_files:
os.system('echo "#include \\"../{0}\\"" >> temp/master_source.metal'.format(src_file))
# Generate combined source
clang = find_clang()
# 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
if os.system('which gcc') == 0:
print('combining source files using gcc -E')
os.system('gcc -xc++ -E temp/master_source.metal > temp/master_source.metal.pp')
else:
print('combining source files using clang -E')
os.system('clang -xc++ -E temp/master_source.metal > temp/master_source.metal.pp')
temp_fname = 'temp_master_source.metal'
with open(temp_fname, 'wb') as temp_file:
for src_file in src_files:
temp_file.write('#include "%s"\n' % src_file)
args = [clang]
if not os.name == 'nt':
args += ['-xc++']
args += ['-E', temp_fname]
combined_source = subprocess.check_output(args)
# Remove '@@' tokens
final_combined_src_string = ''
with open('temp/master_source.metal.pp', 'rt') as in_file:
final_combined_src_string = in_file.read().replace('@@', '')
in_file.close()
final_combined_src_string = combined_source.replace('@@', '')
# Generate final file:
with open('mtl_default_shaders_src_autogen.inc', 'wt') as out_file:
......@@ -120,9 +137,7 @@ def main():
out_file.write(')";\n')
out_file.close()
# Clean up
os.system('rm -rf temp')
os.remove(temp_fname)
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