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