Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dump-shader-skp switch to help ShaderWarmUp #8148

Merged
merged 4 commits into from
Mar 14, 2019

Conversation

liyuqian
Copy link
Contributor

@liyuqian liyuqian commented Mar 13, 2019

Allow Flutter to automatically dump the skp that triggers new shader compilations. This is useful for writing custom ShaderWarmUp to reduce jank. By default, it's not enabled to reduce the overhead. This is only available in profile or debug build.

Later, we can add service protocol support to pull the skp from the client to the host. Currently, it works fine for Android-based devices (including our urgent internal clients) where we can adb shell into the cache directory.

@@ -37,6 +37,8 @@
public static final String ARG_SKIA_DETERMINISTIC_RENDERING = "--skia-deterministic-rendering";
public static final String ARG_KEY_TRACE_SKIA = "trace-skia";
public static final String ARG_TRACE_SKIA = "--trace-skia";
public static final String ARG_KEY_DUMP_SHADER_SKP = "dump-shader-skp";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these need to be pulled out of the Intent in fromIntent()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Fixed.

Interestingly, we also have a similar logic in FlutterActivityDelegate.java. What's the difference between the two?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FlutterActivityDelegate is a mechanism in the old version of the embedding. FlutterShellArgs is part of the new embedding.

if (DrawToSurface(*layer_tree)) {
last_layer_tree_ = std::move(layer_tree);
}

#if FLUTTER_RUNTIME_MODE != FLUTTER_RUNTIME_MODE_RELEASE
if (persistent_cache->IsDumpingSkp() && persistent_cache->IsAccessed()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the #ifdefs, can all of this just be made conditional on IsDumpingSkp (which presumably will be false in release mode)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Let's make sure all the code compiles in all configurations. LTO should get rid of the unreachable code anyway. I also followed the same pattern in the raster cache which I will correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then I'll remove those #ifdefs assuming that there won't be a big impact on our binary code size. @goderbauer : if you find any significant regression related to this PR, please let me know and I'm happy to either revert it or add the #ifdefs back.


std::stringstream name_stream;
int current_index = skp_index_++;
skp_index_ %= kMaxSkpIndex;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why limit the maximum number of pictures captured? I'd suggest appending the timestamp to the end of the skp as well (std::to_string(fml::TimePoint::Now() or something)). Just so its in increasing order. This is a profiling feature anyway so the disk usage is not a concern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

skp_index_ %= kMaxSkpIndex;
name_stream << "shader_dump_" << current_index << ".skp";
std::string file_name = name_stream.str();
FML_LOG(INFO) << "Dumping " << file_name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to leave this log in here? We don't display this log level by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I see that only --verbose-logging will display such logs. I'll just leave it here and either send --verbose-logging manually or wait flutter/flutter#29320 to be fixed 😃

@@ -81,6 +81,7 @@ bool PersistentCache::IsValid() const {
// |GrContextOptions::PersistentCache|
sk_sp<SkData> PersistentCache::load(const SkData& key) {
TRACE_EVENT0("flutter", "PersistentCacheLoad");
is_accessed_ = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we only interested in pictures where a persistent cache entry is stored? In cases of cache loads, we are already reusing something that we have seen (and cached) before. My anticipation of the logic was:

  1. Skia asks us to store shaders for a new picture we have never seen before.
  2. We store the skp for that picture.

Copy link
Member

@chinmaygarde chinmaygarde Mar 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this some more: Maybe you didn't mean for this feature to say "give me the SKP dumps of new pictures that cause shader compilations", but instead, "give me all SKP dumps of pictures that already caused shader compilations". If the latter is the case, just look for all SKPs on disk. Either way, the is_accessed logic I think can be made more elegant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Changed the flag to switch on store instead on load.

liyuqian added a commit to liyuqian/flutter that referenced this pull request Mar 13, 2019
This is the accompanying change for
flutter/engine#8148 and it needs the engine PR
to land first.
@liyuqian liyuqian merged commit 66fdeb1 into flutter:master Mar 14, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 14, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 14, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 14, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 14, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 14, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 15, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 15, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 15, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Mar 15, 2019
flutter/engine@403337e...b36068c

git log 403337e..b36068c --no-merges --oneline
b36068c Roll src/third_party/skia 05201fc7e77e..aefecad7c0d2 (5 commits) (flutter/engine#8176)
b32d0ab Bugfix: Prevent crash when responding to a platform message after FlutterJNI detaches from native (#28651). (flutter/engine#8170)
d9b2f09 Roll src/third_party/skia 512e38091c85..05201fc7e77e (10 commits) (flutter/engine#8173)
4b01d79 Add frame and target time metadata to vsync events and connect platform vsync events using flows. (flutter/engine#8172)
f7a0922 [fuchsia] Remove deprecated libraries from snapshot (flutter/engine#8085)
09db84f Android Embedding PR 19: Add accessibility to new FlutterView. (flutter/engine#8109)
246f0e3 Add an allocator specific check to ensure that strings passed to the timeline are not heap allocated. (flutter/engine#8168)
7a6bb99 Roll src/third_party/skia feb720f746dc..512e38091c85 (11 commits) (flutter/engine#8169)
5825bda Roll src/third_party/dart 7d560f8385..7418238239 (61 commits)
66fdeb1 Add dump-shader-skp switch to help ShaderWarmUp (flutter/engine#8148)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff (jsimmons@google.com), and stop
the roller if necessary.
liyuqian added a commit to flutter/flutter that referenced this pull request Mar 15, 2019
This is the accompanying change for flutter/engine#8148 and it needs the engine PR to land first.

For #813
RBogie pushed a commit to RBogie/flutter-engine that referenced this pull request Apr 8, 2019
Allow Flutter to automatically dump the skp that triggers new shader compilations. This is useful for writing custom ShaderWarmUp to reduce jank. By default, it's not enabled to reduce the overhead. This is only available in profile or debug build.

Later, we can add service protocol support to pull the skp from the client to the host. Currently, it works fine for Android-based devices (including our urgent internal clients) where we can `adb shell` into the cache directory.
RBogie added a commit to RBogie/flutter-engine that referenced this pull request Apr 8, 2019
RBogie added a commit to RBogie/flutter-engine that referenced this pull request Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants