1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include <stdint.h>
#include <array>
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/time/time.h"
#include "base/timer/lap_timer.h"
#include "cc/raster/raster_buffer.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_frame_sink.h"
#include "cc/test/fake_layer_tree_frame_sink_client.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/fake_picture_layer_impl.h"
#include "cc/test/fake_raster_source.h"
#include "cc/test/fake_tile_manager.h"
#include "cc/test/fake_tile_manager_client.h"
#include "cc/test/fake_tile_task_manager.h"
#include "cc/test/layer_test_common.h"
#include "cc/test/test_layer_tree_host_base.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/test/test_tile_priorities.h"
#include "cc/tiles/eviction_tile_priority_queue.h"
#include "cc/tiles/tile.h"
#include "cc/tiles/tile_priority.h"
#include "cc/trees/layer_tree_impl.h"
#include "components/viz/test/begin_frame_args_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_result_reporter.h"
namespace cc {
namespace {
static const int kTimeLimitMillis = 2000;
static const int kWarmupRuns = 5;
static const int kTimeCheckInterval = 10;
class TileManagerPerfTest : public TestLayerTreeHostBase {
public:
TileManagerPerfTest()
: timer_(kWarmupRuns,
base::Milliseconds(kTimeLimitMillis),
kTimeCheckInterval) {}
void InitializeFrameSink() override {
host_impl()->SetVisible(true);
host_impl()->InitializeFrameSink(layer_tree_frame_sink());
tile_manager()->SetTileTaskManagerForTesting(
std::make_unique<FakeTileTaskManagerImpl>());
}
void SetupDefaultTreesWithFixedTileSize(const gfx::Size& layer_bounds,
const gfx::Size& tile_size) {
scoped_refptr<FakeRasterSource> pending_raster_source =
FakeRasterSource::CreateFilledWithImages(layer_bounds);
scoped_refptr<FakeRasterSource> active_raster_source =
FakeRasterSource::CreateFilledWithImages(layer_bounds);
SetupPendingTree(std::move(active_raster_source), tile_size, Region());
ActivateTree();
SetupPendingTree(std::move(pending_raster_source), tile_size, Region());
}
perf_test::PerfResultReporter SetUpReporter(const std::string& story_name) {
perf_test::PerfResultReporter reporter("tile_manager", story_name);
reporter.RegisterImportantMetric("_raster_tile_queue_construct", "runs/s");
reporter.RegisterImportantMetric("_raster_tile_queue_construct_and_iterate",
"runs/s");
reporter.RegisterImportantMetric("_eviction_tile_queue_construct",
"runs/s");
reporter.RegisterImportantMetric(
"_eviction_tile_queue_construct_and_iterate", "runs/s");
return reporter;
}
void RunRasterQueueConstructTest(const std::string& test_name,
int layer_count) {
auto priorities = std::to_array<TreePriority>({
SAME_PRIORITY_FOR_BOTH_TREES,
SMOOTHNESS_TAKES_PRIORITY,
NEW_CONTENT_TAKES_PRIORITY,
});
int priority_count = 0;
std::vector<FakePictureLayerImpl*> layers = CreateLayers(layer_count, 10);
for (auto* layer : layers)
layer->UpdateTiles();
timer_.Reset();
do {
std::unique_ptr<RasterTilePriorityQueue> queue(
host_impl()->BuildRasterQueue(priorities[priority_count],
RasterTilePriorityQueue::Type::ALL));
priority_count = (priority_count + 1) % std::size(priorities);
timer_.NextLap();
} while (!timer_.HasTimeLimitExpired());
perf_test::PerfResultReporter reporter = SetUpReporter(test_name);
reporter.AddResult("_raster_tile_queue_construct", timer_.LapsPerSecond());
}
void RunRasterQueueConstructAndIterateTest(const std::string& test_name,
int layer_count,
int tile_count) {
auto priorities = std::to_array<TreePriority>({
SAME_PRIORITY_FOR_BOTH_TREES,
SMOOTHNESS_TAKES_PRIORITY,
NEW_CONTENT_TAKES_PRIORITY,
});
std::vector<FakePictureLayerImpl*> layers = CreateLayers(layer_count, 100);
for (auto* layer : layers)
layer->UpdateTiles();
int priority_count = 0;
timer_.Reset();
do {
int count = tile_count;
std::unique_ptr<RasterTilePriorityQueue> queue(
host_impl()->BuildRasterQueue(priorities[priority_count],
RasterTilePriorityQueue::Type::ALL));
while (count--) {
ASSERT_FALSE(queue->IsEmpty());
ASSERT_TRUE(queue->Top().tile());
queue->Pop();
}
priority_count = (priority_count + 1) % std::size(priorities);
timer_.NextLap();
} while (!timer_.HasTimeLimitExpired());
perf_test::PerfResultReporter reporter = SetUpReporter(test_name);
reporter.AddResult("_raster_tile_queue_construct_and_iterate",
timer_.LapsPerSecond());
}
void RunEvictionQueueConstructTest(const std::string& test_name,
int layer_count) {
auto priorities = std::to_array<TreePriority>({
SAME_PRIORITY_FOR_BOTH_TREES,
SMOOTHNESS_TAKES_PRIORITY,
NEW_CONTENT_TAKES_PRIORITY,
});
int priority_count = 0;
std::vector<FakePictureLayerImpl*> layers = CreateLayers(layer_count, 10);
for (auto* layer : layers) {
layer->UpdateTiles();
for (size_t i = 0; i < layer->num_tilings(); ++i) {
tile_manager()->InitializeTilesWithResourcesForTesting(
layer->tilings()->tiling_at(i)->AllTilesForTesting());
}
}
timer_.Reset();
do {
std::unique_ptr<EvictionTilePriorityQueue> queue(
host_impl()->BuildEvictionQueue(priorities[priority_count]));
priority_count = (priority_count + 1) % std::size(priorities);
timer_.NextLap();
} while (!timer_.HasTimeLimitExpired());
perf_test::PerfResultReporter reporter = SetUpReporter(test_name);
reporter.AddResult("_eviction_tile_queue_construct",
timer_.LapsPerSecond());
}
void RunEvictionQueueConstructAndIterateTest(const std::string& test_name,
int layer_count,
int tile_count) {
auto priorities = std::to_array<TreePriority>({
SAME_PRIORITY_FOR_BOTH_TREES,
SMOOTHNESS_TAKES_PRIORITY,
NEW_CONTENT_TAKES_PRIORITY,
});
int priority_count = 0;
std::vector<FakePictureLayerImpl*> layers =
CreateLayers(layer_count, tile_count);
for (auto* layer : layers) {
layer->UpdateTiles();
for (size_t i = 0; i < layer->num_tilings(); ++i) {
tile_manager()->InitializeTilesWithResourcesForTesting(
layer->tilings()->tiling_at(i)->AllTilesForTesting());
}
}
timer_.Reset();
do {
int count = tile_count;
std::unique_ptr<EvictionTilePriorityQueue> queue(
host_impl()->BuildEvictionQueue(priorities[priority_count]));
while (count--) {
ASSERT_FALSE(queue->IsEmpty());
ASSERT_TRUE(queue->Top().tile());
queue->Pop();
}
priority_count = (priority_count + 1) % std::size(priorities);
timer_.NextLap();
} while (!timer_.HasTimeLimitExpired());
perf_test::PerfResultReporter reporter = SetUpReporter(test_name);
reporter.AddResult("_eviction_tile_queue_construct_and_iterate",
timer_.LapsPerSecond());
}
std::vector<FakePictureLayerImpl*> CreateLayers(int layer_count,
int num_tiles_in_high_res) {
// Compute the width/height required for high res to get
// num_tiles_in_high_res tiles.
float width = std::sqrt(static_cast<float>(num_tiles_in_high_res));
float height = num_tiles_in_high_res / width;
// Adjust the width and height to account for the fact that tiles
// are bigger than 1x1.
const gfx::Size tile_size = LayerTreeSettings().default_tile_size;
width *= tile_size.width();
height *= tile_size.height();
// Ensure that we start with blank trees and no tiles.
ResetTrees();
gfx::Size layer_bounds(width, height);
gfx::Rect viewport(width / 5, height / 5);
host_impl()->active_tree()->SetDeviceViewportRect(viewport);
SetupDefaultTreesWithFixedTileSize(layer_bounds, tile_size);
std::vector<FakePictureLayerImpl*> layers;
// Pending layer counts as one layer.
layers.push_back(pending_layer());
// Create the rest of the layers as children of the root layer.
scoped_refptr<FakeRasterSource> raster_source =
FakeRasterSource::CreateFilledWithImages(layer_bounds);
while (static_cast<int>(layers.size()) < layer_count) {
auto* child_layer = AddLayer<FakePictureLayerImpl>(
host_impl()->pending_tree(), raster_source);
child_layer->SetBounds(layer_bounds);
child_layer->SetDrawsContent(true);
layers.push_back(child_layer);
CopyProperties(pending_layer(), child_layer);
}
// Property trees need to be rebuilt because layers were added above.
host_impl()->pending_tree()->set_needs_update_draw_properties();
UpdateDrawProperties(host_impl()->pending_tree());
for (FakePictureLayerImpl* layer : layers)
layer->CreateAllTiles();
return layers;
}
GlobalStateThatImpactsTilePriority GlobalStateForTest() {
GlobalStateThatImpactsTilePriority state;
const gfx::Size tile_size = LayerTreeSettings().default_tile_size;
state.soft_memory_limit_in_bytes =
10000u * 4u *
static_cast<size_t>(tile_size.width() * tile_size.height());
state.hard_memory_limit_in_bytes = state.soft_memory_limit_in_bytes;
state.num_resources_limit = 10000;
state.memory_limit_policy = ALLOW_ANYTHING;
state.tree_priority = SMOOTHNESS_TAKES_PRIORITY;
return state;
}
void RunPrepareTilesTest(const std::string& test_name,
int layer_count,
int approximate_tile_count_per_layer) {
std::vector<FakePictureLayerImpl*> layers =
CreateLayers(layer_count, approximate_tile_count_per_layer);
timer_.Reset();
do {
host_impl()->AdvanceToNextFrame(base::Milliseconds(1));
for (auto* layer : layers)
layer->UpdateTiles();
GlobalStateThatImpactsTilePriority global_state(GlobalStateForTest());
tile_manager()->PrepareTiles(global_state);
tile_manager()->PrepareToDraw();
timer_.NextLap();
} while (!timer_.HasTimeLimitExpired());
perf_test::PerfResultReporter reporter("prepare_tiles", test_name);
reporter.RegisterImportantMetric("", "runs/s");
reporter.AddResult("", timer_.LapsPerSecond());
}
TileManager* tile_manager() { return host_impl()->tile_manager(); }
protected:
base::LapTimer timer_;
};
// Failing. https://crbug.com/792995
TEST_F(TileManagerPerfTest, DISABLED_PrepareTiles) {
RunPrepareTilesTest("2_100", 2, 100);
RunPrepareTilesTest("2_500", 2, 500);
RunPrepareTilesTest("2_1000", 2, 1000);
RunPrepareTilesTest("10_100", 10, 100);
RunPrepareTilesTest("10_500", 10, 500);
RunPrepareTilesTest("10_1000", 10, 1000);
RunPrepareTilesTest("50_100", 100, 100);
RunPrepareTilesTest("50_500", 100, 500);
RunPrepareTilesTest("50_1000", 100, 1000);
}
TEST_F(TileManagerPerfTest, RasterTileQueueConstruct) {
RunRasterQueueConstructTest("2", 2);
RunRasterQueueConstructTest("10", 10);
RunRasterQueueConstructTest("50", 50);
}
TEST_F(TileManagerPerfTest, RasterTileQueueConstructAndIterate) {
RunRasterQueueConstructAndIterateTest("2_16", 2, 16);
RunRasterQueueConstructAndIterateTest("2_32", 2, 32);
RunRasterQueueConstructAndIterateTest("2_64", 2, 64);
RunRasterQueueConstructAndIterateTest("2_128", 2, 128);
RunRasterQueueConstructAndIterateTest("10_16", 10, 16);
RunRasterQueueConstructAndIterateTest("10_32", 10, 32);
RunRasterQueueConstructAndIterateTest("10_64", 10, 64);
RunRasterQueueConstructAndIterateTest("10_128", 10, 128);
RunRasterQueueConstructAndIterateTest("50_16", 50, 16);
RunRasterQueueConstructAndIterateTest("50_32", 50, 32);
RunRasterQueueConstructAndIterateTest("50_64", 50, 64);
RunRasterQueueConstructAndIterateTest("50_128", 50, 128);
}
TEST_F(TileManagerPerfTest, EvictionTileQueueConstruct) {
RunEvictionQueueConstructTest("2", 2);
RunEvictionQueueConstructTest("10", 10);
RunEvictionQueueConstructTest("50", 50);
}
TEST_F(TileManagerPerfTest, EvictionTileQueueConstructAndIterate) {
RunEvictionQueueConstructAndIterateTest("2_16", 2, 16);
RunEvictionQueueConstructAndIterateTest("2_32", 2, 32);
RunEvictionQueueConstructAndIterateTest("2_64", 2, 64);
RunEvictionQueueConstructAndIterateTest("2_128", 2, 128);
RunEvictionQueueConstructAndIterateTest("10_16", 10, 16);
RunEvictionQueueConstructAndIterateTest("10_32", 10, 32);
RunEvictionQueueConstructAndIterateTest("10_64", 10, 64);
RunEvictionQueueConstructAndIterateTest("10_128", 10, 128);
RunEvictionQueueConstructAndIterateTest("50_16", 50, 16);
RunEvictionQueueConstructAndIterateTest("50_32", 50, 32);
RunEvictionQueueConstructAndIterateTest("50_64", 50, 64);
RunEvictionQueueConstructAndIterateTest("50_128", 50, 128);
}
} // namespace
} // namespace cc
|