Skip to content

Commit

Permalink
cc: Clear one copy destintation texture if size doesn't match content
Browse files Browse the repository at this point in the history
Ever since crrev.com/c/3289549 landed and ANGLE robust resource init was
disabled, GL shared images are strict about enforcing no uninitialized
access. One copy raster doesn't explicitly clear its resources unlike
GPU raster, which seems to cause an issue when non-exact resource reuse
is enabled. Sometimes, we acquire a resource such that the tiles content
rect is smaller than the resource size leading to the part outside the
content rect being uninitialized.

This CL fixes the issue by clearing the resource if its size doesn't
match the full raster rect. Merely copying the difference from the
staging buffer doesn't work since the staging buffer can also be of a
different size than the destination resource due to a separate reuse
mechanism.

(cherry picked from commit ea7c4e5)

Bug: 1313091
Change-Id: I460037038b68e1a404bbc474637f50405cd604fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3574955
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Commit-Queue: Sunny Sachanandani <sunnyps@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#989987}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3576712
Reviewed-by: Sunny Sachanandani <sunnyps@chromium.org>
Commit-Queue: Srinivas Sista <srinivassista@chromium.org>
Auto-Submit: Srinivas Sista <srinivassista@chromium.org>
Cr-Commit-Position: refs/branch-heads/4990@{#3}
Cr-Branched-From: d749b19-refs/heads/main@{#989870}
  • Loading branch information
sunnyps authored and Chromium LUCI CQ committed Apr 7, 2022
1 parent 0c6f595 commit 901ff38
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cc/raster/one_copy_raster_buffer_provider.cc
Expand Up @@ -32,6 +32,7 @@
#include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/command_buffer/common/shared_image_trace_utils.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/buffer_format_util.h"
#include "ui/gl/trace_util.h"

Expand Down Expand Up @@ -292,6 +293,8 @@ gpu::SyncToken OneCopyRasterBufferProvider::PlaybackAndCopyOnWorkerThread(
std::unique_ptr<StagingBuffer> staging_buffer =
staging_pool_.AcquireStagingBuffer(resource_size, resource_format,
previous_content_id);
DCHECK(staging_buffer->size.width() >= raster_full_rect.width() &&
staging_buffer->size.height() >= raster_full_rect.height());

PlaybackToStagingBuffer(staging_buffer.get(), raster_source, raster_full_rect,
raster_dirty_rect, transform, resource_format,
Expand Down Expand Up @@ -393,6 +396,8 @@ gpu::SyncToken OneCopyRasterBufferProvider::CopyOnWorkerThread(
return gpu::SyncToken();
}

bool needs_clear = false;

if (mailbox->IsZero()) {
uint32_t usage =
gpu::SHARED_IMAGE_USAGE_DISPLAY | gpu::SHARED_IMAGE_USAGE_RASTER;
Expand All @@ -401,6 +406,9 @@ gpu::SyncToken OneCopyRasterBufferProvider::CopyOnWorkerThread(
*mailbox = sii->CreateSharedImage(
resource_format, resource_size, color_space, kTopLeft_GrSurfaceOrigin,
kPremul_SkAlphaType, usage, gpu::kNullSurfaceHandle);
// Clear the resource if we're not going to initialize it fully from the
// copy due to non-exact resource reuse. See https://crbug.com/1313091
needs_clear = rect_to_copy.size() != resource_size;
}

// Create staging shared image.
Expand Down Expand Up @@ -452,6 +460,20 @@ gpu::SyncToken OneCopyRasterBufferProvider::CopyOnWorkerThread(
ri->BeginQueryEXT(query_target, staging_buffer->query_id);
}

// Clear to ensure the resource is fully initialized and BeginAccess succeeds.
if (needs_clear) {
int clear_bytes_per_row = viz::ResourceSizes::UncheckedWidthInBytes<int>(
resource_size.width(), resource_format);
SkImageInfo dst_info = SkImageInfo::MakeN32Premul(resource_size.width(),
resource_size.height());
SkBitmap bitmap;
if (bitmap.tryAllocPixels(dst_info, clear_bytes_per_row)) {
bitmap.eraseColor(raster_source->background_color());
ri->WritePixels(*mailbox, 0, 0, mailbox_texture_target,
clear_bytes_per_row, dst_info, bitmap.getPixels());
}
}

int bytes_per_row = viz::ResourceSizes::UncheckedWidthInBytes<int>(
rect_to_copy.width(), staging_buffer->format);
int chunk_size_in_rows =
Expand Down

0 comments on commit 901ff38

Please sign in to comment.