-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gpu: win: DComp layer SharedImageBackings
The CL introduces two new SharedImageBackings (IDCompositionSurface- and IDXGISwapChain-based) and a factory to create them. It does not introduce any users of these backings. The new DCompImageBackingFactory is inserted at a higher priority than the D3DImageBackingFactory, so it gets the first-change opportunity to back SI. To draw to the DCompSurfaceImageBacking, we continue the design used by DirectCompositionChildSurfaceWin of binding the DComp surface to a pbuffer and GLFB0 (this is opaque to the SI caller and non-interleaved drawing is a requirement of using this backing). The DXGISwapChainImageBacking binds the back buffer to a texture, similar to how D3DImageBacking does. Note, this change does not preserve: - DirectCompositionVerifyDrawOffset behavior (added in https://chromium-review.googlesource.com/c/chromium/src/+/3554067), because it is no longer needed due to (https://chromium-review.googlesource.com/c/angle/angle/+/3827081). - Ability to nest DComp surface draws (via SuspendDraw and ResumeDraw) Change-Id: I9d2b45552e4fdda7c67d417251b1a1ec99ba8670 Bug: 1378741 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3863757 Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com> Reviewed-by: Rafael Cintron <rafael.cintron@microsoft.com> Reviewed-by: Sunny Sachanandani <sunnyps@chromium.org> Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org> Cr-Commit-Position: refs/heads/main@{#1067712}
- Loading branch information
1 parent
9f028e6
commit 455b94a
Showing
25 changed files
with
1,588 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
gpu/command_buffer/service/shared_image/dcomp_image_backing_factory.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "gpu/command_buffer/service/shared_image/dcomp_image_backing_factory.h" | ||
|
||
#include <d3d11_1.h> | ||
|
||
#include "components/viz/common/resources/resource_format_utils.h" | ||
#include "components/viz/common/resources/shared_image_format.h" | ||
#include "gpu/command_buffer/common/shared_image_usage.h" | ||
#include "gpu/command_buffer/service/shared_image/dcomp_surface_image_backing.h" | ||
#include "gpu/command_buffer/service/shared_image/dxgi_swap_chain_image_backing.h" | ||
#include "ui/gfx/color_space_win.h" | ||
#include "ui/gl/direct_composition_child_surface_win.h" | ||
|
||
namespace gpu { | ||
|
||
namespace { | ||
|
||
// Check if a format is supported by DXGI for DComp surfaces or swap chains. | ||
// https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/converting-data-color-space | ||
bool IsFormatSupportedForScanout(viz::SharedImageFormat format) { | ||
if (format.is_multi_plane()) { | ||
return false; | ||
} | ||
|
||
switch (format.resource_format()) { | ||
case viz::ResourceFormat::RGBA_8888: | ||
case viz::ResourceFormat::BGRA_8888: | ||
case viz::ResourceFormat::RGBX_8888: | ||
case viz::ResourceFormat::BGRX_8888: | ||
case viz::ResourceFormat::RGBA_F16: | ||
case viz::ResourceFormat::RGBA_1010102: | ||
return true; | ||
|
||
default: | ||
return false; | ||
} | ||
} | ||
|
||
} // namespace | ||
|
||
DCompImageBackingFactory::DCompImageBackingFactory() = default; | ||
|
||
DCompImageBackingFactory::~DCompImageBackingFactory() = default; | ||
|
||
std::unique_ptr<SharedImageBacking> DCompImageBackingFactory::CreateSharedImage( | ||
const Mailbox& mailbox, | ||
viz::SharedImageFormat format, | ||
SurfaceHandle surface_handle, | ||
const gfx::Size& size, | ||
const gfx::ColorSpace& color_space, | ||
GrSurfaceOrigin surface_origin, | ||
SkAlphaType alpha_type, | ||
uint32_t usage, | ||
bool is_thread_safe) { | ||
DCHECK(!is_thread_safe); | ||
|
||
// DXGI only supports a handful of formats for scan-out, so we map the | ||
// requested format to a supported compatible DXGI format. | ||
DXGI_FORMAT internal_format = gfx::ColorSpaceWin::GetDXGIFormat(color_space); | ||
|
||
if (usage & SHARED_IMAGE_USAGE_SCANOUT_DCOMP_SURFACE) { | ||
DCHECK_NE(internal_format, DXGI_FORMAT_R10G10B10A2_UNORM); | ||
return DCompSurfaceImageBacking::Create(mailbox, format, internal_format, | ||
size, color_space, surface_origin, | ||
alpha_type, usage); | ||
} else { | ||
return DXGISwapChainImageBacking::Create(mailbox, format, internal_format, | ||
size, color_space, surface_origin, | ||
alpha_type, usage); | ||
} | ||
} | ||
|
||
std::unique_ptr<SharedImageBacking> DCompImageBackingFactory::CreateSharedImage( | ||
const Mailbox& mailbox, | ||
viz::SharedImageFormat format, | ||
const gfx::Size& size, | ||
const gfx::ColorSpace& color_space, | ||
GrSurfaceOrigin surface_origin, | ||
SkAlphaType alpha_type, | ||
uint32_t usage, | ||
base::span<const uint8_t> pixel_data) { | ||
NOTREACHED(); | ||
return nullptr; | ||
} | ||
|
||
std::unique_ptr<SharedImageBacking> DCompImageBackingFactory::CreateSharedImage( | ||
const Mailbox& mailbox, | ||
int client_id, | ||
gfx::GpuMemoryBufferHandle handle, | ||
gfx::BufferFormat format, | ||
gfx::BufferPlane plane, | ||
SurfaceHandle surface_handle, | ||
const gfx::Size& size, | ||
const gfx::ColorSpace& color_space, | ||
GrSurfaceOrigin surface_origin, | ||
SkAlphaType alpha_type, | ||
uint32_t usage) { | ||
NOTREACHED(); | ||
return nullptr; | ||
} | ||
|
||
bool DCompImageBackingFactory::IsSupported( | ||
uint32_t usage, | ||
viz::SharedImageFormat format, | ||
const gfx::Size& size, | ||
bool thread_safe, | ||
gfx::GpuMemoryBufferType gmb_type, | ||
GrContextType gr_context_type, | ||
base::span<const uint8_t> pixel_data) { | ||
constexpr uint32_t kDXGISwapChainUsage = SHARED_IMAGE_USAGE_DISPLAY_READ | | ||
SHARED_IMAGE_USAGE_DISPLAY_WRITE | | ||
SHARED_IMAGE_USAGE_SCANOUT; | ||
constexpr uint32_t kDCompSurfaceUsage = | ||
SHARED_IMAGE_USAGE_DISPLAY_WRITE | SHARED_IMAGE_USAGE_SCANOUT | | ||
SHARED_IMAGE_USAGE_SCANOUT_DCOMP_SURFACE; | ||
|
||
bool is_usage_valid = | ||
usage == kDXGISwapChainUsage || usage == kDCompSurfaceUsage; | ||
if (!is_usage_valid) { | ||
return false; | ||
} | ||
|
||
if (!IsFormatSupportedForScanout(format)) { | ||
return false; | ||
} | ||
|
||
// IDCompositionDevice2::CreateSurface does not support rgb10. In cases where | ||
// dc overlays are to be used for rgb10, the caller should use swap chains | ||
// instead. | ||
if (usage == kDCompSurfaceUsage && | ||
format.resource_format() == viz::ResourceFormat::RGBA_1010102) { | ||
return false; | ||
} | ||
|
||
if (thread_safe) { | ||
return false; | ||
} | ||
|
||
if (gmb_type != gfx::GpuMemoryBufferType::EMPTY_BUFFER) { | ||
return false; | ||
} | ||
|
||
if (!pixel_data.empty()) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} // namespace gpu |
Oops, something went wrong.