Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 843ecc5

Browse files
authored
[Impeller] Add stroke benchmarks that create UVs with no transform (#50847)
The current stroke benchmarks exercise their PositionUVWriter variants with a worst case texture mapping that includes an effect transform. These benchmarks won't track any improvements we make to the case that does not include a transform. This PR adds new benchmarks that track performance of computing texture coords with just a set of texture bounds and no transform.
1 parent e922da6 commit 843ecc5

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

impeller/geometry/geometry_benchmarks.cc

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -97,20 +97,28 @@ static void BM_Polyline(benchmark::State& state, Args&&... args) {
9797
state.counters["TotalPointCount"] = point_count;
9898
}
9999

100+
enum class UVMode {
101+
kNoUV,
102+
kUVRect,
103+
kUVRectTx,
104+
};
105+
100106
template <class... Args>
101107
static void BM_StrokePolyline(benchmark::State& state, Args&&... args) {
102108
auto args_tuple = std::make_tuple(std::move(args)...);
103109
auto path = std::get<Path>(args_tuple);
104110
auto cap = std::get<Cap>(args_tuple);
105111
auto join = std::get<Join>(args_tuple);
106-
auto generate_uv = std::get<bool>(args_tuple);
112+
auto generate_uv = std::get<UVMode>(args_tuple);
107113

108114
const Scalar stroke_width = 5.0f;
109115
const Scalar miter_limit = 10.0f;
110116
const Scalar scale = 1.0f;
111117
const Point texture_origin = Point(0, 0);
112118
const Size texture_size = Size(100, 100);
113-
const Matrix effect_transform = Matrix::MakeScale({2.0f, 2.0f, 1.0f});
119+
const Matrix effect_transform = (generate_uv == UVMode::kUVRectTx)
120+
? Matrix::MakeScale({2.0f, 2.0f, 1.0f})
121+
: Matrix();
114122

115123
auto points = std::make_unique<std::vector<Point>>();
116124
points->reserve(2048);
@@ -123,15 +131,15 @@ static void BM_StrokePolyline(benchmark::State& state, Args&&... args) {
123131
size_t point_count = 0u;
124132
size_t single_point_count = 0u;
125133
while (state.KeepRunning()) {
126-
if (generate_uv) {
134+
if (generate_uv == UVMode::kNoUV) {
135+
auto vertices = ImpellerBenchmarkAccessor::GenerateSolidStrokeVertices(
136+
polyline, stroke_width, miter_limit, join, cap, scale);
137+
single_point_count = vertices.size();
138+
} else {
127139
auto vertices = ImpellerBenchmarkAccessor::GenerateSolidStrokeVerticesUV(
128140
polyline, stroke_width, miter_limit, join, cap, scale, //
129141
texture_origin, texture_size, effect_transform);
130142
single_point_count = vertices.size();
131-
} else {
132-
auto vertices = ImpellerBenchmarkAccessor::GenerateSolidStrokeVertices(
133-
polyline, stroke_width, miter_limit, join, cap, scale);
134-
single_point_count = vertices.size();
135143
}
136144
point_count += single_point_count;
137145
}
@@ -157,24 +165,21 @@ static void BM_Convex(benchmark::State& state, Args&&... args) {
157165
state.counters["TotalPointCount"] = point_count;
158166
}
159167

160-
#define MAKE_STROKE_BENCHMARK_CAPTURE(path, cap, join, closed) \
161-
BENCHMARK_CAPTURE(BM_StrokePolyline, stroke_##path##_##cap##_##join, \
162-
Create##path(closed), Cap::k##cap, Join::k##join, false)
163-
164-
#define MAKE_STROKE_BENCHMARK_CAPTURE_UV(path, cap, join, closed) \
165-
BENCHMARK_CAPTURE(BM_StrokePolyline, stroke_##path##_##cap##_##join##_uv, \
166-
Create##path(closed), Cap::k##cap, Join::k##join, true)
168+
#define MAKE_STROKE_BENCHMARK_CAPTURE(path, cap, join, closed, uvname, uvtype) \
169+
BENCHMARK_CAPTURE(BM_StrokePolyline, stroke_##path##_##cap##_##join##uvname, \
170+
Create##path(closed), Cap::k##cap, Join::k##join, uvtype)
167171

168-
#define MAKE_STROKE_BENCHMARK_CAPTURE_CAPS_JOINS(path, uv) \
169-
MAKE_STROKE_BENCHMARK_CAPTURE##uv(path, Butt, Bevel, false); \
170-
MAKE_STROKE_BENCHMARK_CAPTURE##uv(path, Butt, Miter, false); \
171-
MAKE_STROKE_BENCHMARK_CAPTURE##uv(path, Butt, Round, false); \
172-
MAKE_STROKE_BENCHMARK_CAPTURE##uv(path, Square, Bevel, false); \
173-
MAKE_STROKE_BENCHMARK_CAPTURE##uv(path, Round, Bevel, false)
172+
#define MAKE_STROKE_BENCHMARK_CAPTURE_CAPS_JOINS(path, uvname, uvtype) \
173+
MAKE_STROKE_BENCHMARK_CAPTURE(path, Butt, Bevel, false, uvname, uvtype); \
174+
MAKE_STROKE_BENCHMARK_CAPTURE(path, Butt, Miter, false, uvname, uvtype); \
175+
MAKE_STROKE_BENCHMARK_CAPTURE(path, Butt, Round, false, uvname, uvtype); \
176+
MAKE_STROKE_BENCHMARK_CAPTURE(path, Square, Bevel, false, uvname, uvtype); \
177+
MAKE_STROKE_BENCHMARK_CAPTURE(path, Round, Bevel, false, uvname, uvtype)
174178

175-
#define MAKE_STROKE_BENCHMARK_CAPTURE_UVS(path) \
176-
MAKE_STROKE_BENCHMARK_CAPTURE_CAPS_JOINS(path, ); \
177-
MAKE_STROKE_BENCHMARK_CAPTURE_CAPS_JOINS(path, _UV)
179+
#define MAKE_STROKE_BENCHMARK_CAPTURE_UVS(path) \
180+
MAKE_STROKE_BENCHMARK_CAPTURE_CAPS_JOINS(path, , UVMode::kNoUV); \
181+
MAKE_STROKE_BENCHMARK_CAPTURE_CAPS_JOINS(path, _uv, UVMode::kUVRectTx); \
182+
MAKE_STROKE_BENCHMARK_CAPTURE_CAPS_JOINS(path, _uvNoTx, UVMode::kUVRect)
178183

179184
BENCHMARK_CAPTURE(BM_Polyline, cubic_polyline, CreateCubic(true), false);
180185
BENCHMARK_CAPTURE(BM_Polyline, cubic_polyline_tess, CreateCubic(true), true);
@@ -201,8 +206,9 @@ BENCHMARK_CAPTURE(BM_Polyline,
201206
MAKE_STROKE_BENCHMARK_CAPTURE_UVS(Quadratic);
202207

203208
BENCHMARK_CAPTURE(BM_Convex, rrect_convex, CreateRRect(), true);
204-
MAKE_STROKE_BENCHMARK_CAPTURE(RRect, Butt, Bevel, );
205-
MAKE_STROKE_BENCHMARK_CAPTURE_UV(RRect, Butt, Bevel, );
209+
MAKE_STROKE_BENCHMARK_CAPTURE(RRect, Butt, Bevel, , , UVMode::kNoUV);
210+
MAKE_STROKE_BENCHMARK_CAPTURE(RRect, Butt, Bevel, , _uv, UVMode::kUVRectTx);
211+
MAKE_STROKE_BENCHMARK_CAPTURE(RRect, Butt, Bevel, , _uvNoTx, UVMode::kUVRect);
206212

207213
namespace {
208214

0 commit comments

Comments
 (0)