Skip to content

Commit b5d4f55

Browse files
authored
Merge branch 'master' into iphone_duo_uiscreen_wrong_display
2 parents f672394 + 7ebd815 commit b5d4f55

29 files changed

Lines changed: 1477 additions & 117 deletions

File tree

‎DEPS‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ vars = {
5555
# updated revision list of existing dependencies. You will need to
5656
# gclient sync before and after update deps to ensure all deps are updated.
5757
# updated revision list of existing dependencies.
58-
'dart_revision': '1d16c04dc3466eae19d688e22e47e9a5c0f5910b',
58+
'dart_revision': '65fc979759ca82d3f750fb644fd00f963d47e111',
5959

6060
# WARNING: DO NOT EDIT MANUALLY
6161
# The lines between blank lines above and below are generated by a script. See create_updated_flutter_deps.py

‎dev/devicelab/lib/tasks/perf_tests.dart‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,11 @@ class PerfTest {
15491549
if (data['99th_percentile_gpu_memory_mb'] != null) '99th_percentile_gpu_memory_mb',
15501550
if (data['worst_gpu_memory_mb'] != null) 'worst_gpu_memory_mb',
15511551
],
1552+
// Impeller shader warmup, reported by the new gallery's transition test.
1553+
if (data['shader_warmed_draw_percent'] != null) 'shader_warmed_draw_percent',
1554+
if (data['shader_lazy_variants'] != null) 'shader_lazy_variants',
1555+
if (data['shader_warmed_never_drawn_variants'] != null)
1556+
'shader_warmed_never_drawn_variants',
15521557
],
15531558
);
15541559
});

‎dev/devicelab/test/perf_tests_test.dart‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,50 @@ void main() {
151151
expect(result.data!['illegal_refresh_rate_frame_count'], 10);
152152
},
153153
);
154+
155+
test('reports Impeller shader warmup metrics when they are in the data', () async {
156+
final fakeData = <String, dynamic>{
157+
'frame_count': 5,
158+
'average_frame_build_time_millis': 0.1,
159+
'worst_frame_build_time_millis': 0.1,
160+
'90th_percentile_frame_build_time_millis': 0.1,
161+
'99th_percentile_frame_build_time_millis': 0.1,
162+
'average_frame_rasterizer_time_millis': 0.1,
163+
'worst_frame_rasterizer_time_millis': 0.1,
164+
'90th_percentile_frame_rasterizer_time_millis': 0.1,
165+
'99th_percentile_frame_rasterizer_time_millis': 0.1,
166+
'old_gen_gc_count': 1,
167+
'total_ui_gc_time': 1,
168+
'average_vsync_transitions_missed': 1,
169+
'90th_percentile_vsync_transitions_missed': 1,
170+
'99th_percentile_vsync_transitions_missed': 1,
171+
'shader_warmed_draw_percent': 92.65,
172+
'shader_lazy_variants': 20,
173+
'shader_warmed_never_drawn_variants': 3,
174+
};
175+
const resultFileName = 'fake_result';
176+
void driveCallback(List<String> arguments) {
177+
final resultFile = File('$perfTestOutputPath/$resultFileName.json')
178+
..createSync(recursive: true);
179+
resultFile.writeAsStringSync(json.encode(fakeData));
180+
}
181+
182+
final perfTest = PerfTest(
183+
testDirectory.absolute.path,
184+
testTarget.absolute.path,
185+
'test_file',
186+
resultFilename: resultFileName,
187+
device: device,
188+
flutterDriveCallback: driveCallback,
189+
);
190+
final TaskResult result = await perfTest.run();
191+
expect(
192+
result.benchmarkScoreKeys,
193+
containsAll(<String>[
194+
'shader_warmed_draw_percent',
195+
'shader_lazy_variants',
196+
'shader_warmed_never_drawn_variants',
197+
]),
198+
);
199+
});
154200
}

‎dev/integration_tests/new_gallery/test_driver/transitions_perf_test.dart‎

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:convert' show json;
6-
import 'dart:io' show sleep, stdout;
5+
import 'dart:convert' show JsonEncoder, json;
6+
import 'dart:io' show File, sleep, stdout;
77

88
import 'package:flutter_driver/flutter_driver.dart';
99
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
@@ -220,6 +220,94 @@ Future<void> runDemos(
220220
}
221221
}
222222

223+
/// Summarizes how well the Impeller pipelines created up front (warmed) covered
224+
/// the draws made so far, as reported by `_flutter.getPipelineUsage`.
225+
///
226+
/// Returns no metrics, rather than failing the benchmark, if pipeline usage is
227+
/// unavailable, for example because the app is not rendering with Impeller.
228+
Future<Map<String, Object?>> pipelineWarmupMetrics(FlutterDriver driver) async {
229+
try {
230+
final Map<String, Object?>? views = (await driver.serviceClient.callMethod(
231+
'_flutter.listViews',
232+
)).json;
233+
if (views case {'views': [{'id': final String viewId}, ...]}) {
234+
final Map<String, Object?>? usage = (await driver.serviceClient.callMethod(
235+
'_flutter.getPipelineUsage',
236+
args: <String, Object?>{'viewId': viewId},
237+
)).json;
238+
if (usage case {'pipelines': final List<Object?> pipelines}) {
239+
return _summarizePipelineUsage(pipelines);
240+
}
241+
throw FormatException(
242+
'Expected a "pipelines" list in the _flutter.getPipelineUsage response for view '
243+
'$viewId, but got keys ${usage?.keys.toList()}.',
244+
);
245+
}
246+
throw FormatException(
247+
'Expected at least one Flutter view in the _flutter.listViews response, but got $views.',
248+
);
249+
} catch (error) {
250+
stdout.writeln('Not reporting pipeline warmup metrics: $error');
251+
return const <String, Object?>{};
252+
}
253+
}
254+
255+
/// The warmup metrics for the `pipelines` of a `_flutter.getPipelineUsage`
256+
/// response. Also logs the pipelines that were created lazily, to help track
257+
/// down regressions.
258+
Map<String, Object?> _summarizePipelineUsage(List<Object?> pipelines) {
259+
var totalDraws = 0;
260+
var warmedDraws = 0;
261+
var warmedNeverDrawn = 0;
262+
final lazyPipelines = <String>[];
263+
for (final pipeline in pipelines) {
264+
if (pipeline case {
265+
'label': final String label,
266+
'constants': final List<Object?> constants,
267+
'count': final int count,
268+
'eagerly_created': final bool eagerlyCreated,
269+
}) {
270+
totalDraws += count;
271+
if (!eagerlyCreated) {
272+
final name = constants.isEmpty ? label : '$label $constants';
273+
lazyPipelines.add('$name: $count draws');
274+
} else if (count == 0) {
275+
warmedNeverDrawn += 1;
276+
} else {
277+
warmedDraws += count;
278+
}
279+
} else {
280+
throw FormatException(
281+
'Expected a label, constants, count and eagerly_created in each '
282+
'_flutter.getPipelineUsage entry, but got $pipeline.',
283+
);
284+
}
285+
}
286+
if (totalDraws == 0) {
287+
throw FormatException(
288+
'_flutter.getPipelineUsage reported ${pipelines.length} pipelines, but no draws.',
289+
);
290+
}
291+
292+
final double warmedDrawPercent = double.parse(
293+
(warmedDraws * 100 / totalDraws).toStringAsFixed(2),
294+
);
295+
stdout.writeln(
296+
'Impeller pipeline warmup: ${warmedDrawPercent.toStringAsFixed(2)}% of $totalDraws draws '
297+
'used a warmed pipeline, $warmedNeverDrawn warmed pipelines were never drawn with, and '
298+
'${lazyPipelines.length} pipelines were created lazily:',
299+
);
300+
lazyPipelines.sort();
301+
for (final pipeline in lazyPipelines) {
302+
stdout.writeln(' $pipeline');
303+
}
304+
return <String, Object?>{
305+
'shader_warmed_draw_percent': warmedDrawPercent,
306+
'shader_lazy_variants': lazyPipelines.length,
307+
'shader_warmed_never_drawn_variants': warmedNeverDrawn,
308+
};
309+
}
310+
223311
void main([List<String> args = const <String>[]]) {
224312
group('Flutter Gallery transitions', () {
225313
late FlutterDriver driver;
@@ -335,11 +423,20 @@ void main([List<String> args = const <String>[]]) {
335423
);
336424

337425
final summary = TimelineSummary.summarize(timeline);
338-
await summary.writeTimelineToFile('transitions', pretty: true);
426+
// The summary is written once every demo has run, so that it can include
427+
// the pipeline warmup metrics.
428+
await summary.writeTimelineToFile('transitions', pretty: true, includeSummary: false);
339429

340430
// Execute the remaining tests.
341431
final unprofiledDemos = Set<String>.from(_allDemos)..removeAll(_profiledDemos);
342432
await runDemos(unprofiledDemos.toList(), driver);
433+
434+
final summaryJson = <String, Object?>{
435+
...summary.summaryJson,
436+
...await pipelineWarmupMetrics(driver),
437+
};
438+
await File('$testOutputsDirectory/transitions.timeline_summary.json')
439+
.writeAsString(const JsonEncoder.withIndent(' ').convert(summaryJson));
343440
}, timeout: Timeout.none);
344441
});
345442
}

‎engine/src/flutter/impeller/entity/contents/content_context.cc‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,16 @@ class GenericVariants {
4747
pipelines_.push_back(std::make_pair(p_key, std::move(pipeline)));
4848
}
4949

50-
void SetDefault(const ContentContextOptions& options,
50+
/// Defaults are created ahead of time rather than on first use, so they are
51+
/// logged as eagerly created with the pipeline library.
52+
void SetDefault(PipelineLibrary& pipeline_library,
53+
const ContentContextOptions& options,
5154
std::unique_ptr<GenericRenderPipelineHandle> pipeline) {
5255
default_options_ = options;
5356
if (pipeline) {
57+
if (std::optional<PipelineDescriptor> desc = pipeline->GetDescriptor()) {
58+
pipeline_library.LogPipelineCreation(*desc);
59+
}
5460
Set(options, std::move(pipeline));
5561
}
5662
}
@@ -113,9 +119,10 @@ class Variants : public GenericVariants {
113119
GenericVariants::Set(options, std::move(pipeline));
114120
}
115121

116-
void SetDefault(const ContentContextOptions& options,
122+
void SetDefault(PipelineLibrary& pipeline_library,
123+
const ContentContextOptions& options,
117124
std::unique_ptr<PipelineHandleT> pipeline) {
118-
GenericVariants::SetDefault(options, std::move(pipeline));
125+
GenericVariants::SetDefault(pipeline_library, options, std::move(pipeline));
119126
}
120127

121128
void CreateDefault(const Context& context,
@@ -128,11 +135,11 @@ class Variants : public GenericVariants {
128135
VALIDATION_LOG << "Failed to create default pipeline.";
129136
return;
130137
}
131-
context.GetPipelineLibrary()->LogPipelineCreation(*desc);
132138
options.ApplyToPipelineDescriptor(*desc);
133139
desc_ = desc;
134-
SetDefault(options, std::make_unique<PipelineHandleT>(context, desc_,
135-
/*async=*/true));
140+
SetDefault(*context.GetPipelineLibrary(), options,
141+
std::make_unique<PipelineHandleT>(context, desc_,
142+
/*async=*/true));
136143
}
137144

138145
PipelineHandleT* Get(const ContentContextOptions& options) const {
@@ -147,8 +154,8 @@ class Variants : public GenericVariants {
147154
if (result != nullptr) {
148155
return result;
149156
}
150-
SetDefault(default_options_.value(), std::make_unique<PipelineHandleT>(
151-
context, desc_, /*async=*/false));
157+
Set(default_options_.value(),
158+
std::make_unique<PipelineHandleT>(context, desc_, /*async=*/false));
152159
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
153160
return Get(default_options_.value());
154161
}
@@ -704,7 +711,7 @@ ContentContext::ContentContext(
704711
clip_pipeline_descriptor->SetColorAttachmentDescriptors(
705712
std::move(clip_color_attachments));
706713
pipelines_->clip.SetDefault(
707-
options,
714+
*context_->GetPipelineLibrary(), options,
708715
std::make_unique<ClipPipeline>(*context_, clip_pipeline_descriptor));
709716
pipelines_->texture_downsample.CreateDefault(
710717
*context_, options_no_msaa_no_depth_stencil);

‎engine/src/flutter/impeller/entity/contents/pipeline_variant_recording.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class GenericRenderPipelineHandle;
4444
///
4545
struct RecordedPipelineVariant {
4646
/// The descriptor the variant's pipeline was created with. This is what
47-
/// `PipelineLibrary::GetPipelineUseCounts` is keyed by.
47+
/// `PipelineLibrary::GetPipelineUsage` is keyed by.
4848
PipelineDescriptor descriptor;
4949
ContentContextOptions options;
5050
/// True if the variant was created ahead of time (warmed) by the

‎engine/src/flutter/impeller/entity/contents/pipeline_variant_recording_unittests.cc‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "gtest/gtest.h"
1111
#include "impeller/entity/contents/content_context.h"
1212
#include "impeller/entity/entity_playground.h"
13+
#include "impeller/renderer/pipeline_library.h"
1314

1415
namespace impeller {
1516
namespace testing {
@@ -138,5 +139,39 @@ TEST_P(PipelineVariantRecordingTest, ReportsEachContextSeparately) {
138139
EXPECT_EQ(count_lazy(observer.GetReports()[1]), 1u);
139140
}
140141

142+
TEST_P(PipelineVariantRecordingTest,
143+
DefaultPipelinesAreLoggedAsEagerlyCreated) {
144+
#if FLUTTER_RUNTIME_MODE != FLUTTER_RUNTIME_MODE_DEBUG && \
145+
FLUTTER_RUNTIME_MODE != FLUTTER_RUNTIME_MODE_PROFILE
146+
GTEST_SKIP() << "Pipeline usage logging is only in debug and profile builds.";
147+
#else
148+
ContentContext content_context(GetContext(), GetTypographerContext());
149+
ASSERT_TRUE(content_context.IsValid());
150+
151+
ContentContextOptions default_options{
152+
.sample_count = SampleCount::kCount4,
153+
.color_attachment_pixel_format =
154+
GetContext()->GetCapabilities()->GetDefaultColorFormat()};
155+
PipelineRef solid_fill =
156+
content_context.GetSolidFillPipeline(default_options);
157+
ASSERT_TRUE(solid_fill);
158+
PipelineRef clip = content_context.GetClipPipeline(default_options);
159+
ASSERT_TRUE(clip);
160+
PipelineRef lazy_solid_fill =
161+
content_context.GetSolidFillPipeline(MakeLazyOptions(*GetContext()));
162+
ASSERT_TRUE(lazy_solid_fill);
163+
164+
const PipelineUsageMap usage =
165+
GetContext()->GetPipelineLibrary()->GetPipelineUsage();
166+
auto is_eagerly_created = [&usage](const PipelineDescriptor& descriptor) {
167+
auto found = usage.find(descriptor);
168+
return found != usage.end() && found->second.eagerly_created;
169+
};
170+
EXPECT_TRUE(is_eagerly_created(solid_fill->GetDescriptor()));
171+
EXPECT_TRUE(is_eagerly_created(clip->GetDescriptor()));
172+
EXPECT_FALSE(is_eagerly_created(lazy_solid_fill->GetDescriptor()));
173+
#endif
174+
}
175+
141176
} // namespace testing
142177
} // namespace impeller

‎engine/src/flutter/impeller/playground/pipeline_variant_recorder.cc‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ void PipelineVariantRecorder::Harvest(
350350
if (!library) {
351351
return;
352352
}
353-
const auto use_counts = library->GetPipelineUseCounts();
353+
const PipelineUsageMap pipeline_usage = library->GetPipelineUsage();
354354
const std::string backend = BackendTypeToString(context.GetBackendType());
355355

356356
Lock lock(mutex_);
@@ -377,11 +377,11 @@ void PipelineVariantRecorder::Harvest(
377377
}
378378

379379
record.latest.clear();
380-
for (const auto& [descriptor, count] : use_counts) {
381-
if (count <= 0) {
380+
for (const auto& [descriptor, usage] : pipeline_usage) {
381+
if (usage.count <= 0) {
382382
continue;
383383
}
384-
const uint64_t total = static_cast<uint64_t>(count);
384+
const uint64_t total = static_cast<uint64_t>(usage.count);
385385
record.latest[descriptor] = total;
386386
auto known = record.known.find(descriptor);
387387
if (known == record.known.end()) {

‎engine/src/flutter/impeller/renderer/BUILD.gn‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ impeller_component("renderer") {
9696
"../geometry",
9797
"../runtime_stage",
9898
"../tessellator",
99+
"//third_party/abseil-cpp/absl/container:flat_hash_map",
99100
"//third_party/abseil-cpp/absl/status",
100101
]
101102

0 commit comments

Comments
 (0)