Commit 33c8f181 authored by Idan Raiter's avatar Idan Raiter Committed by Commit Bot

[WebGPU] Use swapchain format when creating shared image

This change passes the swapchain format to where we create the shared image.
This is required to be able to render both bgra and rgba, since dawn verifies
the texture descriptor of the shared image matches the one requested in the
javascript.

Bug: 976495
Change-Id: Ief4693649b6e67d363702063afab38fffd290062
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1728343
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Reviewed-by: default avatarKai Ninomiya <kainino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683816}
parent 25bb8c09
......@@ -24,8 +24,9 @@ GPUSwapChain::GPUSwapChain(GPUCanvasContext* context,
device_(descriptor->device()),
context_(context),
usage_(AsDawnEnum<DawnTextureUsageBit>(descriptor->usage())) {
swap_buffers_ = base::AdoptRef(
new WebGPUSwapBufferProvider(this, GetDawnControlClient(), usage_));
swap_buffers_ = base::AdoptRef(new WebGPUSwapBufferProvider(
this, GetDawnControlClient(), usage_,
AsDawnEnum<DawnTextureFormat>(descriptor->format())));
}
GPUSwapChain::~GPUSwapChain() {
......
......@@ -13,13 +13,28 @@
namespace blink {
namespace {
viz::ResourceFormat DawnFormatToViz(DawnTextureFormat format) {
if (format == DAWN_TEXTURE_FORMAT_BGRA8_UNORM) {
return viz::BGRA_8888;
}
if (format == DAWN_TEXTURE_FORMAT_RGBA8_UNORM) {
return viz::RGBA_8888;
}
NOTREACHED();
return viz::RGBA_8888;
}
} // namespace
WebGPUSwapBufferProvider::WebGPUSwapBufferProvider(
Client* client,
scoped_refptr<DawnControlClientHolder> dawn_control_client,
DawnTextureUsageBit usage)
DawnTextureUsageBit usage,
DawnTextureFormat format)
: dawn_control_client_(dawn_control_client),
client_(client),
usage_(usage) {
usage_(usage),
format_(DawnFormatToViz(format)) {
// Create a layer that will be used by the canvas and will ask for a
// SharedImage each frame.
layer_ = cc::TextureLayer::CreateForMailbox(this);
......@@ -81,8 +96,7 @@ DawnTexture WebGPUSwapBufferProvider::GetNewTexture(DawnDevice device,
// Create a new swap buffer.
// TODO(cwallez@chromium.org): have some recycling mechanism.
gpu::Mailbox mailbox = sii->CreateSharedImage(
viz::RGBA_8888, static_cast<gfx::Size>(size),
gfx::ColorSpace::CreateSRGB(),
format_, static_cast<gfx::Size>(size), gfx::ColorSpace::CreateSRGB(),
gpu::SHARED_IMAGE_USAGE_WEBGPU | gpu::SHARED_IMAGE_USAGE_DISPLAY);
gpu::SyncToken creation_token = sii->GenUnverifiedSyncToken();
......@@ -156,7 +170,7 @@ bool WebGPUSwapBufferProvider::PrepareTransferableResource(
current_swap_buffer_->access_finished_token, current_swap_buffer_->size,
false);
out_resource->color_space = gfx::ColorSpace::CreateSRGB();
out_resource->format = viz::RGBA_8888;
out_resource->format = format_;
// This holds a ref on the SwapBuffers that will keep it alive until the
// mailbox is released (and while the release callback is running).
......
......@@ -35,7 +35,8 @@ class PLATFORM_EXPORT WebGPUSwapBufferProvider
WebGPUSwapBufferProvider(
Client* client,
scoped_refptr<DawnControlClientHolder> dawn_control_client,
DawnTextureUsageBit usage);
DawnTextureUsageBit usage,
DawnTextureFormat format);
~WebGPUSwapBufferProvider() override;
cc::Layer* CcLayer();
......@@ -88,6 +89,7 @@ class PLATFORM_EXPORT WebGPUSwapBufferProvider
uint32_t wire_texture_id_ = 0;
uint32_t wire_texture_generation_ = 0;
scoped_refptr<SwapBuffer> current_swap_buffer_;
viz::ResourceFormat format_;
};
} // namespace blink
......
......@@ -58,8 +58,9 @@ class WebGPUSwapBufferProviderForTests : public WebGPUSwapBufferProvider {
bool* alive,
Client* client,
scoped_refptr<DawnControlClientHolder> dawn_control_client,
DawnTextureUsageBit usage)
: WebGPUSwapBufferProvider(client, dawn_control_client, usage),
DawnTextureUsageBit usage,
DawnTextureFormat format)
: WebGPUSwapBufferProvider(client, dawn_control_client, usage, format),
alive_(alive) {}
~WebGPUSwapBufferProviderForTests() override { *alive_ = false; }
......@@ -83,7 +84,8 @@ class WebGPUSwapBufferProviderTest : public testing::Test {
base::MakeRefCounted<DawnControlClientHolder>(std::move(provider));
provider_ = base::MakeRefCounted<WebGPUSwapBufferProviderForTests>(
&provider_alive_, &client_, dawn_control_client_,
DAWN_TEXTURE_USAGE_BIT_OUTPUT_ATTACHMENT);
DAWN_TEXTURE_USAGE_BIT_OUTPUT_ATTACHMENT,
DAWN_TEXTURE_FORMAT_RGBA8_UNORM);
}
scoped_refptr<DawnControlClientHolder> dawn_control_client_;
......
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