Holy size savings Batman!
Optimize and compress shaders for size in release modes.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user