diff --git a/BUILD.gn b/BUILD.gn index 98a238deb35e0..a3cd12f7aa565 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -125,6 +125,7 @@ group("flutter") { "//flutter/display_list:display_list_builder_benchmarks", "//flutter/display_list:display_list_region_benchmarks", "//flutter/fml:fml_benchmarks", + "//flutter/impeller/aiks:canvas_benchmarks", "//flutter/impeller/geometry:geometry_benchmarks", "//flutter/lib/ui:ui_benchmarks", "//flutter/shell/common:shell_benchmarks", diff --git a/ci/builders/linux_host_engine.json b/ci/builders/linux_host_engine.json index 8c1f46f614f84..23fa252dc4ede 100644 --- a/ci/builders/linux_host_engine.json +++ b/ci/builders/linux_host_engine.json @@ -209,6 +209,7 @@ "flutter/display_list:display_list_builder_benchmarks", "flutter/fml:fml_benchmarks", "flutter/impeller/geometry:geometry_benchmarks", + "flutter/impeller/aiks:canvas_benchmarks", "flutter/lib/ui:ui_benchmarks", "flutter/shell/common:shell_benchmarks", "flutter/shell/testing", diff --git a/ci/builders/standalone/linux_benchmarks.json b/ci/builders/standalone/linux_benchmarks.json index 53b6a460db062..a408d9cf77866 100644 --- a/ci/builders/standalone/linux_benchmarks.json +++ b/ci/builders/standalone/linux_benchmarks.json @@ -23,6 +23,7 @@ "flutter/display_list:display_list_builder_benchmarks", "flutter/fml:fml_benchmarks", "flutter/impeller/geometry:geometry_benchmarks", + "flutter/impeller/aiks:canvas_benchmarks", "flutter/lib/ui:ui_benchmarks", "flutter/shell/common:shell_benchmarks", "flutter/shell/testing", diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 34ad289b5f0c7..22d3e68741eb6 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -4857,6 +4857,7 @@ ORIGIN: ../../../flutter/impeller/aiks/aiks_playground_inspector.cc + ../../../f ORIGIN: ../../../flutter/impeller/aiks/aiks_playground_inspector.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/aiks/canvas.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/aiks/canvas.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/impeller/aiks/canvas_benchmarks.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/aiks/canvas_recorder.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/aiks/canvas_type.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/impeller/aiks/color_filter.cc + ../../../flutter/LICENSE @@ -7648,6 +7649,7 @@ FILE: ../../../flutter/impeller/aiks/aiks_playground_inspector.cc FILE: ../../../flutter/impeller/aiks/aiks_playground_inspector.h FILE: ../../../flutter/impeller/aiks/canvas.cc FILE: ../../../flutter/impeller/aiks/canvas.h +FILE: ../../../flutter/impeller/aiks/canvas_benchmarks.cc FILE: ../../../flutter/impeller/aiks/canvas_recorder.h FILE: ../../../flutter/impeller/aiks/canvas_type.h FILE: ../../../flutter/impeller/aiks/color_filter.cc diff --git a/impeller/aiks/BUILD.gn b/impeller/aiks/BUILD.gn index f341021bdf5d3..3d714e58b5c24 100644 --- a/impeller/aiks/BUILD.gn +++ b/impeller/aiks/BUILD.gn @@ -121,3 +121,12 @@ impeller_component("aiks_unittests_golden") { "//flutter/testing:testing_lib", ] } + +executable("canvas_benchmarks") { + testonly = true + sources = [ "canvas_benchmarks.cc" ] + deps = [ + ":aiks", + "//flutter/benchmarking", + ] +} diff --git a/impeller/aiks/canvas_benchmarks.cc b/impeller/aiks/canvas_benchmarks.cc new file mode 100644 index 0000000000000..8f4a310e0ceb7 --- /dev/null +++ b/impeller/aiks/canvas_benchmarks.cc @@ -0,0 +1,63 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/benchmarking/benchmarking.h" + +#include "impeller/aiks/canvas.h" + +namespace impeller { + +namespace { + +using CanvasCallback = size_t (*)(Canvas&); + +size_t DrawRect(Canvas& canvas) { + for (auto i = 0; i < 500; i++) { + canvas.DrawRect(Rect::MakeLTRB(0, 0, 100, 100), + {.color = Color::DarkKhaki()}); + } + return 500; +} + +size_t DrawCircle(Canvas& canvas) { + for (auto i = 0; i < 500; i++) { + canvas.DrawCircle({100, 100}, 5, {.color = Color::DarkKhaki()}); + } + return 500; +} + +size_t DrawLine(Canvas& canvas) { + for (auto i = 0; i < 500; i++) { + canvas.DrawLine({0, 0}, {100, 100}, {.color = Color::DarkKhaki()}); + } + return 500; +} +} // namespace + +// A set of benchmarks that measures the CPU cost of encoding canvas operations. +// These benchmarks do not measure the cost of conversion through the HAL, no +// do they measure the GPU side cost of executing the required shader programs. +template +static void BM_CanvasRecord(benchmark::State& state, Args&&... args) { + auto args_tuple = std::make_tuple(std::move(args)...); + auto test_proc = std::get(args_tuple); + + size_t op_count = 0u; + size_t canvas_count = 0u; + while (state.KeepRunning()) { + // A new canvas is allocated for each iteration to avoid the benchmark + // becoming a measurement of only the entity vector re-allocation time. + Canvas canvas; + op_count += test_proc(canvas); + canvas_count++; + } + state.counters["TotalOpCount"] = op_count; + state.counters["TotalCanvasCount"] = canvas_count; +} + +BENCHMARK_CAPTURE(BM_CanvasRecord, draw_rect, &DrawRect); +BENCHMARK_CAPTURE(BM_CanvasRecord, draw_circle, &DrawCircle); +BENCHMARK_CAPTURE(BM_CanvasRecord, draw_line, &DrawLine); + +} // namespace impeller diff --git a/testing/benchmark/generate_metrics.sh b/testing/benchmark/generate_metrics.sh index 80761055f961d..3c8168c01ed2f 100644 --- a/testing/benchmark/generate_metrics.sh +++ b/testing/benchmark/generate_metrics.sh @@ -15,3 +15,4 @@ $ENGINE_PATH/src/out/host_release/shell_benchmarks --benchmark_format=json > $EN $ENGINE_PATH/src/out/host_release/ui_benchmarks --benchmark_format=json > $ENGINE_PATH/src/out/host_release/ui_benchmarks.json $ENGINE_PATH/src/out/host_release/display_list_builder_benchmarks --benchmark_format=json > $ENGINE_PATH/src/out/host_release/display_list_builder_benchmarks.json $ENGINE_PATH/src/out/host_release/geometry_benchmarks --benchmark_format=json > $ENGINE_PATH/src/out/host_release/geometry_benchmarks.json +$ENGINE_PATH/src/out/host_release/canvas_benchmarks --benchmark_format=json > $ENGINE_PATH/src/out/host_release/canvas_benchmarks.json diff --git a/testing/benchmark/upload_metrics.sh b/testing/benchmark/upload_metrics.sh index c3f66e9e6d3e0..e28c514d6b4e2 100644 --- a/testing/benchmark/upload_metrics.sh +++ b/testing/benchmark/upload_metrics.sh @@ -48,3 +48,5 @@ cd "$SCRIPT_DIR" --json $ENGINE_PATH/src/out/host_release/display_list_builder_benchmarks.json "$@" "$DART" --disable-dart-dev bin/parse_and_send.dart \ --json $ENGINE_PATH/src/out/host_release/geometry_benchmarks.json "$@" +"$DART" --disable-dart-dev bin/parse_and_send.dart \ + --json $ENGINE_PATH/src/out/host_release/canvas_benchmarks.json "$@" diff --git a/testing/run_tests.py b/testing/run_tests.py index 003cb661da0c6..62ebcd507592a 100755 --- a/testing/run_tests.py +++ b/testing/run_tests.py @@ -580,6 +580,10 @@ def run_engine_benchmarks(build_dir, executable_filter): build_dir, 'geometry_benchmarks', executable_filter, icu_flags ) + run_engine_executable( + build_dir, 'canvas_benchmarks', executable_filter, icu_flags + ) + if is_linux(): run_engine_executable( build_dir, 'txt_benchmarks', executable_filter, icu_flags