From 0ba039231ab46a59b445328207143386d923753e Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 13 Nov 2023 10:16:50 -0800 Subject: [PATCH] [Impeller] Add convex tess benchmark. (flutter/engine#47956) Since most shapes are convex, we should benchmark this too. --- .../impeller/geometry/geometry_benchmarks.cc | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/engine/src/flutter/impeller/geometry/geometry_benchmarks.cc b/engine/src/flutter/impeller/geometry/geometry_benchmarks.cc index ca97d7b181..7f88021a0d 100644 --- a/engine/src/flutter/impeller/geometry/geometry_benchmarks.cc +++ b/engine/src/flutter/impeller/geometry/geometry_benchmarks.cc @@ -16,6 +16,8 @@ namespace { Path CreateCubic(); /// Similar to the path above, but with all cubics replaced by quadratics. Path CreateQuadratic(); +/// Create a rounded rect. +Path CreateRRect(); } // namespace static Tessellator tess; @@ -62,12 +64,38 @@ static void BM_Polyline(benchmark::State& state, Args&&... args) { state.counters["TotalPointCount"] = point_count; } +template +static void BM_Convex(benchmark::State& state, Args&&... args) { + auto args_tuple = std::make_tuple(std::move(args)...); + auto path = std::get(args_tuple); + + size_t point_count = 0u; + size_t single_point_count = 0u; + auto points = std::make_unique>(); + points->reserve(2048); + while (state.KeepRunning()) { + auto [points, index] = tess.TessellateConvex(path, 1.0f); + single_point_count = index.size(); + point_count += index.size(); + } + state.counters["SinglePointCount"] = single_point_count; + state.counters["TotalPointCount"] = point_count; +} + BENCHMARK_CAPTURE(BM_Polyline, cubic_polyline, CreateCubic(), false); BENCHMARK_CAPTURE(BM_Polyline, cubic_polyline_tess, CreateCubic(), true); BENCHMARK_CAPTURE(BM_Polyline, quad_polyline, CreateQuadratic(), false); BENCHMARK_CAPTURE(BM_Polyline, quad_polyline_tess, CreateQuadratic(), true); +BENCHMARK_CAPTURE(BM_Convex, rrect_convex, CreateRRect(), true); namespace { + +Path CreateRRect() { + return PathBuilder{} + .AddRoundedRect(Rect::MakeLTRB(0, 0, 400, 400), 16) + .TakePath(); +} + Path CreateCubic() { return PathBuilder{} .MoveTo({359.934, 96.6335})