Skip to content

Commit

Permalink
Reland Allow one-copy and zero-copy task tile worker pools to use com…
Browse files Browse the repository at this point in the history
…pressed textures.

BUG=434699
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review URL: https://codereview.chromium.org/1713503002

Cr-Commit-Position: refs/heads/master@{#376711}
  • Loading branch information
auygun authored and Commit bot committed Feb 22, 2016
1 parent 14bbbf2 commit 2cb8989
Show file tree
Hide file tree
Showing 27 changed files with 252 additions and 113 deletions.
3 changes: 2 additions & 1 deletion blimp/client/feature/compositor/blimp_layer_tree_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ void PopulateCommonLayerTreeSettings(cc::LayerTreeSettings* settings) {
settings->renderer_settings.highp_threshold_min = 2048;
settings->ignore_root_layer_flings = false;
bool use_low_memory_policy = base::SysInfo::IsLowEndDevice();
settings->renderer_settings.use_rgba_4444_textures = use_low_memory_policy;
if (use_low_memory_policy) {
// On low-end we want to be very carefull about killing other
// apps. So initially we use 50% more memory to avoid flickering
// or raster-on-demand.
settings->max_memory_for_prepaint_percentage = 67;

settings->renderer_settings.preferred_tile_format = cc::RGBA_4444;
} else {
// On other devices we have increased memory excessively to avoid
// raster-on-demand already, so now we reserve 50% _only_ to avoid
Expand Down
3 changes: 3 additions & 0 deletions cc/base/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const char kSlowDownRasterScaleFactor[] = "slow-down-raster-scale-factor";
const char kStrictLayerPropertyChangeChecking[] =
"strict-layer-property-change-checking";

// Compress tile textures for GPUs supporting it.
const char kEnableTileCompression[] = "enable-tile-compression";

// Use a BeginFrame signal from browser to renderer to schedule rendering.
const char kEnableBeginFrameScheduling[] = "enable-begin-frame-scheduling";

Expand Down
1 change: 1 addition & 0 deletions cc/base/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ CC_EXPORT extern const char kTopControlsHideThreshold[];
CC_EXPORT extern const char kTopControlsShowThreshold[];
CC_EXPORT extern const char kSlowDownRasterScaleFactor[];
CC_EXPORT extern const char kStrictLayerPropertyChangeChecking[];
CC_EXPORT extern const char kEnableTileCompression[];

// Switches for both the renderer and ui compositors.
CC_EXPORT extern const char kEnableBeginFrameScheduling[];
Expand Down
8 changes: 8 additions & 0 deletions cc/layers/picture_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const int kMinHeightForGpuRasteredTile = 256;
// of using the same tile size.
const int kTileRoundUp = 64;

// For performance reasons and to support compressed tile textures, tile
// width and height should be an even multiple of 4 in size.
const int kTileMinimalAlignment = 4;

} // namespace

namespace cc {
Expand Down Expand Up @@ -781,6 +785,10 @@ gfx::Size PictureLayerImpl::CalculateTileSize(
tile_height = std::min(tile_height, default_tile_height);
}

// Ensure that tile width and height are properly aligned.
tile_width = MathUtil::UncheckedRoundUp(tile_width, kTileMinimalAlignment);
tile_height = MathUtil::UncheckedRoundUp(tile_height, kTileMinimalAlignment);

// Under no circumstance should we be larger than the max texture size.
tile_width = std::min(tile_width, max_texture_size);
tile_height = std::min(tile_height, max_texture_size);
Expand Down
10 changes: 6 additions & 4 deletions cc/layers/picture_layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4890,16 +4890,18 @@ TEST_F(TileSizeTest, TileSizes) {

layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size());
result = layer->CalculateTileSize(gfx::Size(10000, 10000));
EXPECT_EQ(result.width(), 2000 + 2 * PictureLayerTiling::kBorderTexels);
EXPECT_EQ(result.height(), 500 + 2);
EXPECT_EQ(result.width(),
MathUtil::UncheckedRoundUp(
2000 + 2 * PictureLayerTiling::kBorderTexels, 4));
EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aligned.

// Clamp and round-up, when smaller than viewport.
// Tile-height doubles to 50% when width shrinks to <= 50%.
host_impl_.SetViewportSize(gfx::Size(1000, 1000));
layer->set_gpu_raster_max_texture_size(host_impl_.device_viewport_size());
result = layer->CalculateTileSize(gfx::Size(447, 10000));
EXPECT_EQ(result.width(), 448);
EXPECT_EQ(result.height(), 500 + 2);
EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aliged.

// Largest layer is 50% of viewport width (rounded up), and
// 50% of viewport in height.
Expand All @@ -4908,7 +4910,7 @@ TEST_F(TileSizeTest, TileSizes) {
EXPECT_EQ(result.height(), 448);
result = layer->CalculateTileSize(gfx::Size(500, 499));
EXPECT_EQ(result.width(), 512);
EXPECT_EQ(result.height(), 500 + 2);
EXPECT_EQ(result.height(), 504); // 500 + 2, 4-byte aligned.
}

TEST_F(NoLowResPictureLayerImplTest, LowResWasHighResCollision) {
Expand Down
17 changes: 11 additions & 6 deletions cc/output/renderer_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "base/logging.h"
#include "cc/proto/renderer_settings.pb.h"
#include "cc/resources/platform_color.h"

namespace cc {

Expand All @@ -22,9 +23,9 @@ RendererSettings::RendererSettings()
release_overlay_resources_on_swap_complete(false),
refresh_rate(60.0),
highp_threshold_min(0),
use_rgba_4444_textures(false),
texture_id_allocation_chunk_size(64),
use_gpu_memory_buffer_resources(false) {}
use_gpu_memory_buffer_resources(false),
preferred_tile_format(PlatformColor::BestTextureFormat()) {}

RendererSettings::~RendererSettings() {
}
Expand All @@ -41,9 +42,9 @@ void RendererSettings::ToProtobuf(proto::RendererSettings* proto) const {
release_overlay_resources_on_swap_complete);
proto->set_refresh_rate(refresh_rate);
proto->set_highp_threshold_min(highp_threshold_min);
proto->set_use_rgba_4444_textures(use_rgba_4444_textures);
proto->set_texture_id_allocation_chunk_size(texture_id_allocation_chunk_size);
proto->set_use_gpu_memory_buffer_resources(use_gpu_memory_buffer_resources);
proto->set_preferred_tile_format(preferred_tile_format);
}

void RendererSettings::FromProtobuf(const proto::RendererSettings& proto) {
Expand All @@ -58,9 +59,13 @@ void RendererSettings::FromProtobuf(const proto::RendererSettings& proto) {
proto.release_overlay_resources_on_swap_complete();
refresh_rate = proto.refresh_rate();
highp_threshold_min = proto.highp_threshold_min();
use_rgba_4444_textures = proto.use_rgba_4444_textures();
texture_id_allocation_chunk_size = proto.texture_id_allocation_chunk_size();
use_gpu_memory_buffer_resources = proto.use_gpu_memory_buffer_resources();

DCHECK_LE(proto.preferred_tile_format(),
static_cast<uint32_t>(RESOURCE_FORMAT_MAX));
preferred_tile_format =
static_cast<ResourceFormat>(proto.preferred_tile_format());
}

bool RendererSettings::operator==(const RendererSettings& other) const {
Expand All @@ -75,11 +80,11 @@ bool RendererSettings::operator==(const RendererSettings& other) const {
other.release_overlay_resources_on_swap_complete &&
refresh_rate == other.refresh_rate &&
highp_threshold_min == other.highp_threshold_min &&
use_rgba_4444_textures == other.use_rgba_4444_textures &&
texture_id_allocation_chunk_size ==
other.texture_id_allocation_chunk_size &&
use_gpu_memory_buffer_resources ==
other.use_gpu_memory_buffer_resources;
other.use_gpu_memory_buffer_resources &&
preferred_tile_format == other.preferred_tile_format;
}

} // namespace cc
3 changes: 2 additions & 1 deletion cc/output/renderer_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stddef.h>

#include "cc/base/cc_export.h"
#include "cc/resources/resource_format.h"

namespace cc {

Expand All @@ -30,9 +31,9 @@ class CC_EXPORT RendererSettings {
bool release_overlay_resources_on_swap_complete;
double refresh_rate;
int highp_threshold_min;
bool use_rgba_4444_textures;
size_t texture_id_allocation_chunk_size;
bool use_gpu_memory_buffer_resources;
ResourceFormat preferred_tile_format;

void ToProtobuf(proto::RendererSettings* proto) const;
void FromProtobuf(const proto::RendererSettings& proto);
Expand Down
4 changes: 2 additions & 2 deletions cc/output/renderer_settings_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ TEST(RendererSettingsTest, AllFieldsFlipped) {
settings.release_overlay_resources_on_swap_complete = true;
settings.refresh_rate = 6.0;
settings.highp_threshold_min = 1;
settings.use_rgba_4444_textures = true;
settings.texture_id_allocation_chunk_size = 46;
settings.use_gpu_memory_buffer_resources = true;
settings.preferred_tile_format = RGBA_4444;
VerifySerializeAndDeserializeProto(settings);
}

Expand All @@ -48,9 +48,9 @@ TEST(RendererSettingsTest, ArbitraryFieldValues) {
settings.release_overlay_resources_on_swap_complete = true;
settings.refresh_rate = 999.0;
settings.highp_threshold_min = 1;
settings.use_rgba_4444_textures = true;
settings.texture_id_allocation_chunk_size = 12;
settings.use_gpu_memory_buffer_resources = true;
settings.preferred_tile_format = RGBA_4444;
VerifySerializeAndDeserializeProto(settings);
}

Expand Down
6 changes: 3 additions & 3 deletions cc/proto/renderer_settings.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ message RendererSettings {
optional bool release_overlay_resources_on_swap_complete = 8;
optional double refresh_rate = 9;
optional uint32 highp_threshold_min = 10;
optional bool use_rgba_4444_textures = 11;
optional uint32 texture_id_allocation_chunk_size = 12;
optional bool use_gpu_memory_buffer_resources = 13;
optional uint32 texture_id_allocation_chunk_size = 11;
optional bool use_gpu_memory_buffer_resources = 12;
optional uint32 preferred_tile_format = 13;
}
76 changes: 44 additions & 32 deletions cc/raster/one_copy_tile_task_worker_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create(
int max_copy_texture_chromium_size,
bool use_partial_raster,
int max_staging_buffer_usage_in_bytes,
bool use_rgba_4444_texture_format) {
ResourceFormat preferred_tile_format) {
return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool(
task_runner, task_graph_runner, resource_provider,
max_copy_texture_chromium_size, use_partial_raster,
max_staging_buffer_usage_in_bytes, use_rgba_4444_texture_format));
max_staging_buffer_usage_in_bytes, preferred_tile_format));
}

OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool(
Expand All @@ -199,7 +199,7 @@ OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool(
int max_copy_texture_chromium_size,
bool use_partial_raster,
int max_staging_buffer_usage_in_bytes,
bool use_rgba_4444_texture_format)
ResourceFormat preferred_tile_format)
: task_runner_(task_runner),
task_graph_runner_(task_graph_runner),
namespace_token_(task_graph_runner->GetNamespaceToken()),
Expand All @@ -212,7 +212,7 @@ OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool(
use_partial_raster_(use_partial_raster),
bytes_scheduled_since_last_flush_(0),
max_staging_buffer_usage_in_bytes_(max_staging_buffer_usage_in_bytes),
use_rgba_4444_texture_format_(use_rgba_4444_texture_format),
preferred_tile_format_(preferred_tile_format),
staging_buffer_usage_in_bytes_(0),
free_staging_buffer_usage_in_bytes_(0),
staging_buffer_expiration_delay_(
Expand Down Expand Up @@ -285,9 +285,13 @@ void OneCopyTileTaskWorkerPool::CheckForCompletedTasks() {

ResourceFormat OneCopyTileTaskWorkerPool::GetResourceFormat(
bool must_support_alpha) const {
return use_rgba_4444_texture_format_
? RGBA_4444
: resource_provider_->best_texture_format();
if (resource_provider_->IsResourceFormatSupported(preferred_tile_format_) &&
(DoesResourceFormatSupportAlpha(preferred_tile_format_) ||
!must_support_alpha)) {
return preferred_tile_format_;
}

return resource_provider_->best_texture_format();
}

bool OneCopyTileTaskWorkerPool::GetResourceRequiresSwizzle(
Expand Down Expand Up @@ -427,31 +431,39 @@ void OneCopyTileTaskWorkerPool::PlaybackAndCopyOnWorkerThread(
#endif
}

int bytes_per_row =
(BitsPerPixel(resource->format()) * resource->size().width()) / 8;
int chunk_size_in_rows =
std::max(1, max_bytes_per_copy_operation_ / bytes_per_row);
// Align chunk size to 4. Required to support compressed texture formats.
chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4);
int y = 0;
int height = resource->size().height();
while (y < height) {
// Copy at most |chunk_size_in_rows|.
int rows_to_copy = std::min(chunk_size_in_rows, height - y);
DCHECK_GT(rows_to_copy, 0);

gl->CopySubTextureCHROMIUM(
staging_buffer->texture_id, resource_lock->texture_id(), 0, y, 0, y,
resource->size().width(), rows_to_copy, false, false, false);
y += rows_to_copy;

// Increment |bytes_scheduled_since_last_flush_| by the amount of memory
// used for this copy operation.
bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row;

if (bytes_scheduled_since_last_flush_ >= max_bytes_per_copy_operation_) {
gl->ShallowFlushCHROMIUM();
bytes_scheduled_since_last_flush_ = 0;
// Since compressed texture's cannot be pre-allocated we might have an
// unallocated resource in which case we need to perform a full size copy.
if (IsResourceFormatCompressed(resource->format())) {
gl->CompressedCopyTextureCHROMIUM(staging_buffer->texture_id,
resource_lock->texture_id());
} else {
int bytes_per_row =
(BitsPerPixel(resource->format()) * resource->size().width()) / 8;
int chunk_size_in_rows =
std::max(1, max_bytes_per_copy_operation_ / bytes_per_row);
// Align chunk size to 4. Required to support compressed texture formats.
chunk_size_in_rows = MathUtil::UncheckedRoundUp(chunk_size_in_rows, 4);
int y = 0;
int height = resource->size().height();
while (y < height) {
// Copy at most |chunk_size_in_rows|.
int rows_to_copy = std::min(chunk_size_in_rows, height - y);
DCHECK_GT(rows_to_copy, 0);

gl->CopySubTextureCHROMIUM(
staging_buffer->texture_id, resource_lock->texture_id(), 0, y, 0, y,
resource->size().width(), rows_to_copy, false, false, false);
y += rows_to_copy;

// Increment |bytes_scheduled_since_last_flush_| by the amount of memory
// used for this copy operation.
bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row;

if (bytes_scheduled_since_last_flush_ >=
max_bytes_per_copy_operation_) {
gl->ShallowFlushCHROMIUM();
bytes_scheduled_since_last_flush_ = 0;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions cc/raster/one_copy_tile_task_worker_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CC_EXPORT OneCopyTileTaskWorkerPool
int max_copy_texture_chromium_size,
bool use_partial_raster,
int max_staging_buffer_usage_in_bytes,
bool use_rgba_4444_texture_format);
ResourceFormat preferred_tile_format);

// Overridden from TileTaskWorkerPool:
TileTaskRunner* AsTileTaskRunner() override;
Expand Down Expand Up @@ -95,7 +95,7 @@ class CC_EXPORT OneCopyTileTaskWorkerPool
int max_copy_texture_chromium_size,
bool use_partial_raster,
int max_staging_buffer_usage_in_bytes,
bool use_rgba_4444_texture_format);
ResourceFormat preferred_tile_format);

private:
struct StagingBuffer {
Expand Down Expand Up @@ -152,7 +152,7 @@ class CC_EXPORT OneCopyTileTaskWorkerPool
StagingBufferDeque busy_buffers_;
int bytes_scheduled_since_last_flush_;
const int max_staging_buffer_usage_in_bytes_;
bool use_rgba_4444_texture_format_;
ResourceFormat preferred_tile_format_;
int staging_buffer_usage_in_bytes_;
int free_staging_buffer_usage_in_bytes_;
const base::TimeDelta staging_buffer_expiration_delay_;
Expand Down
Loading

0 comments on commit 2cb8989

Please sign in to comment.