Commit 577c50d8 authored by Corentin Wallez's avatar Corentin Wallez Committed by Commit Bot

WebGPUTest: add a helper to create a new device.

This simplifies some redundant logic in tests and allows future tests to
create multiple devices.

Bug: chromium:1059777

Change-Id: I1ae7d91090a5c13269513328691fab7fed4374a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095121Reviewed-by: default avatarAustin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748291}
parent 564fad0b
......@@ -53,10 +53,10 @@ TEST_F(WebGPUFenceTest, InitialValue) {
LOG(ERROR) << "Test skipped";
return;
}
webgpu()->RequestDeviceAsync(kAdapterServiceID, kDeviceProperties,
base::BindOnce(&OnRequestDeviceCallback));
wgpu::Device device =
wgpu::Device::Acquire(webgpu()->GetDevice(kDeviceClientID));
DeviceAndClientID device_and_id = GetNewDeviceAndClientID();
wgpu::Device device = device_and_id.device;
wgpu::Queue queue = device.CreateQueue();
{
wgpu::FenceDescriptor fence_desc{nullptr, nullptr, 0};
......@@ -76,10 +76,10 @@ TEST_F(WebGPUFenceTest, GetCompletedValue) {
LOG(ERROR) << "Test skipped";
return;
}
webgpu()->RequestDeviceAsync(kAdapterServiceID, kDeviceProperties,
base::BindOnce(&OnRequestDeviceCallback));
wgpu::Device device =
wgpu::Device::Acquire(webgpu()->GetDevice(kDeviceClientID));
DeviceAndClientID device_and_id = GetNewDeviceAndClientID();
wgpu::Device device = device_and_id.device;
wgpu::Queue queue = device.CreateQueue();
wgpu::FenceDescriptor fence_desc{nullptr, nullptr, 0};
wgpu::Fence fence = queue.CreateFence(&fence_desc);
......@@ -95,10 +95,10 @@ TEST_F(WebGPUFenceTest, OnCompletion) {
LOG(ERROR) << "Test skipped";
return;
}
webgpu()->RequestDeviceAsync(kAdapterServiceID, kDeviceProperties,
base::BindOnce(&OnRequestDeviceCallback));
wgpu::Device device =
wgpu::Device::Acquire(webgpu()->GetDevice(kDeviceClientID));
DeviceAndClientID device_and_id = GetNewDeviceAndClientID();
wgpu::Device device = device_and_id.device;
wgpu::Queue queue = device.CreateQueue();
wgpu::FenceDescriptor fence_desc{nullptr, nullptr, 0};
wgpu::Fence fence = queue.CreateFence(&fence_desc);
......@@ -117,10 +117,10 @@ TEST_F(WebGPUFenceTest, SignalManyTimes) {
LOG(ERROR) << "Test skipped";
return;
}
webgpu()->RequestDeviceAsync(kAdapterServiceID, kDeviceProperties,
base::BindOnce(&OnRequestDeviceCallback));
wgpu::Device device =
wgpu::Device::Acquire(webgpu()->GetDevice(kDeviceClientID));
DeviceAndClientID device_and_id = GetNewDeviceAndClientID();
wgpu::Device device = device_and_id.device;
wgpu::Queue queue = device.CreateQueue();
wgpu::FenceDescriptor fence_desc{nullptr, nullptr, 0};
wgpu::Fence fence = queue.CreateFence(&fence_desc);
......
......@@ -82,7 +82,7 @@ TEST_F(WebGPUMailboxTest, WriteToMailboxThenReadFromIt) {
return;
}
// Create a the shared image
// Create the shared image
SharedImageInterface* sii = GetSharedImageInterface();
Mailbox mailbox = sii->CreateSharedImage(
viz::ResourceFormat::RGBA_8888, {1, 1}, gfx::ColorSpace::CreateSRGB(),
......@@ -90,20 +90,18 @@ TEST_F(WebGPUMailboxTest, WriteToMailboxThenReadFromIt) {
SyncToken mailbox_produced_token = sii->GenVerifiedSyncToken();
webgpu()->WaitSyncTokenCHROMIUM(mailbox_produced_token.GetConstData());
webgpu()->RequestDeviceAsync(kAdapterServiceID, kDeviceProperties,
base::BindOnce(&OnRequestDeviceCallback));
wgpu::Device device =
wgpu::Device::Acquire(webgpu()->GetDevice(kDeviceClientID));
DeviceAndClientID device_and_id = GetNewDeviceAndClientID();
wgpu::Device device = device_and_id.device;
webgpu::DawnDeviceClientID device_client_id = device_and_id.client_id;
// Part 1: Write to the texture using Dawn
{
// Register the shared image as a Dawn texture in the wire.
gpu::webgpu::ReservedTexture reservation =
webgpu()->ReserveTexture(kDeviceClientID);
webgpu()->ReserveTexture(device_client_id);
webgpu()->AssociateMailbox(
kDeviceClientID, 0, reservation.id, reservation.generation,
device_client_id, 0, reservation.id, reservation.generation,
WGPUTextureUsage_OutputAttachment, reinterpret_cast<GLbyte*>(&mailbox));
wgpu::Texture texture = wgpu::Texture::Acquire(reservation.texture);
......@@ -137,13 +135,13 @@ TEST_F(WebGPUMailboxTest, WriteToMailboxThenReadFromIt) {
{
// Register the shared image as a Dawn texture in the wire.
gpu::webgpu::ReservedTexture reservation =
webgpu()->ReserveTexture(kDeviceClientID);
webgpu()->ReserveTexture(device_client_id);
// Make sure previous Dawn wire commands are sent so that the texture IDs
// are validated correctly.
webgpu()->FlushCommands();
webgpu()->AssociateMailbox(kDeviceClientID, 0, reservation.id,
webgpu()->AssociateMailbox(device_client_id, 0, reservation.id,
reservation.generation, WGPUTextureUsage_CopySrc,
reinterpret_cast<GLbyte*>(&mailbox));
wgpu::Texture texture = wgpu::Texture::Acquire(reservation.texture);
......@@ -212,19 +210,19 @@ TEST_F(WebGPUMailboxTest, ErrorWhenUsingTextureAfterDissociate) {
webgpu()->WaitSyncTokenCHROMIUM(mailbox_produced_token.GetConstData());
// Create the device, and expect a validation error.
webgpu()->RequestDeviceAsync(kAdapterServiceID, kDeviceProperties,
base::BindOnce(&OnRequestDeviceCallback));
wgpu::Device device =
wgpu::Device::Acquire(webgpu()->GetDevice(kDeviceClientID));
DeviceAndClientID device_and_id = GetNewDeviceAndClientID();
wgpu::Device device = device_and_id.device;
webgpu::DawnDeviceClientID device_client_id = device_and_id.client_id;
device.SetUncapturedErrorCallback(ToMockUncapturedErrorCallback, 0);
// Associate and immediately dissociate the image.
gpu::webgpu::ReservedTexture reservation =
webgpu()->ReserveTexture(kDeviceClientID);
webgpu()->ReserveTexture(device_client_id);
wgpu::Texture texture = wgpu::Texture::Acquire(reservation.texture);
webgpu()->AssociateMailbox(
kDeviceClientID, 0, reservation.id, reservation.generation,
device_client_id, 0, reservation.id, reservation.generation,
WGPUTextureUsage_OutputAttachment, reinterpret_cast<GLbyte*>(&mailbox));
webgpu()->DissociateMailbox(reservation.id, reservation.generation);
......@@ -273,22 +271,21 @@ TEST_F(WebGPUMailboxTest, UseA_UseB_DestroyA_DestroyB) {
SHARED_IMAGE_USAGE_WEBGPU);
// Get a WebGPU device to associate the shared images to.
webgpu()->RequestDeviceAsync(kAdapterServiceID, kDeviceProperties,
base::BindOnce(&OnRequestDeviceCallback));
wgpu::Device device =
wgpu::Device::Acquire(webgpu()->GetDevice(kDeviceClientID));
DeviceAndClientID device_and_id = GetNewDeviceAndClientID();
wgpu::Device device = device_and_id.device;
webgpu::DawnDeviceClientID device_client_id = device_and_id.client_id;
// Associate both mailboxes
gpu::webgpu::ReservedTexture reservationA =
webgpu()->ReserveTexture(kDeviceClientID);
webgpu()->ReserveTexture(device_client_id);
webgpu()->AssociateMailbox(
kDeviceClientID, 0, reservationA.id, reservationA.generation,
device_client_id, 0, reservationA.id, reservationA.generation,
WGPUTextureUsage_OutputAttachment, reinterpret_cast<GLbyte*>(&mailboxA));
gpu::webgpu::ReservedTexture reservationB =
webgpu()->ReserveTexture(kDeviceClientID);
webgpu()->ReserveTexture(device_client_id);
webgpu()->AssociateMailbox(
kDeviceClientID, 0, reservationB.id, reservationB.generation,
device_client_id, 0, reservationB.id, reservationB.generation,
WGPUTextureUsage_OutputAttachment, reinterpret_cast<GLbyte*>(&mailboxB));
// Dissociate both mailboxes in the same order.
......
......@@ -7,6 +7,7 @@
#include <dawn/dawn_proc.h>
#include <dawn/webgpu.h>
#include "base/bind.h"
#include "base/test/test_simple_task_runner.h"
#include "build/build_config.h"
#include "components/viz/test/test_gpu_service_holder.h"
......@@ -26,9 +27,6 @@ void OnRequestAdapterCallback(uint32_t adapter_service_id,
} // anonymous namespace
void OnRequestDeviceCallback(bool is_request_device_success,
webgpu::DawnDeviceClientID device_client_id) {}
WebGPUTest::Options::Options() = default;
WebGPUTest::WebGPUTest() = default;
......@@ -135,6 +133,26 @@ void WebGPUTest::WaitForCompletion(wgpu::Device device) {
}
}
WebGPUTest::DeviceAndClientID WebGPUTest::GetNewDeviceAndClientID() {
DeviceAndClientID result;
result.client_id = next_device_client_id_;
webgpu()->RequestDeviceAsync(
kAdapterServiceID, {},
base::BindOnce(
[](webgpu::DawnDeviceClientID expected_client_id, bool success,
webgpu::DawnDeviceClientID assigned_client_id) {
ASSERT_TRUE(success);
ASSERT_EQ(expected_client_id, assigned_client_id);
},
result.client_id));
result.device = wgpu::Device::Acquire(webgpu()->GetDevice(result.client_id));
next_device_client_id_++;
return result;
}
TEST_F(WebGPUTest, FlushNoCommands) {
Initialize(WebGPUTest::Options());
......
......@@ -57,14 +57,19 @@ class WebGPUTest : public testing::Test {
void RunPendingTasks();
void WaitForCompletion(wgpu::Device device);
const uint32_t kAdapterServiceID = 0u;
const webgpu::DawnDeviceClientID kDeviceClientID = 1u;
const WGPUDeviceProperties kDeviceProperties = {};
struct DeviceAndClientID {
wgpu::Device device;
webgpu::DawnDeviceClientID client_id;
};
DeviceAndClientID GetNewDeviceAndClientID();
private:
std::unique_ptr<viz::TestGpuServiceHolder> gpu_service_holder_;
std::unique_ptr<WebGPUInProcessContext> context_;
bool is_initialized_ = false;
webgpu::DawnDeviceClientID next_device_client_id_ = 1;
const uint32_t kAdapterServiceID = 0u;
};
} // namespace gpu
......
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