Promote LoseForTesting to ForceLoss device so that user agents can use.

Bug: chromium:1356738
Change-Id: I348837ad4224124d9adba1ecf69a05b2060760c9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100566
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Loko Kung 2022-08-29 22:33:50 +00:00 committed by Dawn LUCI CQ
parent be4c9f48aa
commit 3a53edcf18
5 changed files with 21 additions and 10 deletions

View File

@ -1159,7 +1159,11 @@
"tags": ["dawn"]
},
{
"name": "lose for testing",
"name": "force loss",
"args": [
{"name": "type", "type": "device lost reason"},
{"name": "message", "type": "char", "annotation": "const*", "length": "strlen"}
],
"tags": ["dawn"]
},
{

View File

@ -479,7 +479,9 @@ void DeviceBase::APIDestroy() {
Destroy();
}
void DeviceBase::HandleError(InternalErrorType type, const char* message) {
void DeviceBase::HandleError(InternalErrorType type,
const char* message,
WGPUDeviceLostReason lost_reason) {
if (type == InternalErrorType::DeviceLost) {
mState = State::Disconnected;
@ -519,7 +521,7 @@ void DeviceBase::HandleError(InternalErrorType type, const char* message) {
if (type == InternalErrorType::DeviceLost) {
// The device was lost, call the application callback.
if (mDeviceLostCallback != nullptr) {
mDeviceLostCallback(WGPUDeviceLostReason_Undefined, message, mDeviceLostUserdata);
mDeviceLostCallback(lost_reason, message, mDeviceLostUserdata);
mDeviceLostCallback = nullptr;
}
@ -668,12 +670,11 @@ MaybeError DeviceBase::ValidateIsAlive() const {
return {};
}
void DeviceBase::APILoseForTesting() {
void DeviceBase::APIForceLoss(wgpu::DeviceLostReason reason, const char* message) {
if (mState != State::Alive) {
return;
}
HandleError(InternalErrorType::Internal, "Device lost for testing");
HandleError(InternalErrorType::Internal, message, ToAPI(reason));
}
DeviceBase::State DeviceBase::GetState() const {

View File

@ -65,7 +65,13 @@ class DeviceBase : public RefCountedWithExternalCount {
DeviceBase(AdapterBase* adapter, const DeviceDescriptor* descriptor);
~DeviceBase() override;
void HandleError(InternalErrorType type, const char* message);
// Handles the error, causing a device loss if applicable. Almost always when a device loss
// occurs because of an error, we want to call the device loss callback with an undefined
// reason, but the ForceLoss API allows for an injection of the reason, hence the default
// argument.
void HandleError(InternalErrorType type,
const char* message,
WGPUDeviceLostReason lost_reason = WGPUDeviceLostReason_Undefined);
bool ConsumedError(MaybeError maybeError) {
if (DAWN_UNLIKELY(maybeError.IsError())) {
@ -343,7 +349,7 @@ class DeviceBase : public RefCountedWithExternalCount {
void EmitDeprecationWarning(const char* warning);
void EmitLog(const char* message);
void EmitLog(WGPULoggingType loggingType, const char* message);
void APILoseForTesting();
void APIForceLoss(wgpu::DeviceLostReason reason, const char* message);
QueueBase* GetQueue() const;
// AddFutureSerial is used to update the mFutureSerial with the max serial needed to be

View File

@ -996,7 +996,7 @@ void DawnTestBase::LoseDeviceForTesting(wgpu::Device device) {
EXPECT_CALL(mDeviceLostCallback,
Call(WGPUDeviceLostReason_Undefined, testing::_, resolvedDevice.Get()))
.Times(1);
resolvedDevice.LoseForTesting();
resolvedDevice.ForceLoss(wgpu::DeviceLostReason::Undefined, "Device lost for testing");
}
std::ostringstream& DawnTestBase::AddBufferExpectation(const char* file,

View File

@ -408,7 +408,7 @@ TEST_P(DeviceLostTest, LoseDeviceForTestingOnce) {
mDeviceLostCallback.MakeUserdata(device.Get()));
EXPECT_CALL(mDeviceLostCallback, Call(WGPUDeviceLostReason_Undefined, testing::_, device.Get()))
.Times(0);
device.LoseForTesting();
device.ForceLoss(wgpu::DeviceLostReason::Undefined, "Device lost for testing");
FlushWire();
testing::Mock::VerifyAndClearExpectations(&mDeviceLostCallback);
}