Commit 69ee817d authored by Corentin Wallez's avatar Corentin Wallez Committed by Commit Bot

Revert "Add SharedImageRepresentationDawn"

This reverts commit 3192c3b0.

Reason for revert: compile failure on Mac GPU FYI

Original change's description:
> Add SharedImageRepresentationDawn
> 
> This will allow viewing shared images as Dawn textures, for example so
> they can be rendered to via WebGPU. This representation is implemented
> for IOSurface-backed shared images.
> 
> Also adds a test to render an IOSurface backed shared image using Dawn,
> and reading it back with Skia.
> 
> BUG=chromium:938895
> 
> Change-Id: If64ea4a67368687ff54326bdb20094f17902ad2c
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1511419
> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
> Reviewed-by: Antoine Labour <piman@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#644717}

TBR=vmiura@chromium.org,cwallez@chromium.org,piman@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: chromium:938895
Change-Id: I951280b86bbd706f6fc75c46ab180013b9f6ff81
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1543253Reviewed-by: default avatarCorentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#645270}
parent 41c21df5
......@@ -310,13 +310,6 @@ test("gl_tests") {
"//ui/platform_window:platform_impls",
]
}
if (use_dawn) {
deps += [
"//third_party/dawn:libdawn_native",
"//third_party/dawn/src/dawn:libdawn",
]
}
}
test("gpu_unittests") {
......
......@@ -288,7 +288,6 @@ target(link_target_type, "gles2_sources") {
"//gpu/command_buffer/common:raster_sources",
"//gpu/command_buffer/common:webgpu_sources",
"//skia",
"//third_party/dawn/src/dawn:dawn_headers",
]
deps = [
":disk_cache_proto",
......@@ -312,7 +311,6 @@ target(link_target_type, "gles2_sources") {
"//ui/gfx/geometry",
"//ui/gfx/ipc/color",
"//ui/gl",
"//ui/gl:buildflags",
"//ui/gl/init",
]
......
......@@ -58,13 +58,6 @@ std::unique_ptr<SharedImageRepresentationSkia> SharedImageBacking::ProduceSkia(
return nullptr;
}
std::unique_ptr<SharedImageRepresentationDawn> SharedImageBacking::ProduceDawn(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
DawnDevice device) {
return nullptr;
}
void SharedImageBacking::AddRef(SharedImageRepresentation* representation) {
AutoLock auto_lock(this);
......
......@@ -5,10 +5,6 @@
#ifndef GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_BACKING_H_
#define GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_BACKING_H_
#include <dawn/dawn.h>
#include <memory>
#include "base/containers/flat_map.h"
#include "base/optional.h"
#include "base/synchronization/lock.h"
......@@ -32,7 +28,6 @@ class SharedImageRepresentation;
class SharedImageRepresentationGLTexture;
class SharedImageRepresentationGLTexturePassthrough;
class SharedImageRepresentationSkia;
class SharedImageRepresentationDawn;
class MemoryTypeTracker;
// Represents the actual storage (GL texture, VkImage, GMB) for a SharedImage.
......@@ -102,10 +97,6 @@ class GPU_GLES2_EXPORT SharedImageBacking {
virtual std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
SharedImageManager* manager,
MemoryTypeTracker* tracker);
virtual std::unique_ptr<SharedImageRepresentationDawn> ProduceDawn(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
DawnDevice device);
// Used by subclasses in Destroy.
bool have_context() const;
......
......@@ -5,7 +5,6 @@
#include "gpu/command_buffer/service/shared_image_backing_factory_iosurface.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/optional.h"
#include "components/viz/common/resources/resource_format_utils.h"
#include "components/viz/common/resources/resource_sizes.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
......@@ -15,16 +14,9 @@
#include "gpu/command_buffer/service/texture_manager.h"
#include "third_party/skia/include/core/SkPromiseImageTexture.h"
#include "ui/gfx/mac/io_surface.h"
#include "ui/gl/buildflags.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_image_io_surface.h"
// Usage of BUILDFLAG(USE_DAWN) needs to be after the include for
// ui/gl/buildflags.h
#if BUILDFLAG(USE_DAWN)
#include <dawn_native/MetalBackend.h>
#endif // BUILDFLAG(USE_DAWN)
namespace gpu {
namespace {
......@@ -82,22 +74,6 @@ void FlushIOSurfaceGLOperations() {
api->glFlushFn();
}
base::Optional<DawnTextureFormat> GetDawnFormat(viz::ResourceFormat format) {
switch (format) {
case viz::RED_8:
case viz::ALPHA_8:
case viz::LUMINANCE_8:
return DAWN_TEXTURE_FORMAT_R8_UNORM;
case viz::RG_88:
return DAWN_TEXTURE_FORMAT_R8_G8_UNORM;
case viz::RGBA_8888:
case viz::BGRA_8888:
return DAWN_TEXTURE_FORMAT_B8_G8_R8_A8_UNORM;
default:
return {};
}
}
} // anonymous namespace
// Representation of a SharedImageBackingIOSurface as a GL Texture.
......@@ -182,62 +158,6 @@ class SharedImageRepresentationSkiaIOSurface
gles2::Texture* texture_;
};
// Representation of a SharedImageBackingIOSurface as a Dawn Texture.
#if BUILDFLAG(USE_DAWN)
class SharedImageRepresentationDawnIOSurface
: public SharedImageRepresentationDawn {
public:
SharedImageRepresentationDawnIOSurface(
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker,
DawnDevice device,
base::ScopedCFTypeRef<IOSurfaceRef> io_surface,
DawnTextureFormat dawn_format)
: SharedImageRepresentationDawn(manager, backing, tracker),
io_surface_(std::move(io_surface)),
device_(device),
dawn_format_(dawn_format) {
DCHECK(device_);
DCHECK(io_surface_);
}
~SharedImageRepresentationDawnIOSurface() override {}
DawnTexture BeginAccess(DawnTextureUsageBit usage) final {
DawnTextureDescriptor desc;
desc.nextInChain = nullptr;
desc.format = dawn_format_;
desc.usage = usage;
desc.dimension = DAWN_TEXTURE_DIMENSION_2D;
desc.size = {size().width(), size().height(), 1};
desc.arrayLayerCount = 1;
desc.mipLevelCount = 1;
desc.sampleCount = 1;
return dawn_native::metal::WrapIOSurface(device_, &desc, io_surface_.get(),
0);
}
void EndAccess() final {
// macOS has a global GPU command queue so synchronization between APIs and
// devices is automatic. However on Metal, dawnQueueSubmit "commits" the
// Metal command buffers but they aren't "scheduled" in the global queue
// immediately. (that work seems offloaded to a different thread?)
// Wait for all the previous submitted commands to be scheduled to have
// scheduling races between commands using the IOSurface on different APIs.
// This is a blocking call but should be almost instant.
TRACE_EVENT0("gpu", "SharedImageRepresentationDawnIOSurface::EndAccess");
dawn_native::metal::WaitForCommandsToBeScheduled(device_);
}
private:
base::ScopedCFTypeRef<IOSurfaceRef> io_surface_;
DawnDevice device_;
DawnTextureFormat dawn_format_;
};
#endif // BUILDFLAG(USE_DAWN)
// Implementation of SharedImageBacking by wrapping IOSurfaces
class SharedImageBackingIOSurface : public SharedImageBacking {
public:
......@@ -247,7 +167,6 @@ class SharedImageBackingIOSurface : public SharedImageBacking {
const gfx::ColorSpace& color_space,
uint32_t usage,
base::ScopedCFTypeRef<IOSurfaceRef> io_surface,
base::Optional<DawnTextureFormat> dawn_format,
size_t estimated_size)
: SharedImageBacking(mailbox,
format,
......@@ -256,8 +175,7 @@ class SharedImageBackingIOSurface : public SharedImageBacking {
usage,
estimated_size,
false /* is_thread_safe */),
io_surface_(std::move(io_surface)),
dawn_format_(dawn_format) {
io_surface_(std::move(io_surface)) {
DCHECK(io_surface_);
}
~SharedImageBackingIOSurface() final { DCHECK(!io_surface_); }
......@@ -326,23 +244,6 @@ class SharedImageBackingIOSurface : public SharedImageBacking {
manager, this, promise_texture, tracker, texture);
}
std::unique_ptr<SharedImageRepresentationDawn> ProduceDawn(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
DawnDevice device) override {
#if BUILDFLAG(USE_DAWN)
if (!dawn_format_) {
LOG(ERROR) << "Format not supported for Dawn";
return nullptr;
}
return std::make_unique<SharedImageRepresentationDawnIOSurface>(
manager, this, tracker, device, io_surface_, dawn_format_.value());
#else // BUILDFLAG(USE_DAWN)
return nullptr;
#endif // BUILDFLAG(USE_DAWN)
}
private:
gles2::Texture* GenGLTexture() {
GLFormatInfo gl_info = GetGLFormatInfo(format());
......@@ -412,7 +313,6 @@ class SharedImageBackingIOSurface : public SharedImageBacking {
}
base::ScopedCFTypeRef<IOSurfaceRef> io_surface_;
base::Optional<DawnTextureFormat> dawn_format_;
bool is_cleared_ = false;
// A texture for the associated legacy mailbox.
......@@ -483,7 +383,7 @@ SharedImageBackingFactoryIOSurface::CreateSharedImage(
return std::make_unique<SharedImageBackingIOSurface>(
mailbox, format, size, color_space, usage, std::move(io_surface),
GetDawnFormat(format), estimated_size);
estimated_size);
}
std::unique_ptr<SharedImageBacking>
......
......@@ -22,16 +22,10 @@
#include "third_party/skia/include/core/SkPromiseImageTexture.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "ui/gl/buildflags.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_surface.h"
#include "ui/gl/init/gl_factory.h"
#if BUILDFLAG(USE_DAWN)
#include <dawn/dawncpp.h>
#include <dawn_native/DawnNative.h>
#endif // BUILDFLAG(USE_DAWN)
namespace gpu {
namespace {
......@@ -159,7 +153,7 @@ TEST_F(SharedImageBackingFactoryIOSurfaceTest, Basic) {
// Test to check interaction between Gl and skia GL representations.
// We write to a GL texture using gl representation and then read from skia
// representation.
TEST_F(SharedImageBackingFactoryIOSurfaceTest, GL_SkiaGL) {
TEST_F(SharedImageBackingFactoryIOSurfaceTest, GLSkiaGL) {
// Create a backing using mailbox.
auto mailbox = Mailbox::GenerateForSharedImage();
auto format = viz::ResourceFormat::RGBA_8888;
......@@ -239,119 +233,5 @@ TEST_F(SharedImageBackingFactoryIOSurfaceTest, GL_SkiaGL) {
EXPECT_FALSE(mailbox_manager_.ConsumeTexture(mailbox));
}
#if BUILDFLAG(USE_DAWN)
// Test to check interaction between Dawn and skia GL representations.
TEST_F(SharedImageBackingFactoryIOSurfaceTest, Dawn_SkiaGL) {
// Create a Dawn Metal device
dawn_native::Instance instance;
instance.DiscoverDefaultAdapters();
std::vector<dawn_native::Adapter> adapters = instance.GetAdapters();
auto adapter_it = std::find_if(
adapters.begin(), adapters.end(), [](dawn_native::Adapter adapter) {
return adapter.GetBackendType() == dawn_native::BackendType::Metal;
});
ASSERT_NE(adapter_it, adapters.end());
dawn::Device device = dawn::Device::Acquire(adapter_it->CreateDevice());
DawnProcTable procs = dawn_native::GetProcs();
dawnSetProcs(&procs);
// Create a backing using mailbox.
auto mailbox = Mailbox::GenerateForSharedImage();
auto format = viz::ResourceFormat::RGBA_8888;
gfx::Size size(1, 1);
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2 | SHARED_IMAGE_USAGE_DISPLAY;
auto backing = backing_factory_->CreateSharedImage(mailbox, format, size,
color_space, usage);
EXPECT_TRUE(backing);
std::unique_ptr<SharedImageRepresentationFactoryRef> factory_ref =
shared_image_manager_.Register(std::move(backing),
memory_type_tracker_.get());
// Create a SharedImageRepresentationDawn.
auto dawn_representation =
shared_image_representation_factory_->ProduceDawn(mailbox, device.Get());
EXPECT_TRUE(dawn_representation);
// Clear the shared image to green using Dawn.
{
dawn::Texture texture =
dawn::Texture::Acquire(dawn_representation->BeginAccess(
DAWN_TEXTURE_USAGE_BIT_OUTPUT_ATTACHMENT));
dawn::RenderPassColorAttachmentDescriptor colorDesc;
colorDesc.attachment = texture.CreateDefaultTextureView();
colorDesc.resolveTarget = nullptr;
colorDesc.loadOp = dawn::LoadOp::Clear;
colorDesc.storeOp = dawn::StoreOp::Store;
colorDesc.clearColor = {0, 255, 0, 255};
dawn::RenderPassColorAttachmentDescriptor* colorAttachmentsPtr = &colorDesc;
dawn::RenderPassDescriptor renderPassDesc;
renderPassDesc.colorAttachmentCount = 1;
renderPassDesc.colorAttachments = &colorAttachmentsPtr;
renderPassDesc.depthStencilAttachment = nullptr;
dawn::CommandEncoder encoder = device.CreateCommandEncoder();
dawn::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPassDesc);
pass.EndPass();
dawn::CommandBuffer commands = encoder.Finish();
dawn::Queue queue = device.CreateQueue();
queue.Submit(1, &commands);
}
dawn_representation->EndAccess();
// Next create a SharedImageRepresentationSkia to read back the texture data.
auto skia_representation =
shared_image_representation_factory_->ProduceSkia(mailbox);
EXPECT_TRUE(skia_representation);
auto promise_texture = skia_representation->BeginReadAccess(nullptr);
EXPECT_TRUE(promise_texture);
if (promise_texture) {
GrBackendTexture backend_texture = promise_texture->backendTexture();
EXPECT_TRUE(backend_texture.isValid());
EXPECT_EQ(size.width(), backend_texture.width());
EXPECT_EQ(size.height(), backend_texture.height());
}
// Create an Sk Image from GrBackendTexture.
auto sk_image = SkImage::MakeFromTexture(
gr_context(), promise_texture->backendTexture(), kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr);
SkImageInfo dst_info =
SkImageInfo::Make(size.width(), size.height(), kRGBA_8888_SkColorType,
kOpaque_SkAlphaType, nullptr);
const int num_pixels = size.width() * size.height();
std::unique_ptr<uint8_t[]> dst_pixels(new uint8_t[num_pixels * 4]());
// Read back pixels from Sk Image.
EXPECT_TRUE(sk_image->readPixels(dst_info, dst_pixels.get(),
dst_info.minRowBytes(), 0, 0));
skia_representation->EndReadAccess();
// Compare the pixel values.
EXPECT_EQ(dst_pixels[0], 0);
EXPECT_EQ(dst_pixels[1], 255);
EXPECT_EQ(dst_pixels[2], 0);
EXPECT_EQ(dst_pixels[3], 255);
// Shut down Dawn
device = dawn::Device();
dawnSetProcs(nullptr);
skia_representation.reset();
factory_ref.reset();
EXPECT_FALSE(mailbox_manager_.ConsumeTexture(mailbox));
}
#endif // BUILDFLAG(USE_DAWN)
} // anonymous namespace
} // namespace gpu
......@@ -299,10 +299,4 @@ SharedImageRepresentationFactory::ProduceSkia(const Mailbox& mailbox) {
return manager_->ProduceSkia(mailbox, tracker_.get());
}
std::unique_ptr<SharedImageRepresentationDawn>
SharedImageRepresentationFactory::ProduceDawn(const Mailbox& mailbox,
DawnDevice device) {
return manager_->ProduceDawn(mailbox, tracker_.get(), device);
}
} // namespace gpu
......@@ -119,9 +119,6 @@ class GPU_GLES2_EXPORT SharedImageRepresentationFactory {
ProduceGLTexturePassthrough(const Mailbox& mailbox);
std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
const Mailbox& mailbox);
std::unique_ptr<SharedImageRepresentationDawn> ProduceDawn(
const Mailbox& mailbox,
DawnDevice device);
private:
SharedImageManager* manager_;
......
......@@ -6,7 +6,6 @@
#include <inttypes.h>
#include <memory>
#include <utility>
#include "base/logging.h"
......@@ -197,30 +196,6 @@ std::unique_ptr<SharedImageRepresentationSkia> SharedImageManager::ProduceSkia(
return representation;
}
std::unique_ptr<SharedImageRepresentationDawn> SharedImageManager::ProduceDawn(
const Mailbox& mailbox,
MemoryTypeTracker* tracker,
DawnDevice device) {
CALLED_ON_VALID_THREAD();
AutoLock autolock(this);
auto found = images_.find(mailbox);
if (found == images_.end()) {
LOG(ERROR) << "SharedImageManager::ProduceDawn: Trying to Produce a "
"Dawn representation from a non-existent mailbox.";
return nullptr;
}
auto representation = (*found)->ProduceDawn(this, tracker, device);
if (!representation) {
LOG(ERROR) << "SharedImageManager::ProduceDawn: Trying to produce a "
"Skia representation from an incompatible mailbox.";
return nullptr;
}
return representation;
}
void SharedImageManager::OnRepresentationDestroyed(
const Mailbox& mailbox,
SharedImageRepresentation* representation) {
......
......@@ -44,10 +44,6 @@ class GPU_GLES2_EXPORT SharedImageManager {
std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
const Mailbox& mailbox,
MemoryTypeTracker* ref);
std::unique_ptr<SharedImageRepresentationDawn> ProduceDawn(
const Mailbox& mailbox,
MemoryTypeTracker* ref,
DawnDevice device);
// Called by SharedImageRepresentation in the destructor.
void OnRepresentationDestroyed(const Mailbox& mailbox,
......
......@@ -5,8 +5,6 @@
#ifndef GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_REPRESENTATION_H_
#define GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_REPRESENTATION_H_
#include <dawn/dawn.h>
#include "base/callback_helpers.h"
#include "components/viz/common/resources/resource_format.h"
#include "gpu/command_buffer/service/shared_image_backing.h"
......@@ -161,17 +159,6 @@ class SharedImageRepresentationSkia : public SharedImageRepresentation {
virtual void EndReadAccess() = 0;
};
class SharedImageRepresentationDawn : public SharedImageRepresentation {
public:
SharedImageRepresentationDawn(SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker)
: SharedImageRepresentation(manager, backing, tracker) {}
virtual DawnTexture BeginAccess(DawnTextureUsageBit usage) = 0;
virtual void EndAccess() = 0;
};
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_REPRESENTATION_H_
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