diff --git a/engine/src/flutter/impeller/compiler/compiler.cc b/engine/src/flutter/impeller/compiler/compiler.cc index 9bd9e076d8..27778f43bf 100644 --- a/engine/src/flutter/impeller/compiler/compiler.cc +++ b/engine/src/flutter/impeller/compiler/compiler.cc @@ -298,6 +298,10 @@ Compiler::Compiler(const fml::Mapping& source_mapping, { spirv_cross::CompilerMSL::Options msl_options; msl_options.platform = spirv_cross::CompilerMSL::Options::Platform::macOS; + // If this version specification changes, the GN rules that process the + // Metal to AIR must be updated as well. + msl_options.msl_version = + spirv_cross::CompilerMSL::Options::make_msl_version(1, 2); msl_compiler->set_msl_options(msl_options); } diff --git a/engine/src/flutter/impeller/tools/build_metal_library.py b/engine/src/flutter/impeller/tools/build_metal_library.py index fa06b8f45d..ef4913f72a 100644 --- a/engine/src/flutter/impeller/tools/build_metal_library.py +++ b/engine/src/flutter/impeller/tools/build_metal_library.py @@ -29,6 +29,10 @@ def Main(): parser.add_argument("--source", type=str, action="append", required=True, help="The source file to compile. Can be specified multiple times.") + parser.add_argument("--optimize", action="store_true", default=False, + help="If available optimizations must be applied to the compiled Metal sources.") + parser.add_argument("--platform", required=True, choices=["mac", "ios"], + help="Select the platform.") args = parser.parse_args() @@ -36,11 +40,21 @@ def Main(): command = [ "xcrun", + ] + + if args.platform == "mac": + command += [ + "-sdk", + "macosx", + ] + elif args.platform == "ios": + command += [ + "-sdk", + "iphoneos", + ] + + command += [ "metal", - # TODO: Embeds both sources and driver options in the output. This aids in - # debugging but should be removed from release builds. - "-MO", - "-gline-tables-only", # These warnings are from generated code and would make no sense to the GLSL # author. "-Wno-unused-variable", @@ -49,9 +63,38 @@ def Main(): "-MF", args.depfile, "-o", - args.output + args.output, ] + # The Metal standard must match the specification in impellerc. + if args.platform == "mac": + command += [ + "--std=macos-metal1.2", + ] + elif args.platform == "ios": + command += [ + "--std=ios-metal1.2", + ] + + if args.optimize: + command += [ + # Like -Os (and thus -O2), but reduces code size further. + "-Oz", + # Allow aggressive, lossy floating-point optimizations. + "-ffast-math", + ] + else: + command += [ + # Embeds both sources and driver options in the output. This aids in + # debugging but should be removed from release builds. + "-frecord-sources", + # Assist the sampling profiler. + "-gline-tables-only", + "-g", + # Optimize for debuggability. + "-Og", + ] + command += args.source subprocess.check_call(command) diff --git a/engine/src/flutter/impeller/tools/impeller.gni b/engine/src/flutter/impeller/tools/impeller.gni index f2310fb5e4..84aab888b0 100644 --- a/engine/src/flutter/impeller/tools/impeller.gni +++ b/engine/src/flutter/impeller/tools/impeller.gni @@ -75,6 +75,18 @@ template("metal_library") { rebase_path(depfile), ] + if (!is_debug) { + args += [ "--optimize" ] + } + + if (is_ios) { + args += [ "--platform=ios" ] + } else if (is_mac) { + args += [ "--platform=mac" ] + } else { + assert(false, "Unsupported platform for generating Metal shaders.") + } + foreach(source, invoker.sources) { args += [ "--source",