[Impeller] Generate a Metal library symbols file for shader debugging. (flutter/engine#39532)

Towards fixing https://github.com/flutter/flutter/issues/120326. This allows you
to specify the sources for the Impeller Metal Library. The user is meant to
navigate to `out/<engine_variant>/shaders/entity.metallib` when Xcode prompts
for sources.

Shader debugging with line by line profiling is still not a turnkey operation
though. This works fine on macOS. But on iOS, I had to bump up the min iOS
version level to iOS 12 at least and specify `-g` to the `metal` compiler for
the sources to show up with profiling. The performance of the shaders was
identical after the changes though so I suspect engine developers will patch in
these flags locally to develop and debug shaders.
This commit is contained in:
Chinmay Garde
2023-02-09 23:08:37 -08:00
committed by GitHub
parent 4d586c0346
commit bff4694739
3 changed files with 12 additions and 2 deletions

View File

@@ -149,6 +149,9 @@ static NSArray<id<MTLLibrary>>* MTLShaderLibraryFromFileData(
<< shader_library_error.localizedDescription.UTF8String;
return nil;
}
if (!label.empty()) {
library.label = @(label.c_str());
}
[found_libraries addObject:library];
}
return found_libraries;

View File

@@ -81,6 +81,8 @@ def main():
'-Oz',
# Allow aggressive, lossy floating-point optimizations.
'-ffast-math',
# Record symbols in a separate *.metallibsym file.
'-frecord-sources=flat',
'-MF',
args.depfile,
'-o',
@@ -97,7 +99,7 @@ def main():
elif args.platform == 'ios':
command += [
'--std=ios-metal1.2',
'-mios-version-min=10.0',
'-mios-version-min=11.0',
]
elif args.platform == 'ios-simulator':
command += [

View File

@@ -130,8 +130,13 @@ template("metal_library") {
inputs = invoker.sources
metal_library_path = "$root_out_dir/shaders/$metal_library_name.metallib"
metal_library_symbols_path =
"$root_out_dir/shaders/$metal_library_name.metallibsym"
outputs = [ metal_library_path ]
outputs = [
metal_library_path,
metal_library_symbols_path,
]
script = "//flutter/impeller/tools/build_metal_library.py"