@@ -29,18 +29,32 @@ def Main():
2929 parser .add_argument ("--source" ,
3030 type = str , action = "append" , required = True ,
3131 help = "The source file to compile. Can be specified multiple times." )
32+ parser .add_argument ("--optimize" , action = "store_true" , default = False ,
33+ help = "If available optimizations must be applied to the compiled Metal sources." )
34+ parser .add_argument ("--platform" , required = True , choices = ["mac" , "ios" ],
35+ help = "Select the platform." )
3236
3337 args = parser .parse_args ()
3438
3539 MakeDirectories (os .path .dirname (args .depfile ))
3640
3741 command = [
3842 "xcrun" ,
43+ ]
44+
45+ if args .platform == "mac" :
46+ command += [
47+ "-sdk" ,
48+ "macosx" ,
49+ ]
50+ elif args .platform == "ios" :
51+ command += [
52+ "-sdk" ,
53+ "iphoneos" ,
54+ ]
55+
56+ command += [
3957 "metal" ,
40- # TODO: Embeds both sources and driver options in the output. This aids in
41- # debugging but should be removed from release builds.
42- "-MO" ,
43- "-gline-tables-only" ,
4458 # These warnings are from generated code and would make no sense to the GLSL
4559 # author.
4660 "-Wno-unused-variable" ,
@@ -49,9 +63,38 @@ def Main():
4963 "-MF" ,
5064 args .depfile ,
5165 "-o" ,
52- args .output
66+ args .output ,
5367 ]
5468
69+ # The Metal standard must match the specification in impellerc.
70+ if args .platform == "mac" :
71+ command += [
72+ "--std=macos-metal1.2" ,
73+ ]
74+ elif args .platform == "ios" :
75+ command += [
76+ "--std=ios-metal1.2" ,
77+ ]
78+
79+ if args .optimize :
80+ command += [
81+ # Like -Os (and thus -O2), but reduces code size further.
82+ "-Oz" ,
83+ # Allow aggressive, lossy floating-point optimizations.
84+ "-ffast-math" ,
85+ ]
86+ else :
87+ command += [
88+ # Embeds both sources and driver options in the output. This aids in
89+ # debugging but should be removed from release builds.
90+ "-frecord-sources" ,
91+ # Assist the sampling profiler.
92+ "-gline-tables-only" ,
93+ "-g" ,
94+ # Optimize for debuggability.
95+ "-Og" ,
96+ ]
97+
5598 command += args .source
5699
57100 subprocess .check_call (command )
0 commit comments