0

graphite: Enable texture_norm16 on GLES2Interface for ANGLE/D3D11

1) Expose texture_norm16 on ES2 command buffer contexts if supported by
   ANGLE. We enabled similar support for Skia for crbug.com/1324371.

2) Change DXGI_FORMAT_B8G8R8X8_UNORM to DXGI_FORMAT_B8G8R8A8_UNORM since
   we don't use the X8 variant anywhere and it's likely to cause issues.

3) Add support for R16 and R16G16 to NumPlanes in d3d_image_backing.cc,
   and other minor refactoring like renaming PlaneFormat/Size to have a
   "Video" prefix and removing SupportsVideoFormat which was used only
   for a CHECK and make the VideoPlaneFormat/Size CHECK instead.

Together these changes make SW decoded HDR video work on Graphite with
--enable-features=use-r16-texture, tested with the following flags:

--enable-features=SkiaGraphite,use-r16-texture
--disable-accelerated-video-decode
--force-color-profile=scrgb-linear

Bug: 1487765
Change-Id: Ibdde06c79834fe17282430ad101670b2e44c73b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4918035
Reviewed-by: Peng Huang <penghuang@chromium.org>
Auto-Submit: Sunny Sachanandani <sunnyps@chromium.org>
Commit-Queue: Sunny Sachanandani <sunnyps@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1207262}
This commit is contained in:
Sunny Sachanandani
2023-10-09 20:37:45 +00:00
committed by Chromium LUCI CQ
parent d6a0691a9f
commit 11fcd1e13e
4 changed files with 34 additions and 45 deletions

@ -1506,11 +1506,17 @@ void FeatureInfo::InitializeFeatures() {
feature_flags_.gpu_memory_buffer_formats.Put(gfx::BufferFormat::RG_88);
}
if (IsWebGL2OrES3OrHigherContext() &&
const bool is_texture_norm16_supported_for_webgl2_or_es3 =
IsWebGL2OrES3OrHigherContext() &&
(gl_version_info_->is_desktop_core_profile ||
(gl_version_info_->IsAtLeastGL(2, 1) &&
gfx::HasExtension(extensions, "GL_ARB_texture_rg")) ||
gfx::HasExtension(extensions, "GL_EXT_texture_norm16"))) {
gfx::HasExtension(extensions, "GL_EXT_texture_norm16"));
const bool is_texture_norm16_supported_for_angle_es2 =
is_passthrough_cmd_decoder_ && context_type_ == CONTEXT_TYPE_OPENGLES2 &&
gfx::HasExtension(extensions, "GL_EXT_texture_norm16");
if (is_texture_norm16_supported_for_webgl2_or_es3 ||
is_texture_norm16_supported_for_angle_es2) {
AddExtensionString("GL_EXT_texture_norm16");
feature_flags_.ext_texture_norm16 = true;

@ -52,19 +52,6 @@ namespace gpu {
namespace {
bool SupportsVideoFormat(DXGI_FORMAT dxgi_format) {
switch (dxgi_format) {
case DXGI_FORMAT_NV12:
case DXGI_FORMAT_P010:
case DXGI_FORMAT_B8G8R8A8_UNORM:
case DXGI_FORMAT_R10G10B10A2_UNORM:
case DXGI_FORMAT_R16G16B16A16_FLOAT:
return true;
default:
return false;
}
}
size_t NumPlanes(DXGI_FORMAT dxgi_format) {
switch (dxgi_format) {
case DXGI_FORMAT_NV12:
@ -72,49 +59,44 @@ size_t NumPlanes(DXGI_FORMAT dxgi_format) {
return 2;
case DXGI_FORMAT_R8_UNORM:
case DXGI_FORMAT_R8G8_UNORM:
case DXGI_FORMAT_R16_UNORM:
case DXGI_FORMAT_R16G16_UNORM:
case DXGI_FORMAT_R8G8B8A8_UNORM:
case DXGI_FORMAT_B8G8R8A8_UNORM:
case DXGI_FORMAT_R10G10B10A2_UNORM:
case DXGI_FORMAT_R16G16B16A16_FLOAT:
return 1;
default:
NOTREACHED() << "Unsupported DXGI format: " << dxgi_format;
return 0;
NOTREACHED_NORETURN() << "Unsupported DXGI format: " << dxgi_format;
}
}
viz::SharedImageFormat PlaneFormat(DXGI_FORMAT dxgi_format, size_t plane) {
viz::SharedImageFormat VideoPlaneFormat(DXGI_FORMAT dxgi_format, size_t plane) {
DCHECK_LT(plane, NumPlanes(dxgi_format));
viz::SharedImageFormat format;
switch (dxgi_format) {
case DXGI_FORMAT_NV12:
// Y plane is accessed as R8 and UV plane is accessed as RG88 in D3D.
format = plane == 0 ? viz::SinglePlaneFormat::kR_8
: viz::SinglePlaneFormat::kRG_88;
break;
// Y plane is accessed as R8 and UV plane is accessed as R8G8 in D3D.
return plane == 0 ? viz::SinglePlaneFormat::kR_8
: viz::SinglePlaneFormat::kRG_88;
case DXGI_FORMAT_P010:
format = plane == 0 ? viz::SinglePlaneFormat::kR_16
: viz::SinglePlaneFormat::kRG_1616;
break;
// Y plane is accessed as R16 and UV plane is accessed as R16G16 in D3D.
return plane == 0 ? viz::SinglePlaneFormat::kR_16
: viz::SinglePlaneFormat::kRG_1616;
case DXGI_FORMAT_B8G8R8A8_UNORM:
format = viz::SinglePlaneFormat::kBGRA_8888;
break;
return viz::SinglePlaneFormat::kBGRA_8888;
case DXGI_FORMAT_R10G10B10A2_UNORM:
format = viz::SinglePlaneFormat::kRGBA_1010102;
break;
return viz::SinglePlaneFormat::kRGBA_1010102;
case DXGI_FORMAT_R16G16B16A16_FLOAT:
format = viz::SinglePlaneFormat::kRGBA_F16;
break;
return viz::SinglePlaneFormat::kRGBA_F16;
default:
NOTREACHED();
format = viz::SinglePlaneFormat::kBGRA_8888;
NOTREACHED_NORETURN() << "Unsupported DXGI video format: " << dxgi_format;
}
return format;
}
gfx::Size PlaneSize(DXGI_FORMAT dxgi_format,
const gfx::Size& size,
size_t plane) {
gfx::Size VideoPlaneSize(DXGI_FORMAT dxgi_format,
const gfx::Size& size,
size_t plane) {
DCHECK_LT(plane, NumPlanes(dxgi_format));
switch (dxgi_format) {
case DXGI_FORMAT_NV12:
@ -126,8 +108,7 @@ gfx::Size PlaneSize(DXGI_FORMAT dxgi_format,
case DXGI_FORMAT_R16G16B16A16_FLOAT:
return size;
default:
NOTREACHED();
return gfx::Size();
NOTREACHED_NORETURN() << "Unsupported DXGI video format: " << dxgi_format;
}
}
@ -347,7 +328,6 @@ D3DImageBacking::CreateFromVideoTexture(
unsigned array_slice,
scoped_refptr<DXGISharedHandleState> dxgi_shared_handle_state) {
CHECK(d3d11_texture);
CHECK(SupportsVideoFormat(dxgi_format));
CHECK_EQ(mailboxes.size(), NumPlanes(dxgi_format));
// DXGI shared handle is required for WebGPU/Dawn/D3D12 interop.
@ -360,8 +340,8 @@ D3DImageBacking::CreateFromVideoTexture(
plane_index++) {
const auto& mailbox = mailboxes[plane_index];
const auto plane_format = PlaneFormat(dxgi_format, plane_index);
const auto plane_size = PlaneSize(dxgi_format, size, plane_index);
const auto plane_format = VideoPlaneFormat(dxgi_format, plane_index);
const auto plane_size = VideoPlaneSize(dxgi_format, size, plane_index);
// Shared image does not need to store the colorspace since it is already
// stored on the VideoFrame which is provided upon presenting the overlay.

@ -35,7 +35,7 @@ DXGI_FORMAT GetDXGIFormatForCreateTexture(viz::SharedImageFormat format) {
} else if (format == viz::SinglePlaneFormat::kRGBA_8888) {
return DXGI_FORMAT_R8G8B8A8_UNORM;
} else if (format == viz::SinglePlaneFormat::kBGRX_8888) {
return DXGI_FORMAT_B8G8R8X8_UNORM;
return DXGI_FORMAT_B8G8R8A8_UNORM;
} else if (format == viz::SinglePlaneFormat::kRGBX_8888) {
return DXGI_FORMAT_R8G8B8A8_UNORM;
} else if (format == viz::SinglePlaneFormat::kR_8) {

@ -360,9 +360,12 @@ TEST_P(GLTextureImageBackingFactoryWithFormatTest, Basic) {
// We use |supports_ar30_| and |supports_ab30_| to detect RGB10A2/BGR10A2
// support. It's possible Skia might support these formats even if the Chrome
// feature flags are false. We just check here that the feature flags don't
// allow Chrome to do something that Skia doesn't support.
// allow Chrome to do something that Skia doesn't support. Skia also doesn't
// support using R16/RG16 SkSurfaces with Ganesh so disallow those too.
if ((format != viz::SinglePlaneFormat::kBGRA_1010102 || supports_ar30_) &&
(format != viz::SinglePlaneFormat::kRGBA_1010102 || supports_ab30_)) {
(format != viz::SinglePlaneFormat::kRGBA_1010102 || supports_ab30_) &&
format != viz::SinglePlaneFormat::kR_16 &&
format != viz::SinglePlaneFormat::kRG_1616) {
ASSERT_TRUE(scoped_write_access);
auto* surface = scoped_write_access->surface(/*plane_index=*/0);
ASSERT_TRUE(surface);