Skip to content

Commit b29df1d

Browse files
walley892gaaclarke
andauthored
Add path rendering benchmarks (flutter#188654)
Adds primitive rendering benchmarks for path drawing operations. Pre work for implementing a solution to [185117](flutter#185117) ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: gaaclarke <[email protected]>
1 parent 1204b7a commit b29df1d

1 file changed

Lines changed: 101 additions & 1 deletion

File tree

‎engine/src/flutter/display_list/benchmarking/dl_benchmarks.cc‎

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ constexpr size_t kRRectsToDraw = 5000;
159159
constexpr size_t kRSEsToDraw = 5000;
160160
constexpr size_t kDRRectsToDraw = 2000;
161161
constexpr size_t kArcSweepSetsToDraw = 1000;
162+
constexpr size_t kPathsToDraw = 2000;
162163
constexpr size_t kImagesToDraw = 500;
163164
constexpr size_t kFixedCanvasSize = 1024;
164165

@@ -940,6 +941,98 @@ void BM_DrawPath(benchmark::State& state,
940941
"DrawPath-" + label);
941942
}
942943

944+
void BM_DrawPathPrimitives(benchmark::State& state,
945+
BackendType backend_type,
946+
unsigned attributes,
947+
PathVerb type) {
948+
auto surface_provider = DlSurfaceProvider::Create(backend_type);
949+
DisplayListBuilder builder;
950+
DlPaint paint = GetPaintForRun(attributes);
951+
952+
CheckAttributes(attributes, state, DisplayListOpFlags::kDrawPathFlags);
953+
954+
size_t length = state.range(0);
955+
surface_provider->InitializeSurface(length * 2, length * 2);
956+
auto surface = surface_provider->GetPrimarySurface();
957+
surface->Clear(DlColor::kTransparent());
958+
surface->FlushSubmitCpuSync();
959+
960+
DlPathBuilder path_builder;
961+
DlPoint center = DlPoint(length / 2.0f, length / 2.0f);
962+
float radius = length / 2.0f;
963+
964+
switch (type) {
965+
case PathVerb::kLine:
966+
GetLinesPath(path_builder, 10, center, radius);
967+
break;
968+
case PathVerb::kQuad:
969+
GetQuadsPath(path_builder, 10, center, radius);
970+
break;
971+
case PathVerb::kConic:
972+
GetConicsPath(path_builder, 10, center, radius);
973+
break;
974+
case PathVerb::kCubic:
975+
GetCubicsPath(path_builder, 10, center, radius);
976+
break;
977+
}
978+
DlPath path = path_builder.TakePath();
979+
980+
const DlPoint delta(0.5f, 0.5f);
981+
RectAnimator animator(DlRect::MakeWH(length, length), delta, surface);
982+
983+
state.counters["DrawCallCount"] = kPathsToDraw;
984+
for (size_t i = 0; i < kPathsToDraw; i++) {
985+
builder.Save();
986+
builder.Translate(animator.GetPoint().x, animator.GetPoint().y);
987+
builder.DrawPath(path, paint);
988+
builder.Restore();
989+
animator.Animate();
990+
}
991+
992+
auto display_list = builder.Build();
993+
994+
// Prime any path conversions
995+
surface->RenderDisplayList(display_list);
996+
surface->FlushSubmitCpuSync();
997+
998+
// We only want to time the actual rasterization.
999+
size_t items_processed = 0;
1000+
for ([[maybe_unused]] auto _ : state) {
1001+
surface->RenderDisplayList(display_list);
1002+
items_processed += kPathsToDraw;
1003+
surface->FlushSubmitCpuSync();
1004+
}
1005+
state.SetItemsProcessed(items_processed);
1006+
1007+
std::string label = VerbToString(type);
1008+
SaveSnapshotIfNecessary(surface_provider, surface, state,
1009+
"DrawPathPrimitives-" + label);
1010+
}
1011+
1012+
void BM_DrawPathLine(benchmark::State& state,
1013+
BackendType backend_type,
1014+
unsigned attributes) {
1015+
BM_DrawPathPrimitives(state, backend_type, attributes, PathVerb::kLine);
1016+
}
1017+
1018+
void BM_DrawPathQuad(benchmark::State& state,
1019+
BackendType backend_type,
1020+
unsigned attributes) {
1021+
BM_DrawPathPrimitives(state, backend_type, attributes, PathVerb::kQuad);
1022+
}
1023+
1024+
void BM_DrawPathConic(benchmark::State& state,
1025+
BackendType backend_type,
1026+
unsigned attributes) {
1027+
BM_DrawPathPrimitives(state, backend_type, attributes, PathVerb::kConic);
1028+
}
1029+
1030+
void BM_DrawPathCubic(benchmark::State& state,
1031+
BackendType backend_type,
1032+
unsigned attributes) {
1033+
BM_DrawPathPrimitives(state, backend_type, attributes, PathVerb::kCubic);
1034+
}
1035+
9431036
// Returns a set of vertices that describe a circle that has a
9441037
// radius of `radius` and outer vertex count of approximately
9451038
// `vertex_count`. The final number of vertices will differ as we
@@ -1676,6 +1769,12 @@ constexpr int kFilledShadow10Primitive =
16761769
DRAW_BENCHMARK_SHADOW_PRIMITIVE(BACKEND, TYPE, FilledShadow5) \
16771770
DRAW_BENCHMARK_SHADOW_PRIMITIVE(BACKEND, TYPE, FilledShadow10) \
16781771

1772+
#define DRAW_BENCHMARK_PRIMITIVES_PATH(BACKEND) \
1773+
DRAW_BENCHMARK_PRIMITIVES_TYPE(BACKEND, PathLine) \
1774+
DRAW_BENCHMARK_PRIMITIVES_TYPE(BACKEND, PathQuad) \
1775+
DRAW_BENCHMARK_PRIMITIVES_TYPE(BACKEND, PathConic) \
1776+
DRAW_BENCHMARK_PRIMITIVES_TYPE(BACKEND, PathCubic)
1777+
16791778
#define DRAW_BENCHMARK_PRIMITIVE_SUITE(BACKEND) \
16801779
BENCHMARK_OVERHEAD(SyncOverhead, BACKEND) \
16811780
BENCHMARK_OVERHEAD(EmptyDisplayList, BACKEND) \
@@ -1687,7 +1786,8 @@ constexpr int kFilledShadow10Primitive =
16871786
DRAW_BENCHMARK_PRIMITIVES_TYPE(BACKEND, SimpleRRect) \
16881787
DRAW_BENCHMARK_PRIMITIVES_TYPE(BACKEND, ComplexRRect) \
16891788
DRAW_BENCHMARK_PRIMITIVES_TYPE(BACKEND, SimpleRSE) \
1690-
DRAW_BENCHMARK_PRIMITIVES_TYPE(BACKEND, ComplexRSE)
1789+
DRAW_BENCHMARK_PRIMITIVES_TYPE(BACKEND, ComplexRSE) \
1790+
DRAW_BENCHMARK_PRIMITIVES_PATH(BACKEND)
16911791

16921792
// clang-format on
16931793

0 commit comments

Comments
 (0)