Commit 375e9c25 authored by Daniele Castagna's avatar Daniele Castagna Committed by Commit Bot

gpu: Retry to allocate an image when SCANOUT fails

CreateSharedImage with usage SHARED_IMAGE_USAGE_SCANOUT tries to allocate
the underlying buffer with BufferUsage::SCANOUT.

BufferUsage::SCANOUT might fail in some circumentances when a buffer can
still be allocated, but it's not possible to use it for scanout (e.g: on
virtio_gpu AddFramebuffer will fail for buffers smaller than a certain
threshold).

This changes the logic of CreateSharedImage so that in cases where we fail
to allocate a buffer for scanout, we try again to allocate just for GL.

Bug: 1024019
Test: crrev.com/c/1918316 in webgl_conformance_tests on chromeos-amd64-generic-rel
Change-Id: I20615e0780e47425a4074204f706bc66018e2071
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1933198
Commit-Queue: Daniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarZhenyao Mo <zmo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718970}
parent a5ef61bf
......@@ -883,9 +883,18 @@ SharedImageBackingFactoryGLTexture::CreateSharedImage(
image = image_factory_->CreateAnonymousImage(
size, format_info.buffer_format, gfx::BufferUsage::SCANOUT,
&is_cleared);
// A SCANOUT image should not require copy.
DCHECK(!image || image->ShouldBindOrCopy() == gl::GLImage::BIND);
if (!image || !image->BindTexImage(target)) {
// Scanout images have different constraints than GL images and might fail
// to allocate even if GL images can be created.
if (!image) {
// TODO(dcastagna): Use BufferUsage::GPU_READ_WRITE instead
// BufferUsage::GPU_READ once we add it.
image = image_factory_->CreateAnonymousImage(
size, format_info.buffer_format, gfx::BufferUsage::GPU_READ,
&is_cleared);
}
// The allocated image should not require copy.
if (!image || image->ShouldBindOrCopy() != gl::GLImage::BIND ||
!image->BindTexImage(target)) {
LOG(ERROR) << "CreateSharedImage: Failed to "
<< (image ? "bind" : "create") << " image";
api->glDeleteTexturesFn(1, &service_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment