[MappableSI] Use CPU_ONLY_READ_WRITE for CrOs media capture.
As a part of MappableSI, we are replacing GMB usage with MappableSI. Creating a MappableSI for R8 format in media capture code currently fails in service side code[1]. This is because creating a NativePixmap as part of OzoneImageBacking creation will fail as the underlying buffer is not texturable. Also for media capture code irrespective of the format, we don't really need to hold the GMB handle in the service side SharedImage backing anyways since capture code only need the GMB handle to map. Handle is then sent to renderer which actually creates a shared image which will be used in the GPU process. Hence use SHARED_IMAGE_USAGE_CPU_ONLY_READ_WRITE which instructs the service side that a NativePixmap inside the SharedImage is not necessary for this use case. This allows skipping the service side checks for texturable format. [1] https://source.chromium.org/chromium/chromium/src/+/main:ui/gfx/linux/gbm_wrapper.cc;drc=5d0194cbc9cddc2ad096da32f16d7d1eac5d4a34;l=410 Bug: 40264379, 382679374, 370760466 Change-Id: Ie1263454ca3e857efe521d1fe282f399d3db899f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6072273 Reviewed-by: Colin Blundell <blundell@chromium.org> Commit-Queue: vikas soni <vikassoni@chromium.org> Auto-Submit: vikas soni <vikassoni@chromium.org> Cr-Commit-Position: refs/heads/main@{#1401487}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
0866d0eb4c
commit
ba008f7f0c
gpu/command_buffer/service/shared_image
media/capture/video/chromeos
@ -156,6 +156,9 @@ std::unique_ptr<DawnImageRepresentation> OzoneImageBacking::ProduceDawn(
|
||||
wgpu::BackendType backend_type,
|
||||
std::vector<wgpu::TextureFormat> view_formats,
|
||||
scoped_refptr<SharedContextState> context_state) {
|
||||
// Creating a representation in GPU is not allowed when usage is CPU only.
|
||||
CHECK(!(usage().Has(SHARED_IMAGE_USAGE_CPU_ONLY_READ_WRITE)));
|
||||
|
||||
#if BUILDFLAG(USE_DAWN)
|
||||
wgpu::TextureFormat webgpu_format = ToDawnFormat(format());
|
||||
if (webgpu_format == wgpu::TextureFormat::Undefined) {
|
||||
@ -177,6 +180,9 @@ OzoneImageBacking::ProduceSkiaGraphite(
|
||||
scoped_refptr<SharedContextState> context_state) {
|
||||
CHECK(context_state);
|
||||
CHECK(context_state->IsGraphiteDawn());
|
||||
// Creating a representation in GPU is not allowed when usage is CPU only.
|
||||
CHECK(!(usage().Has(SHARED_IMAGE_USAGE_CPU_ONLY_READ_WRITE)));
|
||||
|
||||
#if BUILDFLAG(SKIA_USE_DAWN)
|
||||
auto device = context_state->dawn_context_provider()->GetDevice();
|
||||
auto backend_type = context_state->dawn_context_provider()->backend_type();
|
||||
@ -283,6 +289,9 @@ OzoneImageBacking::RetainGLTexturePerContextCache() {
|
||||
std::unique_ptr<GLTexturePassthroughImageRepresentation>
|
||||
OzoneImageBacking::ProduceGLTexturePassthrough(SharedImageManager* manager,
|
||||
MemoryTypeTracker* tracker) {
|
||||
// Creating a representation in GPU is not allowed when usage is CPU only.
|
||||
CHECK(!(usage().Has(SHARED_IMAGE_USAGE_CPU_ONLY_READ_WRITE)));
|
||||
|
||||
auto texture_holder = RetainGLTexturePerContextCache();
|
||||
if (!texture_holder) {
|
||||
return nullptr;
|
||||
@ -301,6 +310,9 @@ OzoneImageBacking::ProduceSkiaGanesh(
|
||||
SharedImageManager* manager,
|
||||
MemoryTypeTracker* tracker,
|
||||
scoped_refptr<SharedContextState> context_state) {
|
||||
// Creating a representation in GPU is not allowed when usage is CPU only.
|
||||
CHECK(!(usage().Has(SHARED_IMAGE_USAGE_CPU_ONLY_READ_WRITE)));
|
||||
|
||||
if (context_state->GrContextIsGL()) {
|
||||
auto gl_representation = ProduceGLTexturePassthrough(manager, tracker);
|
||||
if (!gl_representation) {
|
||||
@ -372,6 +384,9 @@ OzoneImageBacking::ProduceSkiaGanesh(
|
||||
std::unique_ptr<OverlayImageRepresentation> OzoneImageBacking::ProduceOverlay(
|
||||
SharedImageManager* manager,
|
||||
MemoryTypeTracker* tracker) {
|
||||
// Creating a representation in GPU is not allowed when usage is CPU only.
|
||||
CHECK(!(usage().Has(SHARED_IMAGE_USAGE_CPU_ONLY_READ_WRITE)));
|
||||
|
||||
return std::make_unique<OverlayOzoneImageRepresentation>(manager, this,
|
||||
tracker);
|
||||
}
|
||||
@ -389,17 +404,18 @@ OzoneImageBacking::OzoneImageBacking(
|
||||
scoped_refptr<gfx::NativePixmap> pixmap,
|
||||
const GpuDriverBugWorkarounds& workarounds,
|
||||
std::optional<gfx::BufferUsage> buffer_usage)
|
||||
: ClearTrackingSharedImageBacking(mailbox,
|
||||
format,
|
||||
size,
|
||||
color_space,
|
||||
surface_origin,
|
||||
alpha_type,
|
||||
usage,
|
||||
std::move(debug_label),
|
||||
GetPixmapSizeInBytes(*pixmap),
|
||||
false,
|
||||
std::move(buffer_usage)),
|
||||
: ClearTrackingSharedImageBacking(
|
||||
mailbox,
|
||||
format,
|
||||
size,
|
||||
color_space,
|
||||
surface_origin,
|
||||
alpha_type,
|
||||
usage,
|
||||
std::move(debug_label),
|
||||
pixmap ? GetPixmapSizeInBytes(*pixmap) : 0,
|
||||
false,
|
||||
std::move(buffer_usage)),
|
||||
pixmap_(std::move(pixmap)),
|
||||
context_state_(std::move(context_state)),
|
||||
workarounds_(workarounds),
|
||||
@ -451,6 +467,9 @@ std::unique_ptr<VulkanImageRepresentation> OzoneImageBacking::ProduceVulkan(
|
||||
gpu::VulkanDeviceQueue* vulkan_device_queue,
|
||||
gpu::VulkanImplementation& vulkan_impl,
|
||||
bool needs_detiling) {
|
||||
// Creating a representation in GPU is not allowed when usage is CPU only.
|
||||
CHECK(!(usage().Has(SHARED_IMAGE_USAGE_CPU_ONLY_READ_WRITE)));
|
||||
|
||||
viz::SharedImageFormat image_format = format();
|
||||
gfx::Size image_size = size();
|
||||
gfx::GpuMemoryBufferHandle gmb_handle = GetGpuMemoryBufferHandle();
|
||||
|
@ -71,7 +71,7 @@ constexpr SharedImageUsageSet kSupportedUsage =
|
||||
SHARED_IMAGE_USAGE_HIGH_PERFORMANCE_GPU | SHARED_IMAGE_USAGE_CPU_UPLOAD |
|
||||
SHARED_IMAGE_USAGE_CPU_WRITE_ONLY |
|
||||
SHARED_IMAGE_USAGE_WEBGPU_STORAGE_TEXTURE |
|
||||
SHARED_IMAGE_USAGE_PROTECTED_VIDEO;
|
||||
SHARED_IMAGE_USAGE_PROTECTED_VIDEO | SHARED_IMAGE_USAGE_CPU_ONLY_READ_WRITE;
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -194,14 +194,21 @@ std::unique_ptr<SharedImageBacking> OzoneImageBackingFactory::CreateSharedImage(
|
||||
gfx::GpuMemoryBufferHandle handle) {
|
||||
DCHECK_EQ(handle.type, gfx::NATIVE_PIXMAP);
|
||||
|
||||
ui::SurfaceFactoryOzone* surface_factory =
|
||||
ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone();
|
||||
scoped_refptr<gfx::NativePixmap> pixmap =
|
||||
surface_factory->CreateNativePixmapFromHandle(
|
||||
kNullSurfaceHandle, size, ToBufferFormat(format),
|
||||
std::move(handle.native_pixmap_handle));
|
||||
if (!pixmap) {
|
||||
return nullptr;
|
||||
scoped_refptr<gfx::NativePixmap> pixmap;
|
||||
|
||||
// We do not create a native pixmap if the backing will be used only by the
|
||||
// CPU. This is usually used for cases where clients needs MappableSI with a
|
||||
// certain format which is not texturable but client wants to map the shared
|
||||
// image in CPU for read/writes.
|
||||
if (!usage.Has(SHARED_IMAGE_USAGE_CPU_ONLY_READ_WRITE)) {
|
||||
ui::SurfaceFactoryOzone* surface_factory =
|
||||
ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone();
|
||||
pixmap = surface_factory->CreateNativePixmapFromHandle(
|
||||
kNullSurfaceHandle, size, ToBufferFormat(format),
|
||||
std::move(handle.native_pixmap_handle));
|
||||
if (!pixmap) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
auto backing = std::make_unique<OzoneImageBacking>(
|
||||
|
@ -12,10 +12,6 @@
|
||||
|
||||
namespace media {
|
||||
|
||||
// Setting some default usage in order to get a mappable shared image.
|
||||
constexpr auto si_usage = gpu::SHARED_IMAGE_USAGE_CPU_WRITE_ONLY |
|
||||
gpu::SHARED_IMAGE_USAGE_DISPLAY_READ;
|
||||
|
||||
CameraBufferFactory::CameraBufferFactory() = default;
|
||||
|
||||
CameraBufferFactory::~CameraBufferFactory() = default;
|
||||
@ -68,9 +64,24 @@ scoped_refptr<gpu::ClientSharedImage> CameraBufferFactory::CreateSharedImage(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// In the media capture process, the underlying GMB handle created via the
|
||||
// below shared image is only used for CPU read/write. It is then later sent
|
||||
// to the renderer which uses the handle to create a new shared image for
|
||||
// drawing. Hence there is no need to create and hold a service side GMB
|
||||
// handle/NativePixmap as a part of OzoneImageBacking created via below
|
||||
// CreateSharedImage call. Creating and holding a NativePixmap via below
|
||||
// CreateSharedImage call also fails for R8 format since it's not a
|
||||
// texturable format for some devices.
|
||||
// Hence we use the special usage flag SHARED_IMAGE_USAGE_CPU_ONLY_READ_WRITE
|
||||
// which instructs the service side code that a NativePixmap inside the
|
||||
// SharedImage is not necessary for this use case.
|
||||
// Note that we'll need to refine this if/when we want to send these
|
||||
// SharedImages over to the renderer process when feasible (i.e., for non-R8
|
||||
// and/or for R8 on devices where it's texturable).
|
||||
auto shared_image = sii->CreateSharedImage(
|
||||
{viz::GetSharedImageFormat(format), size, color_space,
|
||||
gpu::SharedImageUsageSet(si_usage), "CameraBufferFactory"},
|
||||
gpu::SharedImageUsageSet(gpu::SHARED_IMAGE_USAGE_CPU_ONLY_READ_WRITE),
|
||||
"CameraBufferFactory"},
|
||||
gpu::kNullSurfaceHandle, usage);
|
||||
if (!shared_image) {
|
||||
LOG(ERROR) << "Failed to create a shared image.";
|
||||
@ -91,9 +102,24 @@ CameraBufferFactory::CreateSharedImageFromGmbHandle(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// In the media capture process, the underlying GMB handle created via the
|
||||
// below shared image is only used for CPU read/write. It is then later sent
|
||||
// to the renderer which uses the handle to create a new shared image for
|
||||
// drawing. Hence there is no need to create and hold a service side GMB
|
||||
// handle/NativePixmap as a part of OzoneImageBacking created via below
|
||||
// CreateSharedImage call. Creating and holding a NativePixmap via below
|
||||
// CreateSharedImage call also fails for R8 format since it's not a
|
||||
// texturable format for some devices.
|
||||
// Hence we use the special usage flag SHARED_IMAGE_USAGE_CPU_ONLY_READ_WRITE
|
||||
// which instructs the service side code that a NativePixmap inside the
|
||||
// SharedImage is not necessary for this use case.
|
||||
// Note that we'll need to refine this if/when we want to send these
|
||||
// SharedImages over to the renderer process when feasible (i.e., for non-R8
|
||||
// and/or for R8 on devices where it's texturable).
|
||||
auto shared_image = sii->CreateSharedImage(
|
||||
{viz::GetSharedImageFormat(format), size, color_space,
|
||||
gpu::SharedImageUsageSet(si_usage), "CameraBufferFactory"},
|
||||
gpu::SharedImageUsageSet(gpu::SHARED_IMAGE_USAGE_CPU_ONLY_READ_WRITE),
|
||||
"CameraBufferFactory"},
|
||||
gpu::kNullSurfaceHandle, usage, std::move(buffer_handle));
|
||||
if (!shared_image) {
|
||||
LOG(ERROR) << "Failed to create a shared image.";
|
||||
|
Reference in New Issue
Block a user