mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 01:15:39 +00:00
Implement Queue::OnSubmittedWorkDone
This is the replacement for Fence in the single-queue WebGPU world. To keep this CL focused, it doesn't deprecate the fences yet. Bug: chromium:1177476 Change-Id: I09d60732ec67bc1deb49f7a9d57699c049475acf Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/41723 Auto-Submit: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
0a295c027d
commit
c093db250e
@@ -0,0 +1,58 @@
|
||||
// Copyright 2021 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "tests/unittests/validation/ValidationTest.h"
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
using namespace testing;
|
||||
|
||||
class MockQueueWorkDoneCallback {
|
||||
public:
|
||||
MOCK_METHOD(void, Call, (WGPUQueueWorkDoneStatus status, void* userdata));
|
||||
};
|
||||
|
||||
static std::unique_ptr<MockQueueWorkDoneCallback> mockQueueWorkDoneCallback;
|
||||
static void ToMockQueueWorkDone(WGPUQueueWorkDoneStatus status, void* userdata) {
|
||||
mockQueueWorkDoneCallback->Call(status, userdata);
|
||||
}
|
||||
|
||||
class QueueOnSubmittedWorkDoneValidationTests : public ValidationTest {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
ValidationTest::SetUp();
|
||||
mockQueueWorkDoneCallback = std::make_unique<MockQueueWorkDoneCallback>();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
mockQueueWorkDoneCallback = nullptr;
|
||||
ValidationTest::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
// Test that OnSubmittedWorkDone can be called as soon as the queue is created.
|
||||
TEST_F(QueueOnSubmittedWorkDoneValidationTests, CallBeforeSubmits) {
|
||||
EXPECT_CALL(*mockQueueWorkDoneCallback, Call(WGPUQueueWorkDoneStatus_Success, this)).Times(1);
|
||||
device.GetQueue().OnSubmittedWorkDone(0u, ToMockQueueWorkDone, this);
|
||||
|
||||
WaitForAllOperations(device);
|
||||
}
|
||||
|
||||
// Test that OnSubmittedWorkDone is an error if signalValue isn't 0.
|
||||
TEST_F(QueueOnSubmittedWorkDoneValidationTests, SignaledValueNotZeroIsInvalid) {
|
||||
EXPECT_CALL(*mockQueueWorkDoneCallback, Call(WGPUQueueWorkDoneStatus_Error, this)).Times(1);
|
||||
ASSERT_DEVICE_ERROR(device.GetQueue().OnSubmittedWorkDone(1u, ToMockQueueWorkDone, this));
|
||||
|
||||
WaitForAllOperations(device);
|
||||
}
|
||||
99
src/tests/unittests/wire/WireQueueTests.cpp
Normal file
99
src/tests/unittests/wire/WireQueueTests.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
// Copyright 2021 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "tests/unittests/wire/WireTest.h"
|
||||
|
||||
#include "dawn_wire/WireClient.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace dawn_wire;
|
||||
|
||||
class MockQueueWorkDoneCallback {
|
||||
public:
|
||||
MOCK_METHOD(void, Call, (WGPUQueueWorkDoneStatus status, void* userdata));
|
||||
};
|
||||
|
||||
static std::unique_ptr<MockQueueWorkDoneCallback> mockQueueWorkDoneCallback;
|
||||
static void ToMockQueueWorkDone(WGPUQueueWorkDoneStatus status, void* userdata) {
|
||||
mockQueueWorkDoneCallback->Call(status, userdata);
|
||||
}
|
||||
|
||||
class WireQueueTests : public WireTest {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
WireTest::SetUp();
|
||||
mockQueueWorkDoneCallback = std::make_unique<MockQueueWorkDoneCallback>();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
mockQueueWorkDoneCallback = nullptr;
|
||||
WireTest::TearDown();
|
||||
}
|
||||
|
||||
void FlushServer() {
|
||||
WireTest::FlushServer();
|
||||
Mock::VerifyAndClearExpectations(&mockQueueWorkDoneCallback);
|
||||
}
|
||||
};
|
||||
|
||||
// Test that a successful OnSubmittedWorkDone call is forwarded to the client.
|
||||
TEST_F(WireQueueTests, OnSubmittedWorkDoneSuccess) {
|
||||
wgpuQueueOnSubmittedWorkDone(queue, 0u, ToMockQueueWorkDone, this);
|
||||
EXPECT_CALL(api, OnQueueOnSubmittedWorkDone(apiQueue, 0u, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallQueueOnSubmittedWorkDoneCallback(apiQueue, WGPUQueueWorkDoneStatus_Success);
|
||||
}));
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockQueueWorkDoneCallback, Call(WGPUQueueWorkDoneStatus_Success, this)).Times(1);
|
||||
FlushServer();
|
||||
}
|
||||
|
||||
// Test that an error OnSubmittedWorkDone call is forwarded as an error to the client.
|
||||
TEST_F(WireQueueTests, OnSubmittedWorkDoneError) {
|
||||
wgpuQueueOnSubmittedWorkDone(queue, 0u, ToMockQueueWorkDone, this);
|
||||
EXPECT_CALL(api, OnQueueOnSubmittedWorkDone(apiQueue, 0u, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallQueueOnSubmittedWorkDoneCallback(apiQueue, WGPUQueueWorkDoneStatus_Error);
|
||||
}));
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockQueueWorkDoneCallback, Call(WGPUQueueWorkDoneStatus_Error, this)).Times(1);
|
||||
FlushServer();
|
||||
}
|
||||
|
||||
// Test registering an OnSubmittedWorkDone then disconnecting the wire calls the callback with
|
||||
// device loss
|
||||
TEST_F(WireQueueTests, OnSubmittedWorkDoneBeforeDisconnect) {
|
||||
wgpuQueueOnSubmittedWorkDone(queue, 0u, ToMockQueueWorkDone, this);
|
||||
EXPECT_CALL(api, OnQueueOnSubmittedWorkDone(apiQueue, 0u, _, _))
|
||||
.WillOnce(InvokeWithoutArgs([&]() {
|
||||
api.CallQueueOnSubmittedWorkDoneCallback(apiQueue, WGPUQueueWorkDoneStatus_Error);
|
||||
}));
|
||||
FlushClient();
|
||||
|
||||
EXPECT_CALL(*mockQueueWorkDoneCallback, Call(WGPUQueueWorkDoneStatus_DeviceLost, this))
|
||||
.Times(1);
|
||||
GetWireClient()->Disconnect();
|
||||
}
|
||||
|
||||
// Test registering an OnSubmittedWorkDone after disconnecting the wire calls the callback with
|
||||
// device loss
|
||||
TEST_F(WireQueueTests, OnSubmittedWorkDoneAfterDisconnect) {
|
||||
GetWireClient()->Disconnect();
|
||||
|
||||
EXPECT_CALL(*mockQueueWorkDoneCallback, Call(WGPUQueueWorkDoneStatus_DeviceLost, this))
|
||||
.Times(1);
|
||||
wgpuQueueOnSubmittedWorkDone(queue, 0u, ToMockQueueWorkDone, this);
|
||||
}
|
||||
Reference in New Issue
Block a user