Skip to content

Commit

Permalink
Add GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM
Browse files Browse the repository at this point in the history
The SharedImageBackingFactoryGLTexture is responsible for ensuring that
whenever a GLImage-backed SharedImageBacking has GL access requested,
the GL texture be updated to reflect the GLImage.

On macOS, for YUV 420 video (basically all video), this requires copying
the biplanar video into an RGB texture, because there is no mechanism
for sampling from biplanar IOSurfaces exposed on macOS. Note that this
copy can usually skipped because those IOSurfaces can be used as
overlays directly.

The GLRenderer takes a GL read lock when scheduling overlays. This
should trigger this copy unnecessarily, but, fortunately for us all,
SharedImageBackingFactoryGLTexture is a bugfarm and skips updating GL
textures in many different and interesting ways.

Unfortunately, SharedImageBackingFactoryGLTexture can't stay a bugfarm
forever. This adds GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM, which
will act like a GL lock, but will skip doing any GL texture copying or
binding. With this in place, we can make
SharedImageBackingFactoryGLTexture do the appropriate copies that it
should be doing, without causing any regressions.

R=zmo
TBR=raymes (ppapi autogen)

Bug: 1092155
Change-Id: Ia16360cdb3fd616a8f92a4f56cb4f130b4b02b3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2255674
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780857}
  • Loading branch information
ccameron-chromium authored and Commit Bot committed Jun 22, 2020
1 parent 2e7f807 commit 84aa4da
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 17 deletions.
7 changes: 5 additions & 2 deletions gpu/GLES2/extensions/CHROMIUM/CHROMIUM_shared_image.txt
Expand Up @@ -97,8 +97,9 @@ New Procedures and Functions
scope.

INVALID_ENUM is generated if <mode> is not one of
SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM or
SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM.
SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM,
SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM, or
SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM.

The command

Expand All @@ -116,6 +117,7 @@ New Tokens
Accepted by the <mode> parameter of BeginSharedImageAccessCHROMIUM:
SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM 0x8AF6
SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM 0x8AF7
SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM 0x8AF8

Errors

Expand All @@ -129,3 +131,4 @@ Revision History

2018-10-15 Created.
2018-10-31 Added Begin/End calls.
2020-06-21 Added mode SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM.
1 change: 1 addition & 0 deletions gpu/GLES2/gl2extchromium.h
Expand Up @@ -933,6 +933,7 @@ typedef void(GL_APIENTRYP PFNGLUNPREMULTIPLYANDDITHERCOPYCHROMIUMPROC)(
#define GL_CHROMIUM_shared_image 1
#define GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM 0x8AF6
#define GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM 0x8AF7
#define GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM 0x8AF8
#endif /* GL_CHROMIUM_shared_image */

/* GL_CHROMIUM_program_completion_query */
Expand Down
1 change: 1 addition & 0 deletions gpu/command_buffer/build_gles2_cmd_buffer.py
Expand Up @@ -1592,6 +1592,7 @@
'type': 'GLenum',
'is_complete': True,
'valid': [
'GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM',
'GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM',
'GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM',
],
Expand Down
Expand Up @@ -2684,6 +2684,10 @@ static const GLES2Util::EnumToString enum_to_string_table[] = {
0x8AF7,
"GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM",
},
{
0x8AF8,
"GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM",
},
{
0x8B30,
"GL_FRAGMENT_SHADER",
Expand Down Expand Up @@ -7784,6 +7788,8 @@ std::string GLES2Util::GetStringShaderType(uint32_t value) {

std::string GLES2Util::GetStringSharedImageAccessMode(uint32_t value) {
static const EnumToString string_table[] = {
{GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM,
"GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM"},
{GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM,
"GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM"},
{GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM,
Expand Down
Expand Up @@ -77,8 +77,10 @@ bool ExternalVkImageGLRepresentationShared::BeginAccess(GLenum mode) {
}

DCHECK(mode == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM ||
mode == GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM);
const bool readonly = (mode == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM);
mode == GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM ||
mode == GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM);
const bool readonly =
(mode != GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM);

std::vector<SemaphoreHandle> handles;
if (!backing_impl()->BeginAccess(readonly, &handles, true /* is_gl */))
Expand Down Expand Up @@ -111,9 +113,10 @@ void ExternalVkImageGLRepresentationShared::EndAccess() {

DCHECK(current_access_mode_ == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM ||
current_access_mode_ ==
GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM);
GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM ||
current_access_mode_ == GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM);
const bool readonly =
(current_access_mode_ == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM);
(current_access_mode_ != GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM);
current_access_mode_ = 0;

SemaphoreHandle semaphore_handle;
Expand Down
Expand Up @@ -5444,7 +5444,8 @@ error::Error
GLES2DecoderPassthroughImpl::DoBeginSharedImageAccessDirectCHROMIUM(
GLuint client_id,
GLenum mode) {
if (mode != GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM &&
if (mode != GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM &&
mode != GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM &&
mode != GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM) {
InsertError(GL_INVALID_ENUM, "unrecognized access mode");
return error::kNoError;
Expand Down
Expand Up @@ -787,6 +787,7 @@ bool Validators::ShaderTypeValidator::IsValid(const GLenum value) const {
bool Validators::SharedImageAccessModeValidator::IsValid(
const GLenum value) const {
switch (value) {
case GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM:
case GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM:
case GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM:
return true;
Expand Down
3 changes: 2 additions & 1 deletion gpu/command_buffer/service/shared_image_backing_egl_image.cc
Expand Up @@ -37,7 +37,8 @@ class SharedImageRepresentationEglImageGLTexture
}

bool BeginAccess(GLenum mode) override {
if (mode == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM) {
if (mode == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM ||
mode == GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM) {
if (!egl_backing()->BeginRead(this))
return false;
mode_ = RepresentationAccessMode::kRead;
Expand Down
Expand Up @@ -212,7 +212,8 @@ class SharedImageRepresentationGLTextureAHB
gles2::Texture* GetTexture() override { return texture_; }

bool BeginAccess(GLenum mode) override {
if (mode == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM) {
if (mode == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM ||
mode == GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM) {
base::ScopedFD write_sync_fd;
if (!ahb_backing()->BeginRead(this, &write_sync_fd))
return false;
Expand All @@ -227,7 +228,8 @@ class SharedImageRepresentationGLTextureAHB
return false;
}

if (mode == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM) {
if (mode == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM ||
mode == GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM) {
mode_ = RepresentationAccessMode::kRead;
} else if (mode == GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM) {
mode_ = RepresentationAccessMode::kWrite;
Expand Down
12 changes: 6 additions & 6 deletions gpu/command_buffer/service/shared_image_video.cc
Expand Up @@ -145,9 +145,9 @@ class SharedImageRepresentationGLTextureVideo
gles2::Texture* GetTexture() override { return texture_; }

bool BeginAccess(GLenum mode) override {
// This representation should only be called for read.
DCHECK_EQ(mode,
static_cast<GLenum>(GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM));
// This representation should only be called for read or overlay.
DCHECK(mode == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM ||
mode == GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM);

auto* video_backing = static_cast<SharedImageVideo*>(backing());
video_backing->BeginGLReadAccess();
Expand Down Expand Up @@ -182,9 +182,9 @@ class SharedImageRepresentationGLTexturePassthroughVideo
}

bool BeginAccess(GLenum mode) override {
// This representation should only be called for read.
DCHECK_EQ(mode,
static_cast<GLenum>(GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM));
// This representation should only be called for read or overlay.
DCHECK(mode == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM ||
mode == GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM);

auto* video_backing = static_cast<SharedImageVideo*>(backing());
video_backing->BeginGLReadAccess();
Expand Down
2 changes: 1 addition & 1 deletion ppapi/shared_impl/ppb_opengles2_shared.cc
Expand Up @@ -10,7 +10,7 @@

#include "ppapi/shared_impl/ppb_opengles2_shared.h"

#include "base/check.h"
#include "base/logging.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
#include "ppapi/shared_impl/ppb_graphics_3d_shared.h"
#include "ppapi/thunk/enter.h"
Expand Down
1 change: 1 addition & 0 deletions ui/gl/gl_bindings.h
Expand Up @@ -459,6 +459,7 @@
#define GL_CHROMIUM_shared_image 1
#define GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM 0x8AF6
#define GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM 0x8AF7
#define GL_SHARED_IMAGE_ACCESS_MODE_OVERLAY_CHROMIUM 0x8AF8
#endif /* GL_CHROMIUM_shared_image */

#ifndef GL_NV_internalformat_sample_query
Expand Down

0 comments on commit 84aa4da

Please sign in to comment.