Skip to content

Commit 5466588

Browse files
authored
[Impeller] Generate a Metal library symbols file for shader debugging. (#39532)
Towards fixing #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.
1 parent b3e9642 commit 5466588

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

impeller/renderer/backend/metal/context_mtl.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@
149149
<< shader_library_error.localizedDescription.UTF8String;
150150
return nil;
151151
}
152+
if (!label.empty()) {
153+
library.label = @(label.c_str());
154+
}
152155
[found_libraries addObject:library];
153156
}
154157
return found_libraries;

impeller/tools/build_metal_library.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def main():
8181
'-Oz',
8282
# Allow aggressive, lossy floating-point optimizations.
8383
'-ffast-math',
84+
# Record symbols in a separate *.metallibsym file.
85+
'-frecord-sources=flat',
8486
'-MF',
8587
args.depfile,
8688
'-o',
@@ -97,7 +99,7 @@ def main():
9799
elif args.platform == 'ios':
98100
command += [
99101
'--std=ios-metal1.2',
100-
'-mios-version-min=10.0',
102+
'-mios-version-min=11.0',
101103
]
102104
elif args.platform == 'ios-simulator':
103105
command += [

impeller/tools/impeller.gni

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,13 @@ template("metal_library") {
130130
inputs = invoker.sources
131131

132132
metal_library_path = "$root_out_dir/shaders/$metal_library_name.metallib"
133+
metal_library_symbols_path =
134+
"$root_out_dir/shaders/$metal_library_name.metallibsym"
133135

134-
outputs = [ metal_library_path ]
136+
outputs = [
137+
metal_library_path,
138+
metal_library_symbols_path,
139+
]
135140

136141
script = "//flutter/impeller/tools/build_metal_library.py"
137142

0 commit comments

Comments
 (0)