From 710e95360f1e2cf3852f9131fbaeafeb9cdd64d1 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Thu, 9 Feb 2023 21:31:00 -0800 Subject: [PATCH] [Impeller] Generate a Metal library symbols file for shader debugging. 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//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. --- impeller/renderer/backend/metal/context_mtl.mm | 3 +++ impeller/tools/build_metal_library.py | 4 +++- impeller/tools/impeller.gni | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/impeller/renderer/backend/metal/context_mtl.mm b/impeller/renderer/backend/metal/context_mtl.mm index faedec8e5bf2b..b4effef0a3a2e 100644 --- a/impeller/renderer/backend/metal/context_mtl.mm +++ b/impeller/renderer/backend/metal/context_mtl.mm @@ -149,6 +149,9 @@ << shader_library_error.localizedDescription.UTF8String; return nil; } + if (!label.empty()) { + library.label = @(label.c_str()); + } [found_libraries addObject:library]; } return found_libraries; diff --git a/impeller/tools/build_metal_library.py b/impeller/tools/build_metal_library.py index 8556042e5c186..90d5fbf78451d 100644 --- a/impeller/tools/build_metal_library.py +++ b/impeller/tools/build_metal_library.py @@ -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 += [ diff --git a/impeller/tools/impeller.gni b/impeller/tools/impeller.gni index 793d9f10dc814..2db7cb37877c4 100644 --- a/impeller/tools/impeller.gni +++ b/impeller/tools/impeller.gni @@ -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"