64 行
2.7 KiB
Python
64 行
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Build the versioned AIR arithmetic and Dayu's authored Metal boundary."""
|
|
from pathlib import Path
|
|
import argparse
|
|
import re
|
|
import subprocess
|
|
from build_masked_kernel import masked_kernel
|
|
from float_air_boundary import float_boundary
|
|
|
|
|
|
def metal_tools():
|
|
component = subprocess.check_output(
|
|
['xcodebuild', '-showComponent', 'MetalToolchain'], text=True)
|
|
location = re.search(r'^Toolchain Search Path: (.+)$', component, re.MULTILINE)
|
|
if not location:
|
|
raise RuntimeError('Xcode did not report an installed Metal toolchain')
|
|
directory = Path(location.group(1)) / 'Metal.xctoolchain/usr/bin'
|
|
commands = {name: str(directory / name) for name in ('metal-opt', 'metal', 'metallib')}
|
|
for command in commands.values():
|
|
if not Path(command).is_file():
|
|
raise RuntimeError('Installed Metal tool is missing: ' + command)
|
|
return commands
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('--output', required=True, type=Path)
|
|
parser.add_argument('--intermediates', required=True, type=Path)
|
|
args = parser.parse_args()
|
|
tools = metal_tools()
|
|
root = Path(__file__).resolve().parent.parent
|
|
work = args.intermediates.resolve()
|
|
work.mkdir(parents=True, exist_ok=True)
|
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
objects = []
|
|
for name in ('DYGradeKernel', 'DYStatisticsKernel', 'DYLUTExportKernel', 'CSTKernel', 'BasisKernel'):
|
|
target = work / (name + '.air')
|
|
source = root / 'tools/kernels' / (name + '.ll')
|
|
if name == 'DYGradeKernel':
|
|
generated = work / 'DYGradeMasked.ll'
|
|
generated.write_text(masked_kernel(source.read_text()))
|
|
source = generated
|
|
if name in ('CSTKernel', 'BasisKernel'):
|
|
generated = work / (name + 'Float.ll')
|
|
generated.write_text(float_boundary(source.read_text(), name))
|
|
source = generated
|
|
subprocess.run([tools['metal-opt'], str(source),
|
|
'-o', str(target)], check=True)
|
|
objects.append(str(target))
|
|
wrapper = work / 'DYGradeWrapper.air'
|
|
subprocess.run([tools['metal'], '-std=metal3.1',
|
|
'-mmacosx-version-min=14.6', '-c',
|
|
str(root / '大鱼调色/Plugin/DYGrade.metal'), '-o', str(wrapper)], check=True)
|
|
tracking=work / 'DYTracking.air'
|
|
subprocess.run([tools['metal'],'-std=metal3.1','-mmacosx-version-min=14.6','-c',str(root/'大鱼调色/Plugin/DYTracking.metal'),'-o',str(tracking)],check=True)
|
|
objects.append(str(tracking))
|
|
subprocess.run([tools['metallib'], str(wrapper), *objects,
|
|
'-o', str(args.output)], check=True)
|
|
print(args.output)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|